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