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