/
20_content_type.t
88 lines (67 loc) · 2.42 KB
/
20_content_type.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use strict;
use warnings;
use CGI::Header;
use Test::More tests => 26;
use Test::Warn;
my %adaptee;
my $adapter = tie my %adapter, 'CGI::Header', \%adaptee;
%adaptee = ( -type => q{} );
is $adapter{Content_Type}, undef;
ok !exists $adapter{Content_Type};
is delete $adapter{Content_Type}, undef;
%adaptee = ();
is $adapter{Content_Type}, 'text/html; charset=ISO-8859-1';
ok exists $adapter{Content_Type};
is delete $adapter{Content_Type}, 'text/html; charset=ISO-8859-1';
is_deeply \%adaptee, { -type => q{} };
%adaptee = ( -type => 'text/plain' );
is $adapter{Content_Type}, 'text/plain; charset=ISO-8859-1';
ok exists $adapter{Content_Type};
%adaptee = ( -type => undef );
is $adapter{Content_Type}, 'text/html; charset=ISO-8859-1';
ok exists $adapter{Content_Type};
ok %adapter;
%adaptee = ( -type => undef, -charset => 'utf-8' );
is $adapter{Content_Type}, 'text/html; charset=utf-8';
%adaptee = ( -type => 'text/plain', -charset => 'utf-8' );
is delete $adapter{Content_Type}, 'text/plain; charset=utf-8';
is_deeply \%adaptee, { -type => q{} };
# feature
%adaptee = ( -type => 'text/plain; charSet=utf-8' );
is $adapter{Content_Type}, 'text/plain; charSet=utf-8; charset=ISO-8859-1';
# FETCH
%adaptee = ( -charset => 'utf-8' );
is $adapter{Content_Type}, 'text/html; charset=utf-8';
%adaptee = ( -type => q{}, -charset => 'utf-8' );
is $adapter{Content_Type}, undef;
%adaptee = ( -type => 'text/plain; charset=EUC-JP' );
is $adapter{Content_Type}, 'text/plain; charset=EUC-JP';
%adaptee = (
-type => 'text/plain; charset=euc-jp',
-charset => 'utf-8',
);
is $adapter{Content_Type}, 'text/plain; charset=euc-jp';
%adaptee = ( -charset => q{} );
is $adapter{Content_Type}, 'text/html';
%adaptee = ( -type => 'text/plain; Foo=1', -charset => 'utf-8' );
is $adapter{Content_Type}, 'text/plain; Foo=1; charset=utf-8';
# STORE
%adaptee = ();
$adapter{Content_Type} = 'text/plain; charset=utf-8';
is_deeply \%adaptee, {
-type => 'text/plain; charset=utf-8',
-charset => q{}
};
%adaptee = ();
$adapter{Content_Type} = 'text/plain';
is_deeply \%adaptee, { -type => 'text/plain', -charset => q{} };
%adaptee = ( -charset => 'euc-jp' );
$adapter{Content_Type} = 'text/plain; charset=utf-8';
is_deeply \%adaptee, {
-type => 'text/plain; charset=utf-8',
-charset => q{},
};
%adaptee = ();
warning_is { $adapter{Content_Type} = q{} }
"Can't set '-content_type' to neither undef nor an empty string";
is_deeply \%adaptee, {};