RT 4.0.22
[freeside.git] / rt / t / mail / threading.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => 22;
5 RT->Config->Set( NotifyActor => 1 );
6
7 my $queue = RT::Test->load_or_create_queue(
8     Name              => 'General',
9     CorrespondAddress => 'rt-recipient@example.com',
10     CommentAddress    => 'rt-recipient@example.com',
11 );
12 ok $queue && $queue->id, 'loaded or created queue';
13
14 my $user = RT::Test->load_or_create_user(
15     Name         => 'root',
16     EmailAddress => 'root@localhost',
17 );
18 ok $user && $user->id, 'loaded or created user';
19
20 {
21     my $mail = <<EOF;
22 From: root\@localhost
23 Subject: a ticket
24 Message-ID: <some-message-id>
25
26 Foob!
27 EOF
28     my ($status, $id) = RT::Test->send_via_mailgate($mail);
29     ok $id, "created a ticket";
30
31     my @mail = RT::Test->fetch_caught_mails;
32     is scalar @mail, 1, "autoreply";
33     like $mail[0], qr{^In-Reply-To:\s*<some-message-id>$}mi;
34     like $mail[0], qr{^References:\s*<RT-Ticket-\Q$id\E\@example\.com>}mi;
35
36     my $ticket = RT::Ticket->new( RT->SystemUser );
37     $ticket->Load( $id );
38     ok $ticket->id, "loaded ticket";
39
40     ($status, my ($msg)) = $ticket->Correspond( Content => 'boo' );
41     ok $status, "replied to the ticket";
42
43     @mail = RT::Test->fetch_caught_mails;
44     is scalar @mail, 1, "reply";
45     like $mail[0], qr{^References:\s*<RT-Ticket-\Q$id\E\@example\.com>$}mi,
46         "no context, so only pseudo header is referenced";
47 }
48
49 {
50     my ($ticket) = RT::Test->create_ticket(
51         Queue => $queue->id,
52         Requestor => $user->EmailAddress
53     );
54     my $id = $ticket->id;
55     ok $id, "created a ticket";
56
57     my @mail = RT::Test->fetch_caught_mails;
58     is scalar @mail, 1, "autoreply";
59     like $mail[0], qr{^References:\s*<RT-Ticket-\Q$id\E\@example\.com>}mi;
60 }
61
62 {
63     my $scrip = RT::Scrip->new(RT->SystemUser);
64     my ($status, $msg) = $scrip->Create(
65         Description => "Notify requestor on status change",
66         ScripCondition => 'On Status Change',
67         ScripAction    => 'Notify Requestors',
68         Template       => 'Transaction',
69         Stage          => 'TransactionCreate',
70         Queue          => 0,
71     );
72     ok($status, "Scrip created");
73
74     my ($ticket) = RT::Test->create_ticket(
75         Queue => $queue->id,
76         Requestor => $user->EmailAddress,
77     );
78     my $id = $ticket->id;
79     ok $id, "created a ticket";
80
81     RT::Test->fetch_caught_mails;
82     ($status, $msg) = $ticket->SetStatus('open');
83     ok $status, "changed status";
84
85     my @mail = RT::Test->fetch_caught_mails;
86     is scalar @mail, 1, "status change notification";
87     like $mail[0], qr{^References:\s*<RT-Ticket-\Q$id\E\@example\.com>}mi;
88 }