RT 4.0.22
[freeside.git] / rt / t / web / cf_date.t
1
2 use strict;
3 use warnings;
4
5 use RT::Test tests => undef;
6
7 my ( $baseurl, $m ) = RT::Test->started_ok;
8 ok $m->login, 'logged in as root';
9 my $root = RT::User->new(RT->SystemUser);
10 ok( $root->Load('root'), 'load root user' );
11
12 my $cf_name = 'test cf date';
13
14 my $cfid;
15 diag "Create a CF";
16 {
17     $m->follow_link( id => 'tools-config-custom-fields-create');
18     $m->submit_form(
19         form_name => "ModifyCustomField",
20         fields    => {
21             Name          => $cf_name,
22             TypeComposite => 'Date-1',
23             LookupType    => 'RT::Queue-RT::Ticket',
24         },
25     );
26     $m->content_contains('Object created', 'created CF sucessfully' );
27     $cfid = $m->form_name('ModifyCustomField')->value('id');
28     ok $cfid, "found id of the CF in the form, it's #$cfid";
29 }
30
31 diag "apply the CF to General queue";
32 my $queue = RT::Test->load_or_create_queue( Name => 'General' );
33 ok $queue && $queue->id, 'loaded or created queue';
34
35 {
36     $m->follow_link( id => 'tools-config-queues-select');
37     $m->title_is( q/Admin queues/, 'admin-queues screen' );
38     $m->follow_link( text => 'General' );
39     $m->title_is( q/Configuration for queue General/,
40         'admin-queue: general' );
41     $m->follow_link( text => 'Ticket Custom Fields' );
42     $m->title_is( q/Custom Fields for queue General/,
43         'admin-queue: general cfid' );
44
45     $m->form_name('EditCustomFields');
46     $m->tick( "AddCustomField" => $cfid );
47     $m->click('UpdateCFs');
48
49     $m->content_contains('Object created', 'TCF added to the queue' );
50 }
51
52 diag 'check valid inputs with various timezones in ticket create page';
53 {
54     my ( $ticket, $id );
55
56     $m->submit_form(
57         form_name => "CreateTicketInQueue",
58         fields    => { Queue => 'General' },
59     );
60     $m->content_contains('Select date', 'has cf field' );
61
62     $m->submit_form(
63         form_name => "TicketCreate",
64         fields    => {
65             Subject                                       => 'test 2010-05-04',
66             Content                                       => 'test',
67             "Object-RT::Ticket--CustomField-$cfid-Values" => '2010-05-04',
68         },
69     );
70     ok( ($id) = $m->content =~ /Ticket (\d+) created/, "created ticket $id" );
71
72     $ticket = RT::Ticket->new(RT->SystemUser);
73     $ticket->Load($id);
74     is( $ticket->CustomFieldValues($cfid)->First->Content,
75         '2010-05-04', 'date in db' );
76
77     $m->content_contains('test cf date:', 'has no cf date field on the page' );
78     $m->content_contains('Tue May 04 2010',
79         'has cf date value on the page' );
80 }
81
82 diag 'check search build page';
83 {
84     $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
85
86     $m->form_name('BuildQuery');
87     my ($cf_op) =
88       $m->find_all_inputs( type => 'option', name_regex => qr/test cf date/ );
89     is_deeply(
90         [ $cf_op->possible_values ],
91         [ '<', '=', '>' ],
92         'right oprators'
93     );
94
95     my ($cf_field) =
96       $m->find_all_inputs( type => 'text', name_regex => qr/test cf date/ );
97     $m->submit_form(
98         fields => {
99             $cf_op->name    => '=',
100             $cf_field->name => '2010-05-04'
101         },
102         button => 'DoSearch',
103     );
104
105     $m->content_contains( 'Found 1 ticket', 'Found 1 ticket' );
106     $m->content_contains( '2010-05-04',     'got the right ticket' );
107     $m->content_lacks( '2010-05-06', 'did not get the wrong ticket' );
108
109     $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
110     $m->form_name('BuildQuery');
111     $m->submit_form(
112         fields => {
113             $cf_op->name    => '<',
114             $cf_field->name => '2010-05-05'
115         },
116         button => 'DoSearch',
117     );
118     $m->content_contains( 'Found 1 ticket', 'Found 1 ticket' );
119
120     $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
121     $m->form_name('BuildQuery');
122     $m->submit_form(
123         fields => {
124             $cf_op->name    => '>',
125             $cf_field->name => '2010-05-03',
126         },
127         button => 'DoSearch',
128     );
129     $m->content_contains( 'Found 1 ticket', 'Found 1 ticket' );
130
131     $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
132     $m->form_name('BuildQuery');
133     $m->submit_form(
134         fields => {
135             $cf_op->name    => '=',
136             $cf_field->name => '2010-05-05',
137         },
138         button => 'DoSearch',
139     );
140     $m->content_contains( 'Found 0 tickets', 'Found 0 tickets' );
141
142     $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
143     $m->form_name('BuildQuery');
144     $m->submit_form(
145         fields => {
146             $cf_op->name    => '<',
147             $cf_field->name => '2010-05-03',
148         },
149         button => 'DoSearch',
150     );
151     $m->content_contains( 'Found 0 tickets', 'Found 0 tickets' );
152
153     $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
154     $m->form_name('BuildQuery');
155     $m->submit_form(
156         fields => {
157             $cf_op->name    => '>',
158             $cf_field->name => '2010-05-05',
159         },
160         button => 'DoSearch',
161     );
162     $m->content_contains( 'Found 0 tickets', 'Found 0 tickets' );
163 }
164
165 diag 'check invalid inputs';
166 {
167     $m->submit_form(
168         form_name => "CreateTicketInQueue",
169         fields    => { Queue => 'General' },
170     );
171     my $form = $m->form_name("TicketCreate");
172
173     $m->submit_form(
174         form_name => "TicketCreate",
175         fields    => {
176             Subject                                       => 'test',
177             Content                                       => 'test',
178             "Object-RT::Ticket--CustomField-$cfid-Values" => 'foodate',
179         },
180     );
181     $m->content_like( qr/Ticket \d+ created/,
182         "a ticket is created succesfully" );
183
184     $m->content_contains('test cf date:', 'has no cf date field on the page' );
185     $m->content_lacks('foodate', 'invalid dates not set' );
186
187     my @warnings = $m->get_warnings;
188     chomp @warnings;
189     is_deeply( @warnings, q{Couldn't parse date 'foodate' by Time::ParseDate} );
190 }
191
192 diag 'retain values when adding attachments';
193 {
194     my ( $ticket, $id );
195
196     my $txn_cf = RT::CustomField->new( RT->SystemUser );
197     my ( $ret, $msg ) = $txn_cf->Create(
198         Name          => 'test txn cf date',
199         TypeComposite => 'Date-1',
200         LookupType    => 'RT::Queue-RT::Ticket-RT::Transaction',
201     );
202     ok( $ret, "created 'txn datetime': $msg" );
203     $txn_cf->AddToObject(RT::Queue->new(RT->SystemUser));
204     my $txn_cfid = $txn_cf->id;
205
206     $m->submit_form(
207         form_name => "CreateTicketInQueue",
208         fields    => { Queue => 'General' },
209     );
210     $m->content_contains('test cf date', 'has cf' );
211     $m->content_contains('test txn cf date', 'has txn cf' );
212
213     $m->submit_form_ok(
214         {
215             form_name => "TicketCreate",
216             fields    => {
217                 Subject => 'test 2015-06-04',
218                 Content => 'test',
219                 "Object-RT::Ticket--CustomField-$cfid-Values" => '2015-06-04',
220                 "Object-RT::Transaction--CustomField-$txn_cfid-Values" => '2015-08-15',
221             },
222             button => 'AddMoreAttach',
223         },
224         'create test ticket'
225     );
226     $m->form_name("TicketCreate");
227     is( $m->value( "Object-RT::Ticket--CustomField-$cfid-Values" ),
228         "2015-06-04", "ticket cf date value still on form" );
229     is( $m->value( "Object-RT::Transaction--CustomField-$txn_cfid-Values" ),
230         "2015-08-15", "txn cf date date value still on form" );
231
232     $m->submit_form();
233     ok( ($id) = $m->content =~ /Ticket (\d+) created/, "created ticket $id" );
234
235     $m->follow_link_ok( {text => 'Reply'} );
236     $m->title_like( qr/Update/ );
237     $m->content_contains('test txn cf date', 'has txn cf');
238     $m->submit_form_ok(
239         {
240             form_name => "TicketUpdate",
241             fields    => {
242                 Content => 'test',
243                 "Object-RT::Transaction--CustomField-$txn_cfid-Values" => '2015-09-16',
244             },
245             button => 'AddMoreAttach',
246         },
247         'Update test ticket'
248     );
249     $m->form_name("TicketUpdate");
250     is( $m->value( "Object-RT::Transaction--CustomField-$txn_cfid-Values" ),
251         "2015-09-16", "txn date value still on form" );
252
253     $m->follow_link_ok( {text => 'Jumbo'} );
254     $m->title_like( qr/Jumbo/ );
255
256     $m->submit_form_ok(
257         {
258             form_name => "TicketModifyAll",
259             fields    => {
260                 "Object-RT::Transaction--CustomField-$txn_cfid-Values" =>
261                   '2015-12-16',
262             },
263             button => 'AddMoreAttach',
264         },
265         'jumbo form'
266     );
267
268     $m->form_name("TicketModifyAll");
269     is( $m->value( "Object-RT::Transaction--CustomField-$txn_cfid-Values" ),
270         "2015-12-16", "txn date value still on form" );
271 }
272
273 done_testing;