Skip to content

Commit

Permalink
Merge pull request leejo#14 from anazawa/master
Browse files Browse the repository at this point in the history
Add more tests for header(), thanks to Ryo Anazawa.
  • Loading branch information
markstos committed Apr 7, 2012
2 parents 17290e2 + 4ab3e52 commit 33ab585
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile.PL
Expand Up @@ -17,6 +17,7 @@ WriteMakefile(
'File::Spec' => .82,
'FCGI' => 0.67,
},
test => { TESTS => 't/*.t t/headers/*.t' },
'linkext' => { LINKTYPE=>'' }, # no link needed
'dist' => {'COMPRESS'=>'gzip -9f', 'SUFFIX' => 'gz',
'ZIP'=>'/usr/bin/zip','ZIPFLAGS'=>'-rl'},
Expand Down
23 changes: 23 additions & 0 deletions t/headers/attachment.t
@@ -0,0 +1,23 @@
use strict;
use CGI;
use Test::More;

{
my $cgi = CGI->new;
my $got = $cgi->header( -attachment => 'foo.png' );
my $expected = 'Content-Disposition: attachment; filename="foo.png"'
. $CGI::CRLF
. 'Content-Type: text/html; charset=ISO-8859-1'
. $CGI::CRLF x 2;
is $got, $expected, 'attachment';
}

{
my $cgi = CGI->new;
my $got = $cgi->header( -attachment => q{} );
my $expected = "Content-Type: text/html; charset=ISO-8859-1"
. $CGI::CRLF x 2;
is $got, $expected, 'attachment empty string';
}

done_testing;
20 changes: 20 additions & 0 deletions t/headers/charset.t
@@ -0,0 +1,20 @@
use strict;
use CGI;
use Test::More;

{
my $cgi = CGI->new;
my $got = $cgi->header( -charset => 'utf-8' );
my $expected = 'Content-Type: text/html; charset=utf-8'
. $CGI::CRLF x 2;
is $got, $expected, 'charset';
}

{
my $cgi = CGI->new;
my $got = $cgi->header( -charset => q{} );
my $expected = 'Content-Type: text/html' . $CGI::CRLF x 2;
is $got, $expected, 'charset empty string';
}

done_testing;
34 changes: 34 additions & 0 deletions t/headers/cookie.t
@@ -0,0 +1,34 @@
use strict;
use CGI;
use Test::More;

{
my $cgi = CGI->new;
my $got = $cgi->header( -cookie => 'foo' );
my $expected = "^Set-Cookie: foo$CGI::CRLF"
. "Date: [^$CGI::CRLF]+$CGI::CRLF"
. 'Content-Type: text/html; charset=ISO-8859-1'
. $CGI::CRLF x 2;
like $got, qr($expected), 'cookie';
}

{
my $cgi = CGI->new;
my $got = $cgi->header( -cookie => [ 'foo', 'bar' ] );
my $expected = "^Set-Cookie: foo$CGI::CRLF"
. "Set-Cookie: bar$CGI::CRLF"
. "Date: [^$CGI::CRLF]+$CGI::CRLF"
. 'Content-Type: text/html; charset=ISO-8859-1'
. $CGI::CRLF x 2;
like $got, qr($expected), 'cookie arrayref';
}

{
my $cgi = CGI->new;
my $got = $cgi->header( -cookie => q{} );
my $expected = 'Content-Type: text/html; charset=ISO-8859-1'
. $CGI::CRLF x 2;
is $got, $expected, 'cookie empty string';
}

done_testing;
13 changes: 13 additions & 0 deletions t/headers/default.t
@@ -0,0 +1,13 @@
use strict;
use CGI;
use Test::More;

{
my $cgi = CGI->new;
my $got = $cgi->header();
my $expected = 'Content-Type: text/html; charset=ISO-8859-1'
. $CGI::CRLF x 2;
is $got, $expected, 'default';
}

done_testing;
24 changes: 24 additions & 0 deletions t/headers/nph.t
@@ -0,0 +1,24 @@
use strict;
use CGI;
use Test::More;

{
my $cgi = CGI->new;
my $got = $cgi->header( -nph => 1 );
my $expected = "^HTTP/1.0 200 OK$CGI::CRLF"
. "Server: cmdline$CGI::CRLF"
. "Date: [^$CGI::CRLF]+$CGI::CRLF"
. 'Content-Type: text/html; charset=ISO-8859-1'
. $CGI::CRLF x 2;
like $got, qr($expected), 'nph';
}

