first pass RT4 merge, RT#13852
[freeside.git] / rt / t / mail / one-time-recipients.t
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use utf8;
5
6 use RT::Test tests => 38;
7
8 my $queue = RT::Test->load_or_create_queue(
9     Name              => 'General',
10     CorrespondAddress => 'rt-recipient@example.com',
11     CommentAddress    => 'rt-recipient@example.com',
12 );
13 ok $queue && $queue->id, 'loaded or created queue';
14
15 my $user = RT::Test->load_or_create_user(
16     Name         => 'root',
17     EmailAddress => 'root@localhost',
18 );
19 ok $user && $user->id, 'loaded or created user';
20
21 diag "Reply to ticket with actor as one time cc";
22 {
23     my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) );
24     my ($status, undef, $msg) = $ticket->Create(
25         Queue => $queue->id,
26         Subject => 'test',
27         Requestor => 'root@localhost',
28     );
29     ok $status, "created ticket";
30
31     my @mails = RT::Test->fetch_caught_mails;
32     ok @mails, "got some outgoing emails";
33     foreach my $mail ( @mails ) {
34         my $entity = parse_mail( $mail );
35         my $to = $entity->head->get('To');
36         $to =~ s/^\s+|\s+$//; 
37         is $to, 'root@localhost', 'got mail'
38     }
39
40     RT->Config->Set( NotifyActor => 1 );
41     ($status, $msg) = $ticket->Correspond(
42         Content => 'test mail',
43     );
44     ok $status, "replied to a ticket";
45
46     @mails = RT::Test->fetch_caught_mails;
47     ok @mails, "got some outgoing emails";
48     foreach my $mail ( @mails ) {
49         my $entity = parse_mail( $mail );
50         my $to = $entity->head->get('To');
51         $to =~ s/^\s+|\s+$//; 
52         is $to, 'root@localhost', 'got mail'
53     }
54
55     RT->Config->Set( NotifyActor => 0 );
56     ($status, $msg) = $ticket->Correspond(
57         Content => 'test mail',
58     );
59     ok $status, "replied to a ticket";
60
61     @mails = RT::Test->fetch_caught_mails;
62     ok !@mails, "no mail - don't notify actor";
63
64     ($status, $msg) = $ticket->Correspond(
65         Content => 'test mail',
66         CcMessageTo => 'root@localhost',
67     );
68     ok $status, "replied to a ticket";
69
70     @mails = RT::Test->fetch_caught_mails;
71     ok @mails, "got some outgoing emails";
72     foreach my $mail ( @mails ) {
73         my $entity = parse_mail( $mail );
74         my $to = $entity->head->get('Cc');
75         $to =~ s/^\s+|\s+$//; 
76         is $to, 'root@localhost', 'got mail'
77     }
78 }
79
80 diag "Reply to ticket with requestor squelched";
81 {
82     my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) );
83     my ($status, undef, $msg) = $ticket->Create(
84         Queue => $queue->id,
85         Subject => 'test',
86         Requestor => 'test@localhost',
87     );
88     ok $status, "created ticket";
89
90     my @mails = RT::Test->fetch_caught_mails;
91     ok @mails, "got some outgoing emails";
92     foreach my $mail ( @mails ) {
93         my $entity = parse_mail( $mail );
94         my $to = $entity->head->get('To');
95         $to =~ s/^\s+|\s+$//; 
96         is $to, 'test@localhost', 'got mail'
97     }
98
99     ($status, $msg) = $ticket->Correspond(
100         Content => 'test mail',
101     );
102     ok $status, "replied to a ticket";
103
104     @mails = RT::Test->fetch_caught_mails;
105     ok @mails, "got some outgoing emails";
106     foreach my $mail ( @mails ) {
107         my $entity = parse_mail( $mail );
108         my $to = $entity->head->get('To');
109         $to =~ s/^\s+|\s+$//; 
110         is $to, 'test@localhost', 'got mail'
111     }
112
113     $ticket->SquelchMailTo('test@localhost');
114     ($status, $msg) = $ticket->Correspond(
115         Content => 'test mail',
116     );
117     ok $status, "replied to a ticket";
118
119     @mails = RT::Test->fetch_caught_mails;
120     ok !@mails, "no mail - squelched";
121
122     ($status, $msg) = $ticket->Correspond(
123         Content => 'test mail',
124         CcMessageTo => 'test@localhost',
125     );
126     ok $status, "replied to a ticket";
127
128     @mails = RT::Test->fetch_caught_mails;
129     ok @mails, "got some outgoing emails";
130     foreach my $mail ( @mails ) {
131         my $entity = parse_mail( $mail );
132         my $to = $entity->head->get('Cc');
133         $to =~ s/^\s+|\s+$//; 
134         is $to, 'test@localhost', 'got mail'
135     }
136 }
137
138 diag "Reply to ticket with requestor squelched";
139 {
140     my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) );
141     my ($status, undef, $msg) = $ticket->Create(
142         Queue => $queue->id,
143         Subject => 'test',
144         Requestor => 'test@localhost',
145     );
146     ok $status, "created ticket";
147
148     my @mails = RT::Test->fetch_caught_mails;
149     ok @mails, "got some outgoing emails";
150     foreach my $mail ( @mails ) {
151         my $entity = parse_mail( $mail );
152         my $to = $entity->head->get('To');
153         $to =~ s/^\s+|\s+$//; 
154         is $to, 'test@localhost', 'got mail'
155     }
156
157     ($status, $msg) = $ticket->Correspond(
158         Content => 'test mail',
159     );
160     ok $status, "replied to a ticket";
161
162     @mails = RT::Test->fetch_caught_mails;
163     ok @mails, "got some outgoing emails";
164     foreach my $mail ( @mails ) {
165         my $entity = parse_mail( $mail );
166         my $to = $entity->head->get('To');
167         $to =~ s/^\s+|\s+$//; 
168         is $to, 'test@localhost', 'got mail'
169     }
170
171     ($status, $msg) = $ticket->Correspond(
172         Content => 'test mail',
173         SquelchMailTo => ['test@localhost'],
174     );
175     ok $status, "replied to a ticket";
176
177     @mails = RT::Test->fetch_caught_mails;
178     ok !@mails, "no mail - squelched";
179
180     ($status, $msg) = $ticket->Correspond(
181         Content => 'test mail',
182     );
183     ok $status, "replied to a ticket";
184
185     @mails = RT::Test->fetch_caught_mails;
186     ok @mails, "got some outgoing emails";
187     foreach my $mail ( @mails ) {
188         my $entity = parse_mail( $mail );
189         my $to = $entity->head->get('To');
190         $to =~ s/^\s+|\s+$//; 
191         is $to, 'test@localhost', 'got mail'
192     }
193
194     ($status, $msg) = $ticket->Correspond(
195         Content => 'test mail',
196         CcMessageTo => 'test@localhost',
197         SquelchMailTo => ['test@localhost'],
198     );
199     ok $status, "replied to a ticket";
200
201     @mails = RT::Test->fetch_caught_mails;
202     ok @mails, "got some outgoing emails";
203     foreach my $mail ( @mails ) {
204         my $entity = parse_mail( $mail );
205         my $to = $entity->head->get('Cc');
206         $to =~ s/^\s+|\s+$//; 
207         is $to, 'test@localhost', 'got mail'
208     }
209 }