This commit was generated by cvs2svn to compensate for changes in r12472,
[freeside.git] / rt / t / cron.t
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use RT;
6 use RT::Test tests => 18;
7
8
9 ### Set up some testing data.  Test the testing data because why not?
10
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');
18
19 # Create our template, which will be used for tests of RT::Action::Record*.
20
21 my $template_content = 'RT-Send-Cc: tla@example.com
22 RT-Send-Bcc: jesse@example.com
23
24 This is a content string with no content.';
25
26 my $template_obj = RT::Template->new($CurrentUser);
27 $template_obj->Create(Queue       => '0',
28                       Name        => 'recordtest',
29                       Description => 'testing Record actions',
30                       Content     => $template_content,
31                      );
32
33 # Create a queue and some tickets.
34
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');
38
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',
43                                          Priority  => 22,
44                                         );
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'
50                                       );
51 ok($id, 'record test ticket creation 2');
52
53
54 ### OK.  Have data, will travel.
55
56 # First test the search.
57
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),
62                                       );
63 is(ref($search), 'RT::Search::FromSQL', "search created");
64 ok($search->Prepare(), "fromsql search run");
65 my $counter = 0;
66 while(my $t = $search->TicketsObj->Next() ) {
67     is($t->Id(), $ticket1->Id(), "fromsql search results 1");
68     $counter++;
69 }
70 is ($counter, 1, "fromsql search results 2");
71
72 # Right.  Now test the actions.
73
74 ok(require RT::Action::RecordComment);
75 ok(require RT::Action::RecordCorrespondence);
76
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");
84
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");
89
90 1;