Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / rt / t / web / cf_date.t
1
2 use strict;
3 use warnings;
4
5 use RT::Test tests => 35;
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 }