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