5 use RT::Test tests => 32;
6 my ( $baseurl, $m ) = RT::Test->started_ok;
7 ok $m->login, 'logged in as root';
11 my $subject = Encode::decode("UTF-8",'标题');
12 my $content = Encode::decode("UTF-8",'测试');
13 my $filename = Encode::decode("UTF-8",'附件.txt');
15 diag 'test without attachments' if $ENV{TEST_VERBOSE};
18 $m->get_ok( $baseurl . '/Ticket/Create.html?Queue=1' );
20 $m->form_name('TicketModify');
23 fields => { Subject => $subject, Content => $content },
25 $m->content_like( qr/Ticket \d+ created/i, 'created the ticket' );
26 $m->follow_link_ok( { text => 'with headers' },
27 '-> /Ticket/Attachment/WithHeaders/...' );
28 $m->content_contains( $subject, "has subject $subject" );
29 $m->content_contains( $content, "has content $content" );
31 my ( $id ) = $m->uri =~ /(\d+)$/;
32 ok( $id, 'found attachment id' );
33 my $attachment = RT::Attachment->new( $RT::SystemUser );
34 ok($attachment->Load($id), "load att $id");
35 # let make original encoding to gbk
36 ok( $attachment->SetHeader( 'X-RT-Original-Encoding' => 'gbk' ),
37 'set original encoding to gbk' );
39 $m->content_contains( $subject, "has subject $subject" );
40 $m->content_contains( $content, "has content $content" );
43 diag 'test with attachemnts' if $ENV{TEST_VERBOSE};
48 File::Spec->catfile( RT::Test->temp_directory, Encode::encode("UTF-8",$filename) );
49 open( my $fh, '>', $file ) or die $!;
54 $m->get_ok( $baseurl . '/Ticket/Create.html?Queue=1' );
56 $m->form_name('TicketModify');
59 fields => { Subject => $subject, Content => $content, Attach => $file },
61 $m->content_like( qr/Ticket \d+ created/i, 'created the ticket' );
62 $m->content_contains( $filename, 'attached filename' );
63 $m->content_lacks( Encode::encode("UTF-8",$filename), 'no double encoded attached filename' );
64 $m->follow_link_ok( { text => 'with headers' },
65 '-> /Ticket/Attachment/WithHeaders/...' );
67 # subject is in the parent attachment, so there is no 标题
68 $m->content_lacks( $subject, "does not have content $subject" );
69 $m->content_contains( $content, "has content $content" );
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' );
79 $m->content_lacks( $subject, "does not have content $subject" );
80 $m->content_contains( $content, "has content $content" );
85 $m->follow_link_ok( { text => "Download $filename" },
86 '-> /Ticket/Attachment/...' );
87 $m->content_contains( $filename, "has file content $filename" );
89 ( $id ) = $m->uri =~ m{/(\d+)/[^/]+$};
90 ok( $id, 'found attachment id' );
91 $attachment = RT::Attachment->new( $RT::SystemUser );
92 ok($attachment->Load($id), "load att $id");
94 # let make original encoding to gbk
95 ok( $attachment->SetHeader( 'X-RT-Original-Encoding' => 'gbk' ),
96 'set original encoding to gbk' );
98 $m->content_contains( $filename, "has content $filename" );