import rt 3.8.9
[freeside.git] / rt / t / web / ticket_txn_content.t
1 #!/usr/bin/perl -w
2 use strict;
3
4 use RT::Test tests => 37;
5 use File::Temp 'tempfile';
6 use File::Spec;
7 my ( $plain_fh, $plain_file ) =
8   tempfile( 'rttestXXXXXX', SUFFIX => '.txt', UNLINK => 1, TMPDIR => 1 );
9 print $plain_fh "this is plain content";
10 close $plain_fh;
11 my $plain_name = (File::Spec->splitpath($plain_file))[-1];
12
13 my ( $html_fh, $html_file ) =
14   tempfile( 'rttestXXXXXX', SUFFIX => '.html', UNLINK => 1, TMPDIR => 1 );
15 print $html_fh "this is html content";
16 close $html_fh;
17 my $html_name = (File::Spec->splitpath($html_file))[-1];
18
19 my ($baseurl, $m) = RT::Test->started_ok;
20 ok $m->login, 'logged in';
21
22 my $queue = RT::Queue->new($RT::Nobody);
23 my $qid = $queue->Load('General');
24 ok( $qid, "Loaded General queue" );
25
26 RT::Test->set_mail_catcher;
27 RT::Test->clean_caught_mails;
28
29 for my $type ( 'text/plain', 'text/html' ) {
30     $m->form_name('CreateTicketInQueue');
31     $m->field( 'Queue', $qid );
32     $m->submit;
33     is( $m->status, 200, "request successful" );
34     $m->content_like( qr/Create a new ticket/, 'ticket create page' );
35
36     $m->form_name('TicketCreate');
37     $m->field( 'Subject', 'with plain attachment' );
38     $m->field( 'Attach',  $plain_file );
39     $m->field( 'Content', 'this is main content' );
40     $m->field( 'ContentType', $type ) unless $type eq 'text/plain';
41     $m->submit;
42     is( $m->status, 200, "request successful" );
43     $m->content_like( qr/with plain attachment/,
44         'we have subject on the page' );
45     $m->content_like( qr/this is main content/, 'main content' );
46     $m->content_like( qr/Download $plain_name/, 'download plain file link' );
47
48     my ( $mail ) = RT::Test->fetch_caught_mails;
49     like( $mail, qr/this is main content/, 'email contains main content' );
50     # check the email link in page too
51     $m->follow_link_ok( { text => 'Show' }, 'show the email outgoing' );
52     $m->content_like( qr/this is main content/, 'email contains main content');
53     $m->back;
54
55     $m->follow_link_ok( { text => 'Reply' }, "reply to the ticket" );
56     $m->form_name('TicketUpdate');
57     $m->field( 'Attach', $plain_file );
58     $m->click('AddMoreAttach');
59     is( $m->status, 200, "request successful" );
60
61     $m->form_name('TicketUpdate');
62     $m->field( 'Attach',        $html_file );
63     # add UpdateCc so we can get email record
64     $m->field( 'UpdateCc',      'rt-test@example.com' );
65     $m->field( 'UpdateContent', 'this is main reply content' );
66     $m->field( 'UpdateContentType', $type ) unless $type eq 'text/plain';
67     $m->click('SubmitTicket');
68     is( $m->status, 200, "request successful" );
69
70     $m->content_like( qr/this is main reply content/, 'main reply content' );
71     $m->content_like( qr/Download $html_name/, 'download html file link' );
72
73     ( $mail ) = RT::Test->fetch_caught_mails;
74     like( $mail, qr/this is main reply content/, 'email contains main reply content' );
75     # check the email link in page too
76     $m->follow_link_ok( { text => 'Show', n => 2 }, 'show the email outgoing' );
77     $m->content_like( qr/this is main reply content/, 'email contains main reply content');
78     $m->back;
79 }