4 use RT::Test tests => undef;
6 RT->Config->Set( UseTransactionBatch => 1 );
9 # Test the rest of the conditions.
12 # Test cleanup scripts.
14 my $queue_g = RT::Test->load_or_create_queue( Name => 'General' );
15 ok $queue_g && $queue_g->id, 'loaded or created queue';
17 my $queue_r = RT::Test->load_or_create_queue( Name => 'Regression' );
18 ok $queue_r && $queue_r->id, 'loaded or created queue';
20 my ($baseurl, $m) = RT::Test->started_ok;
21 ok $m->login, "logged in";
23 $m->follow_link_ok({id => 'admin-global-scrips-create'});
25 sub prepare_code_with_value {
28 # changing the ticket is an easy scrip check for a test
30 '$self->TicketObj->SetSubject(' .
31 '$self->TicketObj->Subject . ' .
37 # preserve order for checking the subject string later
38 my @values_for_actions;
40 my $conds = RT::ScripConditions->new(RT->SystemUser);
41 foreach my $cond_value ('On Forward', 'On Forward Ticket', 'On Forward Transaction') {
45 ENTRYAGGREGATOR => 'OR',
49 while (my $rec = $conds->Next) {
50 push @values_for_actions, [$rec->Id, '"' . $rec->Name . '"'];
53 @values_for_actions = sort { $a->[0] cmp $b->[0] } @values_for_actions;
55 foreach my $data (@values_for_actions) {
56 my ($condition, $prepare_code_value) = @$data;
57 diag "Create Scrip (Cond #$condition)" if $ENV{TEST_VERBOSE};
58 $m->follow_link_ok({id => 'admin-global-scrips-create'});
59 my $prepare_code = prepare_code_with_value($prepare_code_value);
60 $m->form_name('CreateScrip');
62 'ScripCondition' => $condition,
63 'ScripAction' => 'User Defined',
64 'Template' => 'Blank',
65 'CustomPrepareCode' => $prepare_code,
68 $m->content_like(qr{Scrip Created});
71 my $ticket_obj = RT::Test->create_ticket(
76 my $ticket = $ticket_obj->id;
77 $m->goto_ticket($ticket);
80 { id => 'page-actions-forward' },
81 'follow 1st Forward to forward ticket'
84 diag "Forward Ticket" if $ENV{TEST_VERBOSE};
86 form_name => 'ForwardMessage',
88 To => 'rt-test@example.com, rt-to@example.com',
90 button => 'ForwardAndReturn'
93 $m->text_contains("#${ticket}: subject|On Forward|On Forward Ticket");
95 diag "Forward Transaction" if $ENV{TEST_VERBOSE};
96 # get the first transaction on the ticket
97 my ($transaction) = $ticket_obj->Transactions->First->id;
99 "$baseurl/Ticket/Forward.html?id=1&QuoteTransaction=$transaction"
102 form_name => 'ForwardMessage',
104 To => 'rt-test@example.com, rt-to@example.com',
106 button => 'ForwardAndReturn'
109 $m->text_contains("#${ticket}: subject|On Forward|On Forward Ticket|On Forward|On Forward Transaction");
111 RT::Test->clean_caught_mails;
114 note "check basics in scrip's admin interface";
116 $m->follow_link_ok( { id => 'admin-global-scrips-create' } );
117 ok $m->form_name('CreateScrip');
118 is $m->value_name('Description'), '', 'empty value';
119 is $m->value_name('ScripAction'), '-', 'empty value';
120 is $m->value_name('ScripCondition'), '-', 'empty value';
121 is $m->value_name('Template'), '-', 'empty value';
122 $m->field('Description' => 'test');
124 $m->content_contains("Action is mandatory argument");
126 ok $m->form_name('CreateScrip');
127 is $m->value_name('Description'), 'test', 'value stays on the page';
128 $m->select('ScripAction' => 'Notify Ccs');
130 $m->content_contains("Template is mandatory argument");
132 ok $m->form_name('CreateScrip');
133 is $m->value_name('Description'), 'test', 'value stays on the page';
134 is $m->value_name('ScripAction'), 'Notify Ccs', 'value stays on the page';
135 $m->select('Template' => 'Blank');
137 $m->content_contains("Condition is mandatory argument");
139 ok $m->form_name('CreateScrip');
140 is $m->value_name('Description'), 'test', 'value stays on the page';
141 is $m->value_name('ScripAction'), 'Notify Ccs', 'value stays on the page';
142 $m->select('ScripCondition' => 'On Close');
144 $m->content_contains("Scrip Created");
146 ok $m->form_name('ModifyScrip');
147 is $m->value_name('Description'), 'test', 'correct value';
148 is $m->value_name('ScripCondition'), 'On Close', 'correct value';
149 is $m->value_name('ScripAction'), 'Notify Ccs', 'correct value';
150 is $m->value_name('Template'), 'Blank', 'correct value';
151 $m->field('Description' => 'test test');
154 $m->content_lacks("Template is mandatory argument");
156 ok $m->form_name('ModifyScrip');
157 is $m->value_name('Description'), 'test test', 'correct value';
158 $m->content_contains("Description changed from", "found action result message");
161 note "check application in admin interface";
163 $m->follow_link_ok({ id => 'admin-global-scrips-create' });
166 Description => "testing application",
167 ScripCondition => "On Create",
168 ScripAction => "Open Tickets",
173 $m->content_contains("Scrip Created", "found result message");
175 my ($sid) = ($m->content =~ /Modify scrip #(\d+)/);
176 ok $sid, "found scrip id on the page";
177 RT::Test->object_scrips_are($sid, [0]);
179 $m->follow_link_ok({ id => 'page-applies-to' });
180 ok $m->form_name("AddRemoveScrip"), "found form";
181 $m->tick("RemoveScrip-$sid", 0);
182 $m->click_ok("Update", "update scrip application");
183 RT::Test->object_scrips_are($sid, []);
185 ok $m->form_name("AddRemoveScrip"), "found form";
186 $m->tick("AddScrip-$sid", 0);
187 $m->tick("AddScrip-$sid", $queue_g->id);
188 $m->click_ok("Update", "update scrip application");
189 RT::Test->object_scrips_are($sid, [0], [$queue_g->id, $queue_r->id]);
192 note "check templates in scrip's admin interface";
194 my $template = RT::Template->new( RT->SystemUser );
195 my ($status, $msg) = $template->Create( Queue => $queue_g->id, Name => 'foo' );
196 ok $status, 'created a template';
198 my $templates = RT::Templates->new( RT->SystemUser );
199 $templates->LimitToGlobal;
203 map $_->Name, @{$templates->ItemsArrayRef}
206 $m->follow_link_ok( { id => 'admin-global-scrips-create' } );
207 ok $m->form_name('CreateScrip');
208 my @templates = ($m->find_all_inputs( type => 'option', name => 'Template' ))[0]
210 is_deeply([sort @templates], [sort @default]);
212 $m->follow_link_ok( { id => 'admin-queues' } );
213 $m->follow_link_ok( { text => 'General' } );
214 $m->follow_link_ok( { id => 'page-scrips-create' } );
216 ok $m->form_name('CreateScrip');
217 @templates = ($m->find_all_inputs( type => 'option', name => 'Template' ))[0]
219 is_deeply([sort @templates], [sort @default, 'foo']);
221 note "make sure we can not apply scrip to queue without required template";
222 $m->field('Description' => 'test template');
223 $m->select('ScripCondition' => 'On Close');
224 $m->select('ScripAction' => 'Notify Ccs');
225 $m->select('Template' => 'foo');
227 $m->content_contains("Scrip Created");
229 $m->follow_link_ok( { id => 'page-applies-to' } );
230 my ($id) = ($m->content =~ /Modify associated objects for scrip #(\d+)/);
231 $m->form_name('AddRemoveScrip');
232 $m->tick('AddScrip-'.$id, $queue_r->id);
234 $m->content_like(qr{No template foo in queue Regression or global});
236 note "unapply the scrip from any queue";
237 $m->form_name('AddRemoveScrip');
238 $m->tick('RemoveScrip-'.$id, $queue_g->id);
240 $m->content_like(qr{Object deleted});
242 note "you can pick any template";
243 $m->follow_link_ok( { id => 'page-basics' } );
244 ok $m->form_name('ModifyScrip');
245 @templates = ($m->find_all_inputs( type => 'option', name => 'Template' ))[0]
250 my $t = RT::Templates->new( RT->SystemUser );
252 ('', $t->DistinctFieldValues('Name'))
256 note "go to apply page and apply with template change";
257 $m->follow_link_ok( { id => 'page-applies-to' } );
258 $m->form_name('AddRemoveScrip');
259 $m->field('Template' => 'blank');
260 $m->tick('AddScrip-'.$id, $queue_g->id);
261 $m->tick('AddScrip-'.$id, $queue_r->id);
263 $m->content_contains("Template: Template changed from ");
264 $m->content_contains("Object created");
267 note "apply scrip in different stage to different queues";
269 $m->follow_link_ok( { id => 'admin-queues' } );
270 $m->follow_link_ok( { text => 'General' } );
271 $m->follow_link_ok( { id => 'page-scrips-create'});
273 ok $m->form_name('CreateScrip');
274 $m->field('Description' => 'test stage');
275 $m->select('ScripCondition' => 'On Close');
276 $m->select('ScripAction' => 'Notify Ccs');
277 $m->select('Template' => 'Blank');
279 $m->content_contains("Scrip Created");
281 my ($sid) = ($m->content =~ /Modify scrip #(\d+)/);
282 ok $sid, "found scrip id on the page";
284 $m->follow_link_ok({ text => 'Applies to' });
285 ok $m->form_name('AddRemoveScrip');
286 $m->select('Stage' => 'Batch');
287 $m->tick( "AddScrip-$sid" => $queue_r->id );
289 $m->content_contains("Object created");
291 $m->follow_link_ok({ text => 'General' });
292 $m->follow_link_ok({ id => 'page-scrips' });
294 my (@matches) = $m->content =~ /test stage/g;
296 is scalar @matches, 1, 'scrip mentioned only once';