fix ticketing system error on bootstrap of new install
[freeside.git] / rt / t / web / attachments.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => 159;
5
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';
9
10 my ($url, $m) = RT::Test->started_ok;
11 ok $m->login, 'logged in';
12
13 my $queue = RT::Test->load_or_create_queue( Name => 'General' );
14 ok( $queue && $queue->id, "Loaded General queue" );
15
16 diag "create a ticket in full interface";
17 diag "w/o attachments";
18 {
19     $m->goto_create_ticket( $queue );
20     is($m->status, 200, "request successful");
21
22     $m->form_name('TicketCreate');
23     $m->content_contains("Create a new ticket", 'ticket create page');
24     $m->submit;
25     is($m->status, 200, "request successful");
26 }
27
28 diag "with one attachment";
29 {
30     $m->goto_create_ticket( $queue );
31
32     $m->form_name('TicketCreate');
33     $m->field('Subject', 'Attachments test');
34     $m->field('Attach',  LogoFile);
35     $m->field('Content', 'Some content');
36
37     $m->submit;
38     is($m->status, 200, "request successful");
39
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');
43 }
44
45 diag "with two attachments";
46 {
47     $m->goto_create_ticket( $queue );
48
49     $m->form_name('TicketCreate');
50     $m->field('Attach',  LogoFile);
51     $m->click('AddMoreAttach');
52     is($m->status, 200, "request successful");
53
54     $m->form_name('TicketCreate');
55     $m->field('Attach',  FaviconFile);
56     $m->field('Subject', 'Attachments test');
57     $m->field('Content', 'Some content');
58
59     $m->submit;
60     is($m->status, 200, "request successful");
61
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');
66 }
67
68 diag "with one attachment, but delete one along the way";
69 {
70     $m->goto_create_ticket( $queue );
71
72     $m->form_name('TicketCreate');
73     $m->field('Attach',  LogoFile);
74     $m->click('AddMoreAttach');
75     is($m->status, 200, "request successful");
76
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');
82
83     $m->submit;
84     is($m->status, 200, "request successful");
85
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');
90 }
91
92 diag "with one attachment, but delete one along the way";
93 {
94     $m->goto_create_ticket( $queue );
95
96     $m->form_name('TicketCreate');
97     $m->field('Attach',  LogoFile);
98     $m->click('AddMoreAttach');
99     is($m->status, 200, "request successful");
100
101     $m->form_name('TicketCreate');
102     $m->tick( 'DeleteAttach', LogoFile );
103     $m->click('AddMoreAttach');
104     is($m->status, 200, "request successful");
105
106     $m->form_name('TicketCreate');
107     $m->field('Attach',  FaviconFile);
108     $m->click('AddMoreAttach');
109     is($m->status, 200, "request successful");
110
111     $m->form_name('TicketCreate');
112     $m->field('Subject', 'Attachments test');
113     $m->field('Content', 'Some content');
114
115     $m->submit;
116     is($m->status, 200, "request successful");
117
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');
122 }
123
124 diag "reply to a ticket in full interface";
125 diag "with one attachment";
126 {
127     my $ticket = RT::Test->create_ticket(
128         Queue   => $queue,
129         Subject => 'Attachments test',
130         Content => 'Some content',
131     );
132
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");
140
141     $m->content_contains('Download bpslogo.png', 'page has file name');
142 }
143
144 diag "with two attachments";
145 {
146     my $ticket = RT::Test->create_ticket(
147         Queue   => $queue,
148         Subject => 'Attachments test',
149         Content => 'Some content',
150     );
151
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");
158
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");
164
165     $m->content_contains('Download bpslogo.png', 'page has file name');
166     $m->content_contains('Download favicon.png', 'page has file name');
167 }
168
169 diag "with one attachment, delete one along the way";
170 {
171     my $ticket = RT::Test->create_ticket(
172         Queue   => $queue,
173         Subject => 'Attachments test',
174         Content => 'Some content',
175     );
176
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");
183
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");
190
191     $m->content_lacks('Download bpslogo.png', 'page has file name');
192     $m->content_contains('Download favicon.png', 'page has file name');
193 }
194
195 diag "jumbo interface";
196 diag "with one attachment";
197 {
198     my $ticket = RT::Test->create_ticket(
199         Queue   => $queue,
200         Subject => 'Attachments test',
201         Content => 'Some content',
202     );
203
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");
211
212     $m->goto_ticket( $ticket->id );
213     $m->content_contains('Download bpslogo.png', 'page has file name');
214 }
215
216 diag "with two attachments";
217 {
218     my $ticket = RT::Test->create_ticket(
219         Queue   => $queue,
220         Subject => 'Attachments test',
221         Content => 'Some content',
222     );
223
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");
230
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");
236
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');
240 }
241
242 diag "with one attachment, delete one along the way";
243 {
244     my $ticket = RT::Test->create_ticket(
245         Queue   => $queue,
246         Subject => 'Attachments test',
247         Content => 'Some content',
248     );
249
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");
256
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");
263
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');
267 }
268
269 diag "bulk update";
270 diag "one attachment";
271 {
272     my @tickets = RT::Test->create_tickets(
273         {
274             Queue   => $queue,
275             Subject => 'Attachments test',
276             Content => 'Some content',
277         },
278         {},
279         {},
280     );
281     my $query = join ' OR ', map "id=$_", map $_->id, @tickets;
282     $query =~ s/ /%20/g;
283     $m->get_ok( $url . "/Search/Bulk.html?Query=$query&Rows=10" );
284
285     $m->form_name('BulkUpdate');
286     $m->field('Attach',  FaviconFile);
287     $m->field('UpdateContent', 'Message');
288     $m->submit;
289     is($m->status, 200, "request successful");
290
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');
295     }
296 }
297
298 diag "two attachments";
299 {
300     my @tickets = RT::Test->create_tickets(
301         {
302             Queue   => $queue,
303             Subject => 'Attachments test',
304             Content => 'Some content',
305         },
306         {},
307         {},
308     );
309     my $query = join ' OR ', map "id=$_", map $_->id, @tickets;
310     $query =~ s/ /%20/g;
311     $m->get_ok( $url . "/Search/Bulk.html?Query=$query&Rows=10" );
312
313     $m->form_name('BulkUpdate');
314     $m->field('Attach',  LogoFile);
315     $m->click('AddMoreAttach');
316     is($m->status, 200, "request successful");
317
318     $m->form_name('BulkUpdate');
319     $m->field('Attach',  FaviconFile);
320     $m->field('UpdateContent', 'Message');
321     $m->submit;
322     is($m->status, 200, "request successful");
323
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');
328     }
329 }
330
331 diag "one attachment, delete one along the way";
332 {
333     my @tickets = RT::Test->create_tickets(
334         {
335             Queue   => $queue,
336             Subject => 'Attachments test',
337             Content => 'Some content',
338         },
339         {},
340         {},
341     );
342     my $query = join ' OR ', map "id=$_", map $_->id, @tickets;
343     $query =~ s/ /%20/g;
344     $m->get_ok( $url . "/Search/Bulk.html?Query=$query&Rows=10" );
345
346     $m->form_name('BulkUpdate');
347     $m->field('Attach',  LogoFile);
348     $m->click('AddMoreAttach');
349     is($m->status, 200, "request successful");
350
351     $m->form_name('BulkUpdate');
352     $m->tick('DeleteAttach',  LogoFile);
353     $m->field('Attach',  FaviconFile);
354     $m->field('UpdateContent', 'Message');
355     $m->submit;
356     is($m->status, 200, "request successful");
357
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');
362     }
363 }
364
365 diag "self service";
366 diag "create with attachment";
367 {
368     $m->get_ok( $url . "/SelfService/Create.html?Queue=". $queue->id );
369
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");
375     $m->submit;
376     is($m->status, 200, "request successful");
377
378     $m->content_contains('Download favicon.png', 'page has file name');
379 }
380
381 diag "update with attachment";
382 {
383     my $ticket = RT::Test->create_ticket(
384         Queue   => $queue,
385         Subject => 'Attachments test',
386         Content => 'Some content',
387     );
388
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");
396
397     $m->content_contains('Download favicon.png', 'page has file name');
398 }
399
400 diag "mobile ui";
401
402 diag "simple create + reply";
403 {
404     $m->get_ok( $url . '/m/ticket/create?Queue=' . $queue->id );
405
406     $m->form_name('TicketCreate');
407     $m->field('Subject', 'Attachments test');
408     $m->field('Attach',  LogoFile);
409     $m->field('Content', 'Some content');
410     $m->submit;
411     is($m->status, 200, "request successful");
412
413     $m->content_contains('Attachments test', 'we have subject on the page');
414     $m->content_contains('bpslogo.png', 'page has file name');
415
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");
421
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");
427
428     $m->content_contains('bpslogo.png', 'page has file name');
429     $m->content_contains('favicon.png', 'page has file name');
430 }
431
432
433 diag "check content type and content";
434 {
435     $m->goto_create_ticket( $queue );
436
437     $m->form_name('TicketCreate');
438     $m->field('Attach',  LogoFile);
439     $m->click('AddMoreAttach');
440     is($m->status, 200, "request successful");
441
442     $m->form_name('TicketCreate');
443     $m->field('Attach',  TextFile);
444     $m->field('Subject', 'Attachments test');
445     $m->field('Content', 'Some content');
446
447     $m->submit;
448     is($m->status, 200, "request successful");
449
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');
454
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");
459     $m->back;
460
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',
465     );
466     is($m->content_type, "text/css");
467     is($m->content, RT::Test->file_content(TextFile), "Text content matches");
468 }
469
470 diag "concurent actions";
471 my $m2 = RT::Test::Web->new;
472 ok $m2->login, 'second login';
473
474 diag "update and create";
475 {
476     my $ticket = RT::Test->create_ticket(
477         Queue   => $queue,
478         Subject => 'Attachments test',
479         Content => 'Some content',
480     );
481
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");
488
489     $m->goto_create_ticket( $queue );
490
491     $m->form_name('TicketCreate');
492     $m->field('Attach',  FaviconFile);
493     $m->field('Subject', 'Attachments test');
494     $m->field('Content', 'Some content');
495     $m->submit;
496     is($m->status, 200, "request successful");
497
498     $m->content_lacks('Download bpslogo.png', 'page has file name');
499     $m->content_contains('Download favicon.png', 'page has file name');
500
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');
505 }
506