3 use RT::Test tests => undef;
8 my $root = RT::User->new(RT->SystemUser);
12 my $q = RT::Queue->new(RT->SystemUser);
14 my ($ok, $msg) = $q->AddWatcher( Type => 'AdminCc', PrincipalId => $root->Id );
15 ok($ok, "Added root as a watcher on the General queue");
17 # Create a couple users to test notifications
19 for my $user_name (qw(enduser tech)) {
20 my $user = $users{$user_name} = RT::User->new(RT->SystemUser);
21 $user->Create( Name => ucfirst($user_name),
23 EmailAddress => $user_name.'@example.com');
25 ($val, $msg) = $user->PrincipalObj->GrantRight(Object =>$q, Right => $_)
26 for qw(ModifyTicket OwnTicket ShowTicket);
29 my $t = RT::Ticket->new(RT->SystemUser);
30 my ($tid, $ttrans, $tmsg);
32 diag "Autoreply and AdminCc (Transaction)";
34 ($tid, $ttrans, $tmsg) =
35 $t->Create(Subject => "The internet is broken",
36 Owner => 'Tech', Requestor => 'Enduser',
38 } { from => qr/The default queue/,
39 to => 'enduser@example.com',
40 subject => qr/\Q[example.com #1] AutoReply: The internet is broken\E/,
42 'trouble ticket regarding \*?The internet is broken\*?',
43 'trouble ticket regarding <b>The internet is broken</b>'
45 'Content-Type' => qr{multipart},
46 },{ from => qr/RT System/,
47 bcc => 'root@localhost',
48 subject => qr/\Q[example.com #1] The internet is broken\E/,
50 'Request (\[\d+\])?1(\s*[(<]http://localhost:\d+/Ticket/Display\.html\?id=1[)>])?\s*was acted upon by RT_System',
51 'Request <a href="http://localhost:\d+/Ticket/Display\.html\?id=1">1</a> was acted upon by RT_System\.</b>'
53 'Content-Type' => qr{multipart},
56 diag "Admin Correspondence and Correspondence";
58 ($ok, $tmsg) = $t->Correspond(
59 MIMEObj => HTML::Mason::Commands::MakeMIMEEntity(
60 Body => '<p>This is a test of <b>HTML</b> correspondence.</p>',
64 } { from => qr/RT System/,
65 bcc => 'root@localhost',
66 subject => qr/\Q[example.com #1] The internet is broken\E/,
68 'Ticket URL: (?:\[\d+\])?http://localhost:\d+/Ticket/Display\.html\?id=1.+?'.
69 'This is a test of \*?HTML\*? correspondence\.',
70 'Ticket URL: <a href="(http://localhost:\d+/Ticket/Display\.html\?id=1)">\1</a>.+?'.
71 '<p>This is a test of <b>HTML</b> correspondence\.</p>'
73 'Content-Type' => qr{multipart},
74 },{ from => qr/RT System/,
75 to => 'enduser@example.com',
76 subject => qr/\Q[example.com #1] The internet is broken\E/,
78 'This is a test of \*?HTML\*? correspondence\.',
79 '<p>This is a test of <b>HTML</b> correspondence\.</p>'
81 'Content-Type' => qr{multipart},
85 skip "Only fails on core HTMLFormatter", 9
86 unless RT->Config->Get("HTMLFormatter") eq "core";
87 diag "Failing HTML -> Text conversion";
89 my $body = '<table><tr><td><table><tr><td>Foo</td></tr></table></td></tr></table>';
91 ($ok, $tmsg) = $t->Correspond(
92 MIMEObj => HTML::Mason::Commands::MakeMIMEEntity(
97 } { from => qr/RT System/,
98 bcc => 'root@localhost',
99 subject => qr/\Q[example.com #1] The internet is broken\E/,
100 body => qr{Ticket URL: <a href="(http://localhost:\d+/Ticket/Display\.html\?id=1)">\1</a>.+?$body}s,
101 'Content-Type' => qr{text/html}, # TODO
102 },{ from => qr/RT System/,
103 to => 'enduser@example.com',
104 subject => qr/\Q[example.com #1] The internet is broken\E/,
106 'Content-Type' => qr{text/html}, # TODO
108 } [(qr/uninitialized value/, qr/Failed to downgrade HTML/)x3];
112 diag "Admin Comment in HTML";
114 ($ok, $tmsg) = $t->Comment(
115 MIMEObj => HTML::Mason::Commands::MakeMIMEEntity(
116 Body => '<p>Comment test, <em>please!</em></p>',
120 } { from => qr/RT System/,
121 bcc => 'root@localhost',
122 subject => qr/\Q[example.com #1] [Comment] The internet is broken\E/,
124 'This is a comment about (\[\d+\])?ticket.1(\s*[(<]http://localhost:\d+/Ticket/Display\.html\?id=1[)>])?\..+?'.
125 'It is not sent to the Requestor\(s\):.+?'.
126 'Comment test, _?please!_?',
128 '<p>This is a comment about <a href="http://localhost:\d+/Ticket/Display\.html\?id=1">ticket 1</a>\. '.
129 'It is not sent to the Requestor\(s\):</p>.+?'.
130 '<p>Comment test, <em>please!</em></p>',
132 'Content-Type' => qr{multipart},
136 diag "Resolved in HTML templates";
138 ($ok, $tmsg) = $t->SetStatus('resolved');
139 } { from => qr/RT System/,
140 to => 'enduser@example.com',
141 subject => qr/\Q[example.com #1] Resolved: The internet is broken\E/,
143 'According to our records, your request has been resolved\.',
144 '<p>According to our records, your request has been resolved\.',
146 'Content-Type' => qr{multipart},
150 diag "Status changes in HTML";
151 my $scrip = RT::Scrip->new(RT->SystemUser);
152 my ($sval, $smsg) =$scrip->Create(
153 ScripCondition => 'On Status Change',
154 ScripAction => 'Notify Requestors',
155 Template => 'Status Change in HTML',
157 Description => 'Tell requestors about status changes'
160 ok ($scrip->Id, "Created the scrip");
161 ok ($scrip->TemplateObj->Id, "Created the scrip template");
162 ok ($scrip->ConditionObj->Id, "Created the scrip condition");
163 ok ($scrip->ActionObj->Id, "Created the scrip action");
166 ($ok, $tmsg) = $t->SetStatus('stalled');
167 } { from => qr/RT System/,
168 to => 'enduser@example.com',
169 subject => qr/\Q[example.com #1] Status Changed to: stalled\E/,
171 'http://localhost:\d+/Ticket/Display\.html\?id=1.+?',
172 '<a href="(http://localhost:\d+/Ticket/Display\.html\?id=1)">\1</a>'
174 'Content-Type' => qr{multipart},
180 my ($text, $html) = @_;
182 my $pattern = 'Content-Type: text/plain.+?' . $text . '.+?' .
183 'Content-Type: text/html.+?' . $html;
185 return qr/$pattern/s;