first pass RT4 merge, RT#13852
[freeside.git] / rt / t / web / scrips.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use RT::Test tests => 14;
7
8 # TODO:
9 # Test the rest of the conditions.
10 # Test actions.
11 # Test templates?
12 # Test cleanup scripts.
13
14 my ($baseurl, $m) = RT::Test->started_ok;
15 ok $m->login, "logged in";
16
17 $m->follow_link_ok({id => 'tools-config-global-scrips-create'});
18
19 sub prepare_code_with_value {
20     my $value = shift;
21
22     # changing the ticket is an easy scrip check for a test
23     return
24         '$self->TicketObj->SetSubject(' .
25         '$self->TicketObj->Subject . ' .
26         '"|" . ' . $value .
27         ')';
28 }
29
30 {
31     # preserve order for checking the subject string later
32     my @values_for_actions;
33
34     my $conds = RT::ScripConditions->new(RT->SystemUser);
35     foreach my $cond_value ('On Forward', 'On Forward Ticket', 'On Forward Transaction') {
36         $conds->Limit(
37             FIELD           => 'name',
38             VALUE           => $cond_value,
39             ENTRYAGGREGATOR => 'OR',
40         );
41     }
42
43     while (my $rec = $conds->Next) {
44         push @values_for_actions, [$rec->Id, '"' . $rec->Name . '"'];
45     }
46
47     @values_for_actions = sort { $a->[0] cmp $b->[0] } @values_for_actions;
48
49     foreach my $data (@values_for_actions) {
50         my ($condition, $prepare_code_value) = @$data;
51         diag "Create Scrip (Cond #$condition)" if $ENV{TEST_VERBOSE};
52         $m->follow_link_ok({id => 'tools-config-global-scrips-create'});
53         my $prepare_code = prepare_code_with_value($prepare_code_value);
54         $m->form_name('ModifyScrip');
55         $m->set_fields(
56             'Scrip-new-ScripCondition'    => $condition,
57             'Scrip-new-ScripAction'       => 15, # User Defined
58             'Scrip-new-Template'          => 1,  # Blank
59             'Scrip-new-CustomPrepareCode' => $prepare_code,
60         );
61         $m->submit;
62     }
63
64     my $ticket_obj = RT::Test->create_ticket(
65         Subject => 'subject',
66         Content => 'stuff',
67         Queue   => 1,
68     );
69     my $ticket = $ticket_obj->id;
70     $m->goto_ticket($ticket);
71
72     $m->follow_link_ok(
73         { id => 'page-actions-forward' },
74         'follow 1st Forward to forward ticket'
75     );
76
77     diag "Forward Ticket" if $ENV{TEST_VERBOSE};
78     $m->submit_form(
79         form_name => 'ForwardMessage',
80         fields    => {
81             To => 'rt-test, rt-to@example.com',
82         },
83         button => 'ForwardAndReturn'
84     );
85
86     $m->text_contains("#${ticket}: subject|On Forward|On Forward Ticket");
87
88     diag "Forward Transaction" if $ENV{TEST_VERBOSE};
89     # get the first transaction on the ticket
90     my ($transaction) = $ticket_obj->Transactions->First->id;
91     $m->get(
92         "$baseurl/Ticket/Forward.html?id=1&QuoteTransaction=$transaction"
93     );
94     $m->submit_form(
95         form_name => 'ForwardMessage',
96         fields    => {
97             To => 'rt-test, rt-to@example.com',
98         },
99         button => 'ForwardAndReturn'
100     );
101
102     $m->text_contains("#${ticket}: subject|On Forward|On Forward Ticket|On Forward|On Forward Transaction");
103
104     RT::Test->clean_caught_mails;
105 }