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 => 'rt-test, rt-to@example.com',
40 Cc => 'rt-cc@example.com',
42 button => 'ForwardAndReturn'
44 $m->content_contains( 'Sent email successfully', 'sent mail msg' );
46 'Forwarded Ticket to rt-test, rt-to@example.com, rt-cc@example.com',
48 my ($mail) = RT::Test->fetch_caught_mails;
49 like( $mail, qr!Subject: test forward!, 'Subject field' );
50 like( $mail, qr!To: rt-test, rt-to\@example.com!, 'To field' );
51 like( $mail, qr!Cc: rt-cc\@example.com!i, 'Cc field' );
52 like( $mail, qr!This is a forward of ticket!, 'content' );
53 like( $mail, qr!this is an attachment!, 'att content' );
54 like( $mail, qr!$att_name!, 'att file name' );
57 diag "Forward Transaction" if $ENV{TEST_VERBOSE};
59 $m->follow_link_ok( { text => 'Forward', n => 2 }, 'follow 2nd Forward' );
61 form_name => 'ForwardMessage',
63 To => 'rt-test, rt-to@example.com',
64 Cc => 'rt-cc@example.com',
65 Bcc => 'rt-bcc@example.com'
67 button => 'ForwardAndReturn'
69 $m->content_contains( 'Sent email successfully', 'sent mail msg' );
71 qr/Forwarded Transaction #\d+ to rt-test, rt-to\@example.com, rt-cc\@example.com, rt-bcc\@example.com/,
74 my ($mail) = RT::Test->fetch_caught_mails;
75 like( $mail, qr!Subject: test forward!, 'Subject field' );
76 like( $mail, qr!To: rt-test, rt-to\@example.com!, 'To field' );
77 like( $mail, qr!Cc: rt-cc\@example.com!i, 'Cc field' );
78 like( $mail, qr!Bcc: rt-bcc\@example.com!i, 'Bcc field' );
79 like( $mail, qr!This is a forward of transaction!, 'content' );
80 like( $mail, qr!$att_name!, 'att file name' );
81 like( $mail, qr!this is an attachment!, 'att content' );
84 diag "Forward Ticket without content" if $ENV{TEST_VERBOSE};
86 my $ticket = RT::Test->create_ticket(
87 Subject => 'test forward without content',
90 $m->get_ok( $baseurl . '/Ticket/Forward.html?id=' . $ticket->id );
92 form_name => 'ForwardMessage',
93 fields => { To => 'rt-test@example.com', },
94 button => 'ForwardAndReturn'
96 $m->content_contains( 'Sent email successfully', 'sent mail msg' );
97 my ($mail) = RT::Test->fetch_caught_mails;
98 like( $mail, qr/Subject: Fwd: \[example\.com #\d\] test forward without content/, 'Subject field' );
99 like( $mail, qr/To: rt-test\@example\.com/, 'To field' );
100 like( $mail, qr/This is a forward of ticket #\d/, 'content' );
103 diag "Forward Transaction with attachments but empty content" if $ENV{TEST_VERBOSE};
105 # Create a ticket without content but with a non-text/plain attachment
106 $m->get_ok( $baseurl . '/Ticket/Create.html?Queue=1' );
108 $m->form_name('TicketCreate');
109 my $attach = $m->current_form->find_input('Attach');
110 $attach->filename("awesome.patch");
111 $attach->headers('Content-Type' => 'text/x-diff');
113 Subject => 'test forward, empty content but attachments',
114 Attach => $att_file, # from up top
116 $m->click('AddMoreAttach');
117 $m->form_name('TicketCreate');
118 $attach = $m->current_form->find_input('Attach');
119 $attach->filename("bpslogo.png");
120 $attach->headers('Content-Type' => 'image/png');
122 Attach => RT::Test::get_relocatable_file('bpslogo.png', '..', 'data'), # an image!
125 $m->content_like( qr/Ticket \d+ created/i, 'created the ticket' );
126 $m->content_like( qr/awesome\.patch/, 'uploaded patch file' );
127 $m->content_like( qr/text\/x-diff/, 'uploaded patch file content type' );
128 $m->content_like( qr/bpslogo\.png/, 'uploaded image file' );
129 $m->content_like( qr/image\/png/, 'uploaded image file content type' );
130 RT::Test->clean_caught_mails;
132 $m->follow_link_ok( { text => 'Forward', n => 2 }, 'follow 2nd Forward' );
134 form_name => 'ForwardMessage',
136 To => 'rt-test@example.com',
138 button => 'ForwardAndReturn'
140 $m->content_contains( 'Sent email successfully', 'sent mail msg' );
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/awesome\.patch/, '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 => '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_contains( 'Sent email successfully', 'sent mail msg' );
199 $m->content_like( qr/Forwarded Transaction #\d+ to rt-test\@example\.com/, 'txn msg' );
202 $m->follow_link_ok( { text => 'Forward', n => 1 }, 'follow 1st Forward' );
204 form_name => 'ForwardMessage',
206 To => 'rt-test@example.com',
208 button => 'ForwardAndReturn'
210 $m->content_contains( 'Sent email successfully', 'sent mail msg' );
211 $m->content_like( qr/Forwarded Ticket to rt-test\@example\.com/, 'txn msg' );
213 my ($forward_txn, $forward_ticket) = RT::Test->fetch_caught_mails;
214 my $tag = qr/Fwd: \[example\.com #\d+\]/;
215 like( $forward_txn, qr/Subject: $tag attachments for everyone/, 'Subject field is from txn' );
216 like( $forward_txn, qr/This is a forward of transaction/, 'forward description' );
217 like( $forward_ticket, qr/Subject: $tag test forward, attachments but no "content"/, 'Subject field is from ticket' );
218 like( $forward_ticket, qr/This is a forward of ticket/, 'forward description' );
220 for my $mail ($forward_txn, $forward_ticket) {
221 like( $mail, qr/To: rt-test\@example.com/, 'To field' );
222 like( $mail, qr/awesome\.patch/, 'att file name' );
223 like( $mail, qr/this is an attachment/, 'att content' );
224 like( $mail, qr/text\/x-diff/, 'att content type' );
225 like( $mail, qr/bpslogo\.png/, 'att image file name' );
226 like( $mail, qr/image\/png/, 'att image content type' );
229 RT::Test->clean_caught_mails;
231 diag "Forward Ticket Template with a Subject: line" if $ENV{TEST_VERBOSE};
234 require RT::Template;
235 my $template = RT::Template->new($RT::SystemUser);
236 $template->Load('Forward Ticket');
238 # prepend a Subject: line
239 $template->SetContent("Subject: OVERRIDING SUBJECT\n\n" . $template->Content);
241 my $ticket = RT::Test->create_ticket(
242 Subject => 'test ticket',
246 $m->goto_ticket($ticket->Id);
249 { id => 'page-actions-forward' },
250 'follow 1st Forward to forward ticket'
254 form_name => 'ForwardMessage',
256 To => 'rt-to@example.com',
258 button => 'ForwardAndReturn'
261 my ($mail) = RT::Test->fetch_caught_mails;
262 like($mail, qr/Subject: OVERRIDING SUBJECT/);