import rt 3.8.7
[freeside.git] / rt / t / ticket / merge.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6
7 use RT;
8 use RT::Test tests => '17';
9
10
11 # validate that when merging two tickets, the comments from both tickets
12 # are integrated into the new ticket
13 {
14     my $queue = RT::Queue->new($RT::SystemUser);
15     my ($id,$msg) = $queue->Create(Name => 'MergeTest-'.rand(25));
16     ok ($id,$msg);
17
18     my $t1 = RT::Ticket->new($RT::SystemUser);
19     my ($tid,$transid, $t1msg) =$t1->Create ( Queue => $queue->Name, Subject => 'Merge test. orig');
20     ok ($tid, $t1msg);
21     ($id, $msg) = $t1->Comment(Content => 'This is a Comment on the original');
22     ok($id,$msg);
23
24     my $txns = $t1->Transactions;
25     my $Comments = 0;
26     while (my $txn = $txns->Next) {
27     $Comments++ if ($txn->Type eq 'Comment');
28     }
29     is($Comments,1, "our first ticket has only one Comment");
30
31     my $t2 = RT::Ticket->new($RT::SystemUser);
32     my ($t2id,$t2transid, $t2msg) =$t2->Create ( Queue => $queue->Name, Subject => 'Merge test. duplicate');
33     ok ($t2id, $t2msg);
34
35
36
37     ($id, $msg) = $t2->Comment(Content => 'This is a commet on the duplicate');
38     ok($id,$msg);
39
40
41     $txns = $t2->Transactions;
42      $Comments = 0;
43     while (my $txn = $txns->Next) {
44         $Comments++ if ($txn->Type eq 'Comment');
45     }
46     is($Comments,1, "our second ticket has only one Comment");
47
48     ($id, $msg) = $t1->Comment(Content => 'This is a second  Comment on the original');
49     ok($id,$msg);
50
51     $txns = $t1->Transactions;
52     $Comments = 0;
53     while (my $txn = $txns->Next) {
54         $Comments++ if ($txn->Type eq 'Comment');
55     }
56     is($Comments,2, "our first ticket now has two Comments");
57
58     ($id,$msg) = $t2->MergeInto($t1->id);
59
60     ok($id,$msg);
61     $txns = $t1->Transactions;
62     $Comments = 0;
63     while (my $txn = $txns->Next) {
64         $Comments++ if ($txn->Type eq 'Comment');
65     }
66     is($Comments,3, "our first ticket now has three Comments - we merged safely");
67 }
68
69 # when you try to merge duplicate links on postgres, eveyrything goes to hell due to referential integrity constraints.
70 {
71     my $t = RT::Ticket->new($RT::SystemUser);
72     $t->Create(Subject => 'Main', Queue => 'general');
73
74     ok ($t->id);
75     my $t2 = RT::Ticket->new($RT::SystemUser);
76     $t2->Create(Subject => 'Second', Queue => 'general');
77     ok ($t2->id);
78
79     my $t3 = RT::Ticket->new($RT::SystemUser);
80     $t3->Create(Subject => 'Third', Queue => 'general');
81
82     ok ($t3->id);
83
84     my ($id,$val);
85     ($id,$val) = $t->AddLink(Type => 'DependsOn', Target => $t3->id);
86     ok($id,$val);
87     ($id,$val) = $t2->AddLink(Type => 'DependsOn', Target => $t3->id);
88     ok($id,$val);
89
90     ($id,$val) = $t->MergeInto($t2->id);
91     ok($id,$val);
92 }