Forgot few S_I* imports.
[p5sagit/p5-mst-13.2.git] / t / lib / cgi-html.t
CommitLineData
424ec8fa 1#!./perl
2
3# Test ability to retrieve HTTP request info
4######################### We start with some black magic to print on failure.
5
6BEGIN {
7 chdir 't' if -d 't';
8 @INC = '../lib' if -d '../lib';
9}
10
11BEGIN {$| = 1; print "1..17\n"; }
9d116dd7 12BEGIN {$eol = $^O eq 'VMS' ? "\n" : "\cM\cJ";
092bebab 13 $eol = "\r\n" if $^O eq 'os390' or $^O eq 'vmesa'; }
424ec8fa 14END {print "not ok 1\n" unless $loaded;}
15use CGI (':standard','-no_debug');
16$loaded = 1;
17print "ok 1\n";
18
19######################### End of black magic.
20
21# util
22sub test {
23 local($^W) = 0;
24 my($num, $true,$msg) = @_;
25 print($true ? "ok $num\n" : "not ok $num $msg\n");
26}
27
28# all the automatic tags
29test(2,h1() eq '<H1>',"single tag");
30test(3,h1('fred') eq '<H1>fred</H1>',"open/close tag");
31test(4,h1('fred','agnes','maura') eq '<H1>fred agnes maura</H1>',"open/close tag multiple");
32test(5,h1({-align=>'CENTER'},'fred') eq '<H1 ALIGN="CENTER">fred</H1>',"open/close tag with attribute");
33test(6,h1({-align=>undef},'fred') eq '<H1 ALIGN>fred</H1>',"open/close tag with orphan attribute");
34test(7,h1({-align=>'CENTER'},['fred','agnes']) eq
35 '<H1 ALIGN="CENTER">fred</H1> <H1 ALIGN="CENTER">agnes</H1>',
36 "distributive tag with attribute");
37{
38 local($") = '-';
39 test(8,h1('fred','agnes','maura') eq '<H1>fred-agnes-maura</H1>',"open/close tag \$\" interpolation");
40}
e46ffa55 41test(9,header() eq "Content-Type: text/html${eol}${eol}","header()");
42test(10,header(-type=>'image/gif') eq "Content-Type: image/gif${eol}${eol}","header()");
43test(11,header(-type=>'image/gif',-status=>'500 Sucks') eq "Status: 500 Sucks${eol}Content-Type: image/gif${eol}${eol}","header()");
44test(12,header(-nph=>1) eq "HTTP/1.0 200 OK${eol}Content-Type: text/html${eol}${eol}","header()");
424ec8fa 45test(13,start_html() ."\n" eq <<END,"start_html()");
46<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
47<HTML><HEAD><TITLE>Untitled Document</TITLE>
48</HEAD><BODY>
49END
50 ;
51test(14,start_html(-dtd=>"-//IETF//DTD HTML 3.2//FR") ."\n" eq <<END,"start_html()");
52<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.2//FR">
53<HTML><HEAD><TITLE>Untitled Document</TITLE>
54</HEAD><BODY>
55END
56 ;
57test(15,start_html(-Title=>'The world of foo') ."\n" eq <<END,"start_html()");
58<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
59<HTML><HEAD><TITLE>The world of foo</TITLE>
60</HEAD><BODY>
61END
62 ;
63test(16,($cookie=cookie(-name=>'fred',-value=>['chocolate','chip'],-path=>'/')) eq
64 'fred=chocolate&chip; path=/',"cookie()");
e46ffa55 65test(17,header(-Cookie=>$cookie) =~ m!^Set-Cookie: fred=chocolate&chip\; path=/${eol}Date:.*${eol}Content-Type: text/html${eol}${eol}!s,
424ec8fa 66 "header(-cookie)");