8 use RT::Test tests => '29';
11 # validate that when merging two tickets, the comments from both tickets
12 # are integrated into the new ticket
14 my $queue = RT::Queue->new($RT::SystemUser);
15 my ($id,$msg) = $queue->Create(Name => 'MergeTest-'.rand(25));
18 my $t1 = RT::Ticket->new($RT::SystemUser);
19 my ($tid,$transid, $t1msg) =$t1->Create(
20 Queue => $queue->Name,
21 Subject => 'Merge test. orig',
24 ($id, $msg) = $t1->Comment(Content => 'This is a Comment on the original');
27 my $txns = $t1->Transactions;
29 while (my $txn = $txns->Next) {
30 $Comments++ if ($txn->Type eq 'Comment');
32 is($Comments,1, "our first ticket has only one Comment");
34 my $t2 = RT::Ticket->new($RT::SystemUser);
35 my ($t2id,$t2transid, $t2msg) =$t2->Create ( Queue => $queue->Name, Subject => 'Merge test. duplicate');
40 ($id, $msg) = $t2->Comment(Content => 'This is a commet on the duplicate');
44 $txns = $t2->Transactions;
46 while (my $txn = $txns->Next) {
47 $Comments++ if ($txn->Type eq 'Comment');
49 is($Comments,1, "our second ticket has only one Comment");
51 ($id, $msg) = $t1->Comment(Content => 'This is a second Comment on the original');
54 $txns = $t1->Transactions;
56 while (my $txn = $txns->Next) {
57 $Comments++ if ($txn->Type eq 'Comment');
59 is($Comments,2, "our first ticket now has two Comments");
61 ($id,$msg) = $t2->MergeInto($t1->id);
64 $txns = $t1->Transactions;
66 while (my $txn = $txns->Next) {
67 $Comments++ if ($txn->Type eq 'Comment');
69 is($Comments,3, "our first ticket now has three Comments - we merged safely");
72 # when you try to merge duplicate links on postgres, eveyrything goes to hell due to referential integrity constraints.
74 my $t = RT::Ticket->new($RT::SystemUser);
75 $t->Create(Subject => 'Main', Queue => 'general');
78 my $t2 = RT::Ticket->new($RT::SystemUser);
79 $t2->Create(Subject => 'Second', Queue => 'general');
82 my $t3 = RT::Ticket->new($RT::SystemUser);
83 $t3->Create(Subject => 'Third', Queue => 'general');
88 ($id,$val) = $t->AddLink(Type => 'DependsOn', Target => $t3->id);
90 ($id,$val) = $t2->AddLink(Type => 'DependsOn', Target => $t3->id);
93 ($id,$val) = $t->MergeInto($t2->id);
97 my $user = RT::Test->load_or_create_user(
98 Name => 'a user', Password => 'password',
100 ok $user && $user->id, 'loaded or created user';
104 RT::Test->set_rights(
105 { Principal => 'Everyone', Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket TakeTicket)] },
106 { Principal => 'Owner', Right => [qw(ModifyTicket)] },
109 my $t = RT::Ticket->new(RT::CurrentUser->new($user));
110 $t->Create(Subject => 'Main', Queue => 'general');
111 ok ($t->id, "Created ticket");
113 my $t2 = RT::Ticket->new(RT::CurrentUser->new($user));
114 $t2->Create(Subject => 'Second', Queue => 'general');
115 ok ($t2->id, "Created ticket");
117 foreach my $ticket ( $t, $t2 ) {
118 ok( !$ticket->CurrentUserHasRight('ModifyTicket'), "can not modify" );
121 my ($status,$msg) = $t->MergeInto($t2->id);
122 ok(!$status, "Can not merge: $msg");
124 ($status, $msg) = $t->SetOwner( $user->id );
125 ok( $status, "User took ticket");
126 ok( $t->CurrentUserHasRight('ModifyTicket'), "can modify after take" );
128 ($status,$msg) = $t->MergeInto($t2->id);
129 ok(!$status, "Can not merge: $msg");
131 ($status, $msg) = $t2->SetOwner( $user->id );
132 ok( $status, "User took ticket");
133 ok( $t2->CurrentUserHasRight('ModifyTicket'), "can modify after take" );
135 ($status,$msg) = $t->MergeInto($t2->id);
136 ok($status, "Merged tickets: $msg");