summaryrefslogtreecommitdiff
path: root/t/headers
diff options
context:
space:
mode:
Diffstat (limited to 't/headers')
-rw-r--r--t/headers/attachment.t23
-rw-r--r--t/headers/charset.t20
-rw-r--r--t/headers/cookie.t34
-rw-r--r--t/headers/default.t13
-rw-r--r--t/headers/nph.t24
-rw-r--r--t/headers/p3p.t33
-rw-r--r--t/headers/target.t22
-rw-r--r--t/headers/type.t101
8 files changed, 270 insertions, 0 deletions
diff --git a/t/headers/attachment.t b/t/headers/attachment.t
new file mode 100644
index 0000000..967e9b8
--- /dev/null
+++ b/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;
diff --git a/t/headers/charset.t b/t/headers/charset.t
new file mode 100644
index 0000000..500bd9b
--- /dev/null
+++ b/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;
diff --git a/t/headers/cookie.t b/t/headers/cookie.t
new file mode 100644
index 0000000..a62f6fd
--- /dev/null
+++ b/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;
diff --git a/t/headers/default.t b/t/headers/default.t
new file mode 100644
index 0000000..007c6ea
--- /dev/null
+++ b/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;
diff --git a/t/headers/nph.t b/t/headers/nph.t
new file mode 100644
index 0000000..5d0e5e7
--- /dev/null
+++ b/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;
diff --git a/t/headers/p3p.t b/t/headers/p3p.t
new file mode 100644
index 0000000..e10c073
--- /dev/null
+++ b/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;
diff --git a/t/headers/target.t b/t/headers/target.t
new file mode 100644
index 0000000..96c95d1
--- /dev/null
+++ b/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;
diff --git a/t/headers/type.t b/t/headers/type.t
new file mode 100644
index 0000000..536a8b7
--- /dev/null
+++ b/t/headers/type.t
@@ -0,0 +1,101 @@
+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';
+}
+
+{
+ my $cgi = CGI->new;
+ my $got = $cgi->header( -type => 'image/gif' );
+ my $expected = 'Content-Type: image/gif; charset=ISO-8859-1'
+ . $CGI::CRLF x 2;
+ is $got, $expected, 'image type, no charset';
+}
+
+{
+ my $cgi = CGI->new;
+ my $got = $cgi->header(
+ -type => 'image/gif',
+ -charset => '',
+ );
+ my $expected = 'Content-Type: image/gif'
+ . $CGI::CRLF x 2;
+ is $got, $expected, 'image type, no charset';
+}
+
+{
+ my $cgi = CGI->new;
+ my $got = $cgi->header(
+ -type => 'image/gif',
+ -charset => 'utf-8',
+ );
+ my $expected = 'Content-Type: image/gif; charset=utf-8'
+ . $CGI::CRLF x 2;
+ is $got, $expected, 'image type, forced charset';
+}
+
+done_testing;