Merge branch 'patch-5' of https://github.com/gjones2/Freeside (#13854 as this bug...
[freeside.git] / rt / t / api / scrip.t
index 8e8f962..eb54347 100644 (file)
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 use RT;
-use RT::Test tests => 7;
+use RT::Test tests => 25;
 
 
 {
@@ -10,11 +10,11 @@ use RT::Test tests => 7;
 ok (require RT::Scrip);
 
 
-my $q = RT::Queue->new($RT::SystemUser);
+my $q = RT::Queue->new(RT->SystemUser);
 $q->Create(Name => 'ScripTest');
 ok($q->Id, "Created a scriptest queue");
 
-my $s1 = RT::Scrip->new($RT::SystemUser);
+my $s1 = RT::Scrip->new(RT->SystemUser);
 my ($val, $msg) =$s1->Create( Queue => $q->Id,
              ScripAction => 'User Defined',
              ScripCondition => 'User Defined',
@@ -25,7 +25,7 @@ my ($val, $msg) =$s1->Create( Queue => $q->Id,
     );
 ok($val,$msg);
 
-my $ticket = RT::Ticket->new($RT::SystemUser);
+my $ticket = RT::Ticket->new(RT->SystemUser);
 my ($tv,$ttv,$tm) = $ticket->Create(Queue => $q->Id,
                                     Subject => "hair on fire",
                                     );
@@ -34,7 +34,7 @@ ok($tv, $tm);
 is ($ticket->Priority , '87', "Ticket priority is set right");
 
 
-my $ticket2 = RT::Ticket->new($RT::SystemUser);
+my $ticket2 = RT::Ticket->new(RT->SystemUser);
 my ($t2v,$t2tv,$t2m) = $ticket2->Create(Queue => $q->Id,
                                     Subject => "hair in water",
                                     );
@@ -46,4 +46,74 @@ isnt ($ticket2->Priority , '87', "Ticket priority is set right");
 
 }
 
-1;
+
+{
+    my $scrip = RT::Scrip->new($RT::SystemUser);
+    my ( $val, $msg ) = $scrip->Create(
+        ScripCondition => 'On Comment',
+        ScripAction    => 'Notify Owner',
+    );
+    ok( !$val, "missing template: $msg" );
+    ( $val, $msg ) = $scrip->Create(
+        ScripCondition => 'On Comment',
+        ScripAction    => 'Notify Owner',
+        Template       => 'not exists',
+    );
+    ok( !$val, "invalid template: $msg" );
+
+    ( $val, $msg ) = $scrip->Create(
+        ScripAction => 'Notify Owner',
+        Template    => 'Blank',
+    );
+    ok( !$val, "missing condition: $msg" );
+    ( $val, $msg ) = $scrip->Create(
+        ScripCondition => 'not exists',
+        ScripAction    => 'Notify Owner',
+        Template       => 'Blank',
+    );
+    ok( !$val, "invalid condition: $msg" );
+
+    ( $val, $msg ) = $scrip->Create(
+        ScripCondition => 'On Comment',
+        Template       => 'Blank',
+    );
+    ok( !$val, "missing action: $msg" );
+    ( $val, $msg ) = $scrip->Create(
+        ScripCondition => 'On Comment',
+        ScripAction    => 'not exists',
+        Template       => 'Blank',
+    );
+    ok( !$val, "invalid action: $msg" );
+
+    ( $val, $msg ) = $scrip->Create(
+        ScripAction    => 'Notify Owner',
+        ScripCondition => 'On Comment',
+        Template       => 'Blank',
+    );
+    ok( $val, "created scrip: $msg" );
+    $scrip->Load($val);
+    ok( $scrip->id, 'loaded scrip ' . $scrip->id );
+
+    ( $val, $msg ) = $scrip->SetScripCondition();
+    ok( !$val, "missing condition: $msg" );
+    ( $val, $msg ) = $scrip->SetScripCondition('not exists');
+    ok( !$val, "invalid condition: $msg" );
+    ( $val, $msg ) = $scrip->SetScripCondition('On Correspond');
+    ok( $val, "updated condition to 'On Correspond': $msg" );
+
+    ( $val, $msg ) = $scrip->SetScripAction();
+    ok( !$val, "missing action: $msg" );
+    ( $val, $msg ) = $scrip->SetScripAction('not exists');
+    ok( !$val, "invalid action: $msg" );
+    ( $val, $msg ) = $scrip->SetScripAction('Notify AdminCcs');
+    ok( $val, "updated action to 'Notify AdminCcs': $msg" );
+
+    ( $val, $msg ) = $scrip->SetTemplate();
+    ok( !$val, "missing template $msg" );
+    ( $val, $msg ) = $scrip->SetTemplate('not exists');
+    ok( !$val, "invalid template $msg" );
+    ( $val, $msg ) = $scrip->SetTemplate('Forward');
+    ok( $val, "updated template to 'Forward': $msg" );
+
+    ok( $scrip->Delete, 'delete the scrip' );
+}