fix postinst?
[freeside.git] / rt / t / approval / basic.t
index 5974591..e863bf1 100644 (file)
@@ -1,28 +1,19 @@
-
 use strict;
 use warnings;
-use Test::More;
-BEGIN {
-    eval { require Email::Abstract; require Test::Email; 1 }
-        or plan skip_all => 'require Email::Abstract and Test::Email';
-}
-
+use RT::Test tests => undef;
 
-use RT;
-use RT::Test tests => 39;
 use RT::Test::Email;
 
-RT->Config->Set( LogToScreen => 'debug' );
+RT->Config->Set( LogToSTDERR => 'debug' );
 RT->Config->Set( UseTransactionBatch => 1 );
-my ($baseurl, $m) = RT::Test->started_ok;
 
-my $q = RT::Queue->new($RT::SystemUser);
+my $q = RT::Queue->new(RT->SystemUser);
 $q->Load('___Approvals');
 $q->SetDisabled(0);
 
 my %users;
 for my $user_name (qw(minion cfo ceo )) {
-    my $user = $users{$user_name} = RT::User->new($RT::SystemUser);
+    my $user = $users{$user_name} = RT::User->new(RT->SystemUser);
     $user->Create( Name => uc($user_name),
                    Privileged => 1,
                    EmailAddress => $user_name.'@company.com');
@@ -37,7 +28,6 @@ my $approvals =
 Queue: ___Approvals
 Type: approval
 Owner: CFO
-Requestors: {$Tickets{"TOP"}->Requestors}
 Refers-To: TOP
 Subject: CFO Approval for PO: {$Tickets{"TOP"}->Id} - {$Tickets{"TOP"}->Subject}
 Due: {time + 86400}
@@ -50,7 +40,6 @@ ENDOFCONTENT
 Queue: ___Approvals
 Type: approval
 Owner: CEO
-Requestors: {$Tickets{"TOP"}->Requestors}
 Subject: PO approval request for {$Tickets{"TOP"}->Subject}
 Refers-To: TOP
 Depends-On: for-CFO
@@ -61,16 +50,16 @@ Your CFO approved PO ticket {$Tickets{"TOP"}->Id} for minion. you ok with that?
 ENDOFCONTENT
 ';
 
-my $apptemp = RT::Template->new($RT::SystemUser);
+my $apptemp = RT::Template->new(RT->SystemUser);
 $apptemp->Create( Content => $approvals, Name => "PO Approvals", Queue => "0");
 
 ok($apptemp->Id);
 
-$q = RT::Queue->new($RT::SystemUser);
+$q = RT::Queue->new(RT->SystemUser);
 $q->Create(Name => 'PO');
 ok ($q->Id, "Created PO queue");
 
-my $scrip = RT::Scrip->new($RT::SystemUser);
+my $scrip = RT::Scrip->new(RT->SystemUser);
 my ($sval, $smsg) =$scrip->Create( ScripCondition => 'On Create',
                 ScripAction => 'Create Tickets',
                 Template => 'PO Approvals',
@@ -82,7 +71,7 @@ ok ($scrip->TemplateObj->Id, "Created the scrip template");
 ok ($scrip->ConditionObj->Id, "Created the scrip condition");
 ok ($scrip->ActionObj->Id, "Created the scrip action");
 
-my $t = RT::Ticket->new($RT::SystemUser);
+my $t = RT::Ticket->new(RT->SystemUser);
 my ($tid, $ttrans, $tmsg);
 
 mail_ok {
@@ -90,14 +79,17 @@ mail_ok {
         $t->Create(Subject => "PO for stationary",
                    Owner => "root", Requestor => 'minion',
                    Queue => $q->Id);
-} { from => qr/RT System/,
-    to => 'cfo@company.com',
-    subject => qr/New Pending Approval: CFO Approval/,
-    body => qr/pending your approval.*Your approval is requested.*Blah/s
-},{ from => qr/PO via RT/,
+} { from => qr/PO via RT/,
     to => 'minion@company.com',
     subject => qr/PO for stationary/,
     body => qr/automatically generated in response/
+},{ from => qr/RT System/,
+    to => 'root@localhost',
+    subject => qr/PO for stationary/,
+}, { from => qr/RT System/,
+    to => 'cfo@company.com',
+    subject => qr/New Pending Approval: CFO Approval/,
+    body => qr/pending your approval.*Your approval is requested.*Blah/s
 };
 
 ok ($tid,$tmsg);
@@ -141,6 +133,9 @@ mail_ok {
     subject => qr/New Pending Approval: PO approval request for PO/,
     body => qr/pending your approval.*CFO approved.*ok with that\?/s
 },{ from => qr/RT System/,
+    to => 'root@localhost',
+    subject => qr/Ticket Approved:/,
+},{ from => qr/RT System/,
     to => 'minion@company.com',
     subject => qr/Ticket Approved:/,
     body => qr/approved by CFO.*notes: Resources exist to be consumed/s
@@ -169,10 +164,14 @@ mail_ok {
     ok($ok, "ceo can approve - $msg");
 
 } { from => qr/RT System/,
+    to => 'root@localhost',
+    subject => qr/Ticket Approved:/,
+    body => qr/approved by CEO.*Its Owner may now start to act on it.*notes: And consumed they will be/s,
+},{ from => qr/RT System/,
     to => 'minion@company.com',
     subject => qr/Ticket Approved:/,
     body => qr/approved by CEO.*Its Owner may now start to act on it.*notes: And consumed they will be/s,
-}, { from => qr'CEO via RT',
+},{ from => qr/CEO via RT/,
      to => 'root@localhost',
      subject => qr/Ticket Approved/,
      body => qr/The ticket has been approved, you may now start to act on it/,
@@ -207,6 +206,10 @@ mail_ok {
     ok($ok, "cfo can approve - $msg");
 
 } { from => qr/RT System/,
+    to => 'root@localhost',
+    subject => qr/Ticket Rejected: PO for stationary/,
+    body => qr/rejected by CFO.*out of resources/s,
+},{ from => qr/RT System/,
     to => 'minion@company.com',
     subject => qr/Ticket Rejected: PO for stationary/,
     body => qr/rejected by CFO.*out of resources/s,
@@ -216,3 +219,4 @@ $t->Load($t->id);$dependson_ceo->Load($dependson_ceo->id);
 is_deeply([ $t->Status, $dependson_cfo->Status, $dependson_ceo->Status ],
           [ 'rejected', 'rejected', 'deleted'], 'ticket state after cfo rejection');
 
+done_testing;