7 use Test::More tests => 44 + 1; # plus one for warnings check
10 my $shredder_utils = RT::Test::get_relocatable_file('utils.pl',
11 File::Spec->curdir());
12 require $shredder_utils;
16 use_ok('RT::Shredder::Plugin::Tickets');
18 my $plugin = RT::Shredder::Plugin::Tickets->new;
19 isa_ok($plugin, 'RT::Shredder::Plugin::Tickets');
21 is(lc $plugin->Type, 'search', 'correct type');
25 create_savepoint('clean');
27 use_ok('RT::Tickets');
29 { # create parent and child and check functionality of 'with_linked' arg
30 my $parent = RT::Ticket->new( RT->SystemUser );
31 my ($pid) = $parent->Create( Subject => 'parent', Queue => 1 );
32 ok( $pid, "created new ticket" );
33 my $child = RT::Ticket->new( RT->SystemUser );
34 my ($cid) = $child->Create( Subject => 'child', Queue => 1, MemberOf => $pid );
35 ok( $cid, "created new ticket" );
36 $_->ApplyTransactionBatch for $parent, $child;
38 my $plugin = RT::Shredder::Plugin::Tickets->new;
39 isa_ok($plugin, 'RT::Shredder::Plugin::Tickets');
41 my ($status, $msg, @objs);
42 ($status, $msg) = $plugin->TestArgs( query => 'Subject = "parent"' );
43 ok($status, "plugin arguments are ok") or diag "error: $msg";
45 ($status, @objs) = $plugin->Run;
46 ok($status, "executed plugin successfully") or diag "error: @objs";
47 @objs = RT::Shredder->CastObjectsToRecords( Objects => \@objs );
48 is(scalar @objs, 1, "only one object in result set");
49 is($objs[0]->id, $pid, "parent is in result set");
51 ($status, $msg) = $plugin->TestArgs( query => 'Subject = "parent"', with_linked => 1 );
52 ok($status, "plugin arguments are ok") or diag "error: $msg";
54 ($status, @objs) = $plugin->Run;
55 ok($status, "executed plugin successfully") or diag "error: @objs";
56 @objs = RT::Shredder->CastObjectsToRecords( Objects => \@objs );
57 my %has = map { $_->id => 1 } @objs;
58 is(scalar @objs, 2, "two objects in the result set");
59 ok($has{$pid}, "parent is in the result set");
60 ok($has{$cid}, "child is in the result set");
62 my $shredder = shredder_new();
63 $shredder->PutObjects( Objects => \@objs );
64 $shredder->WipeoutAll;
66 cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint");
68 { # create parent and child and link them reqursively to check that we don't hang
69 my $parent = RT::Ticket->new( RT->SystemUser );
70 my ($pid) = $parent->Create( Subject => 'parent', Queue => 1 );
71 ok( $pid, "created new ticket" );
73 my $child = RT::Ticket->new( RT->SystemUser );
74 my ($cid) = $child->Create( Subject => 'child', Queue => 1, MemberOf => $pid );
75 ok( $cid, "created new ticket" );
77 my ($status, $msg) = $child->AddLink( Target => $pid, Type => 'DependsOn' );
78 ok($status, "added reqursive link") or diag "error: $msg";
80 $_->ApplyTransactionBatch for $parent, $child;
82 my $plugin = RT::Shredder::Plugin::Tickets->new;
83 isa_ok($plugin, 'RT::Shredder::Plugin::Tickets');
86 ($status, $msg) = $plugin->TestArgs( query => 'Subject = "parent"' );
87 ok($status, "plugin arguments are ok") or diag "error: $msg";
89 ($status, @objs) = $plugin->Run;
90 ok($status, "executed plugin successfully") or diag "error: @objs";
91 @objs = RT::Shredder->CastObjectsToRecords( Objects => \@objs );
92 is(scalar @objs, 1, "only one object in result set");
93 is($objs[0]->id, $pid, "parent is in result set");
95 ($status, $msg) = $plugin->TestArgs( query => 'Subject = "parent"', with_linked => 1 );
96 ok($status, "plugin arguments are ok") or diag "error: $msg";
98 ($status, @objs) = $plugin->Run;
99 ok($status, "executed plugin successfully") or diag "error: @objs";
100 @objs = RT::Shredder->CastObjectsToRecords( Objects => \@objs );
101 is(scalar @objs, 2, "two objects in the result set");
102 my %has = map { $_->id => 1 } @objs;
103 ok($has{$pid}, "parent is in the result set");
104 ok($has{$cid}, "child is in the result set");
106 my $shredder = shredder_new();
107 $shredder->PutObjects( Objects => \@objs );
108 $shredder->WipeoutAll;
110 cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint");
112 { # create parent and child and check functionality of 'apply_query_to_linked' arg
113 my $parent = RT::Ticket->new( RT->SystemUser );
114 my ($pid) = $parent->Create( Subject => 'parent', Queue => 1 );
115 ok( $pid, "created new ticket" );
116 $parent->SetStatus('resolved');
118 my $child1 = RT::Ticket->new( RT->SystemUser );
119 my ($cid1) = $child1->Create( Subject => 'child', Queue => 1, MemberOf => $pid );
120 ok( $cid1, "created new ticket" );
121 my $child2 = RT::Ticket->new( RT->SystemUser );
122 my ($cid2) = $child2->Create( Subject => 'child', Queue => 1, MemberOf => $pid);
123 ok( $cid2, "created new ticket" );
124 $child2->SetStatus('resolved');
126 $_->ApplyTransactionBatch for $parent, $child1, $child2;
128 my $plugin = RT::Shredder::Plugin::Tickets->new;
129 isa_ok($plugin, 'RT::Shredder::Plugin::Tickets');
131 my ($status, $msg) = $plugin->TestArgs( query => 'Status = "resolved"', apply_query_to_linked => 1 );
132 ok($status, "plugin arguments are ok") or diag "error: $msg";
135 ($status, @objs) = $plugin->Run;
136 ok($status, "executed plugin successfully") or diag "error: @objs";
137 @objs = RT::Shredder->CastObjectsToRecords( Objects => \@objs );
138 is(scalar @objs, 2, "two objects in the result set");
139 my %has = map { $_->id => 1 } @objs;
140 ok($has{$pid}, "parent is in the result set");
141 ok(!$has{$cid1}, "first child is in the result set");
142 ok($has{$cid2}, "second child is in the result set");
144 my $shredder = shredder_new();
145 $shredder->PutObjects( Objects => \@objs );
146 $shredder->WipeoutAll;
148 my $ticket = RT::Ticket->new( RT->SystemUser );
149 $ticket->Load( $cid1 );
150 is($ticket->id, $cid1, 'loaded ticket');
152 $shredder->PutObjects( Objects => $ticket );
153 $shredder->WipeoutAll;
155 cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint");