import rt 3.4.6
[freeside.git] / rt / lib / t / regression / 01ticket_link_searching.t
1 #!/usr/bin/perl -w
2
3 use Test::More tests => 25;
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
21 my ( $childid ) = $child_ticket->Create
22     ( Subject => 'test child',
23       Queue => $queue->Id);
24
25 ok($childid != 0);
26
27 my $parent_ticket = new RT::Ticket( $CurrentUser );
28
29 my ( $parentid ) = $parent_ticket->Create
30     ( Subject => 'test parent',
31       Children => [$childid],
32       Queue => $queue->Id);
33
34 ok($parentid != 0, "We created a parent ticket");
35
36 my $Collection = RT::Tickets->new($CurrentUser);
37 $Collection->LimitMemberOf ($parentid);
38
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");
42
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");
47
48
49
50
51
52 $Collection = RT::Tickets->new($CurrentUser);
53 $Collection->LimitHasMember ($childid);
54
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");
58
59
60
61 $Collection = RT::Tickets->new($CurrentUser);
62 $Collection->FromSQL("HasMember = $childid");
63
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");
67
68
69
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
74 my %has;
75 while (my $t = $Collection->Next) {
76     ++$has{$t->id};
77 }
78 ok ($has{$childid} , "The collection has our child - $childid");
79 ok( !$has{$parentid}, "The collection doesn't have our parent - $parentid");
80
81
82
83
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
88 %has = ();
89 while (my $t = $Collection->Next) {
90     ++$has{$t->id};
91 }
92 ok ($has{$parentid} , "The collection has our parent - $parentid");
93 ok( !$has{$childid}, "The collection doesn't have our child - $childid");
94
95
96 #  Do it all over with TicketSQL
97 #
98
99
100
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
105  %has = ();
106 while (my $t = $Collection->Next) {
107     ++$has{$t->id};
108 }
109 ok (!$has{$parentid} , "The collection doesn't have our parent - $parentid");
110 ok( $has{$childid}, "The collection has our child - $childid");
111
112
113 # Now we find a collection of all the tickets which have no members. they should have no children.
114 # Alternate syntax
115 $Collection = RT::Tickets->new($CurrentUser);
116 $Collection->FromSQL ("HasMember = ''");
117 # must contain parent; must not contain child
118  %has = ();
119 while (my $t = $Collection->Next) {
120     ++$has{$t->id};
121 }
122 ok (!$has{$parentid} , "The collection doesn't have our parent - $parentid");
123 ok( $has{$childid}, "The collection has our child - $childid");
124
125
126
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
131 %has = ();
132 while (my $t = $Collection->Next) {
133     ++$has{$t->id};
134 }
135 ok ($has{$parentid} , "The collection has our parent - $parentid");
136 ok(!$has{$childid}, "The collection doesn't have our child - $childid");
137
138
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
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
151
152
153 1;
154
155