diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 2000-05-01 08:16:10 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 2000-05-01 08:16:10 +0000 |
commit | 3d1a2ec4907585a079fab9dc4764c16e7e3b58e3 (patch) | |
tree | 46ef1a6088ba0cdfe8bf4b813c7c5254f40f17a2 /t/lib | |
parent | f3248e5040f8dfad4ae7c7de65d22997a0107c5f (diff) | |
download | perl-3d1a2ec4907585a079fab9dc4764c16e7e3b58e3.tar.gz |
add CGI.pm v2.66 (from Lincoln Stein)
p4raw-id: //depot/perl@6029
Diffstat (limited to 't/lib')
-rwxr-xr-x | t/lib/cgi-function.t | 50 | ||||
-rwxr-xr-x | t/lib/cgi-html.t | 25 | ||||
-rwxr-xr-x | t/lib/cgi-pretty.t | 39 | ||||
-rwxr-xr-x | t/lib/cgi-request.t | 56 |
4 files changed, 114 insertions, 56 deletions
diff --git a/t/lib/cgi-function.t b/t/lib/cgi-function.t index b4cd56811f..934e27cdc9 100755 --- a/t/lib/cgi-function.t +++ b/t/lib/cgi-function.t @@ -8,7 +8,7 @@ BEGIN { unshift @INC, '../lib' if -d '../lib'; } -BEGIN {$| = 1; print "1..24\n"; } +BEGIN {$| = 1; print "1..27\n"; } END {print "not ok 1\n" unless $loaded;} use Config; use CGI (':standard','keywords'); @@ -24,6 +24,8 @@ sub test { print($true ? "ok $num\n" : "not ok $num $msg\n"); } +my $CRLF = "\015\012"; + # Set up a CGI environment $ENV{REQUEST_METHOD}='GET'; $ENV{QUERY_STRING} ='game=chess&game=checkers&weather=dull'; @@ -36,7 +38,7 @@ $ENV{SERVER_NAME} = 'the.good.ship.lollypop.com'; $ENV{HTTP_LOVE} = 'true'; test(2,request_method() eq 'GET',"CGI::request_method()"); -test(3,query_string() eq 'game=chess&game=checkers&weather=dull',"CGI::query_string()"); +test(3,query_string() eq 'game=chess;game=checkers;weather=dull',"CGI::query_string()"); test(4,param() == 2,"CGI::param()"); test(5,join(' ',sort {$a cmp $b} param()) eq 'game weather',"CGI::param()"); test(6,param('game') eq 'chess',"CGI::param()"); @@ -44,18 +46,18 @@ test(7,param('weather') eq 'dull',"CGI::param()"); test(8,join(' ',param('game')) eq 'chess checkers',"CGI::param()"); test(9,param(-name=>'foo',-value=>'bar'),'CGI::param() put'); test(10,param(-name=>'foo') eq 'bar','CGI::param() get'); -test(11,query_string() eq 'game=chess&game=checkers&weather=dull&foo=bar',"CGI::query_string() redux"); +test(11,query_string() eq 'game=chess;game=checkers;weather=dull;foo=bar',"CGI::query_string() redux"); test(12,http('love') eq 'true',"CGI::http()"); test(13,script_name() eq '/cgi-bin/foo.cgi',"CGI::script_name()"); test(14,url() eq 'http://the.good.ship.lollypop.com:8080/cgi-bin/foo.cgi',"CGI::url()"); test(15,self_url() eq - 'http://the.good.ship.lollypop.com:8080/cgi-bin/foo.cgi/somewhere/else?game=chess&game=checkers&weather=dull&foo=bar', + 'http://the.good.ship.lollypop.com:8080/cgi-bin/foo.cgi/somewhere/else?game=chess;game=checkers;weather=dull;foo=bar', "CGI::url()"); test(16,url(-absolute=>1) eq '/cgi-bin/foo.cgi','CGI::url(-absolute=>1)'); test(17,url(-relative=>1) eq 'foo.cgi','CGI::url(-relative=>1)'); test(18,url(-relative=>1,-path=>1) eq 'foo.cgi/somewhere/else','CGI::url(-relative=>1,-path=>1)'); test(19,url(-relative=>1,-path=>1,-query=>1) eq - 'foo.cgi/somewhere/else?game=chess&game=checkers&weather=dull&foo=bar', + 'foo.cgi/somewhere/else?game=chess;game=checkers;weather=dull;foo=bar', 'CGI::url(-relative=>1,-path=>1,-query=>1)'); Delete('foo'); test(20,!param('foo'),'CGI::delete()'); @@ -65,21 +67,25 @@ $ENV{QUERY_STRING}='mary+had+a+little+lamb'; test(21,join(' ',keywords()) eq 'mary had a little lamb','CGI::keywords'); test(22,join(' ',param('keywords')) eq 'mary had a little lamb','CGI::keywords'); -if (!$Config{d_fork} or $^O eq 'MSWin32' or $^O eq 'VMS') { - for (23,24) { print "ok $_ # Skipped: fork n/a\n" } -} -else { - CGI::_reset_globals; - $test_string = 'game=soccer&game=baseball&weather=nice'; - $ENV{REQUEST_METHOD}='POST'; - $ENV{CONTENT_LENGTH}=length($test_string); - $ENV{QUERY_STRING}='big_balls=basketball&small_balls=golf'; - if (open(CHILD,"|-")) { # cparent - print CHILD $test_string; - close CHILD; - exit 0; - } - # at this point, we're in a new (child) process - test(23,param('weather') eq 'nice',"CGI::param() from POST"); - test(24,url_param('big_balls') eq 'basketball',"CGI::url_param()"); +CGI::_reset_globals; +if ($Config{d_fork}) { + $test_string = 'game=soccer&game=baseball&weather=nice'; + $ENV{REQUEST_METHOD}='POST'; + $ENV{CONTENT_LENGTH}=length($test_string); + $ENV{QUERY_STRING}='big_balls=basketball&small_balls=golf'; + if (open(CHILD,"|-")) { # cparent + print CHILD $test_string; + close CHILD; + exit 0; + } + # at this point, we're in a new (child) process + test(23,param('weather') eq 'nice',"CGI::param() from POST"); + test(24,url_param('big_balls') eq 'basketball',"CGI::url_param()"); +} else { + print "ok 23 # Skip\n"; + print "ok 24 # Skip\n"; } + +test(25,redirect('http://somewhere.else') eq "Status: 302 Moved${CRLF}Location: http://somewhere.else${CRLF}${CRLF}","CGI::redirect() 1"); +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"); +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"); diff --git a/t/lib/cgi-html.t b/t/lib/cgi-html.t index 43d41ec10f..1e20a315fa 100755 --- a/t/lib/cgi-html.t +++ b/t/lib/cgi-html.t @@ -9,7 +9,7 @@ BEGIN { require Config; import Config; } -BEGIN {$| = 1; print "1..20\n"; } +BEGIN {$| = 1; print "1..24\n"; } END {print "not ok 1\n" unless $loaded;} use CGI (':standard','-no_debug','*h3','start_table'); $loaded = 1; @@ -41,12 +41,13 @@ test(7,h1({-align=>'CENTER'},['fred','agnes']) eq test(8,h1('fred','agnes','maura') eq '<H1>fred-agnes-maura</H1>',"open/close tag \$\" interpolation"); } -test(9,header() eq "Content-Type: text/html$crlf$crlf","header()"); -test(10,header(-type=>'image/gif') eq "Content-Type: image/gif$crlf$crlf","header()"); -test(11,header(-type=>'image/gif',-status=>'500 Sucks') eq "Status: 500 Sucks${crlf}Content-Type: image/gif$crlf$crlf","header()"); -test(12,header(-nph=>1) eq "HTTP/1.0 200 OK${crlf}Content-Type: text/html$crlf$crlf","header()"); +test(9,header() eq "Content-Type: text/html; charset=ISO-8859-1$crlf$crlf","header()"); +test(10,header(-type=>'image/gif') eq "Content-Type: image/gif; charset=ISO-8859-1$crlf$crlf","header()"); +test(11,header(-type=>'image/gif',-status=>'500 Sucks') eq "Status: 500 Sucks${crlf}Content-Type: image/gif; charset=ISO-8859-1$crlf$crlf","header()"); +test(12,header(-nph=>1) eq "HTTP/1.0 200 OK${crlf}Content-Type: text/html; charset=ISO-8859-1$crlf$crlf","header()"); test(13,start_html() ."\n" eq <<END,"start_html()"); -<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/html4/loose.dtd"> <HTML><HEAD><TITLE>Untitled Document</TITLE> </HEAD><BODY> END @@ -58,7 +59,8 @@ test(14,start_html(-dtd=>"-//IETF//DTD HTML 3.2//FR") ."\n" eq <<END,"start_html END ; test(15,start_html(-Title=>'The world of foo') ."\n" eq <<END,"start_html()"); -<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/html4/loose.dtd"> <HTML><HEAD><TITLE>The world of foo</TITLE> </HEAD><BODY> END @@ -70,6 +72,9 @@ test(17,header(-Cookie=>$cookie) =~ m!^Set-Cookie: fred=chocolate&chip\; path=/$ test(18,start_h3 eq '<H3>'); test(19,end_h3 eq '</H3>'); test(20,start_table({-border=>undef}) eq '<TABLE BORDER>'); - - - +test(21,h1(escapeHTML("this is <not> \x8bright\x9b")) eq '<H1>this is <not> ‹right›</H1>'); +charset('utf-8'); +test(22,h1(escapeHTML("this is <not> \x8bright\x9b")) eq '<H1>this is <not> ‹right›</H1>'); +test(23,i(p('hello there')) eq '<I><P>hello there</P></I>'); +my $q = new CGI; +test(24,$q->h1('hi') eq '<H1>hi</H1>'); diff --git a/t/lib/cgi-pretty.t b/t/lib/cgi-pretty.t new file mode 100755 index 0000000000..e217a7dbd4 --- /dev/null +++ b/t/lib/cgi-pretty.t @@ -0,0 +1,39 @@ +#!./perl + +# Test ability to retrieve HTTP request info +######################### We start with some black magic to print on failure. +BEGIN { + chdir 't' if -d 't'; + unshift @INC, '../lib' if -d '../lib'; +} + +BEGIN {$| = 1; print "1..5\n"; } +END {print "not ok 1\n" unless $loaded;} +use CGI::Pretty (':standard','-no_debug','*h3','start_table'); +$loaded = 1; +print "ok 1\n"; + +######################### End of black magic. + +# util +sub test { + local($^W) = 0; + my($num, $true,$msg) = @_; + print($true ? "ok $num\n" : "not ok $num $msg\n"); +} + +# all the automatic tags +test(2,h1() eq '<H1>',"single tag"); +test(3,ol(li('fred'),li('ethel')) eq "<OL>\n\t<LI>\n\t\tfred\n\t</LI>\n\t <LI>\n\t\tethel\n\t</LI>\n</OL>\n","basic indentation"); +test(4,p('hi',pre('there'),'frog') eq +'<P> + hi <PRE>there</PRE> + frog +</P> +',"<pre> tags"); +test(5,p('hi',a({-href=>'frog'},'there'),'frog') eq +'<P> + hi <A HREF="frog">there</A> + frog +</P> +',"as-is"); diff --git a/t/lib/cgi-request.t b/t/lib/cgi-request.t index 9e8cdc290a..390c08cccd 100755 --- a/t/lib/cgi-request.t +++ b/t/lib/cgi-request.t @@ -8,10 +8,10 @@ BEGIN { unshift @INC, '../lib' if -d '../lib'; } -BEGIN {$| = 1; print "1..31\n"; } +BEGIN {$| = 1; print "1..33\n"; } END {print "not ok 1\n" unless $loaded;} -use Config; use CGI (); +use Config; $loaded = 1; print "ok 1\n"; @@ -39,7 +39,7 @@ $ENV{HTTP_LOVE} = 'true'; $q = new CGI; test(2,$q,"CGI::new()"); test(3,$q->request_method eq 'GET',"CGI::request_method()"); -test(4,$q->query_string eq 'game=chess&game=checkers&weather=dull',"CGI::query_string()"); +test(4,$q->query_string eq 'game=chess;game=checkers;weather=dull',"CGI::query_string()"); test(5,$q->param() == 2,"CGI::param()"); test(6,join(' ',sort $q->param()) eq 'game weather',"CGI::param()"); test(7,$q->param('game') eq 'chess',"CGI::param()"); @@ -47,18 +47,18 @@ test(8,$q->param('weather') eq 'dull',"CGI::param()"); test(9,join(' ',$q->param('game')) eq 'chess checkers',"CGI::param()"); test(10,$q->param(-name=>'foo',-value=>'bar'),'CGI::param() put'); test(11,$q->param(-name=>'foo') eq 'bar','CGI::param() get'); -test(12,$q->query_string eq 'game=chess&game=checkers&weather=dull&foo=bar',"CGI::query_string() redux"); +test(12,$q->query_string eq 'game=chess;game=checkers;weather=dull;foo=bar',"CGI::query_string() redux"); test(13,$q->http('love') eq 'true',"CGI::http()"); test(14,$q->script_name eq '/cgi-bin/foo.cgi',"CGI::script_name()"); test(15,$q->url eq 'http://the.good.ship.lollypop.com:8080/cgi-bin/foo.cgi',"CGI::url()"); test(16,$q->self_url eq - 'http://the.good.ship.lollypop.com:8080/cgi-bin/foo.cgi/somewhere/else?game=chess&game=checkers&weather=dull&foo=bar', + 'http://the.good.ship.lollypop.com:8080/cgi-bin/foo.cgi/somewhere/else?game=chess;game=checkers;weather=dull;foo=bar', "CGI::url()"); test(17,$q->url(-absolute=>1) eq '/cgi-bin/foo.cgi','CGI::url(-absolute=>1)'); test(18,$q->url(-relative=>1) eq 'foo.cgi','CGI::url(-relative=>1)'); test(19,$q->url(-relative=>1,-path=>1) eq 'foo.cgi/somewhere/else','CGI::url(-relative=>1,-path=>1)'); test(20,$q->url(-relative=>1,-path=>1,-query=>1) eq - 'foo.cgi/somewhere/else?game=chess&game=checkers&weather=dull&foo=bar', + 'foo.cgi/somewhere/else?game=chess;game=checkers;weather=dull;foo=bar', 'CGI::url(-relative=>1,-path=>1,-query=>1)'); $q->delete('foo'); test(21,!$q->param('foo'),'CGI::delete()'); @@ -73,22 +73,30 @@ test(26,$q->param('foo') eq 'bar','CGI::param() redux'); test(27,$q=new CGI({'foo'=>'bar','bar'=>'froz'}),"CGI::new() redux 2"); test(28,$q->param('bar') eq 'froz',"CGI::param() redux 2"); -if (!$Config{d_fork} or $^O eq 'MSWin32' or $^O eq 'VMS') { - for (29..31) { print "ok $_ # Skipped: fork n/a\n" } -} -else { - $q->_reset_globals; - $test_string = 'game=soccer&game=baseball&weather=nice'; - $ENV{REQUEST_METHOD}='POST'; - $ENV{CONTENT_LENGTH}=length($test_string); - $ENV{QUERY_STRING}='big_balls=basketball&small_balls=golf'; - if (open(CHILD,"|-")) { # cparent - print CHILD $test_string; - close CHILD; - exit 0; - } - # at this point, we're in a new (child) process - test(29,$q=new CGI,"CGI::new() from POST"); - test(30,$q->param('weather') eq 'nice',"CGI::param() from POST"); - test(31,$q->url_param('big_balls') eq 'basketball',"CGI::url_param()"); +# test tied interface +my $p = $q->Vars; +test(29,$p->{bar} eq 'froz',"tied interface fetch"); +$p->{bar} = join("\0",qw(foo bar baz)); +test(30,join(' ',$q->param('bar')) eq 'foo bar baz','tied interface store'); + +# test posting +$q->_reset_globals; +if ($Config{d_fork}) { + $test_string = 'game=soccer&game=baseball&weather=nice'; + $ENV{REQUEST_METHOD}='POST'; + $ENV{CONTENT_LENGTH}=length($test_string); + $ENV{QUERY_STRING}='big_balls=basketball&small_balls=golf'; + if (open(CHILD,"|-")) { # cparent + print CHILD $test_string; + close CHILD; + exit 0; + } + # at this point, we're in a new (child) process + test(31,$q=new CGI,"CGI::new() from POST"); + test(32,$q->param('weather') eq 'nice',"CGI::param() from POST"); + test(33,$q->url_param('big_balls') eq 'basketball',"CGI::url_param()"); +} else { + print "ok 31 # Skip\n"; + print "ok 32 # Skip\n"; + print "ok 33 # Skip\n"; } |