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