first pass RT4 merge, RT#13852
[freeside.git] / rt / t / customfields / date_search.t
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use RT::Test nodata => 1, tests => 13;
7
8 my $q = RT::Queue->new(RT->SystemUser);
9 ok( $q->Create( Name => 'DateCFTest' . $$ ), 'create queue' );
10
11 my $cf = RT::CustomField->new(RT->SystemUser);
12 ok(
13     $cf->Create(
14         Name       => 'date-' . $$,
15         Type       => 'Date',
16         MaxValues  => 1,
17         LookupType => RT::Ticket->CustomFieldLookupType,
18     ),
19     'create cf date'
20 );
21 ok( $cf->AddToObject($q), 'date cf apply to queue' );
22
23 my $ticket = RT::Ticket->new(RT->SystemUser);
24
25 ok(
26     $ticket->Create(
27         Queue                    => $q->id,
28         Subject                  => 'Test',
29         'CustomField-' . $cf->id => '2010-05-04',
30     ),
31     'create ticket with cf set to 2010-05-04'
32 );
33
34 is( $ticket->CustomFieldValues->First->Content, '2010-05-04', 'date in db is' );
35
36 {
37
38     my $tickets = RT::Tickets->new(RT->SystemUser);
39     $tickets->LimitCustomField(
40         CUSTOMFIELD => $cf->id,
41         OPERATOR    => '=',
42         VALUE       => '2010-05-04',
43     );
44     is( $tickets->Count, 1, 'found the ticket with exact date: 2010-05-04' );
45
46 }
47
48 {
49     my $tickets = RT::Tickets->new(RT->SystemUser);
50     $tickets->LimitCustomField(
51         CUSTOMFIELD => $cf->id,
52         OPERATOR    => '>',
53         VALUE       => '2010-05-03',
54     );
55
56     is( $tickets->Count, 1, 'found ticket with > 2010-05-03' );
57 }
58
59 {
60     my $tickets = RT::Tickets->new(RT->SystemUser);
61     $tickets->LimitCustomField(
62         CUSTOMFIELD => $cf->id,
63         OPERATOR    => '<',
64         VALUE       => '2010-05-05',
65     );
66
67     is( $tickets->Count, 1, 'found ticket with < 2010-05-05' );
68 }
69
70 {
71
72     my $tickets = RT::Tickets->new(RT->SystemUser);
73     $tickets->LimitCustomField(
74         CUSTOMFIELD => $cf->id,
75         OPERATOR    => '=',
76         VALUE       => '2010-05-05',
77     );
78
79     is( $tickets->Count, 0, 'did not find the ticket with = 2010-05-05' );
80 }
81
82 {
83
84     my $tickets = RT::Tickets->new(RT->SystemUser);
85     $tickets->LimitCustomField(
86         CUSTOMFIELD => $cf->id,
87         OPERATOR    => '<',
88         VALUE       => '2010-05-03',
89     );
90
91     is( $tickets->Count, 0, 'did not find the ticket with < 2010-05-03' );
92 }
93
94 {
95
96     my $tickets = RT::Tickets->new(RT->SystemUser);
97     $tickets->LimitCustomField(
98         CUSTOMFIELD => $cf->id,
99         OPERATOR    => '>',
100         VALUE       => '2010-05-05',
101     );
102
103     is( $tickets->Count, 0, 'did not find the ticket with > 2010-05-05' );
104 }
105
106 $ticket = RT::Ticket->new(RT->SystemUser);
107
108 ok(
109     $ticket->Create(
110         Queue                    => $q->id,
111         Subject                  => 'Test',
112         'CustomField-' . $cf->id => '2010-05-04 11:34:56',
113     ),
114     'create ticket with cf set to 2010-05-04 11:34:56'
115 );
116
117 is( $ticket->CustomFieldValues->First->Content,
118     '2010-05-04', 'date in db only has date' );
119