no need for FS calendar buttons in RT 4.2
[freeside.git] / rt / t / ticket / scrips_batch.t
index f558d3b..0a996ce 100644 (file)
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use RT::Test tests => '19';
+use RT::Test tests => 19;
 use_ok('RT');
 use_ok('RT::Ticket');
 
@@ -16,36 +16,39 @@ ok $m->login, 'logged in as root';
 
 my $sid;
 {
-    $m->follow_link_ok( { text => 'Configuration' } );
-    $m->follow_link_ok( { text => 'Queues' } );
+    $m->follow_link_ok( { id => 'admin-queues' } );
     $m->follow_link_ok( { text => $queue->Name } );
-    $m->follow_link_ok( { text => 'Scrips' } );
-    $m->follow_link_ok( { text => 'New scrip' } );
-    $m->form_number(3);
-    $m->field('Scrip-new-Description' => 'test');
-    $m->select('Scrip-new-ScripCondition' => 'On Transaction');
-    $m->select('Scrip-new-ScripAction' => 'User Defined');
-    $m->select('Scrip-new-Template' => 'Global template: Blank');
-    $m->select('Scrip-new-Stage' => 'TransactionBatch');
-    $m->field('Scrip-new-CustomPrepareCode' => 'return 1;');
-    $m->field('Scrip-new-CustomCommitCode' => 'return 1;');
-    $m->submit;
-    $m->content_like( qr/Scrip Created/ );
-
-    ($sid) = ($m->content =~ /Scrip\s*#(\d+)/);
-
-    my $form = $m->form_number(3);
-    is $m->value("Scrip-$sid-Description"), 'test', 'correct description';
-    is value_name($form, "Scrip-$sid-ScripCondition"), 'On Transaction', 'correct condition';
-    is value_name($form, "Scrip-$sid-ScripAction"), 'User Defined', 'correct action';
-    is value_name($form, "Scrip-$sid-Template"), 'Global template: Blank', 'correct template';
-    is value_name($form, "Scrip-$sid-Stage"), 'TransactionBatch', 'correct stage';
+    $m->follow_link_ok( { id => 'page-scrips-create'});
+
+    $m->form_name('CreateScrip');
+    $m->field('Description' => 'test');
+    $m->select('ScripCondition' => 'On Transaction');
+    $m->select('ScripAction' => 'User Defined');
+    $m->select('Template' => 'Blank');
+    $m->select('Stage' => 'Batch');
+    $m->field('CustomPrepareCode' => 'return 1;');
+    $m->field('CustomCommitCode' => 'return 1;');
+    $m->click('Create');
+    $m->content_contains("Scrip Created");
+
+    my $form = $m->form_name('ModifyScrip');
+    $sid = $form->value('id');
+    is $m->value("Description"), 'test', 'correct description';
+    is value_name($form, "ScripCondition"), 'On Transaction', 'correct condition';
+    is value_name($form, "ScripAction"), 'User Defined', 'correct action';
+    is value_name($form, "Template"), 'Blank', 'correct template';
+
+    {
+        my $rec = RT::ObjectScrip->new( RT->SystemUser );
+        $rec->LoadByCols( Scrip => $sid, ObjectId => $queue->id );
+        is $rec->Stage, 'TransactionBatch', "correct stage";
+    }
 
-    use File::Temp qw(tempfile);
-    my ($tmp_fh, $tmp_fn) = tempfile();
+    my $tmp_fn = File::Spec->catfile( RT::Test->temp_directory, 'transactions' );
+    open my $tmp_fh, '+>', $tmp_fn or die $!;
 
     my $code = <<END;
-open my \$fh, '>', '$tmp_fn' or die "Couldn't open '$tmp_fn':\$!";
+open( my \$fh, '>', '$tmp_fn' ) or die "Couldn't open '$tmp_fn':\$!";
 
 my \$batch = \$self->TicketObj->TransactionBatch;
 unless ( \$batch && \@\$batch ) {
@@ -58,17 +61,17 @@ foreach my \$txn ( \@\$batch ) {
 return 1;
 END
 
-    $m->field( "Scrip-$sid-CustomCommitCode" => $code );
-    $m->submit;
+    $m->field( "CustomCommitCode" => $code );
+    $m->click('Update');
 
     $m->goto_create_ticket( $queue );
-    $m->form_number(3);
+    $m->form_name('TicketCreate');
     $m->submit;
 
     is_deeply parse_handle($tmp_fh), ['Create'], 'Create';
 
     $m->follow_link_ok( { text => 'Resolve' } );
-    $m->form_number(3);
+    $m->form_name('TicketUpdate');
     $m->field( "UpdateContent" => 'resolve it' );
     $m->click('SubmitTicket');