1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
use strict;
use warnings;
use RT::Test tests => undef;
use RT::Test::Email;
use Test::Warn;
my $root = RT::User->new(RT->SystemUser);
$root->Load('root');
# Set root as admincc
my $q = RT::Queue->new(RT->SystemUser);
$q->Load('General');
my ($ok, $msg) = $q->AddWatcher( Type => 'AdminCc', PrincipalId => $root->Id );
ok($ok, "Added root as a watcher on the General queue");
# Create a couple users to test notifications
my %users;
for my $user_name (qw(enduser tech)) {
my $user = $users{$user_name} = RT::User->new(RT->SystemUser);
$user->Create( Name => ucfirst($user_name),
Privileged => 1,
EmailAddress => $user_name.'@example.com');
my ($val, $msg);
($val, $msg) = $user->PrincipalObj->GrantRight(Object =>$q, Right => $_)
for qw(ModifyTicket OwnTicket ShowTicket);
}
my $t = RT::Ticket->new(RT->SystemUser);
my ($tid, $ttrans, $tmsg);
diag "Autoreply and AdminCc (Transaction)";
mail_ok {
($tid, $ttrans, $tmsg) =
$t->Create(Subject => "The internet is broken",
Owner => 'Tech', Requestor => 'Enduser',
Queue => 'General');
} { from => qr/The default queue/,
to => 'enduser@example.com',
subject => qr/\Q[example.com #1] AutoReply: The internet is broken\E/,
body => parts_regex(
'trouble ticket regarding The internet is broken',
'trouble ticket regarding <b>The internet is broken</b>'
),
'Content-Type' => qr{multipart},
},{ from => qr/RT System/,
bcc => 'root@localhost',
subject => qr/\Q[example.com #1] The internet is broken\E/,
body => parts_regex(
'Request 1 \(http://localhost:\d+/Ticket/Display\.html\?id=1\)\s+?was acted upon by RT_System',
'Request <a href="http://localhost:\d+/Ticket/Display\.html\?id=1">1</a> was acted upon by RT_System\.</b>'
),
'Content-Type' => qr{multipart},
};
diag "Admin Correspondence and Correspondence";
mail_ok {
($ok, $tmsg) = $t->Correspond(
MIMEObj => HTML::Mason::Commands::MakeMIMEEntity(
Body => '<p>This is a test of <b>HTML</b> correspondence.</p>',
Type => 'text/html',
),
);
} { from => qr/RT System/,
bcc => 'root@localhost',
subject => qr/\Q[example.com #1] The internet is broken\E/,
body => parts_regex(
'Ticket URL: http://localhost:\d+/Ticket/Display\.html\?id=1.+?'.
'This is a test of HTML correspondence\.',
'Ticket URL: <a href="(http://localhost:\d+/Ticket/Display\.html\?id=1)">\1</a>.+?'.
'<p>This is a test of <b>HTML</b> correspondence\.</p>'
),
'Content-Type' => qr{multipart},
},{ from => qr/RT System/,
to => 'enduser@example.com',
subject => qr/\Q[example.com #1] The internet is broken\E/,
body => parts_regex(
'This is a test of HTML correspondence\.',
'<p>This is a test of <b>HTML</b> correspondence\.</p>'
),
'Content-Type' => qr{multipart},
};
diag "Failing HTML -> Text conversion";
warnings_like {
my $body = '<table><tr><td><table><tr><td>Foo</td></tr></table></td></tr></table>';
mail_ok {
($ok, $tmsg) = $t->Correspond(
MIMEObj => HTML::Mason::Commands::MakeMIMEEntity(
Body => $body,
Type => 'text/html',
),
);
} { from => qr/RT System/,
bcc => 'root@localhost',
subject => qr/\Q[example.com #1] The internet is broken\E/,
body => qr{Ticket URL: <a href="(http://localhost:\d+/Ticket/Display\.html\?id=1)">\1</a>.+?$body}s,
'Content-Type' => qr{text/html}, # TODO
},{ from => qr/RT System/,
to => 'enduser@example.com',
subject => qr/\Q[example.com #1] The internet is broken\E/,
body => qr{<table><tr><td><table><tr><td>Foo</td></tr></table></td></tr></table>},
'Content-Type' => qr{text/html}, # TODO
};
} [(qr/uninitialized value/, qr/Failed to downgrade HTML/)x3];
diag "Admin Comment in HTML";
mail_ok {
($ok, $tmsg) = $t->Comment(
MIMEObj => HTML::Mason::Commands::MakeMIMEEntity(
Body => '<p>Comment test, <em>please!</em></p>',
Type => 'text/html',
),
);
} { from => qr/RT System/,
bcc => 'root@localhost',
subject => qr/\Q[example.com #1] [Comment] The internet is broken\E/,
body => parts_regex(
'This is a comment about ticket 1 \(http://localhost:\d+/Ticket/Display\.html\?id=1\)\..+?'.
'It is not sent to the Requestor\(s\):.+?'.
'Comment test, please!',
'<p>This is a comment about <a href="http://localhost:\d+/Ticket/Display\.html\?id=1">ticket 1</a>\. '.
'It is not sent to the Requestor\(s\):</p>.+?'.
'<p>Comment test, <em>please!</em></p>',
),
'Content-Type' => qr{multipart},
};
diag "Resolved in HTML templates";
mail_ok {
($ok, $tmsg) = $t->SetStatus('resolved');
} { from => qr/RT System/,
to => 'enduser@example.com',
subject => qr/\Q[example.com #1] Resolved: The internet is broken\E/,
body => parts_regex(
'According to our records, your request has been resolved\.',
'<p>According to our records, your request has been resolved\.',
),
'Content-Type' => qr{multipart},
};
diag "Status changes in HTML";
my $scrip = RT::Scrip->new(RT->SystemUser);
my ($sval, $smsg) =$scrip->Create(
ScripCondition => 'On Status Change',
ScripAction => 'Notify Requestors',
Template => 'Status Change in HTML',
Queue => $q->Id,
Description => 'Tell requestors about status changes'
);
ok ($sval, $smsg);
ok ($scrip->Id, "Created the scrip");
ok ($scrip->TemplateObj->Id, "Created the scrip template");
ok ($scrip->ConditionObj->Id, "Created the scrip condition");
ok ($scrip->ActionObj->Id, "Created the scrip action");
mail_ok {
($ok, $tmsg) = $t->SetStatus('stalled');
} { from => qr/RT System/,
to => 'enduser@example.com',
subject => qr/\Q[example.com #1] Status Changed to: stalled\E/,
body => parts_regex(
'http://localhost:\d+/Ticket/Display\.html\?id=1.+?',
'<a href="(http://localhost:\d+/Ticket/Display\.html\?id=1)">\1</a>'
),
'Content-Type' => qr{multipart},
};
done_testing;
sub parts_regex {
my ($text, $html) = @_;
my $pattern = 'Content-Type: text/plain.+?' . $text . '.+?' .
'Content-Type: text/html.+?' . $html;
return qr/$pattern/s;
}
|