make testsuite somewhat location independent
[p5sagit/p5-mst-13.2.git] / t / lib / cgi-html.t
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';
8     unshift @INC, '../lib' if -d '../lib';
9     require Config; import Config;
10 }
11
12 BEGIN {$| = 1; print "1..20\n"; }
13 BEGIN {$eol = "\n"   if $^O eq 'VMS';
14        $eol = "\r\n" if $Config{ebcdic} eq 'define';
15        $eol = "\cM\cJ" unless defined $eol; }
16 END {print "not ok 1\n" unless $loaded;}
17 use CGI (':standard','-no_debug','*h3','start_table');
18 $loaded = 1;
19 print "ok 1\n";
20
21 ######################### End of black magic.
22
23 # util
24 sub test {
25     local($^W) = 0;
26     my($num, $true,$msg) = @_;
27     print($true ? "ok $num\n" : "not ok $num $msg\n");
28 }
29
30 # all the automatic tags
31 test(2,h1() eq '<H1>',"single tag");
32 test(3,h1('fred') eq '<H1>fred</H1>',"open/close tag");
33 test(4,h1('fred','agnes','maura') eq '<H1>fred agnes maura</H1>',"open/close tag multiple");
34 test(5,h1({-align=>'CENTER'},'fred') eq '<H1 ALIGN="CENTER">fred</H1>',"open/close tag with attribute");
35 test(6,h1({-align=>undef},'fred') eq '<H1 ALIGN>fred</H1>',"open/close tag with orphan attribute");
36 test(7,h1({-align=>'CENTER'},['fred','agnes']) eq 
37      '<H1 ALIGN="CENTER">fred</H1> <H1 ALIGN="CENTER">agnes</H1>',
38      "distributive tag with attribute");
39 {
40     local($") = '-'; 
41     test(8,h1('fred','agnes','maura') eq '<H1>fred-agnes-maura</H1>',"open/close tag \$\" interpolation");
42 }
43 test(9,header() eq "Content-Type: text/html${eol}${eol}","header()");
44 test(10,header(-type=>'image/gif') eq "Content-Type: image/gif${eol}${eol}","header()");
45 test(11,header(-type=>'image/gif',-status=>'500 Sucks') eq "Status: 500 Sucks${eol}Content-Type: image/gif${eol}${eol}","header()");
46 test(12,header(-nph=>1) eq "HTTP/1.0 200 OK${eol}Content-Type: text/html${eol}${eol}","header()");
47 test(13,start_html() ."\n" eq <<END,"start_html()");
48 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
49 <HTML><HEAD><TITLE>Untitled Document</TITLE>
50 </HEAD><BODY>
51 END
52     ;
53 test(14,start_html(-dtd=>"-//IETF//DTD HTML 3.2//FR") ."\n" eq <<END,"start_html()");
54 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.2//FR">
55 <HTML><HEAD><TITLE>Untitled Document</TITLE>
56 </HEAD><BODY>
57 END
58     ;
59 test(15,start_html(-Title=>'The world of foo') ."\n" eq <<END,"start_html()");
60 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
61 <HTML><HEAD><TITLE>The world of foo</TITLE>
62 </HEAD><BODY>
63 END
64     ;
65 test(16,($cookie=cookie(-name=>'fred',-value=>['chocolate','chip'],-path=>'/')) eq 
66      'fred=chocolate&chip; path=/',"cookie()");
67 test(17,header(-Cookie=>$cookie) =~ m!^Set-Cookie: fred=chocolate&chip\; path=/${eol}Date:.*${eol}Content-Type: text/html${eol}${eol}!s,
68      "header(-cookie)");
69 test(18,start_h3 eq '<H3>');
70 test(19,end_h3 eq '</H3>');
71 test(20,start_table({-border=>undef}) eq '<TABLE BORDER>');