1 use Test::MockTime qw(set_fixed_time restore_time);
6 use RT::Test nodata => 1, tests => undef;
9 { Principal => 'Everyone', Right => [qw(
10 SeeQueue ShowTicket CreateTicket SeeCustomField ModifyCustomField
14 my $q = RT::Test->load_or_create_queue( Name => 'General' );
15 ok $q && $q->id, 'loaded or created a queue';
17 my $user_m = RT::Test->load_or_create_user( Name => 'moscow', Timezone => 'Europe/Moscow' );
18 ok $user_m && $user_m->id;
19 $user_m = RT::CurrentUser->new( $user_m );
21 my $user_b = RT::Test->load_or_create_user( Name => 'boston', Timezone => 'America/New_York' );
22 ok $user_b && $user_b->id;
23 $user_b = RT::CurrentUser->new( $user_b );
25 my $cf = RT::CustomField->new(RT->SystemUser);
31 LookupType => RT::Ticket->CustomFieldLookupType,
35 ok( $cf->AddToObject($q), 'date cf apply to queue' );
36 my $cf_name = $cf->Name;
38 my $ticket = RT::Ticket->new(RT->SystemUser);
44 'CustomField-' . $cf->id => '2010-05-04',
46 'create ticket with cf set to 2010-05-04'
49 is( $ticket->CustomFieldValues->First->Content, '2010-05-04', 'date in db is' );
53 my $tickets = RT::Tickets->new(RT->SystemUser);
54 $tickets->LimitCustomField(
55 CUSTOMFIELD => $cf->id,
57 VALUE => '2010-05-04',
59 is( $tickets->Count, 1, 'found the ticket with exact date: 2010-05-04' );
64 my $tickets = RT::Tickets->new(RT->SystemUser);
65 $tickets->LimitCustomField(
66 CUSTOMFIELD => $cf->id,
68 VALUE => '2010-05-03',
71 is( $tickets->Count, 1, 'found ticket with > 2010-05-03' );
75 my $tickets = RT::Tickets->new(RT->SystemUser);
76 $tickets->LimitCustomField(
77 CUSTOMFIELD => $cf->id,
79 VALUE => '2010-05-05',
82 is( $tickets->Count, 1, 'found ticket with < 2010-05-05' );
87 my $tickets = RT::Tickets->new(RT->SystemUser);
88 $tickets->LimitCustomField(
89 CUSTOMFIELD => $cf->id,
91 VALUE => '2010-05-05',
94 is( $tickets->Count, 0, 'did not find the ticket with = 2010-05-05' );
98 my $tickets = RT::Tickets->new(RT->SystemUser);
99 $tickets->FromSQL( "'CF.{$cf_name}' = 'May 4 2010'" );
100 is( $tickets->Count, 1, 'found the ticket with = May 4 2010' );
102 $tickets->FromSQL( "'CF.{$cf_name}' < 'May 4 2010'" );
103 is( $tickets->Count, 0, 'did not find the ticket with < May 4 2010' );
105 $tickets->FromSQL( "'CF.{$cf_name}' < 'May 5 2010'" );
106 is( $tickets->Count, 1, 'found the ticket with < May 5 2010' );
108 $tickets->FromSQL( "'CF.{$cf_name}' > 'May 3 2010'" );
109 is( $tickets->Count, 1, 'found the ticket with > May 3 2010' );
115 my $tickets = RT::Tickets->new(RT->SystemUser);
116 $tickets->LimitCustomField(
117 CUSTOMFIELD => $cf->id,
119 VALUE => '2010-05-03',
122 is( $tickets->Count, 0, 'did not find the ticket with < 2010-05-03' );
127 my $tickets = RT::Tickets->new(RT->SystemUser);
128 $tickets->LimitCustomField(
129 CUSTOMFIELD => $cf->id,
131 VALUE => '2010-05-05',
134 is( $tickets->Count, 0, 'did not find the ticket with > 2010-05-05' );
138 my $tickets = RT::Tickets->new(RT->SystemUser);
139 $tickets->LimitCustomField(
140 CUSTOMFIELD => $cf->id,
145 is( $tickets->Count, 0, 'did not find the ticket with date IS NULL' );
149 my $tickets = RT::Tickets->new(RT->SystemUser);
150 $tickets->LimitCustomField(
151 CUSTOMFIELD => $cf->id,
152 OPERATOR => 'IS NOT',
156 is( $tickets->Count, 1, 'did find the ticket with date IS NOT NULL' );
159 # relative search by users in different TZs
161 my $ticket = RT::Ticket->new(RT->SystemUser);
162 my ($tid) = $ticket->Create(
165 'CustomField-' . $cf->id => '2013-02-12',
168 set_fixed_time("2013-02-10T23:10:00Z");
169 my $tickets = RT::Tickets->new($user_m);
170 $tickets->FromSQL("'CustomField.{$cf_name}' = 'tomorrow' AND id = $tid");
171 is( $tickets->Count, 1, 'found the ticket' );
173 set_fixed_time("2013-02-10T15:10:00Z");
174 $tickets = RT::Tickets->new($user_m);
175 $tickets->FromSQL("'CustomField.{$cf_name}' = 'tomorrow' AND id = $tid");
176 is( $tickets->Count, 0, 'found no tickets' );
178 set_fixed_time("2013-02-10T23:10:00Z");
179 $tickets = RT::Tickets->new($user_b);
180 $tickets->FromSQL("'CustomField.{$cf_name}' = 'tomorrow' AND id = $tid");
181 is( $tickets->Count, 0, 'found no tickets' );
183 set_fixed_time("2013-02-11T23:10:00Z");
184 $tickets = RT::Tickets->new($user_b);
185 $tickets->FromSQL("'CustomField.{$cf_name}' = 'tomorrow' AND id = $tid");
186 is( $tickets->Count, 1, 'found the tickets' );