import rt 3.8.9
[freeside.git] / rt / t / api / scrip.t
1
2 use strict;
3 use warnings;
4 use RT;
5 use RT::Test tests => 25;
6
7
8 {
9
10 ok (require RT::Scrip);
11
12
13 my $q = RT::Queue->new($RT::SystemUser);
14 $q->Create(Name => 'ScripTest');
15 ok($q->Id, "Created a scriptest queue");
16
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");',
24              Template => 'Blank'
25     );
26 ok($val,$msg);
27
28 my $ticket = RT::Ticket->new($RT::SystemUser);
29 my ($tv,$ttv,$tm) = $ticket->Create(Queue => $q->Id,
30                                     Subject => "hair on fire",
31                                     );
32 ok($tv, $tm);
33
34 is ($ticket->Priority , '87', "Ticket priority is set right");
35
36
37 my $ticket2 = RT::Ticket->new($RT::SystemUser);
38 my ($t2v,$t2tv,$t2m) = $ticket2->Create(Queue => $q->Id,
39                                     Subject => "hair in water",
40                                     );
41 ok($t2v, $t2m);
42
43 isnt ($ticket2->Priority , '87', "Ticket priority is set right");
44
45
46
47 }
48
49
50 {
51     my $scrip = RT::Scrip->new($RT::SystemUser);
52     my ( $val, $msg ) = $scrip->Create(
53         ScripCondition => 'On Comment',
54         ScripAction    => 'Notify Owner',
55     );
56     ok( !$val, "missing template: $msg" );
57     ( $val, $msg ) = $scrip->Create(
58         ScripCondition => 'On Comment',
59         ScripAction    => 'Notify Owner',
60         Template       => 'not exists',
61     );
62     ok( !$val, "invalid template: $msg" );
63
64     ( $val, $msg ) = $scrip->Create(
65         ScripAction => 'Notify Owner',
66         Template    => 'Blank',
67     );
68     ok( !$val, "missing condition: $msg" );
69     ( $val, $msg ) = $scrip->Create(
70         ScripCondition => 'not exists',
71         ScripAction    => 'Notify Owner',
72         Template       => 'Blank',
73     );
74     ok( !$val, "invalid condition: $msg" );
75
76     ( $val, $msg ) = $scrip->Create(
77         ScripCondition => 'On Comment',
78         Template       => 'Blank',
79     );
80     ok( !$val, "missing action: $msg" );
81     ( $val, $msg ) = $scrip->Create(
82         ScripCondition => 'On Comment',
83         ScripAction    => 'not exists',
84         Template       => 'Blank',
85     );
86     ok( !$val, "invalid action: $msg" );
87
88     ( $val, $msg ) = $scrip->Create(
89         ScripAction    => 'Notify Owner',
90         ScripCondition => 'On Comment',
91         Template       => 'Blank',
92     );
93     ok( $val, "created scrip: $msg" );
94     $scrip->Load($val);
95     ok( $scrip->id, 'loaded scrip ' . $scrip->id );
96
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" );
103
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" );
110
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" );
117
118     ok( $scrip->Delete, 'delete the scrip' );
119 }
120
121 1;