[Rt-commit] r17080 - rt/3.8/trunk/t/approval

clkao at bestpractical.com clkao at bestpractical.com
Wed Dec 3 02:32:12 EST 2008


Author: clkao
Date: Wed Dec  3 02:32:11 2008
New Revision: 17080

Added:
   rt/3.8/trunk/t/approval/
   rt/3.8/trunk/t/approval/basic.t

Log:
basic tests for 2-stage approval.

Added: rt/3.8/trunk/t/approval/basic.t
==============================================================================
--- (empty file)
+++ rt/3.8/trunk/t/approval/basic.t	Wed Dec  3 02:32:11 2008
@@ -0,0 +1,104 @@
+
+use strict;
+use warnings;
+use Test::More; 
+plan tests => 20;
+use RT;
+use RT::Test;
+RT->Config->Set( LogToScreen => 'debug' );
+my ($baseurl, $m) = RT::Test->started_ok;
+
+my ($user_a, $user_b) = (RT::User->new($RT::SystemUser), RT::User->new($RT::SystemUser));
+my ($user_c) = RT::User->new($RT::SystemUser);
+
+$user_a->Create( Name => 'CFO', Privileged => 1, EmailAddress => 'cfo at company.com');
+$user_b->Create( Name => 'CEO', Privileged => 1, EmailAddress => 'ceo at company.com');
+$user_c->Create( Name => 'minion', Privileged => 1, EmailAddress => 'minion at company.com');
+
+my $q = RT::Queue->new($RT::SystemUser);
+$q->Load('___Approvals');
+
+my ($val, $msg) = $user_a->PrincipalObj->GrantRight(Object =>$q, Right => 'OwnTicket');
+($val, $msg) = $user_b->PrincipalObj->GrantRight(Object =>$q, Right => 'OwnTicket');
+
+my $approvals = 
+'===Create-Ticket: for-CFO
+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}
+Content-Type: text/plain
+Content: Your approval is requested for the PO ticket {$Tickets{"TOP"}->Id}: {$Tickets{"TOP"}->Subject}
+Blah
+Blah
+ENDOFCONTENT
+===Create-Ticket: for-CEO
+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
+Depended-On-By: {$Tickets{"TOP"}->Id}
+Content-Type: text/plain
+Content: 
+Your CFO approved PO ticket {$Tickets{"TOP"}->Id} for minion. you ok with that?
+ENDOFCONTENT
+';
+
+my $apptemp = RT::Template->new($RT::SystemUser);
+$apptemp->Create( Content => $approvals, Name => "PO Approvals", Queue => "0");
+
+ok($apptemp->Id);
+
+my $q = RT::Queue->new($RT::SystemUser);
+$q->Create(Name => 'PO');
+ok ($q->Id, "Created PO queue");
+
+my $scrip = RT::Scrip->new($RT::SystemUser);
+my ($sval, $smsg) =$scrip->Create( ScripCondition => 'On Create',
+                ScripAction => 'Create Tickets',
+                Template => 'PO Approvals',
+                Queue => $q->Id);
+ok ($sval, $smsg);
+ok ($scrip->Id, "Created the scrip");
+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($tid, $ttrans, $tmsg) = $t->Create(Subject => "PO for stationary",
+           Owner => "root", Requestor => 'minion',
+           Queue => $q->Id);
+
+ok ($tid,$tmsg);
+
+is ($t->ReferredToBy->Count,2, "referred to by the two tickets");
+
+my $deps = $t->DependsOn;
+is ($deps->Count, 1, "The ticket we created depends on one other ticket");
+my $dependson_ceo= $deps->First->TargetObj;
+ok ($dependson_ceo->Id, "It depends on a real ticket");
+like($dependson_ceo->Subject, qr/PO approval request.*stationary/);
+
+$deps = $dependson_ceo->DependsOn;
+is ($deps->Count, 1, "The ticket we created depends on one other ticket");
+my $dependson_cfo = $deps->First->TargetObj;
+ok ($dependson_cfo->Id, "It depends on a real ticket");
+
+like($dependson_cfo->Subject, qr/CFO Approval for PO.*stationary/);
+
+is_deeply([ $t->Status, $dependson_cfo->Status, $dependson_ceo->Status ],
+          [ 'new', 'new', 'new']);
+
+$dependson_cfo->SetStatus( Status => 'resolved' );#, Force => 1);
+
+is ($t->DependsOn->Count, 1, "still depends only on the CEO approval");
+is ($t->ReferredToBy->Count,2, "referred to by the two tickets");
+
+is_deeply([ $t->Status, $dependson_cfo->Status, $dependson_ceo->Status ],
+          [ 'new', 'resolved', 'open']);


More information about the Rt-commit mailing list