This commit was generated by cvs2svn to compensate for changes in r4407,
[freeside.git] / rt / lib / t / regression / 05cronsupport.t
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Test::More qw/no_plan/;
5
6 use RT;
7 RT::LoadConfig();
8 RT::Init();
9
10 ### Set up some testing data.  Test the testing data because why not?
11
12 # Create a user with rights, a queue, and some tickets.
13 my $user_obj = RT::User->new($RT::SystemUser);
14 my ($ret, $msg) = $user_obj->LoadOrCreateByEmail('tara@example.com');
15 ok($ret, 'record test user creation');
16 $user_obj->SetName('tara');
17 $user_obj->PrincipalObj->GrantRight(Right => 'SuperUser');
18 my $CurrentUser = RT::CurrentUser->new('tara');
19
20 # Create our template, which will be used for tests of RT::Action::Record*.
21
22 my $template_content = 'RT-Send-Cc: tla@example.com
23 RT-Send-Bcc: jesse@example.com
24
25 This is a content string with no content.';
26
27 my $template_obj = RT::Template->new($CurrentUser);
28 $template_obj->Create(Queue       => '0',
29                       Name        => 'recordtest',
30                       Description => 'testing Record actions',
31                       Content     => $template_content,
32                      );
33
34 # Create a queue and some tickets.
35
36 my $queue_obj = RT::Queue->new($CurrentUser);
37 ($ret, $msg) = $queue_obj->Create(Name => 'recordtest', Description => 'queue for Action::Record testing');
38 ok($ret, 'record test queue creation');
39
40 my $ticket1 = RT::Ticket->new($CurrentUser);
41 my ($id, $tobj, $msg2) = $ticket1->Create(Queue    => $queue_obj,
42                                          Requestor => ['tara@example.com'],
43                                          Subject   => 'bork bork bork',
44                                          Priority  => 22,
45                                         );
46 ok($id, 'record test ticket creation 1');
47 my $ticket2 = RT::Ticket->new($CurrentUser);
48 ($id, $tobj, $msg2) = $ticket2->Create(Queue     => $queue_obj,
49                                       Requestor => ['root@localhost'],
50                                       Subject   => 'hurdy gurdy'
51                                       );
52 ok($id, 'record test ticket creation 2');
53
54
55 ### OK.  Have data, will travel.
56
57 # First test the search.
58
59 ok(require RT::Search::FromSQL, "Search::FromSQL loaded");
60 my $ticketsqlstr = "Requestor.EmailAddress = '" . $CurrentUser->EmailAddress .
61     "' AND Priority > '20'";
62 my $search = RT::Search::FromSQL->new(Argument => $ticketsqlstr, TicketsObj => RT::Tickets->new($CurrentUser),
63                                       );
64 is(ref($search), 'RT::Search::FromSQL', "search created");
65 ok($search->Prepare(), "fromsql search run");
66 my $counter = 0;
67 while(my $t = $search->TicketsObj->Next() ) {
68     is($t->Id(), $ticket1->Id(), "fromsql search results 1");
69     $counter++;
70 }
71 is ($counter, 1, "fromsql search results 2");
72
73 # Right.  Now test the actions.
74
75 ok(require RT::Action::RecordComment);
76 ok(require RT::Action::RecordCorrespondence);
77
78 my ($comment_act, $correspond_act);
79 ok($comment_act = RT::Action::RecordComment->new(TicketObj => $ticket1, TemplateObj => $template_obj, CurrentUser => $CurrentUser), "RecordComment created");
80 ok($correspond_act = RT::Action::RecordCorrespondence->new(TicketObj => $ticket2, TemplateObj => $template_obj, CurrentUser => $CurrentUser), "RecordCorrespondence created");
81 ok($comment_act->Prepare(), "Comment prepared");
82 ok($correspond_act->Prepare(), "Correspond prepared");
83 ok($comment_act->Commit(), "Comment committed");
84 ok($correspond_act->Commit(), "Correspondence committed");
85
86 # Now test for loop suppression.
87 my ($trans, $desc, $transaction) = $ticket2->Comment(MIMEObj => $template_obj->MIMEObj);
88 my $bogus_action = RT::Action::RecordComment->new(TicketObj => $ticket1, TemplateObj => $template_obj, TransactionObj => $transaction, CurrentUser => $CurrentUser);
89 ok(!$bogus_action->Prepare(), "Comment aborted to prevent loop");
90
91 1;