X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=rt%2Ft%2Fmail%2Fone-time-recipients.t;fp=rt%2Ft%2Fmail%2Fone-time-recipients.t;h=1bc172d71981c2e891dd422847e906f6275c6849;hb=1c538bfabc2cd31f27067505f0c3d1a46cba6ef0;hp=a9881cded05f8dc6eca5ec3df05eab24bb83e506;hpb=4f5619288413a185e9933088d9dd8c5afbc55dfa;p=freeside.git diff --git a/rt/t/mail/one-time-recipients.t b/rt/t/mail/one-time-recipients.t index a9881cded..1bc172d71 100644 --- a/rt/t/mail/one-time-recipients.t +++ b/rt/t/mail/one-time-recipients.t @@ -1,7 +1,9 @@ use strict; use warnings; -use RT::Test tests => 38; +use RT::Test tests => undef; +use RT::Test::Email; +use Test::Warn; my $queue = RT::Test->load_or_create_queue( Name => 'General', @@ -17,191 +19,149 @@ my $user = RT::Test->load_or_create_user( ok $user && $user->id, 'loaded or created user'; diag "Reply to ticket with actor as one time cc"; -{ +warnings_are { my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) ); - my ($status, undef, $msg) = $ticket->Create( - Queue => $queue->id, - Subject => 'test', - Requestor => 'root@localhost', - ); - ok $status, "created ticket"; - - my @mails = RT::Test->fetch_caught_mails; - ok @mails, "got some outgoing emails"; - foreach my $mail ( @mails ) { - my $entity = parse_mail( $mail ); - my $to = $entity->head->get('To'); - $to =~ s/^\s+|\s+$//; - is $to, 'root@localhost', 'got mail' - } + mail_ok { + my ($status, undef, $msg) = $ticket->Create( + Queue => $queue->id, + Subject => 'test', + Requestor => 'root@localhost', + ); + ok $status, "created ticket"; + } { To => 'root@localhost' }; RT->Config->Set( NotifyActor => 1 ); - ($status, $msg) = $ticket->Correspond( - Content => 'test mail', - ); - ok $status, "replied to a ticket"; - - @mails = RT::Test->fetch_caught_mails; - ok @mails, "got some outgoing emails"; - foreach my $mail ( @mails ) { - my $entity = parse_mail( $mail ); - my $to = $entity->head->get('To'); - $to =~ s/^\s+|\s+$//; - is $to, 'root@localhost', 'got mail' - } + mail_ok { + my ($status, $msg) = $ticket->Correspond( + Content => 'test mail', + ); + ok $status, "replied to a ticket"; + } { To => 'root@localhost' }; RT->Config->Set( NotifyActor => 0 ); - ($status, $msg) = $ticket->Correspond( - Content => 'test mail', - ); - ok $status, "replied to a ticket"; - - @mails = RT::Test->fetch_caught_mails; - ok !@mails, "no mail - don't notify actor"; - - ($status, $msg) = $ticket->Correspond( - Content => 'test mail', - CcMessageTo => 'root@localhost', - ); - ok $status, "replied to a ticket"; - - @mails = RT::Test->fetch_caught_mails; - ok @mails, "got some outgoing emails"; - foreach my $mail ( @mails ) { - my $entity = parse_mail( $mail ); - my $to = $entity->head->get('Cc'); - $to =~ s/^\s+|\s+$//; - is $to, 'root@localhost', 'got mail' - } -} + mail_ok { + my ($status, $msg) = $ticket->Correspond( + Content => 'test mail', + ); + ok $status, "replied to a ticket"; + }; + + mail_ok { + my ($status, $msg) = $ticket->Correspond( + Content => 'test mail', + CcMessageTo => 'root@localhost', + ); + ok $status, "replied to a ticket"; + } { Cc => 'root@localhost' }; +} []; diag "Reply to ticket with requestor squelched"; -{ +warnings_are { my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) ); - my ($status, undef, $msg) = $ticket->Create( - Queue => $queue->id, - Subject => 'test', - Requestor => 'test@localhost', - ); - ok $status, "created ticket"; - - my @mails = RT::Test->fetch_caught_mails; - ok @mails, "got some outgoing emails"; - foreach my $mail ( @mails ) { - my $entity = parse_mail( $mail ); - my $to = $entity->head->get('To'); - $to =~ s/^\s+|\s+$//; - is $to, 'test@localhost', 'got mail' - } - - ($status, $msg) = $ticket->Correspond( - Content => 'test mail', - ); - ok $status, "replied to a ticket"; - - @mails = RT::Test->fetch_caught_mails; - ok @mails, "got some outgoing emails"; - foreach my $mail ( @mails ) { - my $entity = parse_mail( $mail ); - my $to = $entity->head->get('To'); - $to =~ s/^\s+|\s+$//; - is $to, 'test@localhost', 'got mail' - } + mail_ok { + my ($status, undef, $msg) = $ticket->Create( + Queue => $queue->id, + Subject => 'test', + Requestor => 'test@localhost', + ); + ok $status, "created ticket"; + } { To => 'test@localhost' }; + + mail_ok { + my ($status, $msg) = $ticket->Correspond( + Content => 'test mail', + ); + ok $status, "replied to a ticket"; + } { To => 'test@localhost' }; $ticket->SquelchMailTo('test@localhost'); - ($status, $msg) = $ticket->Correspond( - Content => 'test mail', - ); - ok $status, "replied to a ticket"; - - @mails = RT::Test->fetch_caught_mails; - ok !@mails, "no mail - squelched"; - - ($status, $msg) = $ticket->Correspond( - Content => 'test mail', - CcMessageTo => 'test@localhost', - ); - ok $status, "replied to a ticket"; - - @mails = RT::Test->fetch_caught_mails; - ok @mails, "got some outgoing emails"; - foreach my $mail ( @mails ) { - my $entity = parse_mail( $mail ); - my $to = $entity->head->get('Cc'); - $to =~ s/^\s+|\s+$//; - is $to, 'test@localhost', 'got mail' - } -} + mail_ok { + my ($status, $msg) = $ticket->Correspond( + Content => 'test mail', + ); + ok $status, "replied to a ticket"; + }; + + mail_ok { + my ($status, $msg) = $ticket->Correspond( + Content => 'test mail', + CcMessageTo => 'test@localhost', + ); + ok $status, "replied to a ticket"; + } { Cc => 'test@localhost' }; +} []; diag "Reply to ticket with requestor squelched"; -{ +warnings_are { my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) ); - my ($status, undef, $msg) = $ticket->Create( - Queue => $queue->id, - Subject => 'test', - Requestor => 'test@localhost', - ); - ok $status, "created ticket"; - - my @mails = RT::Test->fetch_caught_mails; - ok @mails, "got some outgoing emails"; - foreach my $mail ( @mails ) { - my $entity = parse_mail( $mail ); - my $to = $entity->head->get('To'); - $to =~ s/^\s+|\s+$//; - is $to, 'test@localhost', 'got mail' - } - - ($status, $msg) = $ticket->Correspond( - Content => 'test mail', - ); - ok $status, "replied to a ticket"; - - @mails = RT::Test->fetch_caught_mails; - ok @mails, "got some outgoing emails"; - foreach my $mail ( @mails ) { - my $entity = parse_mail( $mail ); - my $to = $entity->head->get('To'); - $to =~ s/^\s+|\s+$//; - is $to, 'test@localhost', 'got mail' - } - - ($status, $msg) = $ticket->Correspond( - Content => 'test mail', - SquelchMailTo => ['test@localhost'], - ); - ok $status, "replied to a ticket"; - - @mails = RT::Test->fetch_caught_mails; - ok !@mails, "no mail - squelched"; - - ($status, $msg) = $ticket->Correspond( - Content => 'test mail', - ); - ok $status, "replied to a ticket"; - - @mails = RT::Test->fetch_caught_mails; - ok @mails, "got some outgoing emails"; - foreach my $mail ( @mails ) { - my $entity = parse_mail( $mail ); - my $to = $entity->head->get('To'); - $to =~ s/^\s+|\s+$//; - is $to, 'test@localhost', 'got mail' - } - - ($status, $msg) = $ticket->Correspond( - Content => 'test mail', - CcMessageTo => 'test@localhost', - SquelchMailTo => ['test@localhost'], - ); - ok $status, "replied to a ticket"; - - @mails = RT::Test->fetch_caught_mails; - ok @mails, "got some outgoing emails"; - foreach my $mail ( @mails ) { - my $entity = parse_mail( $mail ); - my $to = $entity->head->get('Cc'); - $to =~ s/^\s+|\s+$//; - is $to, 'test@localhost', 'got mail' - } -} + mail_ok { + my ($status, undef, $msg) = $ticket->Create( + Queue => $queue->id, + Subject => 'test', + Requestor => 'test@localhost', + ); + ok $status, "created ticket"; + } { To => 'test@localhost' }; + + mail_ok { + my ($status, $msg) = $ticket->Correspond( + Content => 'test mail', + ); + ok $status, "replied to a ticket"; + } { To => 'test@localhost' }; + + mail_ok { + my ($status, $msg) = $ticket->Correspond( + Content => 'test mail', + SquelchMailTo => ['test@localhost'], + ); + ok $status, "replied to a ticket"; + }; + + mail_ok { + my ($status, $msg) = $ticket->Correspond( + Content => 'test mail', + ); + ok $status, "replied to a ticket"; + } { To => 'test@localhost' }; + + mail_ok { + my ($status, $msg) = $ticket->Correspond( + Content => 'test mail', + CcMessageTo => 'test@localhost', + SquelchMailTo => ['test@localhost'], + ); + ok $status, "replied to a ticket"; + } { Cc => 'test@localhost' }; +} []; + +diag "Requestor is an RT address"; +warnings_are { + my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) ); + mail_ok { + my ($status, undef, $msg) = $ticket->Create( + Queue => $queue->id, + Subject => 'test', + Requestor => 'rt-address@example.com', + ); + ok $status, "created ticket"; + } { To => 'rt-address@example.com' }; + + RT->Config->Set( RTAddressRegexp => qr/^rt-address\@example\.com$/i ); + mail_ok { + my ($status, $msg) = $ticket->Correspond( + Content => 'test mail', + ); + ok $status, "replied to a ticket"; + }; + + mail_ok { + my ($status, $msg) = $ticket->Correspond( + Content => 'test mail', + CcMessageTo => 'rt-address@example.com', + ); + ok $status, "replied to a ticket"; + }; +} []; + +done_testing;