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