Permalink
Browse files

Merge pull request #14 from anazawa/master

Add more tests for header(), thanks to Ryo Anazawa.
  • Loading branch information...
2 parents 17290e2 + 4ab3e52 commit 33ab58589aa4c1be9ada618f3b190c2049f4b989 @markstos committed Apr 7, 2012
Showing with 241 additions and 0 deletions.
  1. +1 −0 Makefile.PL
  2. +23 −0 t/headers/attachment.t
  3. +20 −0 t/headers/charset.t
  4. +34 −0 t/headers/cookie.t
  5. +13 −0 t/headers/default.t
  6. +24 −0 t/headers/nph.t
  7. +33 −0 t/headers/p3p.t
  8. +22 −0 t/headers/target.t
  9. +71 −0 t/headers/type.t
View
@@ -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'},
@@ -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;
View
@@ -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;
View
@@ -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;
View
@@ -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;
View
@@ -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;
View
@@ -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;
View
@@ -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;
View
@@ -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.