X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Ft%2Fmail%2Fhtml-outgoing.t;fp=rt%2Ft%2Fmail%2Fhtml-outgoing.t;h=a37f52cdd5b2f802d518973a92ec7b37dcfa7b3d;hb=e131b1f71f08b69abb832c1687d1f29682d171f8;hp=0000000000000000000000000000000000000000;hpb=d05d7346bb2387fd9d0354923d577275c5c7f019;p=freeside.git diff --git a/rt/t/mail/html-outgoing.t b/rt/t/mail/html-outgoing.t new file mode 100644 index 000000000..a37f52cdd --- /dev/null +++ b/rt/t/mail/html-outgoing.t @@ -0,0 +1,187 @@ +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 The internet is broken' + ), + '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 (\[\d+\])?1(\s*[(<]http://localhost:\d+/Ticket/Display\.html\?id=1[)>])?\s*was acted upon by RT_System', + 'Request 1 was acted upon by RT_System\.' + ), + 'Content-Type' => qr{multipart}, +}; + +diag "Admin Correspondence and Correspondence"; +mail_ok { + ($ok, $tmsg) = $t->Correspond( + MIMEObj => HTML::Mason::Commands::MakeMIMEEntity( + Body => '

This is a test of HTML correspondence.

', + 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: (?:\[\d+\])?http://localhost:\d+/Ticket/Display\.html\?id=1.+?'. + 'This is a test of \*?HTML\*? correspondence\.', + 'Ticket URL: \1.+?'. + '

This is a test of HTML correspondence\.

' + ), + '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\.', + '

This is a test of HTML correspondence\.

' + ), + 'Content-Type' => qr{multipart}, +}; + +SKIP: { + skip "Only fails on core HTMLFormatter", 9 + unless RT->Config->Get("HTMLFormatter") eq "core"; + diag "Failing HTML -> Text conversion"; + warnings_like { + my $body = '
Foo
'; + 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: \1.+?$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{$body}, + '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 => '

Comment test, please!

', + 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 (\[\d+\])?ticket.1(\s*[(<]http://localhost:\d+/Ticket/Display\.html\?id=1[)>])?\..+?'. + 'It is not sent to the Requestor\(s\):.+?'. + 'Comment test, _?please!_?', + + '

This is a comment about ticket 1\. '. + 'It is not sent to the Requestor\(s\):

.+?'. + '

Comment test, please!

', + ), + '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\.', + '

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.+?', + '\1' + ), + '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; +} +