summaryrefslogtreecommitdiff
path: root/rt/t/web/cf_date.t
blob: a38388972680d6018e14cb0cf134d0f9589ee34d (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273

use strict;
use warnings;

use RT::Test tests => undef;

my ( $baseurl, $m ) = RT::Test->started_ok;
ok $m->login, 'logged in as root';
my $root = RT::User->new(RT->SystemUser);
ok( $root->Load('root'), 'load root user' );

my $cf_name = 'test cf date';

my $cfid;
diag "Create a CF";
{
    $m->follow_link( id => 'admin-custom-fields-create');
    $m->submit_form(
        form_name => "ModifyCustomField",
        fields    => {
            Name          => $cf_name,
            TypeComposite => 'Date-1',
            LookupType    => 'RT::Queue-RT::Ticket',
        },
    );
    $m->content_contains('Object created', 'created CF sucessfully' );
    $cfid = $m->form_name('ModifyCustomField')->value('id');
    ok $cfid, "found id of the CF in the form, it's #$cfid";
}

diag "apply the CF to General queue";
my $queue = RT::Test->load_or_create_queue( Name => 'General' );
ok $queue && $queue->id, 'loaded or created queue';

{
    $m->follow_link( id => 'admin-queues-select');
    $m->title_is( q/Admin queues/, 'admin-queues screen' );
    $m->follow_link( text => 'General' );
    $m->title_is( q/Configuration for queue General/,
        'admin-queue: general' );
    $m->follow_link( id => 'page-custom-fields-tickets' );
    $m->title_is( q/Custom Fields for queue General/,
        'admin-queue: general cfid' );

    $m->form_name('EditCustomFields');
    $m->tick( "AddCustomField" => $cfid );
    $m->click('UpdateCFs');

    $m->content_contains('Object created', 'TCF added to the queue' );
}

diag 'check valid inputs with various timezones in ticket create page';
{
    my ( $ticket, $id );

    $m->submit_form(
        form_name => "CreateTicketInQueue",
        fields    => { Queue => 'General' },
    );
    $m->content_contains('Select date', 'has cf field' );

    $m->submit_form(
        form_name => "TicketCreate",
        fields    => {
            Subject                                       => 'test 2010-05-04',
            Content                                       => 'test',
            "Object-RT::Ticket--CustomField-$cfid-Values" => '2010-05-04',
        },
    );
    ok( ($id) = $m->content =~ /Ticket (\d+) created/, "created ticket $id" );

    $ticket = RT::Ticket->new(RT->SystemUser);
    $ticket->Load($id);
    is( $ticket->CustomFieldValues($cfid)->First->Content,
        '2010-05-04', 'date in db' );

    $m->content_contains('test cf date:', 'has no cf date field on the page' );
    $m->content_contains('Tue May 04 2010',
        'has cf date value on the page' );
}

diag 'check search build page';
{
    $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );

    $m->form_name('BuildQuery');
    my ($cf_op) =
      $m->find_all_inputs( type => 'option', name_regex => qr/test cf date/ );
    is_deeply(
        [ $cf_op->possible_values ],
        [ '<', '=', '>' ],
        'right oprators'
    );

    my ($cf_field) =
      $m->find_all_inputs( type => 'text', name_regex => qr/test cf date/ );
    $m->submit_form(
        fields => {
            $cf_op->name    => '=',
            $cf_field->name => '2010-05-04'
        },
        button => 'DoSearch',
    );

    $m->content_contains( 'Found 1 ticket', 'Found 1 ticket' );
    $m->content_contains( '2010-05-04',     'got the right ticket' );
    $m->content_lacks( '2010-05-06', 'did not get the wrong ticket' );

    $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
    $m->form_name('BuildQuery');
    $m->submit_form(
        fields => {
            $cf_op->name    => '<',
            $cf_field->name => '2010-05-05'
        },
        button => 'DoSearch',
    );
    $m->content_contains( 'Found 1 ticket', 'Found 1 ticket' );

    $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
    $m->form_name('BuildQuery');
    $m->submit_form(
        fields => {
            $cf_op->name    => '>',
            $cf_field->name => '2010-05-03',
        },
        button => 'DoSearch',
    );
    $m->content_contains( 'Found 1 ticket', 'Found 1 ticket' );

    $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
    $m->form_name('BuildQuery');
    $m->submit_form(
        fields => {
            $cf_op->name    => '=',
            $cf_field->name => '2010-05-05',
        },
        button => 'DoSearch',
    );
    $m->content_contains( 'Found 0 tickets', 'Found 0 tickets' );

    $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
    $m->form_name('BuildQuery');
    $m->submit_form(
        fields => {
            $cf_op->name    => '<',
            $cf_field->name => '2010-05-03',
        },
        button => 'DoSearch',
    );
    $m->content_contains( 'Found 0 tickets', 'Found 0 tickets' );

    $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
    $m->form_name('BuildQuery');
    $m->submit_form(
        fields => {
            $cf_op->name    => '>',
            $cf_field->name => '2010-05-05',
        },
        button => 'DoSearch',
    );
    $m->content_contains( 'Found 0 tickets', 'Found 0 tickets' );
}

