3 use Test::More tests => 30;
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 );
20 my ($childid) = $child_ticket->Create(
21 Subject => 'test child',
24 ok($childid, "We created a child ticket");
26 my $parent_ticket = new RT::Ticket( $CurrentUser );
27 my ($parentid) = $parent_ticket->Create(
28 Subject => 'test parent',
29 Children => [ $childid ],
32 ok($parentid, "We created a parent ticket");
35 my $Collection = RT::Tickets->new($CurrentUser);
36 $Collection->LimitMemberOf( $parentid );
37 is($Collection->Count,1, "We found only one result");
38 ok($Collection->First);
39 is($Collection->First->id, $childid, "We found the collection of all children of $parentid with Limit");
41 $Collection = RT::Tickets->new($CurrentUser);
42 $Collection->FromSQL("MemberOf = $parentid");
43 is($Collection->Count, 1, "We found only one result");
44 ok($Collection->First);
45 is($Collection->First->id, $childid, "We found the collection of all children of $parentid with TicketSQL");
48 $Collection = RT::Tickets->new($CurrentUser);
49 $Collection->LimitHasMember ($childid);
50 is($Collection->Count,1, "We found only one result");
51 ok($Collection->First);
52 is($Collection->First->id, $parentid, "We found the collection of all parents of $childid with Limit");
55 $Collection = RT::Tickets->new($CurrentUser);
56 $Collection->FromSQL("HasMember = $childid");
57 is($Collection->Count,1, "We found only one result");
58 ok($Collection->First);
59 is($Collection->First->id, $parentid, "We found the collection of all parents of $childid with TicketSQL");
62 # Now we find a collection of all the tickets which have no members. they should have no children.
63 $Collection = RT::Tickets->new($CurrentUser);
64 $Collection->LimitHasMember('');
65 # must contain child; must not contain parent
67 while (my $t = $Collection->Next) {
70 ok( $has{$childid}, "The collection has our child - $childid");
71 ok( !$has{$parentid}, "The collection doesn't have our parent - $parentid");
74 # Now we find a collection of all the tickets which are not members of anything. they should have no parents.
75 $Collection = RT::Tickets->new($CurrentUser);
76 $Collection->LimitMemberOf('');
77 # must contain parent; must not contain child
79 while (my $t = $Collection->Next) {
82 ok ($has{$parentid} , "The collection has our parent - $parentid");
83 ok( !$has{$childid}, "The collection doesn't have our child - $childid");
86 # Do it all over with TicketSQL
91 # Now we find a collection of all the tickets which have no members. they should have no children.
92 $Collection = RT::Tickets->new($CurrentUser);
93 $Collection->FromSQL ("HasMember IS NULL");
94 # must contain parent; must not contain child
96 while (my $t = $Collection->Next) {
99 ok( !$has{$parentid}, "The collection doesn't have our parent - $parentid");
100 ok( $has{$childid}, "The collection has our child - $childid");
103 # Now we find a collection of all the tickets which have no members. they should have no children.
105 $Collection = RT::Tickets->new($CurrentUser);
106 $Collection->FromSQL("HasMember = ''");
107 # must contain parent; must not contain child
109 while (my $t = $Collection->Next) {
112 ok( !$has{$parentid}, "The collection doesn't have our parent - $parentid");
113 ok( $has{$childid}, "The collection has our child - $childid");
116 # Now we find a collection of all the tickets which are not members of anything. they should have no parents.
117 $Collection = RT::Tickets->new($CurrentUser);
118 $Collection->FromSQL("MemberOf IS NULL");
119 # must not contain parent; must contain parent
121 while (my $t = $Collection->Next) {
124 ok( $has{$parentid}, "The collection has our parent - $parentid");
125 ok( !$has{$childid}, "The collection doesn't have our child - $childid");
128 # Now we find a collection of all the tickets which are not members of anything. they should have no parents.
129 $Collection = RT::Tickets->new($CurrentUser);
130 $Collection->FromSQL("MemberOf = ''");
131 # must not contain parent; must contain parent
133 while (my $t = $Collection->Next) {
136 ok( $has{$parentid}, "The collection has our parent - $parentid");
137 ok( !$has{$childid}, "The collection doesn't have our child - $childid");
140 # Now we find a collection of all the tickets which are not members of the parent ticket
141 $Collection = RT::Tickets->new($CurrentUser);
142 $Collection->FromSQL("MemberOf != $parentid");
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");
150 $Collection = RT::Tickets->new($CurrentUser);
151 $Collection->LimitMemberOf($parentid, OPERATOR => '!=');
153 while (my $t = $Collection->Next) {
156 ok( $has{$parentid}, "The collection has our parent - $parentid");
157 ok( !$has{$childid}, "The collection doesn't have our child - $childid");