rt 4.2.14 (#13852)
[freeside.git] / rt / t / mail / one-time-recipients.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => undef;
5 use RT::Test::Email;
6 use Test::Warn;
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 warnings_are {
23     my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) );
24     mail_ok {
25         my ($status, undef, $msg) = $ticket->Create(
26             Queue => $queue->id,
27             Subject => 'test',
28             Requestor => 'root@localhost',
29         );
30         ok $status, "created ticket";
31     } { To => 'root@localhost' };
32
33     RT->Config->Set( NotifyActor => 1 );
34     mail_ok {
35         my ($status, $msg) = $ticket->Correspond(
36             Content => 'test mail',
37         );
38         ok $status, "replied to a ticket";
39     } { To => 'root@localhost' };
40
41     RT->Config->Set( NotifyActor => 0 );
42     mail_ok {
43         my ($status, $msg) = $ticket->Correspond(
44             Content => 'test mail',
45         );
46         ok $status, "replied to a ticket";
47     };
48
49     mail_ok {
50         my ($status, $msg) = $ticket->Correspond(
51             Content => 'test mail',
52             CcMessageTo => 'root@localhost',
53         );
54         ok $status, "replied to a ticket";
55     } { Cc => 'root@localhost' };
56 } [];
57
58 diag "Reply to ticket with requestor squelched";
59 warnings_are {
60     my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) );
61     mail_ok {
62         my ($status, undef, $msg) = $ticket->Create(
63             Queue => $queue->id,
64             Subject => 'test',
65             Requestor => 'test@localhost',
66         );
67         ok $status, "created ticket";
68     } { To => 'test@localhost' };
69
70     mail_ok {
71         my ($status, $msg) = $ticket->Correspond(
72             Content => 'test mail',
73         );
74         ok $status, "replied to a ticket";
75     } { To => 'test@localhost' };
76
77     $ticket->SquelchMailTo('test@localhost');
78     mail_ok {
79         my ($status, $msg) = $ticket->Correspond(
80             Content => 'test mail',
81         );
82         ok $status, "replied to a ticket";
83     };
84
85     mail_ok {
86         my ($status, $msg) = $ticket->Correspond(
87             Content => 'test mail',
88             CcMessageTo => 'test@localhost',
89         );
90         ok $status, "replied to a ticket";
91     } { Cc => 'test@localhost' };
92 }[];
93
94 diag "Reply to ticket with multiple requestors squelched";
95 warnings_are {
96     my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) );
97     mail_ok {
98         my ($status, undef, $msg) = $ticket->Create(
99             Queue => $queue->id,
100             Subject => 'test squelch',
101             Requestor => ['test@localhost','bob@localhost','fred@localhost' ],
102         );
103         ok $status, "created ticket";
104     } { To => 'bob@localhost, fred@localhost, test@localhost' };
105
106     mail_ok {
107         my ($status,$msg) = $ticket->Correspond(
108             Content => 'squelched email',
109             SquelchMailTo => ['bob@localhost', 'fred@localhost'],
110         );
111         ok $status, "replied to a ticket";
112     } { To => 'test@localhost' };
113
114 } [];
115
116 diag "Reply to ticket with requestor squelched";
117 warnings_are {
118     my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) );
119     mail_ok {
120         my ($status, undef, $msg) = $ticket->Create(
121             Queue => $queue->id,
122             Subject => 'test',
123             Requestor => 'test@localhost',
124         );
125         ok $status, "created ticket";
126     } { To => 'test@localhost' };
127
128     mail_ok {
129         my ($status, $msg) = $ticket->Correspond(
130             Content => 'test mail',
131         );
132         ok $status, "replied to a ticket";
133     } { To => 'test@localhost' };
134
135     mail_ok {
136         my ($status, $msg) = $ticket->Correspond(
137             Content => 'test mail',
138             SquelchMailTo => ['test@localhost'],
139         );
140         ok $status, "replied to a ticket";
141     };
142
143     mail_ok {
144         my ($status, $msg) = $ticket->Correspond(
145             Content => 'test mail',
146         );
147         ok $status, "replied to a ticket";
148     } { To => 'test@localhost' };
149
150     mail_ok {
151         my ($status, $msg) = $ticket->Correspond(
152             Content => 'test mail',
153             CcMessageTo => 'test@localhost',
154             SquelchMailTo => ['test@localhost'],
155         );
156         ok $status, "replied to a ticket";
157     }  { Cc => 'test@localhost' };
158 } [];
159
160 diag "Requestor is an RT address";
161 warnings_are {
162     my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) );
163     mail_ok {
164         my ($status, undef, $msg) = $ticket->Create(
165             Queue => $queue->id,
166             Subject => 'test',
167             Requestor => 'rt-address@example.com',
168         );
169         ok $status, "created ticket";
170     } { To => 'rt-address@example.com' };
171
172     RT->Config->Set( RTAddressRegexp => qr/^rt-address\@example\.com$/i );
173     mail_ok {
174         my ($status, $msg) = $ticket->Correspond(
175             Content => 'test mail',
176         );
177         ok $status, "replied to a ticket";
178     };
179
180     mail_ok {
181         my ($status, $msg) = $ticket->Correspond(
182             Content => 'test mail',
183             CcMessageTo => 'rt-address@example.com',
184         );
185         ok $status, "replied to a ticket";
186     };
187 } [];
188
189 done_testing;