diag 'check invalid inputs';
{
    $m->submit_form(
        form_name => "CreateTicketInQueue",
        fields    => { Queue => 'General' },
    );
    my $form = $m->form_name("TicketCreate");

    $m->submit_form(
        form_name => "TicketCreate",
        fields    => {
            Subject                                       => 'test',
            Content                                       => 'test',
            "Object-RT::Ticket--CustomField-$cfid-Values" => 'foodate',
        },
    );
    $m->content_like( qr/Ticket \d+ created/,
        "a ticket is created succesfully" );

    $m->content_contains('test cf date:', 'has no cf date field on the page' );
    $m->content_lacks('foodate', 'invalid dates not set' );

    my @warnings = $m->get_warnings;
    chomp @warnings;
    is_deeply( [@warnings], [(q{Couldn't parse date 'foodate' by Time::ParseDate})x2] );
}

diag 'retain values when adding attachments';
{
    my ( $ticket, $id );

    my $txn_cf = RT::CustomField->new( RT->SystemUser );
    my ( $ret, $msg ) = $txn_cf->Create(
        Name          => 'test txn cf date',
        TypeComposite => 'Date-1',
        LookupType    => 'RT::Queue-RT::Ticket-RT::Transaction',
    );
    ok( $ret, "created 'txn datetime': $msg" );
    $txn_cf->AddToObject(RT::Queue->new(RT->SystemUser));
    my $txn_cfid = $txn_cf->id;

    $m->submit_form(
        form_name => "CreateTicketInQueue",
        fields    => { Queue => 'General' },
    );
    $m->content_contains('test cf date', 'has cf' );
    $m->content_contains('test txn cf date', 'has txn cf' );

    $m->submit_form_ok(
        {
            form_name => "TicketCreate",
            fields    => {
                Subject => 'test 2015-06-04',
                Content => 'test',
                "Object-RT::Ticket--CustomField-$cfid-Values" => '2015-06-04',
                "Object-RT::Transaction--CustomField-$txn_cfid-Values" => '2015-08-15',
            },
            button => 'AddMoreAttach',
        },
        'create test ticket'
    );
    $m->form_name("TicketCreate");
    is( $m->value( "Object-RT::Ticket--CustomField-$cfid-Values" ),
        "2015-06-04", "ticket cf date value still on form" );
    is( $m->value( "Object-RT::Transaction--CustomField-$txn_cfid-Values" ),
        "2015-08-15", "txn cf date date value still on form" );

    $m->submit_form();
    ok( ($id) = $m->content =~ /Ticket (\d+) created/, "created ticket $id" );

    $m->follow_link_ok( {text => 'Reply'} );
    $m->title_like( qr/Update/ );
    $m->content_contains('test txn cf date', 'has txn cf');
    $m->submit_form_ok(
        {
            form_name => "TicketUpdate",
            fields    => {
                Content => 'test',
                "Object-RT::Transaction--CustomField-$txn_cfid-Values" => '2015-09-16',
            },
            button => 'AddMoreAttach',
        },
        'Update test ticket'
    );
    $m->form_name("TicketUpdate");
    is( $m->value( "Object-RT::Transaction--CustomField-$txn_cfid-Values" ),
        "2015-09-16", "txn date value still on form" );

    $m->follow_link_ok( {text => 'Jumbo'} );
    $m->title_like( qr/Jumbo/ );

    $m->submit_form_ok(
        {
            form_name => "TicketModifyAll",
            fields    => {
                "Object-RT::Transaction--CustomField-$txn_cfid-Values" =>
                  '2015-12-16',
            },
            button => 'AddMoreAttach',
        },
        'jumbo form'
    );

    $m->form_name("TicketModifyAll");
    is( $m->value( "Object-RT::Transaction--CustomField-$txn_cfid-Values" ),
        "2015-12-16", "txn date value still on form" );
}

done_testing;