Commit | Line | Data |
6b4ac661 |
1 | #!/usr/local/bin/perl -w |
424ec8fa |
2 | |
f0c07f2e |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
5 | if ($ENV{PERL_CORE}) { |
6 | @INC = '../lib'; |
7 | } else { |
8 | # Due to a bug in older versions of MakeMaker & Test::Harness, we must |
9 | # ensure the blib's are in @INC, else we might use the core CGI.pm |
10 | unshift @INC, qw( ../blib/lib ../blib/arch lib ); |
11 | } |
12 | } |
ac734d8b |
13 | |
3ed077a9 |
14 | use Test::More tests => 17; |
424ec8fa |
15 | |
3ed077a9 |
16 | BEGIN { use_ok('CGI'); }; |
424ec8fa |
17 | use CGI (':standard','-no_debug'); |
424ec8fa |
18 | |
ba056755 |
19 | my $CRLF = "\015\012"; |
3ed077a9 |
20 | if ($^O eq 'VMS') { |
ba056755 |
21 | $CRLF = "\n"; # via web server carriage is inserted automatically |
22 | } |
23 | if (ord("\t") != 9) { # EBCDIC? |
24 | $CRLF = "\r\n"; |
25 | } |
26 | |
27 | |
424ec8fa |
28 | # Set up a CGI environment |
3ed077a9 |
29 | $ENV{REQUEST_METHOD} = 'GET'; |
30 | $ENV{QUERY_STRING} = 'game=chess&game=checkers&weather=dull'; |
31 | $ENV{PATH_INFO} = '/somewhere/else'; |
32 | $ENV{PATH_TRANSLATED} = '/usr/local/somewhere/else'; |
33 | $ENV{SCRIPT_NAME} ='/cgi-bin/foo.cgi'; |
424ec8fa |
34 | $ENV{SERVER_PROTOCOL} = 'HTTP/1.0'; |
3ed077a9 |
35 | $ENV{SERVER_PORT} = 8080; |
36 | $ENV{SERVER_NAME} = 'the.good.ship.lollypop.com'; |
37 | |
38 | is(start_form(-action=>'foobar',-method=>'get'), |
39 | qq(<form method="get" action="foobar" enctype="application/x-www-form-urlencoded">\n), |
40 | "start_form()"); |
41 | |
42 | is(submit(), |
43 | qq(<input type="submit" name=".submit" />), |
44 | "submit()"); |
45 | |
46 | is(submit(-name => 'foo', |
47 | -value => 'bar'), |
48 | qq(<input type="submit" name="foo" value="bar" />), |
49 | "submit(-name,-value)"); |
50 | |
51 | is(submit({-name => 'foo', |
52 | -value => 'bar'}), |
53 | qq(<input type="submit" name="foo" value="bar" />), |
54 | "submit({-name,-value})"); |
55 | |
56 | is(textfield(-name => 'weather'), |
57 | qq(<input type="text" name="weather" value="dull" />), |
58 | "textfield({-name})"); |
59 | |
60 | is(textfield(-name => 'weather', |
61 | -value => 'nice'), |
62 | qq(<input type="text" name="weather" value="dull" />), |
63 | "textfield({-name,-value})"); |
64 | |
65 | is(textfield(-name => 'weather', |
66 | -value => 'nice', |
67 | -override => 1), |
68 | qq(<input type="text" name="weather" value="nice" />), |
69 | "textfield({-name,-value,-override})"); |
70 | |
71 | is(checkbox(-name => 'weather', |
72 | -value => 'nice'), |
73 | qq(<input type="checkbox" name="weather" value="nice" />weather), |
74 | "checkbox()"); |
75 | |
76 | is(checkbox(-name => 'weather', |
77 | -value => 'nice', |
78 | -label => 'forecast'), |
79 | qq(<input type="checkbox" name="weather" value="nice" />forecast), |
80 | "checkbox()"); |
81 | |
82 | is(checkbox(-name => 'weather', |
83 | -value => 'nice', |
84 | -label => 'forecast', |
85 | -checked => 1, |
86 | -override => 1), |
ac734d8b |
87 | qq(<input type="checkbox" name="weather" value="nice" checked="1" />forecast), |
3ed077a9 |
88 | "checkbox()"); |
89 | |
90 | is(checkbox(-name => 'weather', |
91 | -value => 'dull', |
92 | -label => 'forecast'), |
ac734d8b |
93 | qq(<input type="checkbox" name="weather" value="dull" checked="1" />forecast), |
3ed077a9 |
94 | "checkbox()"); |
95 | |
96 | is(radio_group(-name => 'game'), |
ac734d8b |
97 | qq(<input type="radio" name="game" value="chess" checked="1" />chess ). |
3ed077a9 |
98 | qq(<input type="radio" name="game" value="checkers" />checkers), |
99 | 'radio_group()'); |
100 | |
101 | is(radio_group(-name => 'game', |
102 | -labels => {'chess' => 'ping pong'}), |
ac734d8b |
103 | qq(<input type="radio" name="game" value="chess" checked="1" />ping pong ). |
3ed077a9 |
104 | qq(<input type="radio" name="game" value="checkers" />checkers), |
105 | 'radio_group()'); |
106 | |
107 | is(checkbox_group(-name => 'game', |
108 | -Values => [qw/checkers chess cribbage/]), |
ac734d8b |
109 | qq(<input type="checkbox" name="game" value="checkers" checked="1" />checkers ). |
110 | qq(<input type="checkbox" name="game" value="chess" checked="1" />chess ). |
3ed077a9 |
111 | qq(<input type="checkbox" name="game" value="cribbage" />cribbage), |
112 | 'checkbox_group()'); |
113 | |
114 | is(checkbox_group(-name => 'game', |
115 | '-values' => [qw/checkers chess cribbage/], |
116 | '-defaults' => ['cribbage'],-override=>1), |
117 | qq(<input type="checkbox" name="game" value="checkers" />checkers ). |
118 | qq(<input type="checkbox" name="game" value="chess" />chess ). |
ac734d8b |
119 | qq(<input type="checkbox" name="game" value="cribbage" checked="1" />cribbage), |
3ed077a9 |
120 | 'checkbox_group()'); |
121 | |
122 | is(popup_menu(-name => 'game', |
123 | '-values' => [qw/checkers chess cribbage/], |
124 | -default => 'cribbage', |
125 | -override => 1)."\n", |
126 | <<END, 'checkbox_group()'); |
6b4ac661 |
127 | <select name="game"> |
128 | <option value="checkers">checkers</option> |
129 | <option value="chess">chess</option> |
ac734d8b |
130 | <option selected="1" value="cribbage">cribbage</option> |
6b4ac661 |
131 | </select> |
424ec8fa |
132 | END |
133 | |