]> Dogcows Code - chaz/p5-CGI-Ex/blob - t/2_fill_04_select.t
1b8f1d4a371416f851de1c04bca3d2cbec475d9f
[chaz/p5-CGI-Ex] / t / 2_fill_04_select.t
1 # -*- Mode: Perl; -*-
2
3 use strict;
4
5 $^W = 1;
6
7 print "1..5\n";
8
9 use CGI::Ex;
10 use CGI;
11
12 print "ok 1\n";
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 = new CGI( { foo1 => '0',
35 foo2 => ['bar1', 'bar2',],
36 foo3 => '' }
37 );
38
39 my $fif = new CGI::Ex;
40 my $output = $fif->fill(scalarref => \$hidden_form_in,
41 fobject => $q);
42
43 my $is_selected = join(" ",map { m/selected/ ? "yes" : "no" } grep /option/, split ("\n",$output));
44
45 if ($is_selected eq "yes no no yes yes no no no no no yes no"){
46 print "ok 2\n";
47 } else {
48 print "Got unexpected is_seleced for select menus:\n$is_selected\n$output\n";
49 print "not ok 2\n";
50 }
51
52 $hidden_form_in = qq{<select multiple name="foo1">
53 <option>bar1</option>
54 <option>bar2</option>
55 <option>bar3</option>
56 </select>
57 <select multiple name="foo2">
58 <option> bar1</option>
59 <option> bar2</option>
60 <option>bar3</option>
61 </select>
62 <select multiple name="foo3">
63 <option>bar1</option>
64 <option selected>bar2</option>
65 <option>bar3</option>
66 </select>
67 <select multiple name="foo4">
68 <option>bar1</option>
69 <option selected>bar2</option>
70 <option>bar3 </option>
71 </select>};
72
73 $q = new CGI( { foo1 => 'bar1',
74 foo2 => ['bar1', 'bar2',],
75 foo3 => '' }
76 );
77
78 $fif = new CGI::Ex;
79 $output = $fif->fill(scalarref => \$hidden_form_in,
80 fobject => $q);
81
82 $is_selected = join(" ",map { m/selected/ ? "yes" : "no" } grep /option/, split ("\n",$output));
83
84 if ($is_selected eq "yes no no yes yes no no no no no yes no"){
85 print "ok 3\n";
86 } else {
87 print "Got unexpected is_seleced for select menus:\n$is_selected\n$output\n";
88 print "not ok 3\n";
89 }
90
91 # test empty option tag
92
93 $hidden_form_in = qq{<select name="x"><option></select>};
94 $fif = new CGI::Ex;
95 $output = $fif->fill(scalarref => \$hidden_form_in,
96 fobject => $q);
97 if ($output eq qq{<select name="x"><option></select>}){
98 print "ok 4\n";
99 } else {
100 print "Got unexpected output for empty option:\n$output\n";
101 print "not ok 4\n";
102 }
103
104 $hidden_form_in = qq{<select name="foo1"><option><option value="bar1"></select>};
105 $fif = new CGI::Ex;
106 $output = $fif->fill(scalarref => \$hidden_form_in,
107 fobject => $q);
108 if ($output =~ m!^<select name="foo1"><option><option( selected(="selected")?| value="bar1"){2}></select>$!){
109 print "ok 5\n";
110 } else {
111 print "Got unexpected output for empty option:\n$output\n";
112 print "not ok 5\n";
113 }
114
This page took 0.034045 seconds and 3 git commands to generate.