]> Dogcows Code - chaz/p5-CGI-Ex/blob - t/2_fill_04_select.t
CGI::Ex 2.00
[chaz/p5-CGI-Ex] / t / 2_fill_04_select.t
1 # -*- Mode: Perl; -*-
2
3 =head1 NAME
4
5 2_fill_04_select.t - Test CGI::Ex::Fill's ability to fill select fields
6
7 =cut
8
9 use strict;
10 use Test::More tests => 5;
11
12 use_ok('CGI::Ex::Fill');
13
14 my $hidden_form_in = qq{<select multiple name="foo1">
15 <option value="0">bar1</option>
16 <option value="bar2">bar2</option>
17 <option value="bar3">bar3</option>
18 </select>
19 <select multiple name="foo2">
20 <option value="bar1">bar1</option>
21 <option value="bar2">bar2</option>
22 <option value="bar3">bar3</option>
23 </select>
24 <select multiple name="foo3">
25 <option value="bar1">bar1</option>
26 <option selected value="bar2">bar2</option>
27 <option value="bar3">bar3</option>
28 </select>
29 <select multiple name="foo4">
30 <option value="bar1">bar1</option>
31 <option selected value="bar2">bar2</option>
32 <option value="bar3">bar3</option>
33 </select>};
34 my $q = {
35 foo1 => '0',
36 foo2 => ['bar1', 'bar2',],
37 foo3 => '',
38 };
39
40 my $output = CGI::Ex::Fill::form_fill($hidden_form_in,
41 $q);
42
43 my $is_selected = join(" ",map { m/selected/ ? "yes" : "no" } grep /option/, split ("\n",$output));
44
45 ok($is_selected eq "yes no no yes yes no no no no no yes no",
46 "Selected should match ($is_selected)");
47
48
49 $hidden_form_in = qq{<select multiple name="foo1">
50 <option>bar1</option>
51 <option>bar2</option>
52 <option>bar3</option>
53 </select>
54 <select multiple name="foo2">
55 <option> bar1</option>
56 <option> bar2</option>
57 <option>bar3</option>
58 </select>
59 <select multiple name="foo3">
60 <option>bar1</option>
61 <option selected>bar2</option>
62 <option>bar3</option>
63 </select>
64 <select multiple name="foo4">
65 <option>bar1</option>
66 <option selected>bar2</option>
67 <option>bar3 </option>
68 </select>};
69
70 $q = {
71 foo1 => 'bar1',
72 foo2 => ['bar1', 'bar2',],
73 foo3 => '',
74 };
75
76 $output = CGI::Ex::Fill::form_fill($hidden_form_in,
77 $q);
78
79 $is_selected = join(" ",map { m/selected/ ? "yes" : "no" } grep /option/, split ("\n",$output));
80
81 ok($is_selected eq "yes no no yes yes no no no no no yes no",
82 "Selected should match ($is_selected)");
83
84 # test empty option tag
85
86 $hidden_form_in = qq{<select name="x"><option></select>};
87
88 $output = CGI::Ex::Fill::form_fill($hidden_form_in,
89 $q);
90 ok($output eq qq{<select name="x"><option></select>},
91 "Should match ($output)");
92
93 $hidden_form_in = qq{<select name="foo1"><option><option value="bar1"></select>};
94 $output = CGI::Ex::Fill::form_fill($hidden_form_in,
95 $q);
96 ok($output =~ m!^<select name="foo1"><option><option( selected(="selected")?| value="bar1"){2}></select>$!,
97 "Should match ($output)");
98
This page took 0.036116 seconds and 4 git commands to generate.