summaryrefslogtreecommitdiff
path: root/rt/t/web/ticket_preserve_basics.t
blob: 145941407d4a8b5d47462def7bd669a46eee63a0 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
use strict;
use warnings;

use RT::Test tests => undef;

my $ticket = RT::Test->create_ticket(
    Subject => 'test ticket basics',
    Queue   => 1,
);

my ( $url, $m ) = RT::Test->started_ok;
ok( $m->login, 'logged in' );

my $root = RT::Test->load_or_create_user( Name => 'root' );

# Failing test where the time units are not preserved when you
# click 'Add more files' on Display
my @form_tries = (
    {Subject => "hello rt"},
    {Status  => "open"},
    {Owner   => $root->id},

    (
        map +{
            "Time$_"           => undef,
            "Time$_-TimeUnits" => 'hours',
        }, qw/Estimated Worked Left/
    ),
    (
        map +{
            "Time$_"           => '1',
            "Time$_-TimeUnits" => 'hours',
        }, qw/Estimated Worked Left/
    ),

    {InitialPriority      => "10"},
    {FinalPriority => "10"},
);

for my $try (@form_tries) {
    $m->goto_create_ticket(1);
    $m->form_name('TicketCreate');
    $m->set_fields(%$try);
    $m->click('AddMoreAttach');
    $m->form_name('TicketCreate');
    for my $field (keys %$try) {
        is(
            $m->value($field),
            defined($try->{$field}) ? $try->{$field} : '',
            "field $field is the same after the form was submitted"
        );
    }
}

# Test for time unit preservation in Jumbo
for my $try (@form_tries) {
    my $jumbo_ticket = RT::Test->create_ticket(
        Subject => 'test jumbo ticket basics',
        Queue   => 1,
    );

    local($try->{Priority}) = delete local($try->{InitialPriority})
        if exists $try->{InitialPriority};

    $m->get( $url . "/Ticket/ModifyAll.html?id=" . $jumbo_ticket->id );
    $m->form_name('TicketModifyAll');
    $m->set_fields(%$try);
    $m->click('AddMoreAttach');
    $m->form_name('TicketModifyAll');
    for my $field (keys %$try) {
        is(
            $m->value($field),
            defined($try->{$field}) ? $try->{$field} : '',
            "field $field is the same after the Jumbo form was submitted"
        );
    }
}

my $cf = RT::Test->load_or_create_custom_field(
    Name       => 'CF1',
    Type       => 'Freeform',
    Pattern    => '.', # mandatory
    Queue      => 'General',
);

# More time unit testing by a failing CF validation
$m->get_ok($url.'/Admin/CustomFields/Objects.html?id='.$cf->id);
$m->form_with_fields('UpdateObjs');
$m->tick('AddCustomField-'.$cf->id => '0'); # Make CF global
$m->click('UpdateObjs');
$m->text_contains('Object created', 'CF applied globally');

# Test for preservation when a ticket is submitted and CF validation fails
for my $try (@form_tries) {
    $m->goto_create_ticket(1);
    $m->form_name('TicketCreate');
    $m->set_fields(%$try);
    $m->submit();
    $m->form_name('TicketCreate');
    for my $field (keys %$try) {
        is(
            $m->value($field),
            defined($try->{$field}) ? $try->{$field} : '',
            "field $field is the same after the form was submitted"
        );
    }
}

undef $m;
done_testing();