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