5 2_fill_04_select.t - Test CGI::Ex::Fill's ability to fill select fields
10 use Test::More tests => 5;
12 use_ok('CGI::Ex::Fill');
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>
19 <select multiple name="foo2">
20 <option value="bar1">bar1</option>
21 <option value="bar2">bar2</option>
22 <option value="bar3">bar3</option>
24 <select multiple name="foo3">
25 <option value="bar1">bar1</option>
26 <option selected value="bar2">bar2</option>
27 <option value="bar3">bar3</option>
29 <select multiple name="foo4">
30 <option value="bar1">bar1</option>
31 <option selected value="bar2">bar2</option>
32 <option value="bar3">bar3</option>
36 foo2 => ['bar1', 'bar2',],
40 my $output = CGI::Ex::Fill::form_fill($hidden_form_in,
43 my $is_selected = join(" ",map { m/selected/ ? "yes" : "no" } grep /option/, split ("\n",$output));
45 ok($is_selected eq "yes no no yes yes no no no no no yes no",
46 "Selected should match ($is_selected)");
49 $hidden_form_in = qq{<select multiple name="foo1">
54 <select multiple name="foo2">
55 <option> bar1</option>
56 <option> bar2</option>
59 <select multiple name="foo3">
61 <option selected>bar2</option>
64 <select multiple name="foo4">
66 <option selected>bar2</option>
67 <option>bar3 </option>
72 foo2 => ['bar1', 'bar2',],
76 $output = CGI::Ex::Fill::form_fill($hidden_form_in,
79 $is_selected = join(" ",map { m/selected/ ? "yes" : "no" } grep /option/, split ("\n",$output));
81 ok($is_selected eq "yes no no yes yes no no no no no yes no",
82 "Selected should match ($is_selected)");
84 # test empty option tag
86 $hidden_form_in = qq{<select name="x"><option></select>};
88 $output = CGI::Ex::Fill::form_fill($hidden_form_in,
90 ok($output eq qq{<select name="x"><option></select>},
91 "Should match ($output)");
93 $hidden_form_in = qq{<select name="foo1"><option><option value="bar1"></select>};
94 $output = CGI::Ex::Fill::form_fill($hidden_form_in,
96 ok($output =~ m!^<select name="foo1"><option><option( selected(="selected")?| value="bar1"){2}></select>$!,
97 "Should match ($output)");