Commit | Line | Data |
424ec8fa |
1 | #!./perl |
2 | |
3 | # Test ability to retrieve HTTP request info |
4 | ######################### We start with some black magic to print on failure. |
5 | |
6 | BEGIN { |
7 | chdir 't' if -d 't'; |
93430cb4 |
8 | unshift @INC, '../lib' if -d '../lib'; |
424ec8fa |
9 | } |
10 | |
3d1a2ec4 |
11 | BEGIN {$| = 1; print "1..27\n"; } |
424ec8fa |
12 | END {print "not ok 1\n" unless $loaded;} |
5152d7c7 |
13 | use Config; |
424ec8fa |
14 | use CGI (':standard','keywords'); |
15 | $loaded = 1; |
16 | print "ok 1\n"; |
17 | |
18 | ######################### End of black magic. |
19 | |
20 | # util |
21 | sub test { |
22 | local($^W) = 0; |
23 | my($num, $true,$msg) = @_; |
24 | print($true ? "ok $num\n" : "not ok $num $msg\n"); |
25 | } |
26 | |
3d1a2ec4 |
27 | my $CRLF = "\015\012"; |
28 | |
424ec8fa |
29 | # Set up a CGI environment |
30 | $ENV{REQUEST_METHOD}='GET'; |
31 | $ENV{QUERY_STRING} ='game=chess&game=checkers&weather=dull'; |
32 | $ENV{PATH_INFO} ='/somewhere/else'; |
33 | $ENV{PATH_TRANSLATED} ='/usr/local/somewhere/else'; |
34 | $ENV{SCRIPT_NAME} ='/cgi-bin/foo.cgi'; |
35 | $ENV{SERVER_PROTOCOL} = 'HTTP/1.0'; |
36 | $ENV{SERVER_PORT} = 8080; |
37 | $ENV{SERVER_NAME} = 'the.good.ship.lollypop.com'; |
38 | $ENV{HTTP_LOVE} = 'true'; |
39 | |
40 | test(2,request_method() eq 'GET',"CGI::request_method()"); |
3d1a2ec4 |
41 | test(3,query_string() eq 'game=chess;game=checkers;weather=dull',"CGI::query_string()"); |
424ec8fa |
42 | test(4,param() == 2,"CGI::param()"); |
43 | test(5,join(' ',sort {$a cmp $b} param()) eq 'game weather',"CGI::param()"); |
44 | test(6,param('game') eq 'chess',"CGI::param()"); |
45 | test(7,param('weather') eq 'dull',"CGI::param()"); |
46 | test(8,join(' ',param('game')) eq 'chess checkers',"CGI::param()"); |
47 | test(9,param(-name=>'foo',-value=>'bar'),'CGI::param() put'); |
48 | test(10,param(-name=>'foo') eq 'bar','CGI::param() get'); |
3d1a2ec4 |
49 | test(11,query_string() eq 'game=chess;game=checkers;weather=dull;foo=bar',"CGI::query_string() redux"); |
424ec8fa |
50 | test(12,http('love') eq 'true',"CGI::http()"); |
51 | test(13,script_name() eq '/cgi-bin/foo.cgi',"CGI::script_name()"); |
52 | test(14,url() eq 'http://the.good.ship.lollypop.com:8080/cgi-bin/foo.cgi',"CGI::url()"); |
53 | test(15,self_url() eq |
3d1a2ec4 |
54 | 'http://the.good.ship.lollypop.com:8080/cgi-bin/foo.cgi/somewhere/else?game=chess;game=checkers;weather=dull;foo=bar', |
424ec8fa |
55 | "CGI::url()"); |
56 | test(16,url(-absolute=>1) eq '/cgi-bin/foo.cgi','CGI::url(-absolute=>1)'); |
57 | test(17,url(-relative=>1) eq 'foo.cgi','CGI::url(-relative=>1)'); |
58 | test(18,url(-relative=>1,-path=>1) eq 'foo.cgi/somewhere/else','CGI::url(-relative=>1,-path=>1)'); |
59 | test(19,url(-relative=>1,-path=>1,-query=>1) eq |
3d1a2ec4 |
60 | 'foo.cgi/somewhere/else?game=chess;game=checkers;weather=dull;foo=bar', |
424ec8fa |
61 | 'CGI::url(-relative=>1,-path=>1,-query=>1)'); |
62 | Delete('foo'); |
63 | test(20,!param('foo'),'CGI::delete()'); |
64 | |
65 | CGI::_reset_globals(); |
66 | $ENV{QUERY_STRING}='mary+had+a+little+lamb'; |
67 | test(21,join(' ',keywords()) eq 'mary had a little lamb','CGI::keywords'); |
68 | test(22,join(' ',param('keywords')) eq 'mary had a little lamb','CGI::keywords'); |
69 | |
3d1a2ec4 |
70 | CGI::_reset_globals; |
71 | if ($Config{d_fork}) { |
72 | $test_string = 'game=soccer&game=baseball&weather=nice'; |
73 | $ENV{REQUEST_METHOD}='POST'; |
74 | $ENV{CONTENT_LENGTH}=length($test_string); |
75 | $ENV{QUERY_STRING}='big_balls=basketball&small_balls=golf'; |
76 | if (open(CHILD,"|-")) { # cparent |
77 | print CHILD $test_string; |
78 | close CHILD; |
79 | exit 0; |
80 | } |
81 | # at this point, we're in a new (child) process |
82 | test(23,param('weather') eq 'nice',"CGI::param() from POST"); |
83 | test(24,url_param('big_balls') eq 'basketball',"CGI::url_param()"); |
84 | } else { |
85 | print "ok 23 # Skip\n"; |
86 | print "ok 24 # Skip\n"; |
424ec8fa |
87 | } |
3d1a2ec4 |
88 | |
89 | test(25,redirect('http://somewhere.else') eq "Status: 302 Moved${CRLF}Location: http://somewhere.else${CRLF}${CRLF}","CGI::redirect() 1"); |
90 | test(26,redirect(-Location=>'http://somewhere.else',-Type=>'text/html') eq "Status: 302 Moved${CRLF}Location: http://somewhere.else${CRLF}Content-Type: text/html; charset=ISO-8859-1${CRLF}${CRLF}","CGI::redirect() 2"); |
91 | test(27,redirect(-Location=>'http://somewhere.else/bin/foo&bar',-Type=>'text/html') eq "Status: 302 Moved${CRLF}Location: http://somewhere.else/bin/foo&bar${CRLF}Content-Type: text/html; charset=ISO-8859-1${CRLF}${CRLF}","CGI::redirect() 2"); |