drop IO::Scalar prereq
[catagits/Catalyst-Runtime.git] / t / unicode_plugin_live.t
CommitLineData
55046410 1use strict;
2use warnings;
3use Test::More;
55046410 4
5# setup library path
6use FindBin qw($Bin);
7use lib "$Bin/lib";
8
9BEGIN {
1ecc166c 10 if ( !eval { require Test::WWW::Mechanize::Catalyst; Test::WWW::Mechanize::Catalyst->VERSION('0.51') } ) {
55046410 11 plan skip_all => 'Need Test::WWW::Mechanize::Catalyst for this test';
1ecc166c 12 }
55046410 13}
14
15# make sure testapp works
16use_ok('TestAppUnicode') or BAIL_OUT($@);
17
55046410 18# a live test against TestAppUnicode, the test application
19use Test::WWW::Mechanize::Catalyst 'TestAppUnicode';
20my $mech = Test::WWW::Mechanize::Catalyst->new;
21$mech->get_ok('http://localhost/', 'get main page');
22$mech->content_like(qr/it works/i, 'see if it has our text');
23is ($mech->response->header('Content-Type'), 'text/html; charset=UTF-8',
24 'Content-Type with charset'
25);
26
27{
28 $mech->get_ok('http://localhost/unicode_no_enc', 'get unicode_no_enc');
29
30 my $exp = "\xE3\x81\xBB\xE3\x81\x92";
31 my $got = Encode::encode_utf8($mech->content);
32
33 is ($mech->response->header('Content-Type'), 'text/plain',
34 'Content-Type with no charset');
35
36 is($got, $exp, 'content contains hoge');
37}
38
39{
40 $mech->get_ok('http://localhost/unicode', 'get unicode');
41
42 is ($mech->response->header('Content-Type'), 'text/plain; charset=UTF-8',
43 'Content-Type with charset');
44
45 my $exp = "\xE3\x81\xBB\xE3\x81\x92";
46 my $got = Encode::encode_utf8($mech->content);
47
48 is($got, $exp, 'content contains hoge');
49}
50
51{
52 $mech->get_ok('http://localhost/not_unicode', 'get bytes');
53 my $exp = "\xE1\x88\xB4\xE5\x99\xB8";
54 my $got = Encode::encode_utf8($mech->content);
55
56 is($got, $exp, 'got 1234 5678');
57}
58
59{
60 $mech->get_ok('http://localhost/file', 'get file');
61 $mech->content_like(qr/this is a test/, 'got filehandle contents');
62}
63
64{
65 # The latin 1 case is the one everyone forgets. I want to really make sure
66 # its right, so lets check the damn bytes.
67 $mech->get_ok('http://localhost/latin1', 'get latin1');
68 is ($mech->response->header('Content-Type'), 'text/plain; charset=UTF-8',
69 'Content-Type with charset');
70
71
72 my $exp = "LATIN SMALL LETTER E WITH ACUTE: \xC3\xA9";
73 my $got = Encode::encode_utf8($mech->content);
74
75 is ($got, $exp, 'content octets are UTF-8');
76}
77
78{
79 $mech->get_ok('http://localhost/shift_jis', 'get shift_jis');
80 is ($mech->response->header('Content-Type'), 'text/plain; charset=Shift_JIS', 'Content-Type with charset');
81 my $exp = "\xE3\x81\xBB\xE3\x81\x92";
82 my $got = Encode::encode_utf8($mech->content);
83 is ($got, $exp, 'content octets are Shift_JIS');
84}
85
86done_testing;
87