8 use Test::More tests => 44;
11 my $shredder_utils = RT::Test::get_relocatable_file('utils.pl',
12 File::Spec->curdir());
13 require $shredder_utils;
17 use_ok('RT::Shredder::Plugin::Tickets');
19 my $plugin = RT::Shredder::Plugin::Tickets->new;
20 isa_ok($plugin, 'RT::Shredder::Plugin::Tickets');
22 is(lc $plugin->Type, 'search', 'correct type');
26 create_savepoint('clean');
28 use_ok('RT::Tickets');
30 { # create parent and child and check functionality of 'with_linked' arg
31 my $parent = RT::Ticket->new( RT->SystemUser );
32 my ($pid) = $parent->Create( Subject => 'parent', Queue => 1 );
33 ok( $pid, "created new ticket" );
34 my $child = RT::Ticket->new( RT->SystemUser );
35 my ($cid) = $child->Create( Subject => 'child', Queue => 1, MemberOf => $pid );
36 ok( $cid, "created new ticket" );
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 my $plugin = RT::Shredder::Plugin::Tickets->new;
81 isa_ok($plugin, 'RT::Shredder::Plugin::Tickets');
84 ($status, $msg) = $plugin->TestArgs( query => 'Subject = "parent"' );
85 ok($status, "plugin arguments are ok") or diag "error: $msg";
87 ($status, @objs) = $plugin->Run;
88 ok($status, "executed plugin successfully") or diag "error: @objs";
89 @objs = RT::Shredder->CastObjectsToRecords( Objects => \@objs );
90 is(scalar @objs, 1, "only one object in result set");
91 is($objs[0]->id, $pid, "parent is in result set");
93 ($status, $msg) = $plugin->TestArgs( query => 'Subject = "parent"', with_linked => 1 );
94 ok($status, "plugin arguments are ok") or diag "error: $msg";
96 ($status, @objs) = $plugin->Run;
97 ok($status, "executed plugin successfully") or diag "error: @objs";
98 @objs = RT::Shredder->CastObjectsToRecords( Objects => \@objs );
99 is(scalar @objs, 2, "two objects in the result set");
100 my %has = map { $_->id => 1 } @objs;
101 ok($has{$pid}, "parent is in the result set");
102 ok($has{$cid}, "child is in the result set");
104 my $shredder = shredder_new();
105 $shredder->PutObjects( Objects => \@objs );
106 $shredder->WipeoutAll;
108 cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint");
110 { # create parent and child and check functionality of 'apply_query_to_linked' arg
111 my $parent = RT::Ticket->new( RT->SystemUser );
112 my ($pid) = $parent->Create( Subject => 'parent', Queue => 1 );
113 ok( $pid, "created new ticket" );
114 $parent->SetStatus('resolved');
116 my $child1 = RT::Ticket->new( RT->SystemUser );
117 my ($cid1) = $child1->Create( Subject => 'child', Queue => 1, MemberOf => $pid );
118 ok( $cid1, "created new ticket" );
119 my $child2 = RT::Ticket->new( RT->SystemUser );
120 my ($cid2) = $child2->Create( Subject => 'child', Queue => 1, MemberOf => $pid);
121 ok( $cid2, "created new ticket" );
122 $child2->SetStatus('resolved');
124 my $plugin = RT::Shredder::Plugin::Tickets->new;
125 isa_ok($plugin, 'RT::Shredder::Plugin::Tickets');
127 my ($status, $msg) = $plugin->TestArgs( query => 'Status = "resolved"', apply_query_to_linked => 1 );
128 ok($status, "plugin arguments are ok") or diag "error: $msg";
131 ($status, @objs) = $plugin->Run;
132 ok($status, "executed plugin successfully") or diag "error: @objs";
133 @objs = RT::Shredder->CastObjectsToRecords( Objects => \@objs );
134 is(scalar @objs, 2, "two objects in the result set");
135 my %has = map { $_->id => 1 } @objs;
136 ok($has{$pid}, "parent is in the result set");
137 ok(!$has{$cid1}, "first child is in the result set");
138 ok($has{$cid2}, "second child is in the result set");
140 my $shredder = shredder_new();
141 $shredder->PutObjects( Objects => \@objs );
142 $shredder->WipeoutAll;
144 my $ticket = RT::Ticket->new( RT->SystemUser );
145 $ticket->Load( $cid1 );
146 is($ticket->id, $cid1, 'loaded ticket');
148 $shredder->PutObjects( Objects => $ticket );
149 $shredder->WipeoutAll;
151 cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint");