import rt 3.8.10
[freeside.git] / rt / lib / t / regression / 10merge.t
1 #!/usr/bin/perl 
2
3 use warnings;
4 use strict;
5
6
7 #
8 # This test script validates that when merging two tickets, the comments from both tickets
9 # are integrated into the new ticket
10
11 use Test::More tests => 13;
12 use RT;
13 RT::LoadConfig;
14 RT::Init;
15
16 use_ok('RT::Ticket');
17 use_ok('RT::Queue');
18
19 my $queue = RT::Queue->new($RT::SystemUser);
20 my ($id,$msg) = $queue->Create(Name => 'MergeTest-'.rand(25));
21 ok ($id,$msg);
22
23 my $t1 = RT::Ticket->new($RT::SystemUser);
24 my ($tid,$transid, $t1msg) =$t1->Create ( Queue => $queue->Name, Subject => 'Merge test. orig');
25 ok ($tid, $t1msg);
26 ($id, $msg) = $t1->Comment(Content => 'This is a Comment on the original');
27 ok($id,$msg);
28
29 my $txns = $t1->Transactions;
30 my $Comments = 0;
31 while (my $txn = $txns->Next) {
32 $Comments++ if ($txn->Type eq 'Comment');
33 }
34 is($Comments,1, "our first ticket has only one Comment");
35
36 my $t2 = RT::Ticket->new($RT::SystemUser);
37 my ($t2id,$t2transid, $t2msg) =$t2->Create ( Queue => $queue->Name, Subject => 'Merge test. duplicate');
38 ok ($t2id, $t2msg);
39
40
41
42 ($id, $msg) = $t2->Comment(Content => 'This is a commet on the duplicate');
43 ok($id,$msg);
44
45
46 $txns = $t2->Transactions;
47  $Comments = 0;
48 while (my $txn = $txns->Next) {
49     $Comments++ if ($txn->Type eq 'Comment');
50 }
51 is($Comments,1, "our second ticket has only one Comment");
52
53 ($id, $msg) = $t1->Comment(Content => 'This is a second  Comment on the original');
54 ok($id,$msg);
55
56 $txns = $t1->Transactions;
57 $Comments = 0;
58 while (my $txn = $txns->Next) {
59     $Comments++ if ($txn->Type eq 'Comment');
60 }
61 is($Comments,2, "our first ticket now has two Comments");
62
63 ($id,$msg) = $t2->MergeInto($t1->id);
64
65 ok($id,$msg);
66 $txns = $t1->Transactions;
67 $Comments = 0;
68 while (my $txn = $txns->Next) {
69     $Comments++ if ($txn->Type eq 'Comment');
70 }
71 is($Comments,3, "our first ticket now has three Comments - we merged safely");
72