5 use RT::Test tests => undef;
7 my $att_file = File::Spec->catfile( RT::Test->temp_directory, 'attachment' );
8 open my $att_fh, '>', $att_file or die $!;
9 print $att_fh "this is an attachment";
11 my $att_name = ( File::Spec->splitpath($att_file) )[-1];
13 my ( $baseurl, $m ) = RT::Test->started_ok;
14 ok $m->login, 'logged in as root';
16 # Create a ticket with content and an attachment
17 $m->get_ok( $baseurl . '/Ticket/Create.html?Queue=1' );
20 form_name => 'TicketCreate',
22 Subject => 'test forward',
23 Content => 'this is content',
27 $m->content_like( qr/Ticket \d+ created/i, 'created the ticket' );
28 RT::Test->clean_caught_mails;
30 diag "Forward Ticket" if $ENV{TEST_VERBOSE};
33 { id => 'page-actions-forward' },
34 'follow 1st Forward to forward ticket'
38 form_name => 'ForwardMessage',
40 To => 'rt-test, rt-to@example.com',
41 Cc => 'rt-cc@example.com',
43 button => 'ForwardAndReturn'
45 $m->content_contains( 'Sent email successfully', 'sent mail msg' );
47 'Forwarded Ticket to rt-test, rt-to@example.com, rt-cc@example.com',
49 my ($mail) = RT::Test->fetch_caught_mails;
50 like( $mail, qr!Subject: test forward!, 'Subject field' );
51 like( $mail, qr!To: rt-test, rt-to\@example.com!, 'To field' );
52 like( $mail, qr!Cc: rt-cc\@example.com!, 'Cc field' );
53 like( $mail, qr!This is a forward of ticket!, 'content' );
54 like( $mail, qr!this is an attachment!, 'att content' );
55 like( $mail, qr!$att_name!, 'att file name' );
58 diag "Forward Transaction" if $ENV{TEST_VERBOSE};
60 $m->follow_link_ok( { text => 'Forward', n => 2 }, 'follow 2nd Forward' );
62 form_name => 'ForwardMessage',
64 To => 'rt-test, rt-to@example.com',
65 Cc => 'rt-cc@example.com',
66 Bcc => 'rt-bcc@example.com'
68 button => 'ForwardAndReturn'
70 $m->content_contains( 'Sent email successfully', 'sent mail msg' );
72 qr/Forwarded Transaction #\d+ to rt-test, rt-to\@example.com, rt-cc\@example.com, rt-bcc\@example.com/,
75 my ($mail) = RT::Test->fetch_caught_mails;
76 like( $mail, qr!Subject: test forward!, 'Subject field' );
77 like( $mail, qr!To: rt-test, rt-to\@example.com!, 'To field' );
78 like( $mail, qr!Cc: rt-cc\@example.com!, 'Cc field' );
79 like( $mail, qr!Bcc: rt-bcc\@example.com!, 'Bcc field' );
80 like( $mail, qr!This is a forward of transaction!, 'content' );
81 like( $mail, qr!$att_name!, 'att file name' );
82 like( $mail, qr!this is an attachment!, 'att content' );
85 diag "Forward Ticket without content" if $ENV{TEST_VERBOSE};
87 my $ticket = RT::Test->create_ticket(
88 Subject => 'test forward without content',
91 $m->get_ok( $baseurl . '/Ticket/Forward.html?id=' . $ticket->id );
93 form_name => 'ForwardMessage',
94 fields => { To => 'rt-test@example.com', },
95 button => 'ForwardAndReturn'
97 $m->content_contains( 'Sent email successfully', 'sent mail msg' );
98 my ($mail) = RT::Test->fetch_caught_mails;
99 like( $mail, qr/Subject: Fwd: \[example\.com #\d\] 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.patch");
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\.patch/, '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_contains( 'Sent email successfully', 'sent mail msg' );
142 $m->content_like( qr/Forwarded Transaction #\d+ to rt-test\@example\.com/, 'txn msg' );
143 my ($mail) = RT::Test->fetch_caught_mails;
144 like( $mail, qr/Subject: test forward, empty content but attachments/, 'Subject field' );
145 like( $mail, qr/To: rt-test\@example.com/, 'To field' );
146 like( $mail, qr/This is a forward of transaction/, 'content' );
147 like( $mail, qr/awesome\.patch/, 'att file name' );
148 like( $mail, qr/this is an attachment/, 'att content' );
149 like( $mail, qr/text\/x-diff/, 'att content type' );
150 like( $mail, qr/bpslogo\.png/, 'att image file name' );
151 like( $mail, qr/image\/png/, 'att image content type' );
154 diag "Forward Transaction with attachments but no 'content' part" if $ENV{TEST_VERBOSE};
156 my $mime = MIME::Entity->build(
157 From => 'test@example.com',
158 Subject => 'attachments for everyone',
159 Type => 'multipart/mixed',
164 Type => 'text/x-diff',
165 Filename => 'awesome.patch',
166 Disposition => 'attachment',
170 Path => RT::Test::get_relocatable_file('bpslogo.png', '..', 'data'),
172 Filename => 'bpslogo.png',
173 Encoding => 'base64',
174 Disposition => 'attachment',
177 my $ticket = RT::Test->create_ticket(
179 Subject => 'test forward, attachments but no "content"',
183 $m->get_ok( $baseurl . '/Ticket/Display.html?id=' . $ticket->Id );
184 $m->content_like( qr/awesome\.patch/, 'uploaded patch file' );
185 $m->content_like( qr/text\/x-diff/, 'uploaded patch file content type' );
186 $m->content_like( qr/bpslogo\.png/, 'uploaded image file' );
187 $m->content_like( qr/image\/png/, 'uploaded image file content type' );
188 RT::Test->clean_caught_mails;
191 $m->follow_link_ok( { text => 'Forward', n => 2 }, 'follow 2nd Forward' );
193 form_name => 'ForwardMessage',
195 To => 'rt-test@example.com',
197 button => 'ForwardAndReturn'
199 $m->content_contains( 'Sent email successfully', 'sent mail msg' );
200 $m->content_like( qr/Forwarded Transaction #\d+ to rt-test\@example\.com/, 'txn msg' );
203 $m->follow_link_ok( { text => 'Forward', n => 1 }, 'follow 1st Forward' );
205 form_name => 'ForwardMessage',
207 To => 'rt-test@example.com',
209 button => 'ForwardAndReturn'
211 $m->content_contains( 'Sent email successfully', 'sent mail msg' );
212 $m->content_like( qr/Forwarded Ticket to rt-test\@example\.com/, 'txn msg' );
214 my ($forward_txn, $forward_ticket) = RT::Test->fetch_caught_mails;
215 my $tag = qr/Fwd: \[example\.com #\d+\]/;
216 like( $forward_txn, qr/Subject: $tag attachments for everyone/, 'Subject field is from txn' );
217 like( $forward_txn, qr/This is a forward of transaction/, 'forward description' );
218 like( $forward_ticket, qr/Subject: $tag test forward, attachments but no "content"/, 'Subject field is from ticket' );
219 like( $forward_ticket, qr/This is a forward of ticket/, 'forward description' );
221 for my $mail ($forward_txn, $forward_ticket) {
222 like( $mail, qr/To: rt-test\@example.com/, 'To field' );
223 like( $mail, qr/awesome\.patch/, 'att file name' );
224 like( $mail, qr/this is an attachment/, 'att content' );
225 like( $mail, qr/text\/x-diff/, 'att content type' );
226 like( $mail, qr/bpslogo\.png/, 'att image file name' );
227 like( $mail, qr/image\/png/, 'att image content type' );
230 RT::Test->clean_caught_mails;
232 diag "Forward Ticket Template with a Subject: line" if $ENV{TEST_VERBOSE};
235 require RT::Template;
236 my $template = RT::Template->new($RT::SystemUser);
237 $template->Load('Forward Ticket');
239 # prepend a Subject: line
240 $template->SetContent("Subject: OVERRIDING SUBJECT\n\n" . $template->Content);
242 my $ticket = RT::Test->create_ticket(
243 Subject => 'test ticket',
247 $m->goto_ticket($ticket->Id);
250 { id => 'page-actions-forward' },
251 'follow 1st Forward to forward ticket'
255 form_name => 'ForwardMessage',
257 To => 'rt-to@example.com',
259 button => 'ForwardAndReturn'
262 my ($mail) = RT::Test->fetch_caught_mails;
263 like($mail, qr/Subject: OVERRIDING SUBJECT/);