5 use RT::Test tests => '19';
9 my $queue = RT::Test->load_or_create_queue( Name => 'Regression' );
10 ok $queue && $queue->id, 'loaded or created queue';
12 RT->Config->Set( UseTransactionBatch => 1 );
14 my ($baseurl, $m) = RT::Test->started_ok;
15 ok $m->login, 'logged in as root';
19 $m->follow_link_ok( { text => 'Configuration' } );
20 $m->follow_link_ok( { text => 'Queues' } );
21 $m->follow_link_ok( { text => $queue->Name } );
22 $m->follow_link_ok( { text => 'Scrips' } );
23 $m->follow_link_ok( { text => 'New scrip' } );
25 $m->field('Scrip-new-Description' => 'test');
26 $m->select('Scrip-new-ScripCondition' => 'On Transaction');
27 $m->select('Scrip-new-ScripAction' => 'User Defined');
28 $m->select('Scrip-new-Template' => 'Global template: Blank');
29 $m->select('Scrip-new-Stage' => 'TransactionBatch');
30 $m->field('Scrip-new-CustomPrepareCode' => 'return 1;');
31 $m->field('Scrip-new-CustomCommitCode' => 'return 1;');
33 $m->content_like( qr/Scrip Created/ );
35 ($sid) = ($m->content =~ /Scrip\s*#(\d+)/);
37 my $form = $m->form_number(3);
38 is $m->value("Scrip-$sid-Description"), 'test', 'correct description';
39 is value_name($form, "Scrip-$sid-ScripCondition"), 'On Transaction', 'correct condition';
40 is value_name($form, "Scrip-$sid-ScripAction"), 'User Defined', 'correct action';
41 is value_name($form, "Scrip-$sid-Template"), 'Global template: Blank', 'correct template';
42 is value_name($form, "Scrip-$sid-Stage"), 'TransactionBatch', 'correct stage';
44 use File::Temp qw(tempfile);
45 my ($tmp_fh, $tmp_fn) = tempfile();
48 open my \$fh, '>', '$tmp_fn' or die "Couldn't open '$tmp_fn':\$!";
50 my \$batch = \$self->TicketObj->TransactionBatch;
51 unless ( \$batch && \@\$batch ) {
52 print \$fh "no batch\n";
55 foreach my \$txn ( \@\$batch ) {
56 print \$fh \$txn->Type ."\n";
61 $m->field( "Scrip-$sid-CustomCommitCode" => $code );
64 $m->goto_create_ticket( $queue );
68 is_deeply parse_handle($tmp_fh), ['Create'], 'Create';
70 $m->follow_link_ok( { text => 'Resolve' } );
72 $m->field( "UpdateContent" => 'resolve it' );
73 $m->click('SubmitTicket');
75 is_deeply parse_handle($tmp_fh), ['Comment', 'Status'], 'Comment + Resolve';
82 my $input = $form->find_input( $field );
84 my @names = $input->value_names;
85 my @values = $input->possible_values;
86 for ( my $i = 0; $i < @values; $i++ ) {
87 return $names[ $i ] if $values[ $i ] eq $input->value;
96 foreach ( @lines ) { s/^\s+//gms; s/\s+$//gms }