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