4 use RT::Test tests => undef;
6 my $att_file = File::Spec->catfile( RT::Test->temp_directory, 'attachment' );
7 open my $att_fh, '>', $att_file or die $!;
8 print $att_fh "this is an attachment";
10 my $att_name = ( File::Spec->splitpath($att_file) )[-1];
12 my ( $baseurl, $m ) = RT::Test->started_ok;
13 ok $m->login, 'logged in as root';
15 # Create a ticket with content and an attachment
16 $m->get_ok( $baseurl . '/Ticket/Create.html?Queue=1' );
19 form_name => 'TicketCreate',
21 Subject => 'test forward',
22 Content => 'this is content',
26 $m->content_like( qr/Ticket \d+ created/i, 'created the ticket' );
27 RT::Test->clean_caught_mails;
29 diag "Forward Ticket" if $ENV{TEST_VERBOSE};
32 { id => 'page-actions-forward' },
33 'follow 1st Forward to forward ticket'
37 form_name => 'ForwardMessage',
39 To => '"Foo" <rt-foo@example.com>, rt-too@example.com',
40 Cc => 'rt-cc@example.com',
43 button => 'ForwardAndReturn'
46 'Forwarded Ticket to Foo <rt-foo@example.com>, <rt-too@example.com>, <rt-cc@example.com>, root (Enoch Root)',
48 my ($mail) = RT::Test->fetch_caught_mails;
49 like( $mail, qr!Subject: test forward!, 'Subject field' );
50 like( $mail, qr!To: .*?rt-foo\@example.com!i, 'To field' );
51 like( $mail, qr!To: .*?rt-too\@example.com!i, 'To field' );
52 like( $mail, qr!Cc: rt-cc\@example.com!i, 'Cc field' );
53 like( $mail, qr!Bcc: root\@localhost!i, 'Bcc field' );
54 like( $mail, qr!This is a forward of ticket!, 'content' );
55 like( $mail, qr!this is an attachment!, 'att content' );
56 like( $mail, qr!$att_name!, 'att file name' );
59 diag "Forward Transaction" if $ENV{TEST_VERBOSE};
61 $m->follow_link_ok( { text => 'Forward', n => 2 }, 'follow 2nd Forward' );
63 form_name => 'ForwardMessage',
65 To => 'rt-to@example.com, rt-too@example.com',
66 Cc => 'rt-cc@example.com',
69 button => 'ForwardAndReturn'
72 qr/Forwarded .*?Transaction #\d+.*? to <rt-to\@example\.com>, <rt-too\@example\.com>, <rt-cc\@example\.com>, root (Enoch Root)/,
75 my ($mail) = RT::Test->fetch_caught_mails;
76 like( $mail, qr!Subject: test forward!, 'Subject field' );
77 like( $mail, qr!To: .*rt-to\@example.com!i, 'To field' );
78 like( $mail, qr!To: .*rt-too\@example.com!i, 'To field' );
79 like( $mail, qr!Cc: rt-cc\@example.com!i, 'Cc field' );
80 like( $mail, qr!Bcc: root\@localhost!i, 'Bcc field' );
81 like( $mail, qr!This is a forward of transaction!, 'content' );
82 like( $mail, qr!$att_name!, 'att file name' );
83 like( $mail, qr!this is an attachment!, 'att content' );
86 diag "Forward Ticket without content" if $ENV{TEST_VERBOSE};
88 my $ticket = RT::Test->create_ticket(
89 Subject => 'test forward without content',
92 $m->get_ok( $baseurl . '/Ticket/Forward.html?id=' . $ticket->id );
94 form_name => 'ForwardMessage',
95 fields => { To => 'rt-test@example.com', },
96 button => 'ForwardAndReturn'
98 my ($mail) = RT::Test->fetch_caught_mails;
99 like( $mail, qr/Subject: \[example\.com #\d\] Fwd: test forward without content/, 'Subject field' );
100 like( $mail, qr/To: rt-test\@example\.com/, 'To field' );
101 like( $mail, qr/This is a forward of ticket #\d/, 'content' );
104 diag "Forward Transaction with attachments but empty content" if $ENV{TEST_VERBOSE};
106 # Create a ticket without content but with a non-text/plain attachment
107 $m->get_ok( $baseurl . '/Ticket/Create.html?Queue=1' );
109 $m->form_name('TicketCreate');
110 my $attach = $m->current_form->find_input('Attach');
111 $attach->filename('awesome.pátch');
112 $attach->headers('Content-Type' => 'text/x-diff');
114 Subject => 'test forward, empty content but attachments',
115 Attach => $att_file, # from up top
117 $m->click('AddMoreAttach');
118 $m->form_name('TicketCreate');
119 $attach = $m->current_form->find_input('Attach');
120 $attach->filename("bpslogo.png");
121 $attach->headers('Content-Type' => 'image/png');
123 Attach => RT::Test::get_relocatable_file('bpslogo.png', '..', 'data'), # an image!
126 $m->content_like( qr/Ticket \d+ created/i, 'created the ticket' );
127 $m->content_like( qr/awesome.p\%C3\%A1tch/, 'uploaded patch file' );
128 $m->content_like( qr/text\/x-diff/, 'uploaded patch file content type' );
129 $m->content_like( qr/bpslogo\.png/, 'uploaded image file' );
130 $m->content_like( qr/image\/png/, 'uploaded image file content type' );
131 RT::Test->clean_caught_mails;
133 $m->follow_link_ok( { text => 'Forward', n => 2 }, 'follow 2nd Forward' );
135 form_name => 'ForwardMessage',
137 To => 'rt-test@example.com',
139 button => 'ForwardAndReturn'
141 $m->content_like( qr/Forwarded .*?Transaction #\d+.*? to <rt-test\@example\.com>/, 'txn msg' );
142 my ($mail) = RT::Test->fetch_caught_mails;
143 like( $mail, qr/Subject: test forward, empty content but attachments/, 'Subject field' );
144 like( $mail, qr/To: rt-test\@example.com/, 'To field' );
145 like( $mail, qr/This is a forward of transaction/, 'content' );
146 like( $mail, qr/filename\*\=\"UTF\-8\'\'awesome.p\%C3\%A1tch\"/, 'att file name' );
147 like( $mail, qr/this is an attachment/, 'att content' );
148 like( $mail, qr/text\/x-diff/, 'att content type' );
149 like( $mail, qr/bpslogo\.png/, 'att image file name' );
150 like( $mail, qr/image\/png/, 'att image content type' );
153 diag "Forward Transaction with attachments but no 'content' part" if $ENV{TEST_VERBOSE};
155 my $mime = MIME::Entity->build(
156 From => '"Tést" <test@example.com>',
157 Subject => 'attachments for everyone',
158 Type => 'multipart/mixed',
163 Type => 'text/x-diff',
164 Filename => 'awesome.patch',
165 Disposition => 'attachment',
169 Path => RT::Test::get_relocatable_file('bpslogo.png', '..', 'data'),
171 Filename => 'bpslogo.png',
172 Encoding => 'base64',
173 Disposition => 'attachment',
176 my $ticket = RT::Test->create_ticket(
178 Subject => 'test forward, attachments but no "content"',
182 $m->get_ok( $baseurl . '/Ticket/Display.html?id=' . $ticket->Id );
183 $m->content_like( qr/awesome\.patch/, 'uploaded patch file' );
184 $m->content_like( qr/text\/x-diff/, 'uploaded patch file content type' );
185 $m->content_like( qr/bpslogo\.png/, 'uploaded image file' );
186 $m->content_like( qr/image\/png/, 'uploaded image file content type' );
187 RT::Test->clean_caught_mails;
190 $m->follow_link_ok( { text => 'Forward', n => 2 }, 'follow 2nd Forward' );
192 form_name => 'ForwardMessage',
194 To => 'rt-test@example.com',
196 button => 'ForwardAndReturn'
198 $m->content_like( qr/Forwarded .*?Transaction #\d+.*? to <rt-test\@example\.com>/, 'txn msg' );
201 $m->follow_link_ok( { text => 'Forward', n => 1 }, 'follow 1st Forward' );
203 form_name => 'ForwardMessage',
205 To => 'rt-test@example.com',
207 button => 'ForwardAndReturn'
209 $m->content_like( qr/Forwarded Ticket to <rt-test\@example\.com>/, 'txn msg' );
211 my ($forward_txn, $forward_ticket) = RT::Test->fetch_caught_mails;
212 my $tag = qr/\[example\.com #\d+\] Fwd:/;
213 like( $forward_txn, qr/Subject: $tag attachments for everyone/, 'Subject field is from txn' );
214 like( $forward_txn, qr/This is a forward of transaction/, 'forward description' );
215 like( $forward_ticket, qr/Subject: $tag test forward, attachments but no "content"/, 'Subject field is from ticket' );
216 like( $forward_ticket, qr/This is a forward of ticket/, 'forward description' );
217 like( $forward_ticket, qr/From: \=\?UTF-8\?.* \<test\@example\.com\>/i );
219 for my $mail ($forward_txn, $forward_ticket) {
220 like( $mail, qr/To: rt-test\@example.com/, 'To field' );
221 like( $mail, qr/awesome\.patch/, 'att file name' );
222 like( $mail, qr/this is an attachment/, 'att content' );
223 like( $mail, qr/text\/x-diff/, 'att content type' );
224 like( $mail, qr/bpslogo\.png/, 'att image file name' );
225 like( $mail, qr/image\/png/, 'att image content type' );
228 RT::Test->clean_caught_mails;
230 diag "Forward Ticket Template with a Subject: line" if $ENV{TEST_VERBOSE};
233 require RT::Template;
234 my $template = RT::Template->new($RT::SystemUser);
235 $template->Load('Forward Ticket');
237 # prepend a Subject: line
238 $template->SetContent("Subject: OVERRIDING SUBJECT\n\n" . $template->Content);
240 my $ticket = RT::Test->create_ticket(
241 Subject => 'test ticket',
245 $m->goto_ticket($ticket->Id);
248 { id => 'page-actions-forward' },
249 'follow 1st Forward to forward ticket'
253 form_name => 'ForwardMessage',
255 To => 'rt-to@example.com',
257 button => 'ForwardAndReturn'
260 my ($mail) = RT::Test->fetch_caught_mails;
261 like($mail, qr/Subject: \[example.com #\d+\] OVERRIDING SUBJECT/);
264 diag "Forward Transaction with non-ascii subject" if $ENV{TEST_VERBOSE};
266 $m->follow_link_ok( { text => 'Forward', n => 2 }, 'follow 2nd Forward' );
267 my $subject = Encode::decode("UTF-8", 'test non-ascii äöü');
269 form_name => 'ForwardMessage',
272 To => 'rt-to@example.com',
274 button => 'ForwardAndReturn'
276 my ($mail) = RT::Test->fetch_caught_mails;
277 if ( $mail =~ /Subject: (.+)/ ) {
278 like( Encode::decode("UTF-8", RT::I18N::DecodeMIMEWordsToUTF8( $1, 'Subject' )), qr/$subject/, 'non-ascii subject' );
280 $m->content_contains( $subject, 'non-ascii subject got displayed correctly' );