Update httemplate/elements/selectlayers.html
[freeside.git] / rt / t / web / ticket_forward.t
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use RT::Test tests => undef;
6 use File::Spec;
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";
10 close $att_fh;
11 my $att_name = ( File::Spec->splitpath($att_file) )[-1];
12
13 my ( $baseurl, $m ) = RT::Test->started_ok;
14 ok $m->login, 'logged in as root';
15
16 # Create a ticket with content and an attachment
17 $m->get_ok( $baseurl . '/Ticket/Create.html?Queue=1' );
18
19 $m->submit_form(
20     form_name => 'TicketCreate',
21     fields    => {
22         Subject => 'test forward',
23         Content => 'this is content',
24         Attach  => $att_file,
25     },
26 );
27 $m->content_like( qr/Ticket \d+ created/i, 'created the ticket' );
28 RT::Test->clean_caught_mails;
29
30 diag "Forward Ticket" if $ENV{TEST_VERBOSE};
31 {
32     $m->follow_link_ok(
33         { id => 'page-actions-forward' },
34         'follow 1st Forward to forward ticket'
35     );
36
37     $m->submit_form(
38         form_name => 'ForwardMessage',
39         fields    => {
40             To => 'rt-test, rt-to@example.com',
41             Cc => 'rt-cc@example.com',
42         },
43         button => 'ForwardAndReturn'
44     );
45     $m->content_contains( 'Sent email successfully', 'sent mail msg' );
46     $m->content_contains(
47         'Forwarded Ticket to rt-test, rt-to@example.com, rt-cc@example.com',
48         'txn msg' );
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' );
56 }
57
58 diag "Forward Transaction" if $ENV{TEST_VERBOSE};
59 {
60     $m->follow_link_ok( { text => 'Forward', n => 2 }, 'follow 2nd Forward' );
61     $m->submit_form(
62         form_name => 'ForwardMessage',
63         fields    => {
64             To  => 'rt-test, rt-to@example.com',
65             Cc  => 'rt-cc@example.com',
66             Bcc => 'rt-bcc@example.com'
67         },
68         button => 'ForwardAndReturn'
69     );
70     $m->content_contains( 'Sent email successfully', 'sent mail msg' );
71     $m->content_like(
72 qr/Forwarded Transaction #\d+ to rt-test, rt-to\@example.com, rt-cc\@example.com, rt-bcc\@example.com/,
73         'txn msg'
74     );
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' );
83 }
84
85 diag "Forward Ticket without content" if $ENV{TEST_VERBOSE};
86 {
87     my $ticket = RT::Test->create_ticket(
88         Subject => 'test forward without content',
89         Queue   => 1,
90     );
91     $m->get_ok( $baseurl . '/Ticket/Forward.html?id=' . $ticket->id );
92     $m->submit_form(
93         form_name => 'ForwardMessage',
94         fields    => { To => 'rt-test@example.com', },
95         button    => 'ForwardAndReturn'
96     );
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' );
102 }
103
104 diag "Forward Transaction with attachments but empty content" if $ENV{TEST_VERBOSE};
105 {
106     # Create a ticket without content but with a non-text/plain attachment
107     $m->get_ok( $baseurl . '/Ticket/Create.html?Queue=1' );
108
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');
113     $m->set_fields(
114         Subject => 'test forward, empty content but attachments',
115         Attach  => $att_file, # from up top
116     );
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');
122     $m->set_fields(
123         Attach  => RT::Test::get_relocatable_file('bpslogo.png', '..', 'data'), # an image!
124     );
125     $m->submit;
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;
132
133     $m->follow_link_ok( { text => 'Forward', n => 2 }, 'follow 2nd Forward' );
134     $m->submit_form(
135         form_name => 'ForwardMessage',
136         fields    => {
137             To  => 'rt-test@example.com',
138         },
139         button => 'ForwardAndReturn'
140     );
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' );
152 }
153
154 diag "Forward Transaction with attachments but no 'content' part" if $ENV{TEST_VERBOSE};
155 {
156     my $mime = MIME::Entity->build(
157         From    => 'test@example.com',
158         Subject => 'attachments for everyone',
159         Type    => 'multipart/mixed',
160     );
161
162     $mime->attach(
163         Path        => $att_file,
164         Type        => 'text/x-diff',
165         Filename    => 'awesome.patch',
166         Disposition => 'attachment',
167     );
168     
169     $mime->attach(
170         Path        => RT::Test::get_relocatable_file('bpslogo.png', '..', 'data'),
171         Type        => 'image/png',
172         Filename    => 'bpslogo.png',
173         Encoding    => 'base64',
174         Disposition => 'attachment',
175     );
176
177     my $ticket = RT::Test->create_ticket(
178         Queue   => 1,
179         Subject => 'test forward, attachments but no "content"',
180         MIMEObj => $mime,
181     );
182
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;
189
190     # Forward txn
191     $m->follow_link_ok( { text => 'Forward', n => 2 }, 'follow 2nd Forward' );
192     $m->submit_form(
193         form_name => 'ForwardMessage',
194         fields    => {
195             To  => 'rt-test@example.com',
196         },
197         button => 'ForwardAndReturn'
198     );
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' );
201     
202     # Forward ticket
203     $m->follow_link_ok( { text => 'Forward', n => 1 }, 'follow 1st Forward' );
204     $m->submit_form(
205         form_name => 'ForwardMessage',
206         fields    => {
207             To  => 'rt-test@example.com',
208         },
209         button => 'ForwardAndReturn'
210     );
211     $m->content_contains( 'Sent email successfully', 'sent mail msg' );
212     $m->content_like( qr/Forwarded Ticket to rt-test\@example\.com/, 'txn msg' );
213
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' );
220
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' );
228     }
229 }
230 RT::Test->clean_caught_mails;
231
232 diag "Forward Ticket Template with a Subject: line" if $ENV{TEST_VERBOSE};
233 {
234
235     require RT::Template;
236     my $template = RT::Template->new($RT::SystemUser);
237     $template->Load('Forward Ticket');
238
239     # prepend a Subject: line
240     $template->SetContent("Subject: OVERRIDING SUBJECT\n\n" . $template->Content);
241
242     my $ticket = RT::Test->create_ticket(
243         Subject => 'test ticket',
244         Queue   => 1,
245     );
246
247     $m->goto_ticket($ticket->Id);
248
249     $m->follow_link_ok(
250         { id => 'page-actions-forward' },
251         'follow 1st Forward to forward ticket'
252     );
253
254     $m->submit_form(
255         form_name => 'ForwardMessage',
256         fields    => {
257             To => 'rt-to@example.com',
258         },
259         button => 'ForwardAndReturn'
260     );
261
262     my ($mail) = RT::Test->fetch_caught_mails;
263     like($mail, qr/Subject: OVERRIDING SUBJECT/);
264 }
265
266 undef $m;
267 done_testing;