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