5 use RT::Test tests => 87;
11 ok(my $testqueue = RT::Queue->new($RT::SystemUser));
12 ok($testqueue->Create( Name => 'ticket tests'));
13 isnt($testqueue->Id , 0);
14 use_ok('RT::CustomField');
15 ok(my $testcf = RT::CustomField->new($RT::SystemUser));
16 my ($ret, $cmsg) = $testcf->Create( Name => 'selectmulti',
17 Queue => $testqueue->id,
18 Type => 'SelectMultiple');
19 ok($ret,"Created the custom field - ".$cmsg);
20 ($ret,$cmsg) = $testcf->AddValue ( Name => 'Value1',
22 Description => 'A testing value');
24 ok($ret, "Added a value - ".$cmsg);
26 ok($testcf->AddValue ( Name => 'Value2',
28 Description => 'Another testing value'));
29 ok($testcf->AddValue ( Name => 'Value3',
31 Description => 'Yet Another testing value'));
33 is($testcf->Values->Count , 3);
37 my $u = RT::User->new($RT::SystemUser);
39 ok ($u->Id, "Found the root user");
40 ok(my $t = RT::Ticket->new($RT::SystemUser));
41 ok(my ($id, $msg) = $t->Create( Queue => $testqueue->Id,
46 is ($t->OwnerObj->Id , $u->Id, "Root is the ticket owner");
47 ok(my ($cfv, $cfm) =$t->AddCustomFieldValue(Field => $testcf->Id,
49 isnt($cfv , 0, "Custom field creation didn't return an error: $cfm");
50 is($t->CustomFieldValues($testcf->Id)->Count , 1);
51 ok($t->CustomFieldValues($testcf->Id)->First &&
52 $t->CustomFieldValues($testcf->Id)->First->Content eq 'Value1');
54 ok(my ($cfdv, $cfdm) = $t->DeleteCustomFieldValue(Field => $testcf->Id,
56 isnt ($cfdv , 0, "Deleted a custom field value: $cfdm");
57 is($t->CustomFieldValues($testcf->Id)->Count , 0);
59 ok(my $t2 = RT::Ticket->new($RT::SystemUser));
61 is($t2->Subject, 'Testing');
62 is($t2->QueueObj->Id, $testqueue->id);
63 is($t2->OwnerObj->Id, $u->Id);
65 my $t3 = RT::Ticket->new($RT::SystemUser);
66 my ($id3, $msg3) = $t3->Create( Queue => $testqueue->Id,
69 my ($cfv1, $cfm1) = $t->AddCustomFieldValue(Field => $testcf->Id,
71 isnt($cfv1 , 0, "Adding a custom field to ticket 1 is successful: $cfm");
72 my ($cfv2, $cfm2) = $t3->AddCustomFieldValue(Field => $testcf->Id,
74 isnt($cfv2 , 0, "Adding a custom field to ticket 2 is successful: $cfm");
75 my ($cfv3, $cfm3) = $t->AddCustomFieldValue(Field => $testcf->Id,
77 isnt($cfv3 , 0, "Adding a custom field to ticket 1 is successful: $cfm");
78 is($t->CustomFieldValues($testcf->Id)->Count , 2,
79 "This ticket has 2 custom field values");
80 is($t3->CustomFieldValues($testcf->Id)->Count , 1,
81 "This ticket has 1 custom field value");
89 ok(require RT::Ticket, "Loading the RT::Ticket library");
96 my $t = RT::Ticket->new($RT::SystemUser);
98 ok( $t->Create(Queue => 'General', Due => '2002-05-21 00:00:00', ReferredToBy => 'http://www.cpan.org', RefersTo => 'http://fsck.com', Subject => 'This is a subject'), "Ticket Created");
100 ok ( my $id = $t->Id, "Got ticket id");
101 like ($t->RefersTo->First->Target , qr/fsck.com/, "Got refers to");
102 like ($t->ReferredToBy->First->Base , qr/cpan.org/, "Got referredtoby");
103 is ($t->ResolvedObj->Unix, 0, "It hasn't been resolved - ". $t->ResolvedObj->Unix);
110 my $ticket = RT::Ticket->new($RT::SystemUser);
111 my ($id, $msg) = $ticket->Create(Subject => "Foo",
112 Owner => $RT::SystemUser->Id,
114 Requestor => ['jesse@example.com'],
117 ok ($id, "Ticket $id was created");
118 ok(my $group = RT::Group->new($RT::SystemUser));
119 ok($group->LoadTicketRoleGroup(Ticket => $id, Type=> 'Requestor'));
120 ok ($group->Id, "Found the requestors object for this ticket");
122 ok(my $jesse = RT::User->new($RT::SystemUser), "Creating a jesse rt::user");
123 $jesse->LoadByEmail('jesse@example.com');
124 ok($jesse->Id, "Found the jesse rt user");
127 ok ($ticket->IsWatcher(Type => 'Requestor', PrincipalId => $jesse->PrincipalId), "The ticket actually has jesse at fsck.com as a requestor");
128 ok (my ($add_id, $add_msg) = $ticket->AddWatcher(Type => 'Requestor', Email => 'bob@fsck.com'), "Added bob at fsck.com as a requestor");
129 ok ($add_id, "Add succeeded: ($add_msg)");
130 ok(my $bob = RT::User->new($RT::SystemUser), "Creating a bob rt::user");
131 $bob->LoadByEmail('bob@fsck.com');
132 ok($bob->Id, "Found the bob rt user");
133 ok ($ticket->IsWatcher(Type => 'Requestor', PrincipalId => $bob->PrincipalId), "The ticket actually has bob at fsck.com as a requestor");
134 ok ( ($add_id, $add_msg) = $ticket->DeleteWatcher(Type =>'Requestor', Email => 'bob@fsck.com'), "Added bob at fsck.com as a requestor");
135 ok (!$ticket->IsWatcher(Type => 'Requestor', PrincipalId => $bob->PrincipalId), "The ticket no longer has bob at fsck.com as a requestor");
138 $group = RT::Group->new($RT::SystemUser);
139 ok($group->LoadTicketRoleGroup(Ticket => $id, Type=> 'Cc'));
140 ok ($group->Id, "Found the cc object for this ticket");
141 $group = RT::Group->new($RT::SystemUser);
142 ok($group->LoadTicketRoleGroup(Ticket => $id, Type=> 'AdminCc'));
143 ok ($group->Id, "Found the AdminCc object for this ticket");
144 $group = RT::Group->new($RT::SystemUser);
145 ok($group->LoadTicketRoleGroup(Ticket => $id, Type=> 'Owner'));
146 ok ($group->Id, "Found the Owner object for this ticket");
147 ok($group->HasMember($RT::SystemUser->UserObj->PrincipalObj), "the owner group has the member 'RT_System'");
154 my $t = RT::Ticket->new($RT::SystemUser);
155 ok($t->Create(Queue => 'general', Subject => 'SquelchTest', SquelchMailTo => 'nobody@example.com'));
157 my @returned = $t->SquelchMailTo();
158 is($#returned, 0, "The ticket has one squelched recipients");
160 my ($ret, $msg) = $t->UnsquelchMailTo('nobody@example.com');
161 ok($ret, "Removed nobody as a squelched recipient - ".$msg);
162 @returned = $t->SquelchMailTo();
163 is($#returned, -1, "The ticket has no squelched recipients". join(',',@returned));
167 @returned = $t->SquelchMailTo('nobody@example.com');
168 is($#returned, 0, "The ticket has one squelched recipients");
170 my @names = $t->Attributes->Names;
171 is(shift @names, 'SquelchMailTo', "The attribute we have is SquelchMailTo");
172 @returned = $t->SquelchMailTo('nobody@example.com');
175 is($#returned, 0, "The ticket has one squelched recipients");
177 @names = $t->Attributes->Names;
178 is(shift @names, 'SquelchMailTo', "The attribute we have is SquelchMailTo");
181 ($ret, $msg) = $t->UnsquelchMailTo('nobody@example.com');
182 ok($ret, "Removed nobody as a squelched recipient - ".$msg);
183 @returned = $t->SquelchMailTo();
184 is($#returned, -1, "The ticket has no squelched recipients". join(',',@returned));
192 my $t1 = RT::Ticket->new($RT::SystemUser);
193 $t1->Create ( Subject => 'Merge test 1', Queue => 'general', Requestor => 'merge1@example.com');
195 my $t2 = RT::Ticket->new($RT::SystemUser);
196 $t2->Create ( Subject => 'Merge test 2', Queue => 'general', Requestor => 'merge2@example.com');
198 my ($msg, $val) = $t1->MergeInto($t2->id);
200 $t1 = RT::Ticket->new($RT::SystemUser);
201 is ($t1->id, undef, "ok. we've got a blank ticket1");
204 is ($t1->id, $t2->id);
206 is ($t1->Requestors->MembersObj->Count, 2);
214 my $root = RT::User->new($RT::SystemUser);
216 ok ($root->Id, "Loaded the root user");
217 my $t = RT::Ticket->new($RT::SystemUser);
219 $t->SetOwner('root');
220 is ($t->OwnerObj->Name, 'root' , "Root owns the ticket");
222 is ($t->OwnerObj->id, $RT::SystemUser->id , "SystemUser owns the ticket");
223 my $txns = RT::Transactions->new($RT::SystemUser);
224 $txns->OrderBy(FIELD => 'id', ORDER => 'DESC');
225 $txns->Limit(FIELD => 'ObjectId', VALUE => '1');
226 $txns->Limit(FIELD => 'ObjectType', VALUE => 'RT::Ticket');
227 $txns->Limit(FIELD => 'Type', OPERATOR => '!=', VALUE => 'EmailRecord');
229 my $steal = $txns->First;
230 is($steal->OldValue , $root->Id , "Stolen from root");
231 is($steal->NewValue , $RT::SystemUser->Id , "Stolen by the systemuser");
238 my $tt = RT::Ticket->new($RT::SystemUser);
239 my ($id, $tid, $msg)= $tt->Create(Queue => 'general',
242 is($tt->Status, 'new', "New ticket is created as new");
244 ($id, $msg) = $tt->SetStatus('open');
246 like($msg, qr/open/i, "Status message is correct");
247 ($id, $msg) = $tt->SetStatus('resolved');
249 like($msg, qr/resolved/i, "Status message is correct");
250 ($id, $msg) = $tt->SetStatus('resolved');