5 use RT::Test tests => undef;
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' );
12 my $cf_name = 'test cf date';
17 $m->follow_link( id => 'tools-config-custom-fields-create');
19 form_name => "ModifyCustomField",
22 TypeComposite => 'Date-1',
23 LookupType => 'RT::Queue-RT::Ticket',
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";
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';
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' );
45 $m->form_name('EditCustomFields');
46 $m->tick( "AddCustomField" => $cfid );
47 $m->click('UpdateCFs');
49 $m->content_contains('Object created', 'TCF added to the queue' );
52 diag 'check valid inputs with various timezones in ticket create page';
57 form_name => "CreateTicketInQueue",
58 fields => { Queue => 'General' },
60 $m->content_contains('Select date', 'has cf field' );
63 form_name => "TicketCreate",
65 Subject => 'test 2010-05-04',
67 "Object-RT::Ticket--CustomField-$cfid-Values" => '2010-05-04',
70 ok( ($id) = $m->content =~ /Ticket (\d+) created/, "created ticket $id" );
72 $ticket = RT::Ticket->new(RT->SystemUser);
74 is( $ticket->CustomFieldValues($cfid)->First->Content,
75 '2010-05-04', 'date in db' );
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' );
82 diag 'check search build page';
84 $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
86 $m->form_name('BuildQuery');
88 $m->find_all_inputs( type => 'option', name_regex => qr/test cf date/ );
90 [ $cf_op->possible_values ],
96 $m->find_all_inputs( type => 'text', name_regex => qr/test cf date/ );
100 $cf_field->name => '2010-05-04'
102 button => 'DoSearch',
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' );
109 $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
110 $m->form_name('BuildQuery');
114 $cf_field->name => '2010-05-05'
116 button => 'DoSearch',
118 $m->content_contains( 'Found 1 ticket', 'Found 1 ticket' );
120 $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
121 $m->form_name('BuildQuery');
125 $cf_field->name => '2010-05-03',
127 button => 'DoSearch',
129 $m->content_contains( 'Found 1 ticket', 'Found 1 ticket' );
131 $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
132 $m->form_name('BuildQuery');
136 $cf_field->name => '2010-05-05',
138 button => 'DoSearch',
140 $m->content_contains( 'Found 0 tickets', 'Found 0 tickets' );
142 $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
143 $m->form_name('BuildQuery');
147 $cf_field->name => '2010-05-03',
149 button => 'DoSearch',
151 $m->content_contains( 'Found 0 tickets', 'Found 0 tickets' );
153 $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
154 $m->form_name('BuildQuery');
158 $cf_field->name => '2010-05-05',
160 button => 'DoSearch',
162 $m->content_contains( 'Found 0 tickets', 'Found 0 tickets' );
165 diag 'check invalid inputs';
168 form_name => "CreateTicketInQueue",
169 fields => { Queue => 'General' },
171 my $form = $m->form_name("TicketCreate");
174 form_name => "TicketCreate",
178 "Object-RT::Ticket--CustomField-$cfid-Values" => 'foodate',
181 $m->content_like( qr/Ticket \d+ created/,
182 "a ticket is created succesfully" );
184 $m->content_contains('test cf date:', 'has no cf date field on the page' );
185 $m->content_lacks('foodate', 'invalid dates not set' );
187 my @warnings = $m->get_warnings;
189 is_deeply( @warnings, q{Couldn't parse date 'foodate' by Time::ParseDate} );
192 diag 'retain values when adding attachments';
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',
202 ok( $ret, "created 'txn datetime': $msg" );
203 $txn_cf->AddToObject(RT::Queue->new(RT->SystemUser));
204 my $txn_cfid = $txn_cf->id;
207 form_name => "CreateTicketInQueue",
208 fields => { Queue => 'General' },
210 $m->content_contains('test cf date', 'has cf' );
211 $m->content_contains('test txn cf date', 'has txn cf' );
215 form_name => "TicketCreate",
217 Subject => 'test 2015-06-04',
219 "Object-RT::Ticket--CustomField-$cfid-Values" => '2015-06-04',
220 "Object-RT::Transaction--CustomField-$txn_cfid-Values" => '2015-08-15',
222 button => 'AddMoreAttach',
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" );
233 ok( ($id) = $m->content =~ /Ticket (\d+) created/, "created ticket $id" );
235 $m->follow_link_ok( {text => 'Reply'} );
236 $m->title_like( qr/Update/ );
237 $m->content_contains('test txn cf date', 'has txn cf');
240 form_name => "TicketUpdate",
243 "Object-RT::Transaction--CustomField-$txn_cfid-Values" => '2015-09-16',
245 button => 'AddMoreAttach',
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" );
253 $m->follow_link_ok( {text => 'Jumbo'} );
254 $m->title_like( qr/Jumbo/ );
258 form_name => "TicketModifyAll",
260 "Object-RT::Transaction--CustomField-$txn_cfid-Values" =>
263 button => 'AddMoreAttach',
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" );