]> Dogcows Code - chaz/p5-CGI-Ex/blob - t/2_fill_00_base.t
CGI::Ex 2.00
[chaz/p5-CGI-Ex] / t / 2_fill_00_base.t
1 # -*-perl-*-
2
3 =head1 NAME
4
5 2_fill_00_base.t - Test CGI::Ex::Fill's base ability.
6
7 =cut
8
9 use strict;
10 use Test::More tests => 6;
11
12 use_ok qw(CGI::Ex::Fill);
13
14 ###----------------------------------------------------------------###
15
16 my $form = {foo => "FOO", bar => "BAR", baz => "BAZ"};
17
18 my $html = '
19 <input type=text name=foo>
20 <input type=text name=foo>
21 <input type=text name=bar value="">
22 <input type=text name=baz value="Something else">
23 <input type=text name=hem value="Another thing">
24 <input type=text name=haw>
25 ';
26
27 CGI::Ex::Fill::form_fill(\$html, $form);
28
29 ok(
30 $html eq '
31 <input type=text name=foo value="FOO">
32 <input type=text name=foo value="FOO">
33 <input type=text name=bar value="BAR">
34 <input type=text name=baz value="BAZ">
35 <input type=text name=hem value="Another thing">
36 <input type=text name=haw value="">
37 ', "perldoc example 1 passed");
38
39 #print $html;
40
41 ###----------------------------------------------------------------###
42
43 $form = {foo => ['aaaa', 'bbbb', 'cccc']};
44
45 $html = '
46 <input type=text name=foo>
47 <input type=text name=foo>
48 <input type=text name=foo>
49 <input type=text name=foo>
50 <input type=text name=foo>
51 ';
52
53 form_fill(\$html, $form);
54
55 ok(
56 $html eq '
57 <input type=text name=foo value="aaaa">
58 <input type=text name=foo value="bbbb">
59 <input type=text name=foo value="cccc">
60 <input type=text name=foo value="">
61 <input type=text name=foo value="">
62 ', "Perldoc example 2 passed");
63
64 #print $html;
65
66 ###----------------------------------------------------------------###
67
68 $form = {foo => 'FOO', bar => ['aaaa', 'bbbb', 'cccc'], baz => 'on'};
69
70 $html = '
71 <input type=checkbox name=foo value="123">
72 <input type=checkbox name=foo value="FOO">
73 <input type=checkbox name=bar value="aaaa">
74 <input type=checkbox name=bar value="cccc">
75 <input type=checkbox name=bar value="dddd" checked="checked">
76 <input type=checkbox name=baz>
77 ';
78
79 form_fill(\$html, $form);
80
81 ok(
82 $html eq '
83 <input type=checkbox name=foo value="123">
84 <input type=checkbox name=foo value="FOO" checked="checked">
85 <input type=checkbox name=bar value="aaaa" checked="checked">
86 <input type=checkbox name=bar value="cccc" checked="checked">
87 <input type=checkbox name=bar value="dddd">
88 <input type=checkbox name=baz checked="checked">
89 ', "Perldoc example 3 passed");
90
91 #print $html;
92
93 ###----------------------------------------------------------------###
94
95 $form = {foo => 'FOO', bar => ['aaaa', 'bbbb', 'cccc']};
96
97 $html = '
98 <select name=foo><option>FOO<option>123<br>
99
100 <select name=bar>
101 <option>aaaa</option>
102 <option value="cccc">cccc</option>
103 <option value="dddd" selected="selected">dddd</option>
104 </select>
105 ';
106
107 form_fill(\$html, $form);
108
109 ok(
110 $html eq '
111 <select name=foo><option selected="selected">FOO<option>123<br>
112
113 <select name=bar>
114 <option selected="selected">aaaa</option>
115 <option value="cccc" selected="selected">cccc</option>
116 <option value="dddd">dddd</option>
117 </select>
118 ', "Perldoc example 4 passed");
119
120 # print $html;
121
122 ###----------------------------------------------------------------###
123
124 $form = {foo => 'FOO', bar => ['aaaa', 'bbbb']};
125
126 $html = '
127 <textarea name=foo></textarea>
128 <textarea name=foo></textarea>
129
130 <textarea name=bar>
131 <textarea name=bar></textarea><br>
132 <textarea name=bar>dddd</textarea><br>
133 <textarea name=bar><br><br>
134 ';
135
136 form_fill(\$html, $form);
137
138 ok(
139 $html eq '
140 <textarea name=foo>FOO</textarea>
141 <textarea name=foo>FOO</textarea>
142
143 <textarea name=bar>aaaa<textarea name=bar>bbbb</textarea><br>
144 <textarea name=bar></textarea><br>
145 <textarea name=bar>', "Perldoc example 5 passed");
146
147 # print $html;
148
149 ###----------------------------------------------------------------###
This page took 0.040277 seconds and 4 git commands to generate.