summaryrefslogtreecommitdiff
path: root/t/10-form.t
blob: 6c170a8000c6dcfcff0930d8218707c5cf45eb32 (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 'no_plan';
  74. use Test::Trap qw(trap $trap);
  75. use Math::BigFloat;
  76. use IO::String;
  77. use LedgerSMB::Form;
  78. sub form_info_func {
  79. return $_[0];
  80. }
  81. sub form_error_func {
  82. print $_[0];
  83. }
  84. my $form = new Form;
  85. my %myconfig;
  86. my $utfstr;
  87. my @r;
  88. my @ary;
  89. my $aryref;
  90. ok(defined $form);
  91. isa_ok($form, 'Form');
  92. ## $form->escape checks
  93. $utfstr = "\xd8\xad";
  94. utf8::decode($utfstr);
  95. for my $sig ('1.3.37', '2.2.4', '2.0.59') {
  96. $ENV{SERVER_SIGNATURE} = 'Apache/'.$sig;
  97. cmp_ok($form->escape('foo'), 'eq', 'foo',
  98. "($sig) escape: foo");
  99. cmp_ok($form->escape('foo bar'), 'eq', 'foo%20bar',
  100. "($sig) escape: foo bar");
  101. cmp_ok($form->escape($utfstr), 'eq', '%d8%ad',
  102. "($sig) escape: U+D8AD");
  103. }
  104. $ENV{SERVER_SIGNATURE} = 'Apache/2.0.22';
  105. cmp_ok($form->escape('foo'), 'eq', 'foo',
  106. '(2.0.22) escape: foo');
  107. cmp_ok($form->escape('foo bar'), 'eq', 'foo%2520bar',
  108. '(2.0.22) escape: foo bar');
  109. cmp_ok($form->escape($utfstr), 'eq', '%25d8%25ad',
  110. '(2.0.22) escape: U+D8AD');
  111. cmp_ok($form->escape('foo%20bar', 1), 'eq', 'foo%2520bar',
  112. '(2.0.22, been) escape: foo bar');
  113. ## $form->unescape checks
  114. $utfstr = "\xd8\xad";
  115. utf8::decode($utfstr);
  116. cmp_ok($form->unescape('+'), 'eq', ' ', 'unescape: +');
  117. cmp_ok($form->unescape('\\'), 'eq', '', 'unescape: \\');
  118. cmp_ok($form->unescape('%20'), 'eq', ' ', 'unescape: %20');
  119. cmp_ok($form->unescape("foo\r\n"), 'eq', "foo\n", 'unescape: foo\r\n');
  120. ok(utf8::is_utf8($form->unescape('foo%d8%ad')), 'unescape: (utf8 output)');
  121. cmp_ok(unpack("H*", $form->unescape('%d8%ad')), 'eq',
  122. unpack("H*", $utfstr), 'unescape: %d8%ad');
  123. cmp_ok(unpack("H*", $form->unescape($form->unescape('%d8%ad'))), 'eq',
  124. unpack("H*", $utfstr), '(2x) unescape: %d8%ad');
  125. ## $form->quote checks
  126. ok(!defined $form->quote(), 'quote: (undef)');
  127. cmp_ok($form->quote(\%myconfig), '==', \%myconfig, 'quote: (reference)');
  128. cmp_ok($form->quote('hello'), 'eq', 'hello', 'quote: hello');
  129. cmp_ok($form->quote('hello"world'), 'eq', 'hello"world',
  130. 'quote: hello"world');
  131. ## $form->unquote checks
  132. ok(!defined $form->unquote(), 'unquote: (undef)');
  133. cmp_ok($form->unquote(\%myconfig), '==', \%myconfig, 'unquote: (reference)');
  134. cmp_ok($form->unquote('hello'), 'eq', 'hello', 'unquote: hello');
  135. cmp_ok($form->unquote('hello"world'), 'eq', 'hello"world',
  136. 'unquote: hello"world');
  137. ## $form->numtextrows checks
  138. cmp_ok($form->numtextrows("hello world\n12345678901234567890\n", 20), '==', 2,
  139. 'numtextrows: 2 rows');
  140. cmp_ok($form->numtextrows("hello world12345678901234567890\n", 20), '==', 2,
  141. 'numtextrows: 2 rows (no space)');
  142. cmp_ok($form->numtextrows("hello world\n12345678901234567890\n", 20, 1), '==', 1,
  143. 'numtextrows: 2 rows (1 max)');
  144. cmp_ok($form->numtextrows("hello world\n12345678901234567890\n", 20, 3), '==', 2,
  145. 'numtextrows: 2 rows (3 max)');
  146. ## $form->debug checks
  147. $form = new Form;
  148. @r = trap{$form->debug};
  149. like($trap->stdout, qr/\naction = \ndbversion = \d+\.\d+\.\d+\nlogin = \nnextsub = \npath = bin\/mozilla\nversion = $form->{version}\n/, 'debug: STDOUT');
  150. SKIP: {
  151. skip 'Environment for file test not clean' if -f "t/lsmb-10.$$";
  152. $form->debug("t/lsmb-10.$$");
  153. ok(-f "t/lsmb-10.$$", "debug: output file t/lsmb-10.$$ created");
  154. open(my $FH, '<', "t/lsmb-10.$$");
  155. my @str = <$FH>;
  156. close($FH);
  157. chomp(@str);
  158. like(join("\n", @str), qr/action = \ndbversion = \d+\.\d+\.\d+\nlogin = \nnextsub = \npath = bin\/mozilla\nversion = $form->{version}/, "debug: t/lsmb-10.$$ contents");
  159. is(unlink("t/lsmb-10.$$"), 1, "debug: removing t/lsmb-10.$$");
  160. ok(!-e "t/lsmb-10.$$", "debug: t/lsmb-10.$$ removed");
  161. };
  162. ## $form->hide_form checks
  163. $form = new Form;
  164. $form->{header} = 1;
  165. @r = trap{$form->hide_form};
  166. 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}" \/>/,
  167. 'hide_form: base');
  168. ok(!$form->{header}, 'hide_form: header flag cleared');
  169. $form->{header} = 1;
  170. @r = trap{$form->hide_form('path')};
  171. is($trap->stdout, "<input type=\"hidden\" name=\"path\" value=\"bin/mozilla\" />\n",
  172. 'hide_form: path');
  173. ok($form->{header}, 'hide_form: header flag not cleared');
  174. ## $form->info checks
  175. $form = new Form;
  176. $ENV{GATEWAY_INTERFACE} = 'yes';
  177. $form->{pre} = 'Blah';
  178. $form->{header} = 'Blah';
  179. @r = trap{$form->info('hello world')};
  180. is($trap->stdout, '<b>hello world</b>',
  181. 'info: CGI, pre-set header content');
  182. ok(!$form->{pre}, 'info: CGI, removed $self->{pre}');
  183. delete $form->{header};
  184. @r = trap{$form->info('hello world')};
  185. like($trap->stdout, qr|Content-Type: text/html; charset=utf-8\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 name="robots" content="noindex,nofollow" />[\n\s]+</head>[\n\s]+<body><b>hello world</b>|,
  186. 'info: CGI, header content');
  187. delete $ENV{GATEWAY_INTERFACE};
  188. delete $ENV{info_function};
  189. $form->{pre} = 'Blah';
  190. $form->{header} = 'Blah';
  191. @r = trap{$form->info('hello world')};
  192. is($trap->stdout, "hello world\n",
  193. 'info: CLI, content');
  194. ok($form->{pre}, 'info: CLI, ignored $self->{pre}');
  195. $ENV{info_function} = 'main::form_info_func';
  196. SKIP: {
  197. skip 'Environment variable info_function could not be set' unless
  198. $ENV{info_function} eq 'main::form_info_func';
  199. is($form->info('hello world'), 'hello world',
  200. 'info: CLI, function call');
  201. };
  202. ## $form->error checks
  203. $form = new Form;
  204. $ENV{GATEWAY_INTERFACE} = 'yes';
  205. $form->{pre} = 'Blah';
  206. $form->{header} = 'Blah';
  207. @r = trap{$form->error('hello world')};
  208. is($trap->exit, 0,
  209. 'error: CGI, normal termination');
  210. is($trap->stdout, '<body><h2 class="error">Error!</h2> <p><b>hello world</b></body>',
  211. 'error: CGI, pre-set header content');
  212. ok(!$form->{pre}, 'error: CGI, removed $self->{pre}');
  213. delete $form->{header};
  214. @r = trap{$form->error('hello world')};
  215. is($trap->exit, 0,
  216. 'error: CGI, normal termination');
  217. like($trap->stdout, qr|Content-Type: text/html; charset=utf-8\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 name="robots" content="noindex,nofollow" />[\n\s]+</head>[\n\s]+<body><h2 class="error">Error!</h2> <p><b>hello world</b></body>|,
  218. 'error: CGI, header content');
  219. delete $ENV{GATEWAY_INTERFACE};
  220. delete $ENV{error_function};
  221. $form->{pre} = 'Blah';
  222. $form->{header} = 'Blah';
  223. @r = trap{$form->error('hello world')};
  224. is($trap->die, "Error: hello world\n",
  225. 'error: CLI, content, terminated');
  226. ok($form->{pre}, 'error: CLI, ignored $self->{pre}');
  227. $ENV{error_function} = 'main::form_error_func';
  228. SKIP: {
  229. skip 'Environment variable error_function could not be set' unless
  230. $ENV{error_function} eq 'main::form_error_func';
  231. @r = trap{$form->error('hello world')};
  232. is($trap->stdout, 'hello world',
  233. 'error: CLI, function call called');
  234. is($trap->die, "Error: hello world\n",
  235. 'error: CLI, function call termination');
  236. };
  237. ## $form->isblank checks
  238. $form = new Form;
  239. $ENV{GATEWAY_INTERFACE} = 'yes';
  240. $form->{header} = 'yes';
  241. $form->{blank} = ' ';
  242. ok(!$form->isblank('version'), 'isblank: Not blank');
  243. @r = trap{$form->isblank('blank', 'hello world')};
  244. is($trap->stdout, '<body><h2 class="error">Error!</h2> <p><b>hello world</b></body>',
  245. 'isblank: Blank');
  246. is($trap->exit, 0,
  247. 'isblank: Blank, termination');
  248. ## $form->header checks
  249. $form = new Form;
  250. $form->{header} = 'yes';
  251. ok(!$form->header, 'header: preset');
  252. $ENV{GATEWAY_INTERFACE} = 'yes';
  253. delete $form->{header};
  254. delete $form->{stylesheet};
  255. delete $form->{charset};
  256. delete $form->{titlebar};
  257. delete $form->{title};
  258. delete $form->{pre};
  259. @r = trap{$form->header};
  260. 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 name="robots" content="noindex,nofollow" />[\n\s]+</head>[\n\s]+|,
  261. 'header: unset');
  262. delete $form->{header};
  263. @r = trap{$form->header(1, 'hello world')};
  264. 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 name="robots" content="noindex,nofollow" />[\n\s]+hello world[\n\s]+</head>[\n\s]+|,
  265. 'header: headeradd');
  266. delete $form->{header};
  267. $form->{pre} = 'hello world';
  268. @r = trap{$form->header};
  269. 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 name="robots" content="noindex,nofollow" />[\n\s]+</head>[\n\s]+hello world \n|,
  270. 'header: pre => \'hello world\'');
  271. delete $form->{pre};
  272. delete $form->{header};
  273. $form->{titlebar} = 'hello';
  274. @r = trap{$form->header};
  275. 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 name="robots" content="noindex,nofollow" />[\n\s]+</head>[\n\s]+|,
  276. 'header: titlebar => \'hello\'');
  277. delete $form->{header};
  278. $form->{title} = 'world';
  279. @r = trap{$form->header};
  280. 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 name="robots" content="noindex,nofollow" />[\n\s]+</head>[\n\s]+|,
  281. 'header: titlebar => \'hello\', title => \'world\'');
  282. delete $form->{title};
  283. delete $form->{titlebar};
  284. delete $form->{header};
  285. $form->{charset} = 'UTF-8';
  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></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: charset => \'UTF-8\'');
  289. delete $form->{charset};
  290. delete $form->{header};
  291. $form->{stylesheet} = "not a real file.$$";
  292. @r = trap{$form->header};
  293. 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 name="robots" content="noindex,nofollow" />[\n\s]+</head>[\n\s]+|,
  294. "header: stylesheet => 'not a real file.$$'");
  295. delete $form->{header};
  296. $form->{stylesheet} = 'ledgersmb.css';
  297. @r = trap{$form->header};
  298. 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/ledgersmb.css" type="text/css" title="LedgerSMB stylesheet" />[\n\s]+<meta name="robots" content="noindex,nofollow" />[\n\s]+</head>[\n\s]+|,
  299. 'header: stylesheet => \'ledgersmb.css\'');
  300. delete $ENV{GATEWAY_INTERFACE};
  301. delete $form->{header};
  302. is($form->header, 1, 'header: non-CGI');
  303. is($form->{header}, 1, 'header: non-CGI header flag set');
  304. ## $form->sort_column checks
  305. ## Note that sort_column merely sorts the value of $form->{sort} to being the
  306. ## first element of the list, adding it if needed
  307. $form = new Form;
  308. @ary = ('projectnumber', 'description', 'name', 'startdate');
  309. $form->{sort} = 'name';
  310. is_deeply([$form->sort_columns(@ary)],
  311. ['name', 'projectnumber', 'description', 'startdate'],
  312. 'sort_column: sort name');
  313. $form->{sort} = 'apple';
  314. is_deeply([$form->sort_columns(@ary)], ['apple', @ary],
  315. 'sort_column: sort non-existent');
  316. is($form->sort_columns, 0,
  317. 'sort_column: sort, no columns');
  318. delete $form->{sort};
  319. is_deeply([$form->sort_columns(@ary)], \@ary,
  320. 'sort_column: sort unset');
  321. ## $form->sort_order checks
  322. ## Note that $ordinal is intended to be a hashref mapping column names to
  323. ## position
  324. $form = new Form;
  325. $aryref = ['projectnumber', 'description', 'name', 'startdate'];
  326. delete $form->{direction};
  327. delete $form->{sort};
  328. delete $form->{oldsort};
  329. is($form->sort_order($aryref),
  330. 'projectnumber ASC,description,name,startdate',
  331. 'sort_order: unset, no ordinal');
  332. is($form->{direction}, 'ASC', 'sort_order: unset direction ASC');
  333. $form->{direction} = 'ASC';
  334. delete $form->{sort};
  335. delete $form->{oldsort};
  336. is($form->sort_order($aryref),
  337. 'projectnumber DESC,description,name,startdate',
  338. 'sort_order: direction => \'ASC\', no ordinal');
  339. is($form->{direction}, 'DESC', 'sort_order: ASC -> DESC, sort unset');
  340. $form->{direction} = 'DESC';
  341. delete $form->{sort};
  342. delete $form->{oldsort};
  343. is($form->sort_order($aryref),
  344. 'projectnumber ASC,description,name,startdate',
  345. 'sort_order: direction => \'DESC\', no ordinal');
  346. is($form->{direction}, 'ASC', 'sort_order: DESC -> ASC, sort unset');
  347. $form->{direction} = 'DESC';
  348. $form->{sort} = 'name';
  349. $form->{oldsort} = 'startdate';
  350. is($form->sort_order($aryref),
  351. 'name DESC,projectnumber,description,startdate',
  352. 'sort_order: direction => \'DESC\', sort => \'name\', no ordinal');
  353. is($form->{direction}, 'DESC', 'sort_order: DESC -/-> ASC, sort != oldsort');
  354. $form->{direction} = 'DESC';
  355. $form->{sort} = 'name';
  356. $form->{oldsort} = 'startdate';
  357. is($form->sort_order($aryref, {name => 2, projectnumber => 3, startdate => 1}),
  358. '2 DESC,3,description,1',
  359. 'sort_order: direction => \'DESC\', sort => \'name\', ordinal');
  360. $form->{direction} = 'DESC';
  361. $form->{sort} = 'name';
  362. $form->{oldsort} = 'startdate';
  363. is($form->sort_order($aryref, {name => 0, projectnumber => 3, startdate => 1}),
  364. 'name DESC,3,description,1',
  365. 'sort_order: direction => \'DESC\', sort => \'name\', ordinal b');
  366. ## $form->print_button checks
  367. $form = new Form;
  368. @r = trap{$form->print_button({'pear' => {'key' => 'P', 'value' => 'Pears'}}, 'pear')};
  369. is($trap->stdout, "<button class=\"submit\" type=\"submit\" name=\"action\" value=\"pear\" accesskey=\"P\" title=\"Pears [Alt-P]\">Pears</button>\n", 'print_button');
  370. ## $form->like checks
  371. $form = new Form;
  372. is($form->like('hello world'), '%hello world%', 'like');