Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / rt / t / web / attachments.t
1 #!/usr/bin/perl -w
2 use strict;
3
4 use RT::Test tests => 33;
5
6 use constant LogoFile => $RT::MasonComponentRoot .'/NoAuth/images/bpslogo.png';
7 use constant FaviconFile => $RT::MasonComponentRoot .'/NoAuth/images/favicon.png';
8 use constant TextFile => $RT::MasonComponentRoot .'/NoAuth/css/print.css';
9
10 my ($baseurl, $m) = RT::Test->started_ok;
11 ok $m->login, 'logged in';
12
13 my $queue = RT::Queue->new(RT->Nobody);
14 my $qid = $queue->Load('General');
15 ok( $qid, "Loaded General queue" );
16
17 $m->form_name('CreateTicketInQueue');
18 $m->field('Queue', $qid);
19 $m->submit;
20 is($m->status, 200, "request successful");
21 $m->content_contains("Create a new ticket", 'ticket create page');
22
23 $m->form_name('TicketCreate');
24 $m->field('Subject', 'Attachments test');
25 $m->field('Attach',  LogoFile);
26 $m->field('Content', 'Some content');
27 $m->submit;
28 is($m->status, 200, "request successful");
29
30 $m->content_contains('Attachments test', 'we have subject on the page');
31 $m->content_contains('Some content', 'and content');
32 $m->content_contains('Download bpslogo.png', 'page has file name');
33
34 open LOGO, "<", LogoFile or die "Can't open logo file: $!";
35 binmode LOGO;
36 my $logo_contents = do {local $/; <LOGO>};
37 close LOGO;
38 $m->follow_link_ok({text => "Download bpslogo.png"});
39 is($m->content_type, "image/png");
40 is($m->content, $logo_contents, "Binary content matches");
41
42 $m->back;
43 $m->follow_link_ok({text => 'Reply'}, "reply to the ticket");
44 $m->form_name('TicketUpdate');
45 $m->field('Attach',  TextFile);
46 $m->click('AddMoreAttach');
47 is($m->status, 200, "request successful");
48
49 $m->form_name('TicketUpdate');
50 $m->field('Attach',  FaviconFile);
51 $m->field('UpdateContent', 'Message');
52 $m->click('SubmitTicket');
53 is($m->status, 200, "request successful");
54
55 $m->content_contains('Download bpslogo.png', 'page has file name');
56 $m->content_contains('Download favicon.png', 'page has file name');
57 $m->content_contains('Download print.css', 'page has file name');
58
59 $m->follow_link_ok( { text => 'Download bpslogo.png' } );
60 is( $m->response->header('Content-Type'), 'image/png', 'Content-Type of png lacks charset' );
61
62 $m->back;
63
64 $m->follow_link_ok( { text => 'Download print.css' } );
65 is( $m->response->header('Content-Type'),
66     'text/css;charset=UTF-8', 'Content-Type of text has charset' );
67
68 diag "test mobile ui";
69 $m->get_ok( $baseurl . '/m/ticket/create?Queue=' . $qid );
70
71 $m->form_name('TicketCreate');
72 $m->field('Subject', 'Attachments test');
73 $m->field('Attach',  LogoFile);
74 $m->field('Content', 'Some content');
75 $m->submit;
76 is($m->status, 200, "request successful");
77
78 $m->content_contains('Attachments test', 'we have subject on the page');
79 $m->content_contains('bpslogo.png', 'page has file name');
80
81 $m->follow_link_ok({text => 'Reply'}, "reply to the ticket");
82 $m->form_name('TicketUpdate');
83 $m->field('Attach',  LogoFile);
84 $m->click('AddMoreAttach');
85 is($m->status, 200, "request successful");
86
87 $m->form_name('TicketUpdate');
88 $m->field('Attach',  FaviconFile);
89 $m->field('UpdateContent', 'Message');
90 $m->click('SubmitTicket');
91 is($m->status, 200, "request successful");
92
93 $m->content_contains('bpslogo.png', 'page has file name');
94 $m->content_contains('favicon.png', 'page has file name');