5 ### Set up some testing data. Test the testing data because why not?
7 # Create a user with rights, a queue, and some tickets.
8 my $user_obj = RT::User->new($RT::SystemUser);
9 my ($ret, $msg) = $user_obj->LoadOrCreateByEmail('tara@example.com');
10 ok($ret, 'record test user creation');
11 $user_obj->SetName('tara');
12 $user_obj->PrincipalObj->GrantRight(Right => 'SuperUser');
13 my $CurrentUser = RT::CurrentUser->new('tara');
15 # Create our template, which will be used for tests of RT::Action::Record*.
17 my $template_content = 'RT-Send-Cc: tla@example.com
18 RT-Send-Bcc: jesse@example.com
20 This is a content string with no content.';
22 my $template_obj = RT::Template->new($CurrentUser);
23 $template_obj->Create(Queue => '0',
25 Description => 'testing Record actions',
26 Content => $template_content,
29 # Create a queue and some tickets.
31 my $queue_obj = RT::Queue->new($CurrentUser);
32 ($ret, $msg) = $queue_obj->Create(Name => 'recordtest', Description => 'queue for Action::Record testing');
33 ok($ret, 'record test queue creation');
35 my $ticket1 = RT::Ticket->new($CurrentUser);
36 my ($id, $tobj, $msg2) = $ticket1->Create(Queue => $queue_obj,
37 Requestor => ['tara@example.com'],
38 Subject => 'bork bork bork',
41 ok($id, 'record test ticket creation 1');
42 my $ticket2 = RT::Ticket->new($CurrentUser);
43 ($id, $tobj, $msg2) = $ticket2->Create(Queue => $queue_obj,
44 Requestor => ['root@localhost'],
45 Subject => 'hurdy gurdy'
47 ok($id, 'record test ticket creation 2');
50 ### OK. Have data, will travel.
52 # First test the search.
54 ok(require RT::Search::FromSQL, "Search::FromSQL loaded");
55 my $ticketsqlstr = "Requestor.EmailAddress = '" . $CurrentUser->EmailAddress .
56 "' AND Priority > '20'";
57 my $search = RT::Search::FromSQL->new(Argument => $ticketsqlstr, TicketsObj => RT::Tickets->new($CurrentUser),
59 is(ref($search), 'RT::Search::FromSQL', "search created");
60 ok($search->Prepare(), "fromsql search run");
62 while(my $t = $search->TicketsObj->Next() ) {
63 is($t->Id(), $ticket1->Id(), "fromsql search results 1");
66 is ($counter, 1, "fromsql search results 2");
68 # Right. Now test the actions.
70 ok(require RT::Action::RecordComment);
71 ok(require RT::Action::RecordCorrespondence);
73 my ($comment_act, $correspond_act);
74 ok($comment_act = RT::Action::RecordComment->new(TicketObj => $ticket1, TemplateObj => $template_obj, CurrentUser => $CurrentUser), "RecordComment created");
75 ok($correspond_act = RT::Action::RecordCorrespondence->new(TicketObj => $ticket2, TemplateObj => $template_obj, CurrentUser => $CurrentUser), "RecordCorrespondence created");
76 ok($comment_act->Prepare(), "Comment prepared");
77 ok($correspond_act->Prepare(), "Correspond prepared");
78 ok($comment_act->Commit(), "Comment committed");
79 ok($correspond_act->Commit(), "Correspondence committed");
81 # Now test for loop suppression.
82 my ($trans, $desc, $transaction) = $ticket2->Comment(MIMEObj => $template_obj->MIMEObj);
83 my $bogus_action = RT::Action::RecordComment->new(TicketObj => $ticket1, TemplateObj => $template_obj, TransactionObj => $transaction, CurrentUser => $CurrentUser);
84 ok(!$bogus_action->Prepare(), "Comment aborted to prevent loop");