X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Ft%2Fweb%2Fscrips.t;h=d669f4c4e5ee51ea41127c824f0c976f234edaac;hb=1c538bfabc2cd31f27067505f0c3d1a46cba6ef0;hp=0ff46bf264ad69a500d1e46b3b4b687f2d6c59e4;hpb=4f5619288413a185e9933088d9dd8c5afbc55dfa;p=freeside.git diff --git a/rt/t/web/scrips.t b/rt/t/web/scrips.t index 0ff46bf26..d669f4c4e 100644 --- a/rt/t/web/scrips.t +++ b/rt/t/web/scrips.t @@ -1,7 +1,9 @@ use strict; use warnings; -use RT::Test tests => 14; +use RT::Test tests => undef; + +RT->Config->Set( UseTransactionBatch => 1 ); # TODO: # Test the rest of the conditions. @@ -9,10 +11,16 @@ use RT::Test tests => 14; # Test templates? # Test cleanup scripts. +my $queue_g = RT::Test->load_or_create_queue( Name => 'General' ); +ok $queue_g && $queue_g->id, 'loaded or created queue'; + +my $queue_r = RT::Test->load_or_create_queue( Name => 'Regression' ); +ok $queue_r && $queue_r->id, 'loaded or created queue'; + my ($baseurl, $m) = RT::Test->started_ok; ok $m->login, "logged in"; -$m->follow_link_ok({id => 'tools-config-global-scrips-create'}); +$m->follow_link_ok({id => 'admin-global-scrips-create'}); sub prepare_code_with_value { my $value = shift; @@ -47,16 +55,17 @@ sub prepare_code_with_value { foreach my $data (@values_for_actions) { my ($condition, $prepare_code_value) = @$data; diag "Create Scrip (Cond #$condition)" if $ENV{TEST_VERBOSE}; - $m->follow_link_ok({id => 'tools-config-global-scrips-create'}); + $m->follow_link_ok({id => 'admin-global-scrips-create'}); my $prepare_code = prepare_code_with_value($prepare_code_value); - $m->form_name('ModifyScrip'); + $m->form_name('CreateScrip'); $m->set_fields( - 'Scrip-new-ScripCondition' => $condition, - 'Scrip-new-ScripAction' => 15, # User Defined - 'Scrip-new-Template' => 1, # Blank - 'Scrip-new-CustomPrepareCode' => $prepare_code, + 'ScripCondition' => $condition, + 'ScripAction' => 'User Defined', + 'Template' => 'Blank', + 'CustomPrepareCode' => $prepare_code, ); - $m->submit; + $m->click('Create'); + $m->content_like(qr{Scrip Created}); } my $ticket_obj = RT::Test->create_ticket( @@ -76,7 +85,7 @@ sub prepare_code_with_value { $m->submit_form( form_name => 'ForwardMessage', fields => { - To => 'rt-test, rt-to@example.com', + To => 'rt-test@example.com, rt-to@example.com', }, button => 'ForwardAndReturn' ); @@ -92,7 +101,7 @@ sub prepare_code_with_value { $m->submit_form( form_name => 'ForwardMessage', fields => { - To => 'rt-test, rt-to@example.com', + To => 'rt-test@example.com, rt-to@example.com', }, button => 'ForwardAndReturn' ); @@ -101,3 +110,191 @@ sub prepare_code_with_value { RT::Test->clean_caught_mails; } + +note "check basics in scrip's admin interface"; +{ + $m->follow_link_ok( { id => 'admin-global-scrips-create' } ); + ok $m->form_name('CreateScrip'); + is $m->value_name('Description'), '', 'empty value'; + is $m->value_name('ScripAction'), '-', 'empty value'; + is $m->value_name('ScripCondition'), '-', 'empty value'; + is $m->value_name('Template'), '-', 'empty value'; + $m->field('Description' => 'test'); + $m->click('Create'); + $m->content_contains("Action is mandatory argument"); + + ok $m->form_name('CreateScrip'); + is $m->value_name('Description'), 'test', 'value stays on the page'; + $m->select('ScripAction' => 'Notify Ccs'); + $m->click('Create'); + $m->content_contains("Template is mandatory argument"); + + ok $m->form_name('CreateScrip'); + is $m->value_name('Description'), 'test', 'value stays on the page'; + is $m->value_name('ScripAction'), 'Notify Ccs', 'value stays on the page'; + $m->select('Template' => 'Blank'); + $m->click('Create'); + $m->content_contains("Condition is mandatory argument"); + + ok $m->form_name('CreateScrip'); + is $m->value_name('Description'), 'test', 'value stays on the page'; + is $m->value_name('ScripAction'), 'Notify Ccs', 'value stays on the page'; + $m->select('ScripCondition' => 'On Close'); + $m->click('Create'); + $m->content_contains("Scrip Created"); + + ok $m->form_name('ModifyScrip'); + is $m->value_name('Description'), 'test', 'correct value'; + is $m->value_name('ScripCondition'), 'On Close', 'correct value'; + is $m->value_name('ScripAction'), 'Notify Ccs', 'correct value'; + is $m->value_name('Template'), 'Blank', 'correct value'; + $m->field('Description' => 'test test'); + $m->click('Update'); + # regression + $m->content_lacks("Template is mandatory argument"); + + ok $m->form_name('ModifyScrip'); + is $m->value_name('Description'), 'test test', 'correct value'; + $m->content_contains("Description changed from", "found action result message"); +} + +note "check application in admin interface"; +{ + $m->follow_link_ok({ id => 'admin-global-scrips-create' }); + $m->submit_form_ok({ + with_fields => { + Description => "testing application", + ScripCondition => "On Create", + ScripAction => "Open Tickets", + Template => "Blank", + }, + button => 'Create', + }, "created scrip"); + $m->content_contains("Scrip Created", "found result message"); + + my ($sid) = ($m->content =~ /Modify scrip #(\d+)/); + ok $sid, "found scrip id on the page"; + RT::Test->object_scrips_are($sid, [0]); + + $m->follow_link_ok({ id => 'page-applies-to' }); + ok $m->form_name("AddRemoveScrip"), "found form"; + $m->tick("RemoveScrip-$sid", 0); + $m->click_ok("Update", "update scrip application"); + RT::Test->object_scrips_are($sid, []); + + ok $m->form_name("AddRemoveScrip"), "found form"; + $m->tick("AddScrip-$sid", 0); + $m->tick("AddScrip-$sid", $queue_g->id); + $m->click_ok("Update", "update scrip application"); + RT::Test->object_scrips_are($sid, [0], [$queue_g->id, $queue_r->id]); +} + +note "check templates in scrip's admin interface"; +{ + my $template = RT::Template->new( RT->SystemUser ); + my ($status, $msg) = $template->Create( Queue => $queue_g->id, Name => 'foo' ); + ok $status, 'created a template'; + + my $templates = RT::Templates->new( RT->SystemUser ); + $templates->LimitToGlobal; + + my @default = ( + '', + map $_->Name, @{$templates->ItemsArrayRef} + ); + + $m->follow_link_ok( { id => 'admin-global-scrips-create' } ); + ok $m->form_name('CreateScrip'); + my @templates = ($m->find_all_inputs( type => 'option', name => 'Template' ))[0] + ->possible_values; + is_deeply([sort @templates], [sort @default]); + + $m->follow_link_ok( { id => 'admin-queues' } ); + $m->follow_link_ok( { text => 'General' } ); + $m->follow_link_ok( { id => 'page-scrips-create' } ); + + ok $m->form_name('CreateScrip'); + @templates = ($m->find_all_inputs( type => 'option', name => 'Template' ))[0] + ->possible_values; + is_deeply([sort @templates], [sort @default, 'foo']); + +note "make sure we can not apply scrip to queue without required template"; + $m->field('Description' => 'test template'); + $m->select('ScripCondition' => 'On Close'); + $m->select('ScripAction' => 'Notify Ccs'); + $m->select('Template' => 'foo'); + $m->click('Create'); + $m->content_contains("Scrip Created"); + + $m->follow_link_ok( { id => 'page-applies-to' } ); + my ($id) = ($m->content =~ /Modify associated objects for scrip #(\d+)/); + $m->form_name('AddRemoveScrip'); + $m->tick('AddScrip-'.$id, $queue_r->id); + $m->click('Update'); + $m->content_like(qr{No template foo in queue Regression or global}); + +note "unapply the scrip from any queue"; + $m->form_name('AddRemoveScrip'); + $m->tick('RemoveScrip-'.$id, $queue_g->id); + $m->click('Update'); + $m->content_like(qr{Object deleted}); + +note "you can pick any template"; + $m->follow_link_ok( { id => 'page-basics' } ); + ok $m->form_name('ModifyScrip'); + @templates = ($m->find_all_inputs( type => 'option', name => 'Template' ))[0] + ->possible_values; + is_deeply( + [sort @templates], + [sort do { + my $t = RT::Templates->new( RT->SystemUser ); + $t->UnLimit; + ('', $t->DistinctFieldValues('Name')) + }], + ); + +note "go to apply page and apply with template change"; + $m->follow_link_ok( { id => 'page-applies-to' } ); + $m->form_name('AddRemoveScrip'); + $m->field('Template' => 'blank'); + $m->tick('AddScrip-'.$id, $queue_g->id); + $m->tick('AddScrip-'.$id, $queue_r->id); + $m->click('Update'); + $m->content_contains("Template: Template changed from "); + $m->content_contains("Object created"); +} + +note "apply scrip in different stage to different queues"; +{ + $m->follow_link_ok( { id => 'admin-queues' } ); + $m->follow_link_ok( { text => 'General' } ); + $m->follow_link_ok( { id => 'page-scrips-create'}); + + ok $m->form_name('CreateScrip'); + $m->field('Description' => 'test stage'); + $m->select('ScripCondition' => 'On Close'); + $m->select('ScripAction' => 'Notify Ccs'); + $m->select('Template' => 'Blank'); + $m->click('Create'); + $m->content_contains("Scrip Created"); + + my ($sid) = ($m->content =~ /Modify scrip #(\d+)/); + ok $sid, "found scrip id on the page"; + + $m->follow_link_ok({ text => 'Applies to' }); + ok $m->form_name('AddRemoveScrip'); + $m->select('Stage' => 'Batch'); + $m->tick( "AddScrip-$sid" => $queue_r->id ); + $m->click('Update'); + $m->content_contains("Object created"); + + $m->follow_link_ok({ text => 'General' }); + $m->follow_link_ok({ id => 'page-scrips' }); + + my (@matches) = $m->content =~ /test stage/g; + # regression + is scalar @matches, 1, 'scrip mentioned only once'; +} + +undef $m; +done_testing;