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 require HTML::FormatText::WithLinks::AndTables;
88 skip "Only fails with older verions of HTML::FormatText::WithLinks::AndTables", 9
89 unless $HTML::FormatText::WithLinks::AndTables::VERSION < 0.03;
90 diag "Failing HTML -> Text conversion";
92 my $body = '<table><tr><td><table><tr><td>Foo</td></tr></table></td></tr></table>';
94 ($ok, $tmsg) = $t->Correspond(
95 MIMEObj => HTML::Mason::Commands::MakeMIMEEntity(
100 } { from => qr/RT System/,
101 bcc => 'root@localhost',
102 subject => qr/\Q[example.com #1] The internet is broken\E/,
103 body => qr{Ticket URL: <a href="(http://localhost:\d+/Ticket/Display\.html\?id=1)">\1</a>.+?$body}s,
104 'Content-Type' => qr{text/html}, # TODO
105 },{ from => qr/RT System/,
106 to => 'enduser@example.com',
107 subject => qr/\Q[example.com #1] The internet is broken\E/,
109 'Content-Type' => qr{text/html}, # TODO
111 } [(qr/uninitialized value/, qr/Failed to downgrade HTML/)x3];
115 diag "Admin Comment in HTML";
117 ($ok, $tmsg) = $t->Comment(
118 MIMEObj => HTML::Mason::Commands::MakeMIMEEntity(
119 Body => '<p>Comment test, <em>please!</em></p>',
123 } { from => qr/RT System/,
124 bcc => 'root@localhost',
125 subject => qr/\Q[example.com #1] [Comment] The internet is broken\E/,
127 'This is a comment about (\[\d+\])?ticket.1(\s*[(<]http://localhost:\d+/Ticket/Display\.html\?id=1[)>])?\..+?'.
128 'It is not sent to the Requestor\(s\):.+?'.
129 'Comment test, _?please!_?',
131 '<p>This is a comment about <a href="http://localhost:\d+/Ticket/Display\.html\?id=1">ticket 1</a>\. '.
132 'It is not sent to the Requestor\(s\):</p>.+?'.
133 '<p>Comment test, <em>please!</em></p>',
135 'Content-Type' => qr{multipart},
139 diag "Resolved in HTML templates";
141 ($ok, $tmsg) = $t->SetStatus('resolved');
142 } { from => qr/RT System/,
143 to => 'enduser@example.com',
144 subject => qr/\Q[example.com #1] Resolved: The internet is broken\E/,
146 'According to our records, your request has been resolved\.',
147 '<p>According to our records, your request has been resolved\.',
149 'Content-Type' => qr{multipart},
153 diag "Status changes in HTML";
154 my $scrip = RT::Scrip->new(RT->SystemUser);
155 my ($sval, $smsg) =$scrip->Create(
156 ScripCondition => 'On Status Change',
157 ScripAction => 'Notify Requestors',
158 Template => 'Status Change in HTML',
160 Description => 'Tell requestors about status changes'
163 ok ($scrip->Id, "Created the scrip");
164 ok ($scrip->TemplateObj->Id, "Created the scrip template");
165 ok ($scrip->ConditionObj->Id, "Created the scrip condition");
166 ok ($scrip->ActionObj->Id, "Created the scrip action");
169 ($ok, $tmsg) = $t->SetStatus('stalled');
170 } { from => qr/RT System/,
171 to => 'enduser@example.com',
172 subject => qr/\Q[example.com #1] Status Changed to: stalled\E/,
174 'http://localhost:\d+/Ticket/Display\.html\?id=1.+?',
175 '<a href="(http://localhost:\d+/Ticket/Display\.html\?id=1)">\1</a>'
177 'Content-Type' => qr{multipart},
183 my ($text, $html) = @_;
185 my $pattern = 'Content-Type: text/plain.+?' . $text . '.+?' .
186 'Content-Type: text/html.+?' . $html;
188 return qr/$pattern/s;