5 use RT::Test tests => 25;
10 ok (require RT::Scrip);
13 my $q = RT::Queue->new(RT->SystemUser);
14 $q->Create(Name => 'ScripTest');
15 ok($q->Id, "Created a scriptest queue");
17 my $s1 = RT::Scrip->new(RT->SystemUser);
18 my ($val, $msg) =$s1->Create( Queue => $q->Id,
19 ScripAction => 'User Defined',
20 ScripCondition => 'User Defined',
21 CustomIsApplicableCode => 'if ($self->TicketObj->Subject =~ /fire/) { return (1);} else { return(0)}',
22 CustomPrepareCode => 'return 1',
23 CustomCommitCode => '$self->TicketObj->SetPriority("87");',
28 my $ticket = RT::Ticket->new(RT->SystemUser);
29 my ($tv,$ttv,$tm) = $ticket->Create(Queue => $q->Id,
30 Subject => "hair on fire",
34 is ($ticket->Priority , '87', "Ticket priority is set right");
37 my $ticket2 = RT::Ticket->new(RT->SystemUser);
38 my ($t2v,$t2tv,$t2m) = $ticket2->Create(Queue => $q->Id,
39 Subject => "hair in water",
43 isnt ($ticket2->Priority , '87', "Ticket priority is set right");
51 my $scrip = RT::Scrip->new($RT::SystemUser);
52 my ( $val, $msg ) = $scrip->Create(
53 ScripCondition => 'On Comment',
54 ScripAction => 'Notify Owner',
56 ok( !$val, "missing template: $msg" );
57 ( $val, $msg ) = $scrip->Create(
58 ScripCondition => 'On Comment',
59 ScripAction => 'Notify Owner',
60 Template => 'not exists',
62 ok( !$val, "invalid template: $msg" );
64 ( $val, $msg ) = $scrip->Create(
65 ScripAction => 'Notify Owner',
68 ok( !$val, "missing condition: $msg" );
69 ( $val, $msg ) = $scrip->Create(
70 ScripCondition => 'not exists',
71 ScripAction => 'Notify Owner',
74 ok( !$val, "invalid condition: $msg" );
76 ( $val, $msg ) = $scrip->Create(
77 ScripCondition => 'On Comment',
80 ok( !$val, "missing action: $msg" );
81 ( $val, $msg ) = $scrip->Create(
82 ScripCondition => 'On Comment',
83 ScripAction => 'not exists',
86 ok( !$val, "invalid action: $msg" );
88 ( $val, $msg ) = $scrip->Create(
89 ScripAction => 'Notify Owner',
90 ScripCondition => 'On Comment',
93 ok( $val, "created scrip: $msg" );
95 ok( $scrip->id, 'loaded scrip ' . $scrip->id );
97 ( $val, $msg ) = $scrip->SetScripCondition();
98 ok( !$val, "missing condition: $msg" );
99 ( $val, $msg ) = $scrip->SetScripCondition('not exists');
100 ok( !$val, "invalid condition: $msg" );
101 ( $val, $msg ) = $scrip->SetScripCondition('On Correspond');
102 ok( $val, "updated condition to 'On Correspond': $msg" );
104 ( $val, $msg ) = $scrip->SetScripAction();
105 ok( !$val, "missing action: $msg" );
106 ( $val, $msg ) = $scrip->SetScripAction('not exists');
107 ok( !$val, "invalid action: $msg" );
108 ( $val, $msg ) = $scrip->SetScripAction('Notify AdminCcs');
109 ok( $val, "updated action to 'Notify AdminCcs': $msg" );
111 ( $val, $msg ) = $scrip->SetTemplate();
112 ok( !$val, "missing template $msg" );
113 ( $val, $msg ) = $scrip->SetTemplate('not exists');
114 ok( !$val, "invalid template $msg" );
115 ( $val, $msg ) = $scrip->SetTemplate('Forward');
116 ok( $val, "updated template to 'Forward': $msg" );
118 ok( $scrip->Delete, 'delete the scrip' );