move op/ipc{msg,sem}.t into lib/ipc_sysv.t
[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"; }
12END {print "not ok 1\n" unless $loaded;}
13use CGI (':standard','-no_debug');
14$loaded = 1;
15print "ok 1\n";
16
17######################### End of black magic.
18
19# util
20sub test {
21 local($^W) = 0;
22 my($num, $true,$msg) = @_;
23 print($true ? "ok $num\n" : "not ok $num $msg\n");
24}
25
26# all the automatic tags
27test(2,h1() eq '<H1>',"single tag");
28test(3,h1('fred') eq '<H1>fred</H1>',"open/close tag");
29test(4,h1('fred','agnes','maura') eq '<H1>fred agnes maura</H1>',"open/close tag multiple");
30test(5,h1({-align=>'CENTER'},'fred') eq '<H1 ALIGN="CENTER">fred</H1>',"open/close tag with attribute");
31test(6,h1({-align=>undef},'fred') eq '<H1 ALIGN>fred</H1>',"open/close tag with orphan attribute");
32test(7,h1({-align=>'CENTER'},['fred','agnes']) eq
33 '<H1 ALIGN="CENTER">fred</H1> <H1 ALIGN="CENTER">agnes</H1>',
34 "distributive tag with attribute");
35{
36 local($") = '-';
37 test(8,h1('fred','agnes','maura') eq '<H1>fred-agnes-maura</H1>',"open/close tag \$\" interpolation");
38}
39test(9,header() eq "Content-Type: text/html\r\n\r\n","header()");
40test(10,header(-type=>'image/gif') eq "Content-Type: image/gif\r\n\r\n","header()");
41test(11,header(-type=>'image/gif',-status=>'500 Sucks') eq "Status: 500 Sucks\r\nContent-Type: image/gif\r\n\r\n","header()");
42test(12,header(-nph=>1) eq "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n","header()");
43test(13,start_html() ."\n" eq <<END,"start_html()");
44<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
45<HTML><HEAD><TITLE>Untitled Document</TITLE>
46</HEAD><BODY>
47END
48 ;
49test(14,start_html(-dtd=>"-//IETF//DTD HTML 3.2//FR") ."\n" eq <<END,"start_html()");
50<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.2//FR">
51<HTML><HEAD><TITLE>Untitled Document</TITLE>
52</HEAD><BODY>
53END
54 ;
55test(15,start_html(-Title=>'The world of foo') ."\n" eq <<END,"start_html()");
56<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
57<HTML><HEAD><TITLE>The world of foo</TITLE>
58</HEAD><BODY>
59END
60 ;
61test(16,($cookie=cookie(-name=>'fred',-value=>['chocolate','chip'],-path=>'/')) eq
62 'fred=chocolate&chip; path=/',"cookie()");
63test(17,header(-Cookie=>$cookie) =~ m!^Set-Cookie: fred=chocolate&chip\; path=/\r\nDate:.*\r\nContent-Type: text/html\r\n\r\n!s,
64 "header(-cookie)");