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