first pass RT4 merge, RT#13852
[freeside.git] / rt / t / web / cf_date.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use RT::Test tests => 35;
7
8 my ( $baseurl, $m ) = RT::Test->started_ok;
9 ok $m->login, 'logged in as root';
10 my $root = RT::User->new(RT->SystemUser);
11 ok( $root->Load('root'), 'load root user' );
12
13 my $cf_name = 'test cf date';
14
15 my $cfid;
16 diag "Create a CF";
17 {
18     $m->follow_link( id => 'tools-config-custom-fields-create');
19     $m->submit_form(
20         form_name => "ModifyCustomField",
21         fields    => {
22             Name          => $cf_name,
23             TypeComposite => 'Date-1',
24             LookupType    => 'RT::Queue-RT::Ticket',
25         },
26     );
27     $m->content_contains('Object created', 'created CF sucessfully' );
28     $cfid = $m->form_name('ModifyCustomField')->value('id');
29     ok $cfid, "found id of the CF in the form, it's #$cfid";
30 }
31
32 diag "apply the CF to General queue";
33 my $queue = RT::Test->load_or_create_queue( Name => 'General' );
34 ok $queue && $queue->id, 'loaded or created queue';
35
36 {
37     $m->follow_link( id => 'tools-config-queues-select');
38     $m->title_is( q/Admin queues/, 'admin-queues screen' );
39     $m->follow_link( text => 'General' );
40     $m->title_is( q/Configuration for queue General/,
41         'admin-queue: general' );
42     $m->follow_link( text => 'Ticket Custom Fields' );
43     $m->title_is( q/Custom Fields for queue General/,
44         'admin-queue: general cfid' );
45
46     $m->form_name('EditCustomFields');
47     $m->tick( "AddCustomField" => $cfid );
48     $m->click('UpdateCFs');
49
50     $m->content_contains('Object created', 'TCF added to the queue' );
51 }
52
53 diag 'check valid inputs with various timezones in ticket create page';
54 {
55     my ( $ticket, $id );
56
57     $m->submit_form(
58         form_name => "CreateTicketInQueue",
59         fields    => { Queue => 'General' },
60     );
61     $m->content_contains('Select date', 'has cf field' );
62
63     $m->submit_form(
64         form_name => "TicketCreate",
65         fields    => {
66             Subject                                       => 'test 2010-05-04',
67             Content                                       => 'test',
68             "Object-RT::Ticket--CustomField-$cfid-Values" => '2010-05-04',
69         },
70     );
71     ok( ($id) = $m->content =~ /Ticket (\d+) created/, "created ticket $id" );
72
73     $ticket = RT::Ticket->new(RT->SystemUser);
74     $ticket->Load($id);
75     is( $ticket->CustomFieldValues($cfid)->First->Content,
76         '2010-05-04', 'date in db' );
77
78     $m->content_contains('test cf date:', 'has no cf date field on the page' );
79     $m->content_contains('Tue May 04 2010',
80         'has cf date value on the page' );
81 }
82
83 diag 'check search build page';
84 {
85     $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
86
87     $m->form_name('BuildQuery');
88     my ($cf_op) =
89       $m->find_all_inputs( type => 'option', name_regex => qr/test cf date/ );
90     is_deeply(
91         [ $cf_op->possible_values ],
92         [ '<', '=', '>' ],
93         'right oprators'
94     );
95
96     my ($cf_field) =
97       $m->find_all_inputs( type => 'text', name_regex => qr/test cf date/ );
98     $m->submit_form(
99         fields => {
100             $cf_op->name    => '=',
101             $cf_field->name => '2010-05-04'
102         },
103         button => 'DoSearch',
104     );
105
106     $m->content_contains( 'Found 1 ticket', 'Found 1 ticket' );
107     $m->content_contains( '2010-05-04',     'got the right ticket' );
108     $m->content_lacks( '2010-05-06', 'did not get the wrong ticket' );
109
110     $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
111     $m->form_name('BuildQuery');
112     $m->submit_form(
113         fields => {
114             $cf_op->name    => '<',
115             $cf_field->name => '2010-05-05'
116         },
117         button => 'DoSearch',
118     );
119     $m->content_contains( 'Found 1 ticket', 'Found 1 ticket' );
120
121     $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
122     $m->form_name('BuildQuery');
123     $m->submit_form(
124         fields => {
125             $cf_op->name    => '>',
126             $cf_field->name => '2010-05-03',
127         },
128         button => 'DoSearch',
129     );
130     $m->content_contains( 'Found 1 ticket', 'Found 1 ticket' );
131
132     $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
133     $m->form_name('BuildQuery');
134     $m->submit_form(
135         fields => {
136             $cf_op->name    => '=',
137             $cf_field->name => '2010-05-05',
138         },
139         button => 'DoSearch',
140     );
141     $m->content_contains( 'Found 0 tickets', 'Found 0 tickets' );
142
143     $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
144     $m->form_name('BuildQuery');
145     $m->submit_form(
146         fields => {
147             $cf_op->name    => '<',
148             $cf_field->name => '2010-05-03',
149         },
150         button => 'DoSearch',
151     );
152     $m->content_contains( 'Found 0 tickets', 'Found 0 tickets' );
153
154     $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
155     $m->form_name('BuildQuery');
156     $m->submit_form(
157         fields => {
158             $cf_op->name    => '>',
159             $cf_field->name => '2010-05-05',
160         },
161         button => 'DoSearch',
162     );
163     $m->content_contains( 'Found 0 tickets', 'Found 0 tickets' );
164 }
165
166 diag 'check invalid inputs';
167 {
168     $m->submit_form(
169         form_name => "CreateTicketInQueue",
170         fields    => { Queue => 'General' },
171     );
172     my $form = $m->form_name("TicketCreate");
173
174     $m->submit_form(
175         form_name => "TicketCreate",
176         fields    => {
177             Subject                                       => 'test',
178             Content                                       => 'test',
179             "Object-RT::Ticket--CustomField-$cfid-Values" => 'foodate',
180         },
181     );
182     $m->content_like( qr/Ticket \d+ created/,
183         "a ticket is created succesfully" );
184
185     $m->content_contains('test cf date:', 'has no cf date field on the page' );
186     $m->content_lacks('foodate', 'invalid dates not set' );
187 }