4 use RT::Test tests => 159;
6 use constant LogoFile => $RT::StaticPath .'/images/bpslogo.png';
7 use constant FaviconFile => $RT::StaticPath .'/images/favicon.png';
8 use constant TextFile => $RT::StaticPath .'/css/mobile.css';
10 my ($url, $m) = RT::Test->started_ok;
11 ok $m->login, 'logged in';
13 my $queue = RT::Test->load_or_create_queue( Name => 'General' );
14 ok( $queue && $queue->id, "Loaded General queue" );
16 diag "create a ticket in full interface";
17 diag "w/o attachments";
19 $m->goto_create_ticket( $queue );
20 is($m->status, 200, "request successful");
22 $m->form_name('TicketCreate');
23 $m->content_contains("Create a new ticket", 'ticket create page');
25 is($m->status, 200, "request successful");
28 diag "with one attachment";
30 $m->goto_create_ticket( $queue );
32 $m->form_name('TicketCreate');
33 $m->field('Subject', 'Attachments test');
34 $m->field('Attach', LogoFile);
35 $m->field('Content', 'Some content');
38 is($m->status, 200, "request successful");
40 $m->content_contains('Attachments test', 'we have subject on the page');
41 $m->content_contains('Some content', 'and content');
42 $m->content_contains('Download bpslogo.png', 'page has file name');
45 diag "with two attachments";
47 $m->goto_create_ticket( $queue );
49 $m->form_name('TicketCreate');
50 $m->field('Attach', LogoFile);
51 $m->click('AddMoreAttach');
52 is($m->status, 200, "request successful");
54 $m->form_name('TicketCreate');
55 $m->field('Attach', FaviconFile);
56 $m->field('Subject', 'Attachments test');
57 $m->field('Content', 'Some content');
60 is($m->status, 200, "request successful");
62 $m->content_contains('Attachments test', 'we have subject on the page');
63 $m->content_contains('Some content', 'and content');
64 $m->content_contains('Download bpslogo.png', 'page has file name');
65 $m->content_contains('Download favicon.png', 'page has file name');
68 diag "with one attachment, but delete one along the way";
70 $m->goto_create_ticket( $queue );
72 $m->form_name('TicketCreate');
73 $m->field('Attach', LogoFile);
74 $m->click('AddMoreAttach');
75 is($m->status, 200, "request successful");
77 $m->form_name('TicketCreate');
78 $m->field('Attach', FaviconFile);
79 $m->tick( 'DeleteAttach', LogoFile );
80 $m->field('Subject', 'Attachments test');
81 $m->field('Content', 'Some content');
84 is($m->status, 200, "request successful");
86 $m->content_contains('Attachments test', 'we have subject on the page');
87 $m->content_contains('Some content', 'and content');
88 $m->content_lacks('Download bpslogo.png', 'page has file name');
89 $m->content_contains('Download favicon.png', 'page has file name');
92 diag "with one attachment, but delete one along the way";
94 $m->goto_create_ticket( $queue );
96 $m->form_name('TicketCreate');
97 $m->field('Attach', LogoFile);
98 $m->click('AddMoreAttach');
99 is($m->status, 200, "request successful");
101 $m->form_name('TicketCreate');
102 $m->tick( 'DeleteAttach', LogoFile );
103 $m->click('AddMoreAttach');
104 is($m->status, 200, "request successful");
106 $m->form_name('TicketCreate');
107 $m->field('Attach', FaviconFile);
108 $m->click('AddMoreAttach');
109 is($m->status, 200, "request successful");
111 $m->form_name('TicketCreate');
112 $m->field('Subject', 'Attachments test');
113 $m->field('Content', 'Some content');
116 is($m->status, 200, "request successful");
118 $m->content_contains('Attachments test', 'we have subject on the page');
119 $m->content_contains('Some content', 'and content');
120 $m->content_lacks('Download bpslogo.png', 'page has file name');
121 $m->content_contains('Download favicon.png', 'page has file name');
124 diag "reply to a ticket in full interface";
125 diag "with one attachment";
127 my $ticket = RT::Test->create_ticket(
129 Subject => 'Attachments test',
130 Content => 'Some content',
133 $m->goto_ticket( $ticket->id );
134 $m->follow_link_ok({text => 'Reply'}, "reply to the ticket");
135 $m->form_name('TicketUpdate');
136 $m->field('Attach', LogoFile);
137 $m->field('UpdateContent', 'Message');
138 $m->click('SubmitTicket');
139 is($m->status, 200, "request successful");
141 $m->content_contains('Download bpslogo.png', 'page has file name');
144 diag "with two attachments";
146 my $ticket = RT::Test->create_ticket(
148 Subject => 'Attachments test',
149 Content => 'Some content',
152 $m->goto_ticket( $ticket->id );
153 $m->follow_link_ok({text => 'Reply'}, "reply to the ticket");
154 $m->form_name('TicketUpdate');
155 $m->field('Attach', LogoFile);
156 $m->click('AddMoreAttach');
157 is($m->status, 200, "request successful");
159 $m->form_name('TicketUpdate');
160 $m->field('Attach', FaviconFile);
161 $m->field('UpdateContent', 'Message');
162 $m->click('SubmitTicket');
163 is($m->status, 200, "request successful");
165 $m->content_contains('Download bpslogo.png', 'page has file name');
166 $m->content_contains('Download favicon.png', 'page has file name');
169 diag "with one attachment, delete one along the way";
171 my $ticket = RT::Test->create_ticket(
173 Subject => 'Attachments test',
174 Content => 'Some content',
177 $m->goto_ticket( $ticket->id );
178 $m->follow_link_ok({text => 'Reply'}, "reply to the ticket");
179 $m->form_name('TicketUpdate');
180 $m->field('Attach', LogoFile);
181 $m->click('AddMoreAttach');
182 is($m->status, 200, "request successful");
184 $m->form_name('TicketUpdate');
185 $m->tick('DeleteAttach', LogoFile);
186 $m->field('Attach', FaviconFile);
187 $m->field('UpdateContent', 'Message');
188 $m->click('SubmitTicket');
189 is($m->status, 200, "request successful");
191 $m->content_lacks('Download bpslogo.png', 'page has file name');
192 $m->content_contains('Download favicon.png', 'page has file name');
195 diag "jumbo interface";
196 diag "with one attachment";
198 my $ticket = RT::Test->create_ticket(
200 Subject => 'Attachments test',
201 Content => 'Some content',
204 $m->goto_ticket( $ticket->id );
205 $m->follow_link_ok({text => 'Jumbo'}, "jumbo the ticket");
206 $m->form_name('TicketModifyAll');
207 $m->field('Attach', LogoFile);
208 $m->field('UpdateContent', 'Message');
209 $m->click('SubmitTicket');
210 is($m->status, 200, "request successful");
212 $m->goto_ticket( $ticket->id );
213 $m->content_contains('Download bpslogo.png', 'page has file name');
216 diag "with two attachments";
218 my $ticket = RT::Test->create_ticket(
220 Subject => 'Attachments test',
221 Content => 'Some content',
224 $m->goto_ticket( $ticket->id );
225 $m->follow_link_ok({text => 'Jumbo'}, "jumbo the ticket");
226 $m->form_name('TicketModifyAll');
227 $m->field('Attach', LogoFile);
228 $m->click('AddMoreAttach');
229 is($m->status, 200, "request successful");
231 $m->form_name('TicketModifyAll');
232 $m->field('Attach', FaviconFile);
233 $m->field('UpdateContent', 'Message');
234 $m->click('SubmitTicket');
235 is($m->status, 200, "request successful");
237 $m->goto_ticket( $ticket->id );
238 $m->content_contains('Download bpslogo.png', 'page has file name');
239 $m->content_contains('Download favicon.png', 'page has file name');
242 diag "with one attachment, delete one along the way";
244 my $ticket = RT::Test->create_ticket(
246 Subject => 'Attachments test',
247 Content => 'Some content',
250 $m->goto_ticket( $ticket->id );
251 $m->follow_link_ok({text => 'Jumbo'}, "jumbo the ticket");
252 $m->form_name('TicketModifyAll');
253 $m->field('Attach', LogoFile);
254 $m->click('AddMoreAttach');
255 is($m->status, 200, "request successful");
257 $m->form_name('TicketModifyAll');
258 $m->tick('DeleteAttach', LogoFile);
259 $m->field('Attach', FaviconFile);
260 $m->field('UpdateContent', 'Message');
261 $m->click('SubmitTicket');
262 is($m->status, 200, "request successful");
264 $m->goto_ticket( $ticket->id );
265 $m->content_lacks('Download bpslogo.png', 'page has file name');
266 $m->content_contains('Download favicon.png', 'page has file name');
270 diag "one attachment";
272 my @tickets = RT::Test->create_tickets(
275 Subject => 'Attachments test',
276 Content => 'Some content',
281 my $query = join ' OR ', map "id=$_", map $_->id, @tickets;
283 $m->get_ok( $url . "/Search/Bulk.html?Query=$query&Rows=10" );
285 $m->form_name('BulkUpdate');
286 $m->field('Attach', FaviconFile);
287 $m->field('UpdateContent', 'Message');
289 is($m->status, 200, "request successful");
291 foreach my $ticket ( @tickets ) {
292 $m->goto_ticket( $ticket->id );
293 $m->content_lacks('Download bpslogo.png', 'page has file name');
294 $m->content_contains('Download favicon.png', 'page has file name');
298 diag "two attachments";
300 my @tickets = RT::Test->create_tickets(
303 Subject => 'Attachments test',
304 Content => 'Some content',
309 my $query = join ' OR ', map "id=$_", map $_->id, @tickets;
311 $m->get_ok( $url . "/Search/Bulk.html?Query=$query&Rows=10" );
313 $m->form_name('BulkUpdate');
314 $m->field('Attach', LogoFile);
315 $m->click('AddMoreAttach');
316 is($m->status, 200, "request successful");
318 $m->form_name('BulkUpdate');
319 $m->field('Attach', FaviconFile);
320 $m->field('UpdateContent', 'Message');
322 is($m->status, 200, "request successful");
324 foreach my $ticket ( @tickets ) {
325 $m->goto_ticket( $ticket->id );
326 $m->content_contains('Download bpslogo.png', 'page has file name');
327 $m->content_contains('Download favicon.png', 'page has file name');
331 diag "one attachment, delete one along the way";
333 my @tickets = RT::Test->create_tickets(
336 Subject => 'Attachments test',
337 Content => 'Some content',
342 my $query = join ' OR ', map "id=$_", map $_->id, @tickets;
344 $m->get_ok( $url . "/Search/Bulk.html?Query=$query&Rows=10" );
346 $m->form_name('BulkUpdate');
347 $m->field('Attach', LogoFile);
348 $m->click('AddMoreAttach');
349 is($m->status, 200, "request successful");
351 $m->form_name('BulkUpdate');
352 $m->tick('DeleteAttach', LogoFile);
353 $m->field('Attach', FaviconFile);
354 $m->field('UpdateContent', 'Message');
356 is($m->status, 200, "request successful");
358 foreach my $ticket ( @tickets ) {
359 $m->goto_ticket( $ticket->id );
360 $m->content_lacks('Download bpslogo.png', 'page has file name');
361 $m->content_contains('Download favicon.png', 'page has file name');
366 diag "create with attachment";
368 $m->get_ok( $url . "/SelfService/Create.html?Queue=". $queue->id );
370 $m->form_name('TicketCreate');
371 $m->field('Attach', FaviconFile);
372 $m->field('Subject', 'Subject');
373 $m->field('Content', 'Message');
374 ok($m->current_form->find_input('AddMoreAttach'), "more than one attachment");
376 is($m->status, 200, "request successful");
378 $m->content_contains('Download favicon.png', 'page has file name');
381 diag "update with attachment";
383 my $ticket = RT::Test->create_ticket(
385 Subject => 'Attachments test',
386 Content => 'Some content',
389 $m->get_ok( $url . "/SelfService/Update.html?id=". $ticket->id );
390 $m->form_name('TicketUpdate');
391 $m->field('Attach', FaviconFile);
392 $m->field('UpdateContent', 'Message');
393 ok($m->current_form->find_input('AddMoreAttach'), "more than one attachment");
394 $m->click('SubmitTicket');
395 is($m->status, 200, "request successful");
397 $m->content_contains('Download favicon.png', 'page has file name');
402 diag "simple create + reply";
404 $m->get_ok( $url . '/m/ticket/create?Queue=' . $queue->id );
406 $m->form_name('TicketCreate');
407 $m->field('Subject', 'Attachments test');
408 $m->field('Attach', LogoFile);
409 $m->field('Content', 'Some content');
411 is($m->status, 200, "request successful");
413 $m->content_contains('Attachments test', 'we have subject on the page');
414 $m->content_contains('bpslogo.png', 'page has file name');
416 $m->follow_link_ok({text => 'Reply'}, "reply to the ticket");
417 $m->form_name('TicketUpdate');
418 $m->field('Attach', LogoFile);
419 $m->click('AddMoreAttach');
420 is($m->status, 200, "request successful");
422 $m->form_name('TicketUpdate');
423 $m->field('Attach', FaviconFile);
424 $m->field('UpdateContent', 'Message');
425 $m->click('SubmitTicket');
426 is($m->status, 200, "request successful");
428 $m->content_contains('bpslogo.png', 'page has file name');
429 $m->content_contains('favicon.png', 'page has file name');
433 diag "check content type and content";
435 $m->goto_create_ticket( $queue );
437 $m->form_name('TicketCreate');
438 $m->field('Attach', LogoFile);
439 $m->click('AddMoreAttach');
440 is($m->status, 200, "request successful");
442 $m->form_name('TicketCreate');
443 $m->field('Attach', TextFile);
444 $m->field('Subject', 'Attachments test');
445 $m->field('Content', 'Some content');
448 is($m->status, 200, "request successful");
450 $m->content_contains('Attachments test', 'we have subject on the page');
451 $m->content_contains('Some content', 'and content');
452 $m->content_contains('Download bpslogo.png', 'page has file name');
453 $m->content_contains('Download mobile.css', 'page has file name');
455 $m->follow_link_ok({text => "Download bpslogo.png"});
456 is($m->response->header('Content-Type'), 'image/png', 'Content-Type of png lacks charset' );
457 is($m->content_type, "image/png");
458 is($m->content, RT::Test->file_content(LogoFile), "Binary content matches");
461 $m->follow_link_ok( { text => 'Download mobile.css' } );
462 is( $m->response->header('Content-Type'),
463 'text/css;charset=UTF-8',
464 'Content-Type of text has charset',
466 is($m->content_type, "text/css");
467 is($m->content, RT::Test->file_content(TextFile), "Text content matches");
470 diag "concurent actions";
471 my $m2 = RT::Test::Web->new;
472 ok $m2->login, 'second login';
474 diag "update and create";
476 my $ticket = RT::Test->create_ticket(
478 Subject => 'Attachments test',
479 Content => 'Some content',
482 $m2->goto_ticket( $ticket->id );
483 $m2->follow_link_ok({text => 'Reply'}, "reply to the ticket");
484 $m2->form_name('TicketUpdate');
485 $m2->field('Attach', LogoFile);
486 $m2->click('AddMoreAttach');
487 is($m2->status, 200, "request successful");
489 $m->goto_create_ticket( $queue );
491 $m->form_name('TicketCreate');
492 $m->field('Attach', FaviconFile);
493 $m->field('Subject', 'Attachments test');
494 $m->field('Content', 'Some content');
496 is($m->status, 200, "request successful");
498 $m->content_lacks('Download bpslogo.png', 'page has file name');
499 $m->content_contains('Download favicon.png', 'page has file name');
501 $m2->form_name('TicketUpdate');
502 $m2->click('SubmitTicket');
503 $m2->content_contains('Download bpslogo.png', 'page has file name');
504 $m2->content_lacks('Download favicon.png', 'page has no file name');