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';
18 # make sure testapp works
19 use_ok('TestAppUnicode') or BAIL_OUT($@);
21 our $TEST_FILE = IO::Scalar->new(\"this is a test");
22 sub IO::Scalar::FILENO { -1 }; # needed?
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'
34 $mech->get_ok('http://localhost/unicode_no_enc', 'get unicode_no_enc');
36 my $exp = "\xE3\x81\xBB\xE3\x81\x92";
37 my $got = Encode::encode_utf8($mech->content);
39 is ($mech->response->header('Content-Type'), 'text/plain',
40 'Content-Type with no charset');
42 is($got, $exp, 'content contains hoge');
46 $mech->get_ok('http://localhost/unicode', 'get unicode');
48 is ($mech->response->header('Content-Type'), 'text/plain; charset=UTF-8',
49 'Content-Type with charset');
51 my $exp = "\xE3\x81\xBB\xE3\x81\x92";
52 my $got = Encode::encode_utf8($mech->content);
54 is($got, $exp, 'content contains hoge');
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);
62 is($got, $exp, 'got 1234 5678');
66 $mech->get_ok('http://localhost/file', 'get file');
67 $mech->content_like(qr/this is a test/, 'got filehandle contents');
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');
78 my $exp = "LATIN SMALL LETTER E WITH ACUTE: \xC3\xA9";
79 my $got = Encode::encode_utf8($mech->content);
81 is ($got, $exp, 'content octets are UTF-8');
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');