1 use Test::MockTime qw(set_fixed_time restore_time);
6 use RT::Test nodata => 1, tests => 21;
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;
20 my $user_b = RT::Test->load_or_create_user( Name => 'boston', Timezone => 'America/New_York' );
21 ok $user_b && $user_b->id;
23 my $cf = RT::CustomField->new(RT->SystemUser);
29 LookupType => RT::Ticket->CustomFieldLookupType,
33 ok( $cf->AddToObject($q), 'date cf apply to queue' );
34 my $cf_name = $cf->Name;
36 my $ticket = RT::Ticket->new(RT->SystemUser);
42 'CustomField-' . $cf->id => '2010-05-04',
44 'create ticket with cf set to 2010-05-04'
47 is( $ticket->CustomFieldValues->First->Content, '2010-05-04', 'date in db is' );
51 my $tickets = RT::Tickets->new(RT->SystemUser);
52 $tickets->LimitCustomField(
53 CUSTOMFIELD => $cf->id,
55 VALUE => '2010-05-04',
57 is( $tickets->Count, 1, 'found the ticket with exact date: 2010-05-04' );
62 my $tickets = RT::Tickets->new(RT->SystemUser);
63 $tickets->LimitCustomField(
64 CUSTOMFIELD => $cf->id,
66 VALUE => '2010-05-03',
69 is( $tickets->Count, 1, 'found ticket with > 2010-05-03' );
73 my $tickets = RT::Tickets->new(RT->SystemUser);
74 $tickets->LimitCustomField(
75 CUSTOMFIELD => $cf->id,
77 VALUE => '2010-05-05',
80 is( $tickets->Count, 1, 'found ticket with < 2010-05-05' );
85 my $tickets = RT::Tickets->new(RT->SystemUser);
86 $tickets->LimitCustomField(
87 CUSTOMFIELD => $cf->id,
89 VALUE => '2010-05-05',
92 is( $tickets->Count, 0, 'did not find the ticket with = 2010-05-05' );
96 my $tickets = RT::Tickets->new(RT->SystemUser);
97 $tickets->FromSQL( "'CF.{$cf_name}' = 'May 4 2010'" );
98 is( $tickets->Count, 1, 'found the ticket with = May 4 2010' );
100 $tickets->FromSQL( "'CF.{$cf_name}' < 'May 4 2010'" );
101 is( $tickets->Count, 0, 'did not find the ticket with < May 4 2010' );
103 $tickets->FromSQL( "'CF.{$cf_name}' < 'May 5 2010'" );
104 is( $tickets->Count, 1, 'found the ticket with < May 5 2010' );
106 $tickets->FromSQL( "'CF.{$cf_name}' > 'May 3 2010'" );
107 is( $tickets->Count, 1, 'found the ticket with > May 3 2010' );
113 my $tickets = RT::Tickets->new(RT->SystemUser);
114 $tickets->LimitCustomField(
115 CUSTOMFIELD => $cf->id,
117 VALUE => '2010-05-03',
120 is( $tickets->Count, 0, 'did not find the ticket with < 2010-05-03' );
125 my $tickets = RT::Tickets->new(RT->SystemUser);
126 $tickets->LimitCustomField(
127 CUSTOMFIELD => $cf->id,
129 VALUE => '2010-05-05',
132 is( $tickets->Count, 0, 'did not find the ticket with > 2010-05-05' );
135 # relative search by users in different TZs
137 my $ticket = RT::Ticket->new(RT->SystemUser);
138 my ($tid) = $ticket->Create(
141 'CustomField-' . $cf->id => '2013-02-12',
144 set_fixed_time("2013-02-10T23:10:00Z");
145 my $tickets = RT::Tickets->new($user_m);
146 $tickets->FromSQL("'CustomField.{$cf_name}' = 'tomorrow' AND id = $tid");
147 is( $tickets->Count, 1, 'found the ticket' );
149 set_fixed_time("2013-02-10T15:10:00Z");
150 $tickets = RT::Tickets->new($user_m);
151 $tickets->FromSQL("'CustomField.{$cf_name}' = 'tomorrow' AND id = $tid");
152 is( $tickets->Count, 0, 'found no tickets' );
154 set_fixed_time("2013-02-10T23:10:00Z");
155 $tickets = RT::Tickets->new($user_b);
156 $tickets->FromSQL("'CustomField.{$cf_name}' = 'tomorrow' AND id = $tid");
157 is( $tickets->Count, 0, 'found no tickets' );
159 set_fixed_time("2013-02-11T23:10:00Z");
160 $tickets = RT::Tickets->new($user_b);
161 $tickets->FromSQL("'CustomField.{$cf_name}' = 'tomorrow' AND id = $tid");
162 is( $tickets->Count, 1, 'found the tickets' );