blib/lib/Mason/Plugin/WithEncoding/t/NoUTF8.pm

filter: Statementstmt 100% 92 / 92 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 99.0% 102 / 103 CC 2 SCAR 2.0
CC
2
Cov
100%
test_no_withencoding
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« blib/lib/Mason/Plugin/WithEncoding/t/UTF8.pm ↑ Summary
1 package Mason::Plugin::WithEncoding::t::NoUTF8;
2 2 $Mason::Plugin::WithEncoding::t::NoUTF8::VERSION = '0.2';
3 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Test::Class::Most parent => 'Mason::Plugin::WithEncoding::Test::Class';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Guard;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Poet::Tools qw(dirname mkpath trim write_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # Setup stolen from Poet::t::Run and Poet::t::PSGIHandler
10  
11 2 ▶sub test_no_withencoding : Tests {
Subroutine test_no_withencoding: called CC=2 SCAR=6.9
Pod undocumented
12 2 my $self = shift;
13  
14 2 my $conf_no_encoding = {
15 'layer' => 'production',
16 'server.port' => 9998,
17 };
18  
19 2 my $poet = $self->temp_env(conf => $conf_no_encoding);
20 2 my $root_dir = $poet->root_dir;
21 2 my $run_log = "$root_dir/logs/run.log";
22  
23 2 ▶ if ( my $pid = fork() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pid = fork) { } 1 1 2
24 # parent
25 1 ▶ scope_guard { kill( 1, $pid ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
26 1 sleep(2);
27  
28 1 my $mech = $self->mech($poet);
29 1 $self->add_comps($poet);
30  
31 # std config, utf8 content, utf8 url, utf8 query
32 1 $mech->get_ok("http://127.0.0.1:9998/♥♥♥?♥♥=♥♥♥♥♥♥♥");
33 # query string goes over wires as encoded ascii, so clients use url encoding to preserve information
34 1 $mech->content_unlike(qr/QUERY STRING FROM REQ: ♥♥=♥♥♥♥♥♥/);
35 1 $mech->content_like(qr[QUERY STRING FROM REQ: \Q%E2%99%A5%E2%99%A5=%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5\E]);
36 1 $mech->content_unlike(qr/QUERY STRING UNESCAPED: ♥♥=♥♥♥♥♥♥♥/);
37 #warn $mech->content;
38 1 $mech->content_like(qr/A QUICK BROWN FOX JUMPS OVER THE LAZY DOG/);
39 1 $mech->content_unlike(qr/a quick brown fox jumps over the lazy dog/);
40 1 $mech->content_unlike(qr/ΔΙΑΦΥΛΆΞΤΕ ΓΕΝΙΚΆ ΤΗ ΖΩΉ ΣΑΣ ΑΠΌ ΒΑΘΕΙΆ ΨΥΧΙΚΆ ΤΡΑΎΜΑΤΑ/); #### WithEncode matches (uc operation works)
41 1 $mech->content_like(qr/διαφυλάξτε γενικά τη ζωή σας από βαθειά ψυχικά τραύματα/); #### WithEncode doesn't match (uc operation works)
42 1 is($mech->content_type, 'text/html', 'Got correct content type');
43 1 is($mech->response->content_type_charset, undef, 'Got correct content-type charset');
44  
45 # std config, utf8 content, utf8 url, no query
46 1 $mech->get_ok("http://127.0.0.1:9998/♥♥♥");
47 1 $mech->content_like(qr/A QUICK BROWN FOX JUMPS OVER THE LAZY DOG/);
48 1 $mech->content_unlike(qr/a quick brown fox jumps over the lazy dog/);
49 1 $mech->content_unlike(qr/ΔΙΑΦΥΛΆΞΤΕ ΓΕΝΙΚΆ ΤΗ ΖΩΉ ΣΑΣ ΑΠΌ ΒΑΘΕΙΆ ΨΥΧΙΚΆ ΤΡΑΎΜΑΤΑ/); #### WithEncode matches (uc operation works)
50 1 $mech->content_like(qr/διαφυλάξτε γενικά τη ζωή σας από βαθειά ψυχικά τραύματα/); #### WithEncode doesn't match (uc operation works)
51 1 is($mech->content_type, 'text/html', 'Got correct content type');
52 1 is($mech->response->content_type_charset, undef, 'Got correct content-type charset');
53  
54 # std config, utf8 content, ascii url, utf8 query
55 1 $mech->get_ok("http://127.0.0.1:9998/utf8?♥♥=♥♥♥♥♥♥♥");
56 # query string goes over wires as encoded ascii, so clients use url encoding to preserve information
57 1 $mech->content_unlike(qr/QUERY STRING FROM REQ: ♥♥=♥♥♥♥♥♥/);
58 1 $mech->content_like(qr[QUERY STRING FROM REQ: \Q%E2%99%A5%E2%99%A5=%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5\E]);
59 1 $mech->content_unlike(qr/QUERY STRING UNESCAPED: ♥♥=♥♥♥♥♥♥♥/);
60 #warn $mech->content;
61 1 $mech->content_like(qr/A QUICK BROWN FOX JUMPS OVER THE LAZY DOG/);
62 1 $mech->content_unlike(qr/a quick brown fox jumps over the lazy dog/);
63 1 $mech->content_unlike(qr/ΔΙΑΦΥΛΆΞΤΕ ΓΕΝΙΚΆ ΤΗ ΖΩΉ ΣΑΣ ΑΠΌ ΒΑΘΕΙΆ ΨΥΧΙΚΆ ΤΡΑΎΜΑΤΑ/); #### WithEncode matches (uc operation works)
64 1 $mech->content_like(qr/διαφυλάξτε γενικά τη ζωή σας από βαθειά ψυχικά τραύματα/); #### WithEncode doesn't match (uc operation works)
65 1 is($mech->content_type, 'text/html', 'Got correct content type');
66 1 is($mech->response->content_type_charset, undef, 'Got correct content-type charset');
67  
68 # std config, utf8 content, ascii url, no query
69 1 $mech->get_ok("http://127.0.0.1:9998/utf8");
70 #warn $mech->content;
71 1 $mech->content_like(qr/A QUICK BROWN FOX JUMPS OVER THE LAZY DOG/);
72 1 $mech->content_unlike(qr/a quick brown fox jumps over the lazy dog/);
73 1 $mech->content_unlike(qr/ΔΙΑΦΥΛΆΞΤΕ ΓΕΝΙΚΆ ΤΗ ΖΩΉ ΣΑΣ ΑΠΌ ΒΑΘΕΙΆ ΨΥΧΙΚΆ ΤΡΑΎΜΑΤΑ/); #### WithEncode matches (uc operation works)
74 1 $mech->content_like(qr/διαφυλάξτε γενικά τη ζωή σας από βαθειά ψυχικά τραύματα/); #### WithEncode doesn't match (uc operation works)
75 1 is($mech->content_type, 'text/html', 'Got correct content type');
76 1 is($mech->response->content_type_charset, undef, 'Got correct content-type charset');
77  
78 # std config, plain content, plain url, no query
79 1 $mech->get_ok("http://127.0.0.1:9998/plain");
80 1 $mech->content_like(qr/LOREM IPSUM DOLOR SIT AMET/);
81 1 $mech->content_unlike(qr/Lorem ipsum dolor sit amet/);
82 #warn $mech->content;
83 1 is($mech->content_type, 'text/html', 'Got correct content type');
84 1 is($mech->response->content_type_charset, undef, 'Got correct content-type charset');
85  
86 # std config, chokes on $.args->{♥} in the page, looks like a bug
87 1 $mech->get("http://127.0.0.1:9998/dies"); # PSGI error: Unrecognized character
88 1 ok($mech->status == 500, 'UTF8 content bug');
89 #$mech->content_like(qr/♥♥♥♥♥♥♥/);
90 1 is($mech->content_type, '', 'Got correct content type');
91 1 is($mech->response->content_type_charset, undef, 'Got correct content-type charset');
92  
93 # std config, json content
94 1 my $expected_from_json = {
95 foo => 'bar',
96 baz => [qw(barp beep)],
97 9 => { one => 1, ex => 'EKS' },
98 heart => '♥',
99 };
100 1 $mech->get_ok("http://127.0.0.1:9999/json");
101 #warn $mech->content;
102 # see comments in UTF8.pm for why I can't use cmp_deeply
103 #cmp_deeply(JSON->new->utf8->decode($mech->content), $expected_from_json, 'Decoded expected data from JSON'); # fails '�' - that's what is in the content
104 #cmp_deeply(JSON->new->decode($mech->content), $expected_from_json, 'Decoded expected data from JSON'); # fails '�'
105  
106 1 my $from_decoded_utf8 = JSON->new->utf8->decode($mech->content); # should work DOESN'T
107 1 my $not_decoded = JSON->new->decode($mech->content); # should break
108  
109 2 ▶ use Encode qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
110 1 my $manually_decoded = JSON->new->decode(Encode::decode('UTF8', $mech->content)); # should work DOESN'T
111 1 my $manually_and_JSON_decoded = JSON->new->utf8->decode(Encode::decode('UTF8', $mech->content)); # should break ISN'T
112  
113 1 ok($from_decoded_utf8->{heart}, 'My heart is true');
114  
115  
116 1 ok($not_decoded->{heart}, 'My heart is true');
117 1 ok($not_decoded->{heart} ne '♥', 'My heart has been mangled');
118  
119 1 is($mech->content_type, 'application/json', 'Got correct content type');
120 1 is($mech->response->content_type_charset, undef, 'Got correct content-type charset');
121  
122 1 local $TODO = "I'm not grokking something";
123 1 is($from_decoded_utf8->{heart}, '♥', 'Found my true ♥'); # why does this fail? 'â�¥'
124 1 is($manually_decoded->{heart}, '♥', 'Found my true ♥'); # why does this fail? 'â�¥'
125 1 ok($manually_and_JSON_decoded->{heart} ne '♥', 'Found my true ♥'); # WHY DOES THIS WORK (when 'eq')???? somewhere it got UTF8 encoded a second time
126 }
127 else {
128 # child
129 1 close STDOUT;
130 1 close STDERR;
131 1 exec( $poet->bin_path("run.pl > $run_log 2>&1") );
132 }
133 2 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
134  
135 2 1;
« blib/lib/Mason/Plugin/WithEncoding/t/UTF8.pm ↑ Summary