{
my $cgi = CGI->new;
my $got = $cgi->header( -nph => 0 );
my $expected = 'Content-Type: text/html; charset=ISO-8859-1'
. $CGI::CRLF x 2;
is $got, $expected, 'nph';
}

done_testing;
33 changes: 33 additions & 0 deletions t/headers/p3p.t
@@ -0,0 +1,33 @@
use strict;
use CGI;
use Test::More;

{
my $cgi = CGI->new;
my $got = $cgi->header( -p3p => "CAO DSP LAW CURa" );
my $expected = 'P3P: policyref="/w3c/p3p.xml", CP="CAO DSP LAW CURa"'
. $CGI::CRLF
. 'Content-Type: text/html; charset=ISO-8859-1'
. $CGI::CRLF x 2;
is $got, $expected, 'p3p';
}

{
my $cgi = CGI->new;
my $got = $cgi->header( -p3p => [ qw/CAO DSP LAW CURa/ ] );
my $expected = 'P3P: policyref="/w3c/p3p.xml", CP="CAO DSP LAW CURa"'
. $CGI::CRLF
. 'Content-Type: text/html; charset=ISO-8859-1'
. $CGI::CRLF x 2;
is $got, $expected, 'p3p arrayref';
}

{
my $cgi = CGI->new;
my $got = $cgi->header( -p3p => q{} );
my $expected = 'Content-Type: text/html; charset=ISO-8859-1'
. $CGI::CRLF x 2;
is $got, $expected, 'p3p empty string';
}

done_testing;
22 changes: 22 additions & 0 deletions t/headers/target.t
@@ -0,0 +1,22 @@
use strict;
use CGI;
use Test::More;

{
my $cgi = CGI->new;
my $got = $cgi->header( -target => 'ResultsWindow' );
my $expected = "Window-Target: ResultsWindow$CGI::CRLF"
. 'Content-Type: text/html; charset=ISO-8859-1'
. $CGI::CRLF x 2;
is $got, $expected, 'target';
}

{
my $cgi = CGI->new;
my $got = $cgi->header( -target => q{} );
my $expected = 'Content-Type: text/html; charset=ISO-8859-1'
. $CGI::CRLF x 2;
is $got, $expected, 'target empty string';
}

done_testing;
71 changes: 71 additions & 0 deletions t/headers/type.t
@@ -0,0 +1,71 @@
use strict;
use CGI;
use Test::More;

{
my $cgi = CGI->new;
my $got = $cgi->header( -type => 'text/plain' );
my $expected = 'Content-Type: text/plain; charset=ISO-8859-1'
. $CGI::CRLF x 2;
is $got, $expected, 'type';
}

{
my $cgi = CGI->new;
my $got = $cgi->header( -type => q{} );
my $expected = $CGI::CRLF x 2;
is $got, $expected, 'type empty string';
}

{
my $cgi = CGI->new;
my $got = $cgi->header( -type => 'text/plain; charset=utf-8' );
my $expected = 'Content-Type: text/plain; charset=utf-8'
. $CGI::CRLF x 2;
is $got, $expected, 'type defines charset';
}

{
my $cgi = CGI->new;
my $got = $cgi->header(
'-type' => 'text/plain',
'-charset' => 'utf-8',
);
my $expected = 'Content-Type: text/plain; charset=utf-8'
. $CGI::CRLF x 2;
is $got, $expected, 'type and charset';
}

{
my $cgi = CGI->new;
my $got = $cgi->header(
'-type' => q{},
'-charset' => 'utf-8',
);
my $expected = $CGI::CRLF x 2;
is $got, $expected, 'type and charset, type is empty string';
}

{
my $cgi = CGI->new;
my $got = $cgi->header(
'-type' => 'text/plain; charset=utf-8',
'-charset' => q{},
);
my $expected = 'Content-Type: text/plain; charset=utf-8'
. $CGI::CRLF x 2;
is $got, $expected, 'type and charset, charset is empty string';
}

{
my $cgi = CGI->new;
my $got = $cgi->header(
'-type' => 'text/plain; charset=utf-8',
'-charset' => 'EUC-JP',
);
my $expected = 'Content-Type: text/plain; charset=utf-8'
. $CGI::CRLF x 2;
is $got, $expected, 'type and charset, type defines charset';
}

done_testing;

0 comments on commit 33ab585

Please sign in to comment.