3 use Test::More tests => 25;
10 #Connect to the database and get RT::SystemUser and RT::Nobody loaded
13 #Get the current user all loaded
14 my $CurrentUser = $RT::SystemUser;
16 my $queue = new RT::Queue($CurrentUser);
17 $queue->Load('General') || Abort(loc("Queue could not be loaded."));
19 my $child_ticket = new RT::Ticket( $CurrentUser );
21 my ( $childid ) = $child_ticket->Create
22 ( Subject => 'test child',
27 my $parent_ticket = new RT::Ticket( $CurrentUser );
29 my ( $parentid ) = $parent_ticket->Create
30 ( Subject => 'test parent',
31 Children => [$childid],
34 ok($parentid != 0, "We created a parent ticket");
36 my $Collection = RT::Tickets->new($CurrentUser);
37 $Collection->LimitMemberOf ($parentid);
39 ok ($Collection->First);
40 is ($Collection->First->id, $childid, "We found the collection of all children of $parentid with Limit");
41 is($Collection->Count,1, "We found only one result");
43 $Collection = RT::Tickets->new($CurrentUser);
44 $Collection->FromSQL( "MemberOf = $parentid");
45 is ($Collection->First->id, $childid, "We found the collection of all children of $parentid with TicketSQL");
46 is($Collection->Count,1, "We found only one result");
52 $Collection = RT::Tickets->new($CurrentUser);
53 $Collection->LimitHasMember ($childid);
55 ok ($Collection->First);
56 is ($Collection->First->id, $parentid, "We found the collection of all parents of $childid with Limit");
57 is($Collection->Count,1, "We found only one result");
61 $Collection = RT::Tickets->new($CurrentUser);
62 $Collection->FromSQL("HasMember = $childid");
64 ok ($Collection->First);
65 is ($Collection->First->id, $parentid, "We found the collection of all parents of $childid with TicketSQL");
66 is($Collection->Count,1, "We found only one result");
70 # Now we find a collection of all the tickets which have no members. they should have no children.
71 $Collection = RT::Tickets->new($CurrentUser);
72 $Collection->LimitHasMember('');
73 # must contain child; must not contain parent
75 while (my $t = $Collection->Next) {
78 ok ($has{$childid} , "The collection has our child - $childid");
79 ok( !$has{$parentid}, "The collection doesn't have our parent - $parentid");
84 # Now we find a collection of all the tickets which are not members of anything. they should have no parents.
85 $Collection = RT::Tickets->new($CurrentUser);
86 $Collection->LimitMemberOf('');
87 # must contain parent; must not contain child
89 while (my $t = $Collection->Next) {
92 ok ($has{$parentid} , "The collection has our parent - $parentid");
93 ok( !$has{$childid}, "The collection doesn't have our child - $childid");
96 # Do it all over with TicketSQL
101 # Now we find a collection of all the tickets which have no members. they should have no children.
102 $Collection = RT::Tickets->new($CurrentUser);
103 $Collection->FromSQL ("HasMember IS NULL");
104 # must contain parent; must not contain child
106 while (my $t = $Collection->Next) {
109 ok (!$has{$parentid} , "The collection doesn't have our parent - $parentid");
110 ok( $has{$childid}, "The collection has our child - $childid");
113 # Now we find a collection of all the tickets which have no members. they should have no children.
115 $Collection = RT::Tickets->new($CurrentUser);
116 $Collection->FromSQL ("HasMember = ''");
117 # must contain parent; must not contain child
119 while (my $t = $Collection->Next) {
122 ok (!$has{$parentid} , "The collection doesn't have our parent - $parentid");
123 ok( $has{$childid}, "The collection has 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 IS NULL");
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 anything. they should have no parents.
140 $Collection = RT::Tickets->new($CurrentUser);
141 $Collection->FromSQL("MemberOf = ''");
142 # must not contain parent; must contain parent
144 while (my $t = $Collection->Next) {
147 ok ($has{$parentid} , "The collection has our parent - $parentid");
148 ok(!$has{$childid}, "The collection doesn't have our child - $childid");