File: unicode_plugin_live.t

package info (click to toggle)
libcatalyst-perl 5.90124-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,992 kB
  • sloc: perl: 11,123; makefile: 7
file content (87 lines) | stat: -rw-r--r-- 2,554 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use strict;
use warnings;
use Test::More;

# setup library path
use FindBin qw($Bin);
use lib "$Bin/lib";

BEGIN {
  if ( !eval { require Test::WWW::Mechanize::Catalyst; Test::WWW::Mechanize::Catalyst->VERSION('0.51') } ) {
    plan skip_all => 'Need Test::WWW::Mechanize::Catalyst for this test';
  }
}

# make sure testapp works
use_ok('TestAppUnicode') or BAIL_OUT($@);

# a live test against TestAppUnicode, the test application
use Test::WWW::Mechanize::Catalyst 'TestAppUnicode';
my $mech = Test::WWW::Mechanize::Catalyst->new;
$mech->get_ok('http://localhost/', 'get main page');
$mech->content_like(qr/it works/i, 'see if it has our text');
is ($mech->response->header('Content-Type'), 'text/html; charset=UTF-8',
    'Content-Type with charset'
);

{
    $mech->get_ok('http://localhost/unicode_no_enc', 'get unicode_no_enc');

    my $exp = "\xE3\x81\xBB\xE3\x81\x92";
    my $got = Encode::encode_utf8($mech->content);

    is ($mech->response->header('Content-Type'), 'text/plain',
        'Content-Type with no charset');

    is($got, $exp, 'content contains hoge');
}

{
    $mech->get_ok('http://localhost/unicode', 'get unicode');

    is ($mech->response->header('Content-Type'), 'text/plain; charset=UTF-8',
        'Content-Type with charset');

    my $exp = "\xE3\x81\xBB\xE3\x81\x92";
    my $got = Encode::encode_utf8($mech->content);

    is($got, $exp, 'content contains hoge');
}

{
    $mech->get_ok('http://localhost/not_unicode', 'get bytes');
    my $exp = "\xE1\x88\xB4\xE5\x99\xB8";
    my $got = Encode::encode_utf8($mech->content);

    is($got, $exp, 'got 1234 5678');
}

{
    $mech->get_ok('http://localhost/file', 'get file');
    $mech->content_like(qr/this is a test/, 'got filehandle contents');
}

{
    # The latin 1 case is the one everyone forgets. I want to really make sure
    # its right, so lets check the damn bytes.
    $mech->get_ok('http://localhost/latin1', 'get latin1');
    is ($mech->response->header('Content-Type'), 'text/plain; charset=UTF-8',
        'Content-Type with charset');


    my $exp = "LATIN SMALL LETTER E WITH ACUTE: \xC3\xA9";
    my $got = Encode::encode_utf8($mech->content);

    is ($got, $exp, 'content octets are UTF-8');
}

{
    $mech->get_ok('http://localhost/shift_jis', 'get shift_jis');
    is ($mech->response->header('Content-Type'), 'text/plain; charset=Shift_JIS', 'Content-Type with charset');
    my $exp = "\xE3\x81\xBB\xE3\x81\x92";
    my $got = Encode::encode_utf8($mech->content);
    is ($got, $exp, 'content octets are Shift_JIS');
}

done_testing;