This commit was generated by cvs2svn to compensate for changes in r3921,
[freeside.git] / rt / lib / t / 05cronsupport.pl.in
1 #!@PERL@ -w
2
3 use strict;
4
5 ### Set up some testing data.  Test the testing data because why not?
6
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');
14
15 # Create our template, which will be used for tests of RT::Action::Record*.
16
17 my $template_content = 'RT-Send-Cc: tla@example.com
18 RT-Send-Bcc: jesse@example.com
19
20 This is a content string with no content.';
21
22 my $template_obj = RT::Template->new($CurrentUser);
23 $template_obj->Create(Queue       => '0',
24                       Name        => 'recordtest',
25                       Description => 'testing Record actions',
26                       Content     => $template_content,
27                      );
28
29 # Create a queue and some tickets.
30
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');
34
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',
39                                          Priority  => 22,
40                                         );
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'
46                                       );
47 ok($id, 'record test ticket creation 2');
48
49
50 ### OK.  Have data, will travel.
51
52 # First test the search.
53
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),
58                                       );
59 is(ref($search), 'RT::Search::FromSQL', "search created");
60 ok($search->Prepare(), "fromsql search run");
61 my $counter = 0;
62 while(my $t = $search->TicketsObj->Next() ) {
63     is($t->Id(), $ticket1->Id(), "fromsql search results 1");
64     $counter++;
65 }
66 is ($counter, 1, "fromsql search results 2");
67
68 # Right.  Now test the actions.
69
70 ok(require RT::Action::RecordComment);
71 ok(require RT::Action::RecordCorrespondence);
72
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");
80
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");