forked from leejo/CGI.pm
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request leejo#14 from anazawa/master
Add more tests for header(), thanks to Ryo Anazawa.
- Loading branch information
Showing
9 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |