RT 4.2.11, ticket#13852
[freeside.git] / rt / t / mail / one-time-recipients.t
index a9881cd..1bc172d 100644 (file)
@@ -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;