import rt 3.8.10
[freeside.git] / rt / t / web / attachment_encoding.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use RT::Test tests => 28;
7 use Encode;
8 my ( $baseurl, $m ) = RT::Test->started_ok;
9 ok $m->login, 'logged in as root';
10
11 $RT::Test::SKIP_REQUEST_WORK_AROUND = 1;
12
13 use utf8;
14
15 use File::Spec;
16
17 diag 'test without attachments' if $ENV{TEST_VERBOSE};
18
19 {
20     $m->get_ok( $baseurl . '/Ticket/Create.html?Queue=1' );
21
22     $m->form_number(3);
23     $m->submit_form(
24         form_number => 3,
25         fields      => { Subject => '标题', Content => '测试' },
26     );
27     $m->content_like( qr/Ticket \d+ created/i, 'created the ticket' );
28     $m->follow_link_ok( { text => 'with headers' },
29         '-> /Ticket/Attachment/WithHeaders/...' );
30     $m->content_contains( '标题', 'has subject 标题' );
31     $m->content_contains( '测试', 'has content 测试' );
32
33     my ( $id ) = $m->uri =~ /(\d+)$/;
34     ok( $id, 'found attachment id' );
35     my $attachment = RT::Attachment->new( $RT::SystemUser );
36     ok($attachment->Load($id), "load att $id");
37     # let make original encoding to gbk
38     ok( $attachment->SetHeader( 'X-RT-Original-Encoding' => 'gbk' ),
39         'set original encoding to gbk' );
40     $m->get( $m->uri );
41     $m->content_contains( '标题', 'has subject 标题' );
42     $m->content_contains( '测试', 'has content 测试' );
43 }
44
45 diag 'test with attachemnts' if $ENV{TEST_VERBOSE};
46
47 {
48
49     my $file =
50       File::Spec->catfile( File::Spec->tmpdir, 'rt_attachemnt_abcde.txt' );
51     open( my $fh, '>', $file ) or die $!;
52     binmode $fh, ':utf8';
53     print $fh '附件';
54     close $fh;
55
56     $m->get_ok( $baseurl . '/Ticket/Create.html?Queue=1' );
57
58     $m->form_number(3);
59     $m->submit_form(
60         form_number => 3,
61         fields => { Subject => '标题', Content => '测试', Attach => $file },
62     );
63     $m->content_like( qr/Ticket \d+ created/i, 'created the ticket' );
64     $m->follow_link_ok( { text => 'with headers' },
65         '-> /Ticket/Attachment/WithHeaders/...' );
66
67     # subject is in the parent attachment, so there is no 标题
68     $m->content_lacks( '标题', 'does not have content 标题' );
69     $m->content_contains( '测试', 'has content 测试' );
70
71     my ( $id ) = $m->uri =~ /(\d+)$/;
72     ok( $id, 'found attachment id' );
73     my $attachment = RT::Attachment->new( $RT::SystemUser );
74     ok($attachment->Load($id), "load att $id");
75     # let make original encoding to gbk
76     ok( $attachment->SetHeader( 'X-RT-Original-Encoding' => 'gbk' ),
77         'set original encoding to gbk' );
78     $m->get( $m->uri );
79     $m->content_lacks( '标题', 'does not have content 标题' );
80     $m->content_contains( '测试', 'has content 测试' );
81
82
83     $m->back;
84     $m->back;
85     $m->follow_link_ok( { text_regex => qr/by Enoch Root/ },
86         '-> /Ticket/Attachment/...' );
87     $m->content_contains( '附件', 'has content 附件' );
88
89     ( $id ) = $m->uri =~ /(\d+)\D+$/;
90     ok( $id, 'found attachment id' );
91     $attachment = RT::Attachment->new( $RT::SystemUser );
92     ok($attachment->Load($id), "load att $id");
93
94     # let make original encoding to gbk
95     ok( $attachment->SetHeader( 'X-RT-Original-Encoding' => 'gbk' ),
96         'set original encoding to gbk' );
97     $m->get( $m->uri );
98     $m->content_contains( '附件', 'has content 附件' );
99
100     unlink $file;
101 }
102
103