import rt 3.8.9
[freeside.git] / rt / lib / t / regression / 01ticket_link_searching.t
1 #!/usr/bin/perl -w
2
3 use Test::More tests => 30;
4 use strict;
5 use RT;
6
7 # Load the config file
8 RT::LoadConfig();
9
10 #Connect to the database and get RT::SystemUser and RT::Nobody loaded
11 RT::Init();
12
13 #Get the current user all loaded
14 my $CurrentUser = $RT::SystemUser;
15
16 my $queue = new RT::Queue($CurrentUser);
17 $queue->Load('General') || Abort(loc("Queue could not be loaded."));
18
19 my $child_ticket = new RT::Ticket( $CurrentUser );
20 my ($childid) = $child_ticket->Create(
21     Subject => 'test child',
22     Queue => $queue->Id,
23 );
24 ok($childid, "We created a child ticket");
25
26 my $parent_ticket = new RT::Ticket( $CurrentUser );
27 my ($parentid) = $parent_ticket->Create(
28     Subject => 'test parent',
29     Children => [ $childid ],
30     Queue => $queue->Id,
31 );
32 ok($parentid, "We created a parent ticket");
33
34
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");
40
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");
46
47
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");
53
54
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");
60
61
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
66 my %has;
67 while (my $t = $Collection->Next) {
68     ++$has{$t->id};
69 }
70 ok( $has{$childid}, "The collection has our child - $childid");
71 ok( !$has{$parentid}, "The collection doesn't have our parent - $parentid");
72
73
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
78 %has = ();
79 while (my $t = $Collection->Next) {
80     ++$has{$t->id};
81 }
82 ok ($has{$parentid} , "The collection has our parent - $parentid");
83 ok( !$has{$childid}, "The collection doesn't have our child - $childid");
84
85
86 #  Do it all over with TicketSQL
87 #
88
89
90
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
95 %has = ();
96 while (my $t = $Collection->Next) {
97     ++$has{$t->id};
98 }
99 ok( !$has{$parentid}, "The collection doesn't have our parent - $parentid");
100 ok( $has{$childid}, "The collection has our child - $childid");
101
102
103 # Now we find a collection of all the tickets which have no members. they should have no children.
104 # Alternate syntax
105 $Collection = RT::Tickets->new($CurrentUser);
106 $Collection->FromSQL("HasMember = ''");
107 # must contain parent; must not contain child
108 %has = ();
109 while (my $t = $Collection->Next) {
110     ++$has{$t->id};
111 }
112 ok( !$has{$parentid}, "The collection doesn't have our parent - $parentid");
113 ok( $has{$childid}, "The collection has our child - $childid");
114
115
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
120 %has = ();
121 while (my $t = $Collection->Next) {
122     ++$has{$t->id};
123 }
124 ok( $has{$parentid}, "The collection has our parent - $parentid");
125 ok( !$has{$childid}, "The collection doesn't have our child - $childid");
126
127
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
132 %has = ();
133 while (my $t = $Collection->Next) {
134     ++$has{$t->id};
135 }
136 ok( $has{$parentid}, "The collection has our parent - $parentid");
137 ok( !$has{$childid}, "The collection doesn't have our child - $childid");
138
139
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");
143 %has = ();
144 while (my $t = $Collection->Next) {
145     ++$has{$t->id};
146 }
147 ok( $has{$parentid}, "The collection has our parent - $parentid");
148 ok( !$has{$childid}, "The collection doesn't have our child - $childid");
149
150 $Collection = RT::Tickets->new($CurrentUser);
151 $Collection->LimitMemberOf($parentid, OPERATOR => '!=');
152 %has = ();
153 while (my $t = $Collection->Next) {
154     ++$has{$t->id};
155 }
156 ok( $has{$parentid}, "The collection has our parent - $parentid");
157 ok( !$has{$childid}, "The collection doesn't have our child - $childid");
158
159 1;