attachment_encoding.t 3.31 KB
Newer Older
sunnavy's avatar
sunnavy committed
1
2
3
4

use strict;
use warnings;

5
use RT::Test tests => 32;
sunnavy's avatar
sunnavy committed
6
7
8
9
10
11
12
13
14
15
16
17
18
use Encode;
my ( $baseurl, $m ) = RT::Test->started_ok;
ok $m->login, 'logged in as root';

use utf8;

use File::Spec;

diag 'test without attachments' if $ENV{TEST_VERBOSE};

{
    $m->get_ok( $baseurl . '/Ticket/Create.html?Queue=1' );

19
    $m->form_name('TicketModify');
sunnavy's avatar
sunnavy committed
20
21
22
23
24
25
26
27
28
29
30
31
32
    $m->submit_form(
        form_number => 3,
        fields      => { Subject => '标题', Content => '测试' },
    );
    $m->content_like( qr/Ticket \d+ created/i, 'created the ticket' );
    $m->follow_link_ok( { text => 'with headers' },
        '-> /Ticket/Attachment/WithHeaders/...' );
    $m->content_contains( '标题', 'has subject 标题' );
    $m->content_contains( '测试', 'has content 测试' );

    my ( $id ) = $m->uri =~ /(\d+)$/;
    ok( $id, 'found attachment id' );
    my $attachment = RT::Attachment->new( $RT::SystemUser );
sunnavy's avatar
sunnavy committed
33
    ok($attachment->Load($id), "load att $id");
sunnavy's avatar
sunnavy committed
34
    # let make original encoding to gbk
sunnavy's avatar
sunnavy committed
35
36
    ok( $attachment->SetHeader( 'X-RT-Original-Encoding' => 'gbk' ),
        'set original encoding to gbk' );
sunnavy's avatar
sunnavy committed
37
38
39
40
41
42
43
44
45
46
    $m->get( $m->uri );
    $m->content_contains( '标题', 'has subject 标题' );
    $m->content_contains( '测试', 'has content 测试' );
}

diag 'test with attachemnts' if $ENV{TEST_VERBOSE};

{

    my $file =
47
      File::Spec->catfile( RT::Test->temp_directory, Encode::encode("UTF-8",'附件.txt') );
48
    open( my $fh, '>', $file ) or die $!;
sunnavy's avatar
sunnavy committed
49
50
51
52
53
54
    binmode $fh, ':utf8';
    print $fh '附件';
    close $fh;

    $m->get_ok( $baseurl . '/Ticket/Create.html?Queue=1' );

55
    $m->form_name('TicketModify');
sunnavy's avatar
sunnavy committed
56
57
58
59
60
    $m->submit_form(
        form_number => 3,
        fields => { Subject => '标题', Content => '测试', Attach => $file },
    );
    $m->content_like( qr/Ticket \d+ created/i, 'created the ticket' );
61
    $m->content_contains( '附件.txt', 'attached filename' );
62
    $m->content_lacks( Encode::encode("UTF-8",'附件.txt'), 'no double encoded attached filename' );
sunnavy's avatar
sunnavy committed
63
64
65
66
67
68
69
70
71
72
    $m->follow_link_ok( { text => 'with headers' },
        '-> /Ticket/Attachment/WithHeaders/...' );

    # subject is in the parent attachment, so there is no 标题
    $m->content_lacks( '标题', 'does not have content 标题' );
    $m->content_contains( '测试', 'has content 测试' );

    my ( $id ) = $m->uri =~ /(\d+)$/;
    ok( $id, 'found attachment id' );
    my $attachment = RT::Attachment->new( $RT::SystemUser );
sunnavy's avatar
sunnavy committed
73
    ok($attachment->Load($id), "load att $id");
sunnavy's avatar
sunnavy committed
74
    # let make original encoding to gbk
sunnavy's avatar
sunnavy committed
75
76
    ok( $attachment->SetHeader( 'X-RT-Original-Encoding' => 'gbk' ),
        'set original encoding to gbk' );
sunnavy's avatar
sunnavy committed
77
78
79
80
81
82
83
    $m->get( $m->uri );
    $m->content_lacks( '标题', 'does not have content 标题' );
    $m->content_contains( '测试', 'has content 测试' );


    $m->back;
    $m->back;
sunnavy's avatar
sunnavy committed
84
    $m->follow_link_ok( { text => 'Download 附件.txt' },
sunnavy's avatar
sunnavy committed
85
86
87
        '-> /Ticket/Attachment/...' );
    $m->content_contains( '附件', 'has content 附件' );

88
    ( $id ) = $m->uri =~ m{/(\d+)/[^/]+$};
sunnavy's avatar
sunnavy committed
89
90
    ok( $id, 'found attachment id' );
    $attachment = RT::Attachment->new( $RT::SystemUser );
sunnavy's avatar
sunnavy committed
91
    ok($attachment->Load($id), "load att $id");
sunnavy's avatar
sunnavy committed
92
93

    # let make original encoding to gbk
sunnavy's avatar
sunnavy committed
94
95
    ok( $attachment->SetHeader( 'X-RT-Original-Encoding' => 'gbk' ),
        'set original encoding to gbk' );
sunnavy's avatar
sunnavy committed
96
97
98
99
100
101
    $m->get( $m->uri );
    $m->content_contains( '附件', 'has content 附件' );

    unlink $file;
}