RT 4.0.22
[freeside.git] / rt / t / web / html_template.t
1
2 use strict;
3 use warnings;
4
5 use RT::Test tests => undef;
6 my ( $baseurl, $m ) = RT::Test->started_ok;
7 ok $m->login, 'logged in as root';
8
9 diag('make Autoreply template a html one and add utf8 chars')
10   if $ENV{TEST_VERBOSE};
11
12 my $template = Encode::decode("UTF-8", "你好 éèà€");
13 my $subject  = Encode::decode("UTF-8", "标题");
14 my $content  = Encode::decode("UTF-8", "测试");
15 {
16     $m->follow_link_ok( { id => 'tools-config-global-templates' },     '-> Templates' );
17     $m->follow_link_ok( { text => 'Autoreply' },     '-> Autoreply' );
18
19     $m->submit_form(
20         form_name => 'ModifyTemplate',
21         fields => {
22             Content => <<EOF,
23 Subject: AutoReply: {\$Ticket->Subject}
24 Content-Type: text/html
25
26 $template
27 {\$Ticket->Subject}
28 -------------------------------------------------------------------------
29 {\$Transaction->Content()}
30
31 EOF
32         },
33     );
34     $m->content_like( qr/Content updated/, 'content is changed' );
35     $m->content_contains( $template, 'content is really updated' );
36 }
37
38 diag('create a ticket to see the autoreply mail') if $ENV{TEST_VERBOSE};
39
40 {
41     $m->get_ok( $baseurl . '/Ticket/Create.html?Queue=1' );
42
43     $m->submit_form(
44         form_name => 'TicketCreate',
45         fields      => { Subject => $subject, Content => "<h1>$content</h1>",
46         ContentType => 'text/html' },
47     );
48     $m->content_like( qr/Ticket \d+ created/i, 'created the ticket' );
49     $m->follow_link( text => 'Show' );
50     $m->content_contains( $template, "html has $template" );
51     $m->content_contains( $subject,
52         "html has ticket subject $subject" );
53     $m->content_contains( "&lt;h1&gt;$content&lt;/h1&gt;",
54         "html has ticket html content $content" );
55 }
56
57 diag('test real mail outgoing') if $ENV{TEST_VERBOSE};
58
59 {
60
61     # $mail is utf8 encoded
62     my ($mail) = RT::Test->fetch_caught_mails;
63     $mail = Encode::decode("UTF-8", $mail );
64     like( $mail, qr/$template.*$template/s, 'mail has template content $template twice' );
65     like( $mail, qr/$subject.*$subject/s,   'mail has ticket subject $sujbect twice' );
66     like( $mail, qr/$content.*$content/s,   'mail has ticket content $content twice' );
67     like( $mail, qr!<h1>$content</h1>!,     'mail has ticket html content <h1>$content</h1>' );
68 }
69
70 undef $m;
71 done_testing;