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'; |
8 | @INC = '../lib' if -d '../lib'; |
9 | } |
10 | |
11 | BEGIN {$| = 1; print "1..17\n"; } |
12 | END {print "not ok 1\n" unless $loaded;} |
13 | use CGI (':standard','-no_debug'); |
14 | $loaded = 1; |
15 | print "ok 1\n"; |
16 | |
17 | ######################### End of black magic. |
18 | |
19 | # util |
20 | sub 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 |
27 | test(2,h1() eq '<H1>',"single tag"); |
28 | test(3,h1('fred') eq '<H1>fred</H1>',"open/close tag"); |
29 | test(4,h1('fred','agnes','maura') eq '<H1>fred agnes maura</H1>',"open/close tag multiple"); |
30 | test(5,h1({-align=>'CENTER'},'fred') eq '<H1 ALIGN="CENTER">fred</H1>',"open/close tag with attribute"); |
31 | test(6,h1({-align=>undef},'fred') eq '<H1 ALIGN>fred</H1>',"open/close tag with orphan attribute"); |
32 | test(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 | } |
39 | test(9,header() eq "Content-Type: text/html\r\n\r\n","header()"); |
40 | test(10,header(-type=>'image/gif') eq "Content-Type: image/gif\r\n\r\n","header()"); |
41 | test(11,header(-type=>'image/gif',-status=>'500 Sucks') eq "Status: 500 Sucks\r\nContent-Type: image/gif\r\n\r\n","header()"); |
42 | test(12,header(-nph=>1) eq "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n","header()"); |
43 | test(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> |
47 | END |
48 | ; |
49 | test(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> |
53 | END |
54 | ; |
55 | test(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> |
59 | END |
60 | ; |
61 | test(16,($cookie=cookie(-name=>'fred',-value=>['chocolate','chip'],-path=>'/')) eq |
62 | 'fred=chocolate&chip; path=/',"cookie()"); |
63 | test(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)"); |