#!/usr/local/bin/perl -w
use Test::More tests => 33;
END { ok $loaded; }
use CGI ( ':standard', '-no_debug', '*h3', 'start_table' );
$loaded = 1;
ok 1;
BEGIN {
$| = 1;
if ( $] > 5.006 ) {
# no utf8
require utf8; # we contain Latin-1
utf8->unimport;
}
}
######################### End of black magic.
my $CRLF = "\015\012";
if ( $^O eq 'VMS' ) {
$CRLF = "\n"; # via web server carriage is inserted automatically
}
if ( ord("\t") != 9 ) { # EBCDIC?
$CRLF = "\r\n";
}
# util
sub test {
local ($^W) = 0;
my ( undef, $true, $msg ) = @_;
ok $true => $msg;
}
# all the automatic tags
is h1(), '
', "single tag";
is h1('fred'), 'fred
', "open/close tag";
is h1( 'fred', 'agnes', 'maura' ), 'fred agnes maura
',
"open/close tag multiple";
is h1( { -align => 'CENTER' }, 'fred' ), 'fred
',
"open/close tag with attribute";
is h1( { -align => undef }, 'fred' ), 'fred
',
"open/close tag with orphan attribute";
is h1( { -align => 'CENTER' }, [ 'fred', 'agnes' ] ),
'fred
agnes
',
"distributive tag with attribute";
{
local $" = '-';
is h1( 'fred', 'agnes', 'maura' ), 'fred-agnes-maura
',
"open/close tag \$\" interpolation";
}
is header(), "Content-Type: text/html; charset=ISO-8859-1${CRLF}${CRLF}",
"header()";
is header( -type => 'image/gif', -charset => '' ), "Content-Type: image/gif${CRLF}${CRLF}",
"header()";
is header( -type => 'image/gif', -status => '500 Sucks' ),
"Status: 500 Sucks${CRLF}Content-Type: image/gif${CRLF}${CRLF}", "header()";
# return to normal
charset( 'ISO-8859-1' );
like header( -nph => 1 ),
qr!HTTP/1.0 200 OK${CRLF}Server: cmdline${CRLF}Date:.+${CRLF}Content-Type: text/html; charset=ISO-8859-1${CRLF}${CRLF}!,
"header()";
is start_html(), <
Untitled Document
END
is start_html(
-Title => 'The world of foo' ,
-Script => [ {-src=> 'foo.js', -charset=>'utf-8'} ],
), <
The world of foo
END
for my $v (qw/ 2.0 3.2 4.0 4.01 /) {
local $CGI::XHTML = 1;
is
start_html( -dtd => "-//IETF//DTD HTML $v//FR", -lang => 'fr' ),
<<"END", 'start_html()';
Untitled Document
END
}
is
start_html( -dtd => "-//IETF//DTD HTML 9.99//FR", -lang => 'fr' ),
<<"END", 'start_html()';
Untitled Document
END
my $cookie =
cookie( -name => 'fred', -value => [ 'chocolate', 'chip' ], -path => '/' );
is $cookie, 'fred=chocolate&chip; path=/', "cookie()";
my $h = header( -Cookie => $cookie );
like $h,
qr!^Set-Cookie: fred=chocolate&chip\; path=/${CRLF}Date:.*${CRLF}Content-Type: text/html; charset=ISO-8859-1${CRLF}${CRLF}!s,
"header(-cookie)";
is start_h3, '';
is end_h3, '
';
is start_table( { -border => undef } ), '';
is h1( escapeHTML("this is \x8bright\x9b") ),
'this is <not> ‹right›
';
charset('utf-8');
is h1( escapeHTML("this is \x8bright\x9b") ),
ord("\t") == 9
? 'this is <not> ‹right›
'
: 'this is <not> »rightº
';
is i( p('hello there') ), 'hello there
';
my $q = CGI->new;
is $q->h1('hi'), 'hi
';
$q->autoEscape(1);
is $q->p( { title => "hello worldè" }, 'hello á' ),
'hello á
';
$q->autoEscape(0);
is $q->p( { title => "hello worldè" }, 'hello á' ),
'hello á
';
is p( { title => "hello worldè" }, 'hello á' ),
'hello á
';
is header( -type => 'image/gif', -charset => 'UTF-8' ),
"Content-Type: image/gif; charset=UTF-8${CRLF}${CRLF}", "header()";