summaryrefslogtreecommitdiff
path: root/rt/t/web/transaction_batch.t
blob: ae04e1fcabd4eb8542ab53af9153d258a418de1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use strict;
use warnings;
use RT;
use RT::Test tests => 12;


my $q = RT::Test->load_or_create_queue ( Name => 'General' );

my $s1 = RT::Scrip->new(RT->SystemUser);
my ($val, $msg) =$s1->Create( Queue => $q->Id,
             ScripCondition    => 'User Defined',
             ScripAction       => 'User Defined',
             CustomIsApplicableCode => 'return ($self->TransactionObj->Field||"") eq "TimeEstimated"',
             CustomPrepareCode => 'return 1',
             CustomCommitCode  => '$self->TicketObj->SetPriority($self->TicketObj->Priority + 2); return 1;',
             Template          => 'Blank',
             Stage             => 'TransactionBatch',
    );
ok($val,$msg);

my $ticket = RT::Ticket->new(RT->SystemUser);
my ($tv,$ttv,$tm) = $ticket->Create(Queue => $q->Id,
                                    Subject => "hair on fire",
                                    );
ok($tv, $tm);

# Flush the Create transaction off of the ticket
$ticket->ApplyTransactionBatch;

my $testuser = RT::Test->load_or_create_user( Name => 'bob', EmailAddress => 'bob@example.com', Password => 'password' );
ok($testuser->Id, "Created test user bob");

ok( RT::Test->add_rights({ Principal => 'Privileged', Right => [qw(ShowTicket ModifyTicket SeeQueue)]}), 'Granted ticket management rights');

my $test_current_user = RT::CurrentUser->new();
$test_current_user->LoadByName($testuser->Name);
my $api_test = RT::Ticket->new($test_current_user);
$api_test->Load($ticket->Id);
is($api_test->Priority,0,"Ticket priority starts at 0");
$api_test->SetTimeEstimated(12);
$api_test->ApplyTransactionBatch;
is($api_test->CurrentUser->UserObj->Name, $testuser->Name,"User didn't change running Transaction Batch scrips");
$api_test->Load($api_test->Id);
is($api_test->Priority,2,"Ticket priority updated");

my ($baseurl, $m) = RT::Test->started_ok;
$m->login('bob','password');
$m->get_ok("$baseurl/Ticket/Modify.html?id=".$ticket->Id);
    $m->submit_form( form_name => 'TicketModify',
        fields => { TimeEstimated => 5 }
    );


$ticket->Load($ticket->Id);
is ($ticket->Priority , 4, "Ticket priority is set right");