7 use RT::Test tests => 63;
9 #Connect to the database and get RT::SystemUser and RT::Nobody loaded
12 #Get the current user all loaded
13 my $CurrentUser = $RT::SystemUser;
15 my $queue = new RT::Queue($CurrentUser);
16 $queue->Load('General') || Abort(loc("Queue could not be loaded."));
18 my $child_ticket = new RT::Ticket( $CurrentUser );
19 my ($childid) = $child_ticket->Create(
20 Subject => 'test child',
23 ok($childid, "We created a child ticket");
25 my $parent_ticket = new RT::Ticket( $CurrentUser );
26 my ($parentid) = $parent_ticket->Create(
27 Subject => 'test parent',
28 Children => [ $childid ],
31 ok($parentid, "We created a parent ticket");
34 my $Collection = RT::Tickets->new($CurrentUser);
35 $Collection->LimitMemberOf( $parentid );
36 is($Collection->Count,1, "We found only one result");
37 ok($Collection->First);
38 is($Collection->First->id, $childid, "We found the collection of all children of $parentid with Limit");
40 $Collection = RT::Tickets->new($CurrentUser);
41 $Collection->FromSQL("MemberOf = $parentid");
42 is($Collection->Count, 1, "We found only one result");
43 ok($Collection->First);
44 is($Collection->First->id, $childid, "We found the collection of all children of $parentid with TicketSQL");
47 $Collection = RT::Tickets->new($CurrentUser);
48 $Collection->LimitHasMember ($childid);
49 is($Collection->Count,1, "We found only one result");
50 ok($Collection->First);
51 is($Collection->First->id, $parentid, "We found the collection of all parents of $childid with Limit");
54 $Collection = RT::Tickets->new($CurrentUser);
55 $Collection->FromSQL("HasMember = $childid");
56 is($Collection->Count,1, "We found only one result");
57 ok($Collection->First);
58 is($Collection->First->id, $parentid, "We found the collection of all parents of $childid with TicketSQL");
61 # Now we find a collection of all the tickets which have no members. they should have no children.
62 $Collection = RT::Tickets->new($CurrentUser);
63 $Collection->LimitHasMember('');
64 # must contain child; must not contain parent
66 while (my $t = $Collection->Next) {
69 ok( $has{$childid}, "The collection has our child - $childid");
70 ok( !$has{$parentid}, "The collection doesn't have our parent - $parentid");
73 # Now we find a collection of all the tickets which are not members of anything. they should have no parents.
74 $Collection = RT::Tickets->new($CurrentUser);
75 $Collection->LimitMemberOf('');
76 # must contain parent; must not contain child
78 while (my $t = $Collection->Next) {
81 ok ($has{$parentid} , "The collection has our parent - $parentid");
82 ok( !$has{$childid}, "The collection doesn't have our child - $childid");
85 # Do it all over with TicketSQL
90 # Now we find a collection of all the tickets which have no members. they should have no children.
91 $Collection = RT::Tickets->new($CurrentUser);
92 $Collection->FromSQL ("HasMember IS NULL");
93 # must contain parent; must not contain child
95 while (my $t = $Collection->Next) {
98 ok( !$has{$parentid}, "The collection doesn't have our parent - $parentid");
99 ok( $has{$childid}, "The collection has our child - $childid");
102 # Now we find a collection of all the tickets which have no members. they should have no children.
104 $Collection = RT::Tickets->new($CurrentUser);
105 $Collection->FromSQL("HasMember = ''");
106 # must contain parent; must not contain child
108 while (my $t = $Collection->Next) {
111 ok( !$has{$parentid}, "The collection doesn't have our parent - $parentid");
112 ok( $has{$childid}, "The collection has our child - $childid");
115 # Now we find a collection of all the tickets which are not members of anything. they should have no parents.
116 $Collection = RT::Tickets->new($CurrentUser);
117 $Collection->FromSQL("MemberOf IS NULL");
118 # must not contain parent; must contain parent
120 while (my $t = $Collection->Next) {
123 ok( $has{$parentid}, "The collection has our parent - $parentid");
124 ok( !$has{$childid}, "The collection doesn't have our child - $childid");
127 # Now we find a collection of all the tickets which are not members of anything. they should have no parents.
128 $Collection = RT::Tickets->new($CurrentUser);
129 $Collection->FromSQL("MemberOf = ''");
130 # must not contain parent; must contain parent
132 while (my $t = $Collection->Next) {
135 ok( $has{$parentid}, "The collection has our parent - $parentid");
136 ok( !$has{$childid}, "The collection doesn't have our child - $childid");
139 # Now we find a collection of all the tickets which are not members of the parent ticket
140 $Collection = RT::Tickets->new($CurrentUser);
141 $Collection->FromSQL("MemberOf != $parentid");
143 while (my $t = $Collection->Next) {
146 ok( $has{$parentid}, "The collection has our parent - $parentid");
147 ok( !$has{$childid}, "The collection doesn't have our child - $childid");
149 $Collection = RT::Tickets->new($CurrentUser);
150 $Collection->LimitMemberOf($parentid, OPERATOR => '!=');
152 while (my $t = $Collection->Next) {
155 ok( $has{$parentid}, "The collection has our parent - $parentid");
156 ok( !$has{$childid}, "The collection doesn't have our child - $childid");
158 my $grand_child_ticket = new RT::Ticket( $CurrentUser );
159 my ($grand_childid) = $child_ticket->Create(
160 Subject => 'test child',
162 MemberOf => $childid,
164 ok($childid, "We created a grand child ticket");
166 my $unlinked_ticket = new RT::Ticket( $CurrentUser );
167 my ($unlinked_id) = $child_ticket->Create(
168 Subject => 'test unlinked',
171 ok($unlinked_id, "We created a grand child ticket");
173 $Collection = RT::Tickets->new($CurrentUser);
174 $Collection->FromSQL( "LinkedTo = $childid" );
175 is($Collection->Count,1, "We found only one result");
176 ok($Collection->First);
177 is($Collection->First->id, $grand_childid, "We found all tickets linked to ticket #$childid");
179 $Collection = RT::Tickets->new($CurrentUser);
180 $Collection->FromSQL( "LinkedFrom = $childid" );
181 is($Collection->Count,1, "We found only one result");
182 ok($Collection->First);
183 is($Collection->First->id, $parentid, "We found all tickets linked from ticket #$childid");
185 $Collection = RT::Tickets->new($CurrentUser);
186 $Collection->FromSQL( "LinkedTo IS NULL" );
187 ok($Collection->Count, "Result is set is not empty");
189 while (my $t = $Collection->Next) {
192 ok( $has{$parentid}, "parent is in collection");
193 ok( $has{$unlinked_id}, "unlinked is in collection");
194 ok( !$has{$childid}, "child is NOT in collection");
195 ok( !$has{$grand_childid}, "grand child too is not in collection");
197 $Collection = RT::Tickets->new($CurrentUser);
198 $Collection->FromSQL( "LinkedTo IS NOT NULL" );
199 ok($Collection->Count, "Result set is not empty");
201 while (my $t = $Collection->Next) {
204 ok( !$has{$parentid}, "The collection has no our parent - $parentid");
205 ok( !$has{$unlinked_id}, "unlinked is not in collection");
206 ok( $has{$childid}, "The collection have our child - $childid");
207 ok( $has{$grand_childid}, "The collection have our grand child - $grand_childid");
209 $Collection = RT::Tickets->new($CurrentUser);
210 $Collection->FromSQL( "LinkedFrom IS NULL" );
211 ok($Collection->Count, "Result is set is not empty");
213 while (my $t = $Collection->Next) {
216 ok( !$has{$parentid}, "parent is NOT in collection");
217 ok( !$has{$childid}, "child is NOT in collection");
218 ok( $has{$grand_childid}, "grand child is in collection");
219 ok( $has{$unlinked_id}, "unlinked is in collection");
221 $Collection = RT::Tickets->new($CurrentUser);
222 $Collection->FromSQL( "LinkedFrom IS NOT NULL" );
223 ok($Collection->Count, "Result set is not empty");
225 while (my $t = $Collection->Next) {
228 ok( $has{$parentid}, "The collection has our parent - $parentid");
229 ok( $has{$childid}, "The collection have our child - $childid");
230 ok( !$has{$grand_childid}, "The collection have no our grand child - $grand_childid");
231 ok( !$has{$unlinked_id}, "unlinked is not in collection");
233 $Collection = RT::Tickets->new($CurrentUser);
234 $Collection->FromSQL( "Linked = $childid" );
235 is($Collection->Count, 2, "We found two tickets: parent and child");
237 while (my $t = $Collection->Next) {
240 ok( !$has{$childid}, "Ticket is not linked to itself");
241 ok( $has{$parentid}, "The collection has our parent");
242 ok( $has{$grand_childid}, "The collection have our child");
243 ok( !$has{$unlinked_id}, "unlinked is not in collection");