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