4 use RT::Test tests => 63;
5 my $plain_file = File::Spec->catfile( RT::Test->temp_directory, 'attachment.txt' );
6 open my $plain_fh, '>', $plain_file or die $!;
7 print $plain_fh "this is plain content";
9 my $plain_name = (File::Spec->splitpath($plain_file))[-1];
11 my $html_file = File::Spec->catfile( RT::Test->temp_directory, 'attachment.html' );
12 open my $html_fh, '>', $html_file or die $!;
13 print $html_fh "this is plain content";
15 my $html_name = (File::Spec->splitpath($html_file))[-1];
17 my ($baseurl, $m) = RT::Test->started_ok;
18 ok $m->login, 'logged in';
20 my $queue = RT::Queue->new(RT->Nobody);
21 my $qid = $queue->Load('General');
22 ok( $qid, "Loaded General queue" );
24 RT::Test->clean_caught_mails;
26 sub follow_parent_with_headers_link {
28 my $link = $m->find_link(@_)->url;
29 $link =~ s{/(\d+)$}{"/" . ($1-1)}e; # get the parent attach
30 $m->get_ok($baseurl . $link);
33 sub follow_with_headers_link {
35 my $link = $m->find_link(@_)->url;
36 $link =~ s{/\d+/(\d+)/.+$}{/WithHeaders/$1}; # frob into a with headers url
37 $m->get_ok($baseurl . $link);
40 for my $type ( 'text/plain', 'text/html' ) {
41 $m->form_name('CreateTicketInQueue');
42 $m->field( 'Queue', $qid );
44 is( $m->status, 200, "request successful" );
45 $m->content_contains('Create a new ticket', 'ticket create page' );
47 $m->form_name('TicketCreate');
48 $m->field( 'Subject', 'with plain attachment' );
49 $m->field( 'Attach', $plain_file );
50 $m->field( 'Content', 'this is main content' );
51 $m->field( 'ContentType', $type ) unless $type eq 'text/plain';
53 is( $m->status, 200, "request successful" );
54 $m->content_contains('with plain attachment',
55 'we have subject on the page' );
56 $m->content_contains('this is main content', 'main content' );
57 $m->content_contains("Download $plain_name", 'download plain file link' );
59 # Check for Message-IDs
60 follow_parent_with_headers_link($m, text => 'with headers', n => 1);
61 $m->content_like(qr/^Message-ID:/im, 'create content has one Message-ID');
62 $m->content_unlike(qr/^Message-ID:.+?Message-ID:/ism, 'but not two Message-IDs');
65 follow_with_headers_link($m, text => "Download $plain_name", n => 1);
66 $m->content_unlike(qr/^Message-ID:/im, 'attachment lacks a Message-ID');
69 my ( $mail ) = RT::Test->fetch_caught_mails;
70 like( $mail, qr/this is main content/, 'email contains main content' );
71 # check the email link in page too
72 $m->follow_link_ok( { text => 'Show' }, 'show the email outgoing' );
73 $m->content_contains('this is main content', 'email contains main content');
76 $m->follow_link_ok( { text => 'Reply' }, "reply to the ticket" );
77 $m->form_name('TicketUpdate');
78 $m->field( 'Attach', $plain_file );
79 $m->click('AddMoreAttach');
80 is( $m->status, 200, "request successful" );
82 $m->form_name('TicketUpdate');
83 $m->field( 'Attach', $html_file );
84 # add UpdateCc so we can get email record
85 $m->field( 'UpdateCc', 'rt-test@example.com' );
86 $m->field( 'UpdateContent', 'this is main reply content' );
87 $m->field( 'UpdateContentType', $type ) unless $type eq 'text/plain';
88 $m->click('SubmitTicket');
89 is( $m->status, 200, "request successful" );
91 $m->content_contains("this is main reply content", 'main reply content' );
92 $m->content_contains("Download $html_name", 'download html file link' );
94 # Check for Message-IDs
95 follow_parent_with_headers_link($m, text => 'with headers', n => 2);
96 $m->content_like(qr/^Message-ID:/im, 'correspondence has one Message-ID');
97 $m->content_unlike(qr/^Message-ID:.+?Message-ID:/ism, 'but not two Message-IDs');
100 follow_with_headers_link($m, text => "Download $plain_name", n => 2);
101 $m->content_unlike(qr/^Message-ID:/im, 'text/plain attach lacks a Message-ID');
104 follow_with_headers_link($m, text => "Download $html_name", n => 1);
105 $m->content_unlike(qr/^Message-ID:/im, 'text/html attach lacks a Message-ID');
108 ( $mail ) = RT::Test->fetch_caught_mails;
109 like( $mail, qr/this is main reply content/, 'email contains main reply content' );
110 # check the email link in page too
111 $m->follow_link_ok( { text => 'Show', n => 2 }, 'show the email outgoing' );
112 $m->content_contains("this is main reply content", 'email contains main reply content');