summaryrefslogtreecommitdiff
path: root/t/10-form.t
blob: 3ab79ff6f6d3f7f104955a92c100aca0c52ceef2 (plain)
  1. #!/usr/bin/perl
  2. ##format_amount in 02-number-handling.t
  3. ##parse_amount in 02-number-handling.t
  4. ##round_amount in 02-number-handling.t
  5. ##current_date in 03-date-handling.t
  6. ##split_date in 03-date-handling.t
  7. ##format_date in 03-date-handling.t
  8. ##from_to in 03-date-handling.t
  9. ##datetonum in 03-date-handling.t
  10. ##add_date in 03-date-handling.t
  11. ##escape in 10-form.t
  12. ##unescape in 10-form.t
  13. ##quote in 10-form.t
  14. ##unquote in 10-form.t
  15. ##numtextrows in 10-form.t
  16. ##debug in 10-form.t
  17. ##hide_form in 10-form.t
  18. ##info in 10-form.t
  19. ##error in 10-form.t
  20. ##isblank in 10-form.t
  21. ##header in 10-form.t
  22. ##sort_columns in 10-form.t
  23. ##sort_order in 10-form.t
  24. ##print_button in 10-form.t
  25. ##encode_all null
  26. ##decode_all null
  27. ##sub new {
  28. ##sub dberror {
  29. ##sub redirect {
  30. ##sub db_parse_numeric {
  31. ##sub callproc {
  32. ##sub get_my_emp_num {
  33. ##sub parse_template {
  34. ##sub format_line {
  35. ##sub cleanup {
  36. ##sub rerun_latex {
  37. ##sub format_string {
  38. ##sub db_init {
  39. ##sub run_custom_queries {
  40. ##sub dbconnect {
  41. ##sub dbconnect_noauto {
  42. ##sub dbquote {
  43. ##sub update_balance {
  44. ##sub update_exchangerate {
  45. ##sub save_exchangerate {
  46. ##sub get_exchangerate {
  47. ##sub check_exchangerate {
  48. ##sub add_shipto {
  49. ##sub get_employee {
  50. ##sub get_name {
  51. ##sub all_vc {
  52. ##sub all_taxaccounts {
  53. ##sub all_employees {
  54. ##sub all_projects {
  55. ##sub all_departments {
  56. ##sub all_years {
  57. ##sub create_links {
  58. ##sub lastname_used {
  59. ##sub like {
  60. ##sub redo_rows {
  61. ##sub get_partsgroup {
  62. ##sub update_status {
  63. ##sub save_status {
  64. ##sub get_recurring {
  65. ##sub save_recurring {
  66. ##sub save_intnotes {
  67. ##sub update_defaults {
  68. ##sub db_prepare_vars {
  69. ##sub audittrail {
  70. use strict;
  71. use warnings;
  72. $ENV{TMPDIR} = 't/var';
  73. use Test::More;
  74. plan skip_all => 'Trap tests could crash Perl on Windows' if $^O eq 'MSWin32';
  75. eval "use Test::Trap";
  76. plan skip_all => 'Test::Trap required for testing Form functions' if $@;
  77. use Test::Trap qw(trap $trap);
  78. plan 'no_plan';
  79. use Math::BigFloat;
  80. use LedgerSMB::Form;
  81. sub form_info_func {
  82. return $_[0];
  83. }
  84. sub form_error_func {
  85. print $_[0];
  86. }
  87. sub redirect {
  88. print "redirected\n";
  89. }
  90. my $form = new Form;
  91. my %myconfig;
  92. my $utfstr;
  93. my @r;
  94. my @ary;
  95. my $aryref;
  96. ok(defined $form);
  97. isa_ok($form, 'Form');
  98. ## $form->escape checks
  99. $utfstr = "\xd8\xad";
  100. utf8::decode($utfstr);
  101. for my $sig ('1.3.37', '2.2.4', '2.0.59') {
  102. $ENV{SERVER_SIGNATURE} = 'Apache/'.$sig;
  103. cmp_ok($form->escape('foo'), 'eq', 'foo',
  104. "($sig) escape: foo");
  105. cmp_ok($form->escape('foo bar'), 'eq', 'foo%20bar',
  106. "($sig) escape: foo bar");
  107. cmp_ok($form->escape($utfstr), 'eq', '%d8%ad',
  108. "($sig) escape: U+D8AD");
  109. }
  110. $ENV{SERVER_SIGNATURE} = 'Apache/2.0.22';
  111. cmp_ok($form->escape('foo'), 'eq', 'foo',
  112. '(2.0.22) escape: foo');
  113. cmp_ok($form->escape('foo bar'), 'eq', 'foo%2520bar',
  114. '(2.0.22) escape: foo bar');
  115. cmp_ok($form->escape($utfstr), 'eq', '%25d8%25ad',
  116. '(2.0.22) escape: U+D8AD');
  117. cmp_ok($form->escape('foo%20bar', 1), 'eq', 'foo%2520bar',
  118. '(2.0.22, been) escape: foo bar');
  119. ## $form->unescape checks
  120. $utfstr = "\xd8\xad";
  121. utf8::decode($utfstr);
  122. cmp_ok($form->unescape('+'), 'eq', ' ', 'unescape: +');
  123. cmp_ok($form->unescape('\\'), 'eq', '', 'unescape: \\');
  124. cmp_ok($form->unescape('%20'), 'eq', ' ', 'unescape: %20');
  125. cmp_ok($form->unescape("foo\r\n"), 'eq', "foo\n", 'unescape: foo\r\n');
  126. ok(utf8::is_utf8($form->unescape('foo%d8%ad')), 'unescape: (utf8 output)');
  127. cmp_ok(unpack("H*", $form->unescape('%d8%ad')), 'eq',
  128. unpack("H*", $utfstr), 'unescape: %d8%ad');
  129. cmp_ok(unpack("H*", $form->unescape($form->unescape('%d8%ad'))), 'eq',
  130. unpack("H*", $utfstr), '(2x) unescape: %d8%ad');
  131. ## $form->quote checks
  132. ok(!defined $form->quote(), 'quote: (undef)');
  133. cmp_ok($form->quote(\%myconfig), '==', \%myconfig, 'quote: (reference)');
  134. cmp_ok($form->quote('hello'), 'eq', 'hello', 'quote: hello');
  135. cmp_ok($form->quote('hello"world'), 'eq', 'hello"world',
  136. 'quote: hello"world');
  137. ## $form->unquote checks
  138. ok(!defined $form->unquote(), 'unquote: (undef)');
  139. cmp_ok($form->unquote(\%myconfig), '==', \%myconfig, 'unquote: (reference)');
  140. cmp_ok($form->unquote('hello'), 'eq', 'hello', 'unquote: hello');
  141. cmp_ok($form->unquote('hello"world'), 'eq', 'hello"world',
  142. 'unquote: hello"world');
  143. ## $form->numtextrows checks
  144. cmp_ok($form->numtextrows("hello world\n12345678901234567890\n", 20), '==', 2,
  145. 'numtextrows: 2 rows');
  146. cmp_ok($form->numtextrows("hello world12345678901234567890\n", 20), '==', 2,
  147. 'numtextrows: 2 rows (no space)');
  148. cmp_ok($form->numtextrows("hello world\n12345678901234567890\n", 20, 1), '==', 1,
  149. 'numtextrows: 2 rows (1 max)');
  150. cmp_ok($form->numtextrows("hello world\n12345678901234567890\n", 20, 3), '==', 2,
  151. 'numtextrows: 2 rows (3 max)');
  152. ## $form->debug checks
  153. $form = new Form;
  154. @r = trap{$form->debug};
  155. like($trap->stdout, qr/\naction = \ndbversion = \d+\.\d+\.\d+\nlogin = \nnextsub = \npath = bin\/mozilla\nversion = \d+\.\d+\.\d+\n/, 'debug: STDOUT');
  156. SKIP: {
  157. skip 'Environment for file test not clean' if -f "t/lsmb-10.$$";
  158. $form->debug("t/lsmb-10.$$");
  159. ok(-f "t/lsmb-10.$$", "debug: output file t/lsmb-10.$$ created");
  160. open(my $FH, '<', "t/lsmb-10.$$");
  161. my @str = <$FH>;
  162. close($FH);
  163. chomp(@str);
  164. like(join("\n", @str), qr/action = \ndbversion = \d+\.\d+\.\d+\nlogin = \nnextsub = \npath = bin\/mozilla\nversion = \d+\.\d+\.\d+/, "debug: t/lsmb-10.$$ contents");
  165. is(unlink("t/lsmb-10.$$"), 1, "debug: removing t/lsmb-10.$$");
  166. ok(!-e "t/lsmb-10.$$", "debug: t/lsmb-10.$$ removed");
  167. };
  168. ## $form->hide_form checks
  169. $form = new Form;
  170. $form->{header} = 1;
  171. @r = trap{$form->hide_form};
  172. like($trap->stdout, qr/<input type="hidden" name="action" value="" \/>\n<input type="hidden" name="dbversion" value="\d+\.\d+\.\d+" \/>\n<input type="hidden" name="login" value="" \/>\n<input type="hidden" name="nextsub" value="" \/>\n<input type="hidden" name="path" value="bin\/mozilla" \/>\n<input type="hidden" name="version" value="$form->{version}" \/>/,
  173. 'hide_form: base');
  174. ok(!$form->{header}, 'hide_form: header flag cleared');
  175. $form->{header} = 1;
  176. @r = trap{$form->hide_form('path')};
  177. is($trap->stdout, "<input type=\"hidden\" name=\"path\" value=\"bin/mozilla\" />\n",
  178. 'hide_form: path');
  179. ok($form->{header}, 'hide_form: header flag not cleared');
  180. ## $form->info checks
  181. $form = new Form;
  182. $ENV{GATEWAY_INTERFACE} = 'yes';
  183. $form->{pre} = 'Blah';
  184. $form->{header} = 'Blah';
  185. @r = trap{$form->info('hello world')};
  186. is($trap->stdout, '<b>hello world</b>',
  187. 'info: CGI, pre-set header content');
  188. ok(!$form->{pre}, 'info: CGI, removed $self->{pre}');
  189. delete $form->{header};
  190. @r = trap{$form->info('hello world')};
  191. like($trap->stdout, qr|Content-Type: text/html; charset=utf-8\n\n+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" \n\s+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n<head>\n\s+<title></title>\n\s+<meta http-equiv="Pragma" content="no-cache" />\n\s+<meta http-equiv="Expires" content="-1" />\n\s+<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />[\n\s]+<meta http-equiv="content-type" content="text/html; charset=utf-8" />[\n\s]+<meta name="robots" content="noindex,nofollow" />[\n\s]+</head>[\n\s]+<body><b>hello world</b>|,
  192. 'info: CGI, header content');
  193. delete $ENV{GATEWAY_INTERFACE};
  194. delete $ENV{info_function};
  195. $form->{pre} = 'Blah';
  196. $form->{header} = 'Blah';
  197. @r = trap{$form->info('hello world')};
  198. is($trap->stdout, "hello world\n",
  199. 'info: CLI, content');
  200. ok($form->{pre}, 'info: CLI, ignored $self->{pre}');
  201. $ENV{info_function} = 'main::form_info_func';
  202. SKIP: {
  203. skip 'Environment variable info_function could not be set' unless
  204. $ENV{info_function} eq 'main::form_info_func';
  205. is($form->info('hello world'), 'hello world',
  206. 'info: CLI, function call');
  207. };
  208. delete $ENV{info_function};
  209. ## $form->error checks
  210. $form = new Form;
  211. $ENV{GATEWAY_INTERFACE} = 'yes';
  212. $form->{pre} = 'Blah';
  213. $form->{header} = 'Blah';
  214. @r = trap{$form->error('hello world')};
  215. is($trap->exit, 0,
  216. 'error: CGI, normal termination');
  217. is($trap->stdout, '<body><h2 class="error">Error!</h2> <p><b>hello world</b></body>',
  218. 'error: CGI, pre-set header content');
  219. ok(!$form->{pre}, 'error: CGI, removed $self->{pre}');
  220. delete $form->{header};
  221. @r = trap{$form->error('hello world')};
  222. is($trap->exit, 0,
  223. 'error: CGI, normal termination');
  224. like($trap->stdout, qr|Content-Type: text/html; charset=utf-8\n\n+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" \n\s+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n<head>\n\s+<title></title>\n\s+<meta http-equiv="Pragma" content="no-cache" />\n\s+<meta http-equiv="Expires" content="-1" />\n\s+<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />[\n\s]+<meta http-equiv="content-type" content="text/html; charset=utf-8" />[\n\s]+<meta name="robots" content="noindex,nofollow" />[\n\s]+</head>[\n\s]+<body><h2 class="error">Error!</h2> <p><b>hello world</b></body>|,
  225. 'error: CGI, header content');
  226. delete $ENV{GATEWAY_INTERFACE};
  227. delete $ENV{error_function};
  228. $form->{pre} = 'Blah';
  229. $form->{header} = 'Blah';
  230. @r = trap{$form->error('hello world')};
  231. is($trap->die, "Error: hello world\n",
  232. 'error: CLI, content, terminated');
  233. ok($form->{pre}, 'error: CLI, ignored $self->{pre}');
  234. $ENV{error_function} = 'main::form_error_func';
  235. SKIP: {
  236. skip 'Environment variable error_function could not be set' unless
  237. $ENV{error_function} eq 'main::form_error_func';
  238. @r = trap{$form->error('hello world')};
  239. is($trap->stdout, 'hello world',
  240. 'error: CLI, function call called');
  241. is($trap->die, "Error: hello world\n",
  242. 'error: CLI, function call termination');
  243. };
  244. ## $form->isblank checks
  245. $form = new Form;
  246. $ENV{GATEWAY_INTERFACE} = 'yes';
  247. $form->{header} = 'yes';
  248. $form->{blank} = ' ';
  249. ok(!$form->isblank('version'), 'isblank: Not blank');
  250. @r = trap{$form->isblank('blank', 'hello world')};
  251. is($trap->stdout, '<body><h2 class="error">Error!</h2> <p><b>hello world</b></body>',
  252. 'isblank: Blank');
  253. is($trap->exit, 0,
  254. 'isblank: Blank, termination');
  255. ## $form->header checks
  256. $form = new Form;
  257. $form->{header} = 'yes';
  258. ok(!$form->header, 'header: preset');
  259. $ENV{GATEWAY_INTERFACE} = 'yes';
  260. delete $form->{header};
  261. delete $form->{stylesheet};
  262. delete $form->{charset};
  263. delete $form->{titlebar};
  264. delete $form->{title};
  265. delete $form->{pre};
  266. @r = trap{$form->header};
  267. like($trap->stdout, qr|Content-Type: text/html; charset=utf-8\n\n+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" \n\s+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n<head>\n\s+<title></title>\n\s+<meta http-equiv="Pragma" content="no-cache" />\n\s+<meta http-equiv="Expires" content="-1" />\n\s+<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />[\n\s]+<meta http-equiv="content-type" content="text/html; charset=utf-8" />[\n\s]+<meta name="robots" content="noindex,nofollow" />[\n\s]+</head>[\n\s]+|,
  268. 'header: unset');
  269. delete $form->{header};
  270. @r = trap{$form->header(1, 'hello world')};
  271. like($trap->stdout, qr|Content-Type: text/html; charset=utf-8\n\n+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" \n\s+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n<head>\n\s+<title></title>\n\s+<meta http-equiv="Pragma" content="no-cache" />\n\s+<meta http-equiv="Expires" content="-1" />\n\s+<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />[\n\s]+<meta http-equiv="content-type" content="text/html; charset=utf-8" />[\n\s]+<meta name="robots" content="noindex,nofollow" />[\n\s]+hello world[\n\s]+</head>[\n\s]+|,
  272. 'header: headeradd');
  273. delete $form->{header};
  274. $form->{pre} = 'hello world';
  275. @r = trap{$form->header};
  276. like($trap->stdout, qr|Content-Type: text/html; charset=utf-8\n\n+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" \n\s+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n<head>\n\s+<title></title>\n\s+<meta http-equiv="Pragma" content="no-cache" />\n\s+<meta http-equiv="Expires" content="-1" />\n\s+<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />[\n\s]+<meta http-equiv="content-type" content="text/html; charset=utf-8" />[\n\s]+<meta name="robots" content="noindex,nofollow" />[\n\s]+</head>[\n\s]+hello world \n|,
  277. 'header: pre => \'hello world\'');
  278. delete $form->{pre};
  279. delete $form->{header};
  280. $form->{titlebar} = 'hello';
  281. @r = trap{$form->header};
  282. like($trap->stdout, qr|Content-Type: text/html; charset=utf-8\n\n+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" \n\s+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n<head>\n\s+<title>hello</title>\n\s+<meta http-equiv="Pragma" content="no-cache" />\n\s+<meta http-equiv="Expires" content="-1" />\n\s+<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />[\n\s]+<meta http-equiv="content-type" content="text/html; charset=utf-8" />[\n\s]+<meta name="robots" content="noindex,nofollow" />[\n\s]+</head>[\n\s]+|,
  283. 'header: titlebar => \'hello\'');
  284. delete $form->{header};
  285. $form->{title} = 'world';
  286. @r = trap{$form->header};
  287. like($trap->stdout, qr|Content-Type: text/html; charset=utf-8\n\n+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" \n\s+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n<head>\n\s+<title>world - hello</title>\n\s+<meta http-equiv="Pragma" content="no-cache" />\n\s+<meta http-equiv="Expires" content="-1" />\n\s+<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />[\n\s]+<meta http-equiv="content-type" content="text/html; charset=utf-8" />[\n\s]+<meta name="robots" content="noindex,nofollow" />[\n\s]+</head>[\n\s]+|,
  288. 'header: titlebar => \'hello\', title => \'world\'');
  289. delete $form->{title};
  290. delete $form->{titlebar};
  291. delete $form->{header};
  292. $form->{charset} = 'UTF-8';
  293. @r = trap{$form->header};
  294. like($trap->stdout, qr|Content-Type: text/html; charset=utf-8\n\n+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" \n\s+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n<head>\n\s+<title></title>\n\s+<meta http-equiv="Pragma" content="no-cache" />\n\s+<meta http-equiv="Expires" content="-1" />\n\s+<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />[\n\s]+<meta http-equiv="content-type" content="text/html; charset=UTF-8" />[\n\s]+<meta name="robots" content="noindex,nofollow" />[\n\s]+</head>[\n\s]+|,
  295. 'header: charset => \'UTF-8\'');
  296. delete $form->{charset};
  297. delete $form->{header};
  298. $form->{stylesheet} = "not a real file.$$";
  299. @r = trap{$form->header};
  300. like($trap->stdout, qr|Content-Type: text/html; charset=utf-8\n\n+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" \n\s+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n<head>\n\s+<title></title>\n\s+<meta http-equiv="Pragma" content="no-cache" />\n\s+<meta http-equiv="Expires" content="-1" />\n\s+<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />[\n\s]+<meta http-equiv="content-type" content="text/html; charset=utf-8" />[\n\s]+<meta name="robots" content="noindex,nofollow" />[\n\s]+</head>[\n\s]+|,
  301. "header: stylesheet => 'not a real file.$$'");
  302. delete $form->{header};
  303. $form->{stylesheet} = 'ledger-smb.css';
  304. @r = trap{$form->header};
  305. like($trap->stdout, qr|Content-Type: text/html; charset=utf-8\n\n+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" \n\s+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n<head>\n\s+<title></title>\n\s+<meta http-equiv="Pragma" content="no-cache" />\n\s+<meta http-equiv="Expires" content="-1" />\n\s+<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />[\n\s]+<link rel="stylesheet" href="css/ledger-smb.css" type="text/css" title="LedgerSMB stylesheet" />[\n\s]+<meta http-equiv="content-type" content="text/html; charset=utf-8" />[\n\s]+<meta name="robots" content="noindex,nofollow" />[\n\s]+</head>[\n\s]+|,
  306. 'header: stylesheet => \'ledgersmb.css\'');
  307. delete $ENV{GATEWAY_INTERFACE};
  308. delete $form->{header};
  309. is($form->header, 1, 'header: non-CGI');
  310. is($form->{header}, 1, 'header: non-CGI header flag set');
  311. ## $form->sort_column checks
  312. ## Note that sort_column merely sorts the value of $form->{sort} to being the
  313. ## first element of the list, adding it if needed
  314. $form = new Form;
  315. @ary = ('projectnumber', 'description', 'name', 'startdate');
  316. $form->{sort} = 'name';
  317. is_deeply([$form->sort_columns(@ary)],
  318. ['name', 'projectnumber', 'description', 'startdate'],
  319. 'sort_column: sort name');
  320. $form->{sort} = 'apple';
  321. is_deeply([$form->sort_columns(@ary)], ['apple', @ary],
  322. 'sort_column: sort non-existent');
  323. is($form->sort_columns, 0,
  324. 'sort_column: sort, no columns');
  325. delete $form->{sort};
  326. is_deeply([$form->sort_columns(@ary)], \@ary,
  327. 'sort_column: sort unset');
  328. ## $form->sort_order checks
  329. ## Note that $ordinal is intended to be a hashref mapping column names to
  330. ## position
  331. $form = new Form;
  332. $aryref = ['projectnumber', 'description', 'name', 'startdate'];
  333. delete $form->{direction};
  334. delete $form->{sort};
  335. delete $form->{oldsort};
  336. is($form->sort_order($aryref),
  337. 'projectnumber ASC,description,name,startdate',
  338. 'sort_order: unset, no ordinal');
  339. is($form->{direction}, 'ASC', 'sort_order: unset direction ASC');
  340. $form->{direction} = 'ASC';
  341. delete $form->{sort};
  342. delete $form->{oldsort};
  343. is($form->sort_order($aryref),
  344. 'projectnumber DESC,description,name,startdate',
  345. 'sort_order: direction => \'ASC\', no ordinal');
  346. is($form->{direction}, 'DESC', 'sort_order: ASC -> DESC, sort unset');
  347. $form->{direction} = 'DESC';
  348. delete $form->{sort};
  349. delete $form->{oldsort};
  350. is($form->sort_order($aryref),
  351. 'projectnumber ASC,description,name,startdate',
  352. 'sort_order: direction => \'DESC\', no ordinal');
  353. is($form->{direction}, 'ASC', 'sort_order: DESC -> ASC, sort unset');
  354. $form->{direction} = 'DESC';
  355. $form->{sort} = 'name';
  356. $form->{oldsort} = 'startdate';
  357. is($form->sort_order($aryref),
  358. 'name DESC,projectnumber,description,startdate',
  359. 'sort_order: direction => \'DESC\', sort => \'name\', no ordinal');
  360. is($form->{direction}, 'DESC', 'sort_order: DESC -/-> ASC, sort != oldsort');
  361. $form->{direction} = 'DESC';
  362. $form->{sort} = 'name';
  363. $form->{oldsort} = 'startdate';
  364. is($form->sort_order($aryref, {name => 2, projectnumber => 3, startdate => 1}),
  365. '2 DESC,3,description,1',
  366. 'sort_order: direction => \'DESC\', sort => \'name\', ordinal');
  367. $form->{direction} = 'DESC';
  368. $form->{sort} = 'name';
  369. $form->{oldsort} = 'startdate';
  370. is($form->sort_order($aryref, {name => 0, projectnumber => 3, startdate => 1}),
  371. 'name DESC,3,description,1',
  372. 'sort_order: direction => \'DESC\', sort => \'name\', ordinal b');
  373. ## $form->print_button checks
  374. $form = new Form;
  375. @r = trap{$form->print_button({'pear' => {'key' => 'P', 'value' => 'Pears'}}, 'pear')};
  376. is($trap->stdout, "<button class=\"submit\" type=\"submit\" name=\"action\" value=\"pear\" accesskey=\"P\" title=\"Pears [Alt-P]\">Pears</button>\n", 'print_button');
  377. ## $form->like checks
  378. $form = new Form;
  379. is($form->like('hello world'), '%hello world%', 'like');
  380. ## $form->redirect checks
  381. $form = new Form;
  382. ok(!defined $form->{callback}, 'redirect: No callback set');
  383. @r = trap{$form->redirect};
  384. is($trap->stdout, "redirected\n", 'redirect: No message or callback redirect');
  385. @r = trap{$form->redirect('hello world')};
  386. is($trap->stdout, "hello world\n",
  387. 'redirect: message, no callback redirect');
  388. $form->{callback} = 1;
  389. @r = trap{$form->redirect};
  390. is($trap->stdout, "redirected\n", 'redirect: callback, no message redirect');
  391. @r = trap{$form->redirect("hello world\n")};
  392. is($trap->stdout, "redirected\n", 'redirect: callback and message redirect');