diff options
Diffstat (limited to 'rt/t/customfields')
-rw-r--r-- | rt/t/customfields/access_via_queue.t | 30 | ||||
-rw-r--r-- | rt/t/customfields/api.t | 28 | ||||
-rw-r--r-- | rt/t/customfields/combo_cascade.t | 1 | ||||
-rw-r--r-- | rt/t/customfields/date_search.t | 75 | ||||
-rw-r--r-- | rt/t/customfields/datetime_search.t | 106 | ||||
-rw-r--r-- | rt/t/customfields/external.t | 9 | ||||
-rw-r--r-- | rt/t/customfields/ip.t | 11 | ||||
-rw-r--r-- | rt/t/customfields/iprange.t | 1 | ||||
-rw-r--r-- | rt/t/customfields/iprangev6.t | 1 | ||||
-rw-r--r-- | rt/t/customfields/ipv6.t | 10 | ||||
-rw-r--r-- | rt/t/customfields/pattern.t | 1 | ||||
-rw-r--r-- | rt/t/customfields/single_values.t | 1 | ||||
-rw-r--r-- | rt/t/customfields/sort_order.t | 1 | ||||
-rw-r--r-- | rt/t/customfields/transaction.t | 1 |
14 files changed, 231 insertions, 45 deletions
diff --git a/rt/t/customfields/access_via_queue.t b/rt/t/customfields/access_via_queue.t index 690e177..a059d69 100644 --- a/rt/t/customfields/access_via_queue.t +++ b/rt/t/customfields/access_via_queue.t @@ -1,9 +1,8 @@ -#!/usr/bin/perl -w use strict; use warnings; -use RT::Test nodata => 1, tests => 37; +use RT::Test nodata => 1, tests => 47; use RT::Ticket; use RT::CustomField; @@ -158,3 +157,30 @@ diag "check that owner can see and edit CF"; $m->content_contains($cf_name, "changed cf"); } +note 'make sure CF is not reset to no value'; +{ + my $t = RT::Test->create_ticket( + Queue => $queue->id, + Subject => 'test', + 'CustomField-'.$cf->id => '2012-02-12', + Cc => $tester->id, + Owner => $tester->id, + ); + ok $t && $t->id, 'created ticket'; + is $t->FirstCustomFieldValue($cf_name), '2012-02-12'; + + $m->goto_ticket($t->id); + $m->follow_link_ok({id => 'page-basics'}); + my $form = $m->form_name('TicketModify'); + my $input = $form->find_input( + 'Object-RT::Ticket-'. $t->id .'-CustomField-'. $cf->id .'-Value' + ); + ok $input, 'found input'; + $m->click('SubmitTicket'); + + my $tid = $t->id; + $t = RT::Ticket->new( $RT::SystemUser ); + $t->Load( $tid ); + is $t->FirstCustomFieldValue($cf_name), '2012-02-12'; +} + diff --git a/rt/t/customfields/api.t b/rt/t/customfields/api.t index d739a57..2e1c079 100644 --- a/rt/t/customfields/api.t +++ b/rt/t/customfields/api.t @@ -1,9 +1,9 @@ -#!/usr/bin/perl use strict; use warnings FATAL => 'all'; -use RT::Test nodata => 1, tests => 139; +use RT::Test nodata => 1, tests => 145; +use Test::Warn; # Before we get going, ditch all object_cfs; this will remove # all custom fields systemwide; @@ -69,13 +69,21 @@ is( $cfvs->Count, 0 ); is( $ticket->FirstCustomFieldValue, undef ); # CF with ID -1 shouldnt exist at all -$cfvs = $ticket->CustomFieldValues( -1 ); +warning_like { + $cfvs = $ticket->CustomFieldValues( -1 ); +} qr{Couldn't load custom field}; is( $cfvs->Count, 0 ); -is( $ticket->FirstCustomFieldValue( -1 ), undef ); +warning_like { + is( $ticket->FirstCustomFieldValue( -1 ), undef ); +} qr{Couldn't load custom field}; -$cfvs = $ticket->CustomFieldValues( 'SomeUnexpedCustomFieldName' ); +warning_like { + $cfvs = $ticket->CustomFieldValues( 'SomeUnexpedCustomFieldName' ); +} qr{Couldn't load custom field}; is( $cfvs->Count, 0 ); -is( $ticket->FirstCustomFieldValue( 'SomeUnexpedCustomFieldName' ), undef ); +warning_like { + is( $ticket->FirstCustomFieldValue( 'SomeUnexpedCustomFieldName' ), undef ); +} qr{Couldn't load custom field}; for (@custom_fields) { $cfvs = $ticket->CustomFieldValues( $_->id ); @@ -183,9 +191,13 @@ $test_add_delete_cycle->( sub { return $_[0] } ); $ticket->AddCustomFieldValue( Field => $local_cf2->id , Value => 'Baz' ); $ticket->AddCustomFieldValue( Field => $global_cf3->id , Value => 'Baz' ); # now if we ask for cf values on RecordCustomFields4 we should not get any -$cfvs = $ticket->CustomFieldValues( 'RecordCustomFields4' ); +warning_like { + $cfvs = $ticket->CustomFieldValues( 'RecordCustomFields4' ); +} qr{Couldn't load custom field}; is( $cfvs->Count, 0, "No custom field values for non-Queue cf" ); -is( $ticket->FirstCustomFieldValue( 'RecordCustomFields4' ), undef, "No first custom field value for non-Queue cf" ); +warning_like { + is( $ticket->FirstCustomFieldValue( 'RecordCustomFields4' ), undef, "No first custom field value for non-Queue cf" ); +} qr{Couldn't load custom field}; { my $cfname = $global_cf3->Name; diff --git a/rt/t/customfields/combo_cascade.t b/rt/t/customfields/combo_cascade.t index 28eee45..fba2fac 100644 --- a/rt/t/customfields/combo_cascade.t +++ b/rt/t/customfields/combo_cascade.t @@ -1,4 +1,3 @@ -#!/usr/bin/perl use warnings; use strict; diff --git a/rt/t/customfields/date_search.t b/rt/t/customfields/date_search.t index b425b9e..2a8e6ce 100644 --- a/rt/t/customfields/date_search.t +++ b/rt/t/customfields/date_search.t @@ -1,17 +1,29 @@ -#!/usr/bin/perl +use Test::MockTime qw(set_fixed_time restore_time); use warnings; use strict; -use RT::Test nodata => 1, tests => 13; +use RT::Test nodata => 1, tests => 21; -my $q = RT::Queue->new(RT->SystemUser); -ok( $q->Create( Name => 'DateCFTest' . $$ ), 'create queue' ); +RT::Test->set_rights( + { Principal => 'Everyone', Right => [qw( + SeeQueue ShowTicket CreateTicket SeeCustomField ModifyCustomField + )] }, +); + +my $q = RT::Test->load_or_create_queue( Name => 'General' ); +ok $q && $q->id, 'loaded or created a queue'; + +my $user_m = RT::Test->load_or_create_user( Name => 'moscow', Timezone => 'Europe/Moscow' ); +ok $user_m && $user_m->id; + +my $user_b = RT::Test->load_or_create_user( Name => 'boston', Timezone => 'America/New_York' ); +ok $user_b && $user_b->id; my $cf = RT::CustomField->new(RT->SystemUser); ok( $cf->Create( - Name => 'date-' . $$, + Name => 'TestDate', Type => 'Date', MaxValues => 1, LookupType => RT::Ticket->CustomFieldLookupType, @@ -19,6 +31,7 @@ ok( 'create cf date' ); ok( $cf->AddToObject($q), 'date cf apply to queue' ); +my $cf_name = $cf->Name; my $ticket = RT::Ticket->new(RT->SystemUser); @@ -80,6 +93,22 @@ is( $ticket->CustomFieldValues->First->Content, '2010-05-04', 'date in db is' ); } { + my $tickets = RT::Tickets->new(RT->SystemUser); + $tickets->FromSQL( "'CF.{$cf_name}' = 'May 4 2010'" ); + is( $tickets->Count, 1, 'found the ticket with = May 4 2010' ); + + $tickets->FromSQL( "'CF.{$cf_name}' < 'May 4 2010'" ); + is( $tickets->Count, 0, 'did not find the ticket with < May 4 2010' ); + + $tickets->FromSQL( "'CF.{$cf_name}' < 'May 5 2010'" ); + is( $tickets->Count, 1, 'found the ticket with < May 5 2010' ); + + $tickets->FromSQL( "'CF.{$cf_name}' > 'May 3 2010'" ); + is( $tickets->Count, 1, 'found the ticket with > May 3 2010' ); +} + + +{ my $tickets = RT::Tickets->new(RT->SystemUser); $tickets->LimitCustomField( @@ -103,17 +132,33 @@ is( $ticket->CustomFieldValues->First->Content, '2010-05-04', 'date in db is' ); is( $tickets->Count, 0, 'did not find the ticket with > 2010-05-05' ); } -$ticket = RT::Ticket->new(RT->SystemUser); - -ok( - $ticket->Create( +# relative search by users in different TZs +{ + my $ticket = RT::Ticket->new(RT->SystemUser); + my ($tid) = $ticket->Create( Queue => $q->id, Subject => 'Test', - 'CustomField-' . $cf->id => '2010-05-04 11:34:56', - ), - 'create ticket with cf set to 2010-05-04 11:34:56' -); + 'CustomField-' . $cf->id => '2013-02-12', + ); -is( $ticket->CustomFieldValues->First->Content, - '2010-05-04', 'date in db only has date' ); + set_fixed_time("2013-02-10T23:10:00Z"); + my $tickets = RT::Tickets->new($user_m); + $tickets->FromSQL("'CustomField.{$cf_name}' = 'tomorrow' AND id = $tid"); + is( $tickets->Count, 1, 'found the ticket' ); + + set_fixed_time("2013-02-10T15:10:00Z"); + $tickets = RT::Tickets->new($user_m); + $tickets->FromSQL("'CustomField.{$cf_name}' = 'tomorrow' AND id = $tid"); + is( $tickets->Count, 0, 'found no tickets' ); + + set_fixed_time("2013-02-10T23:10:00Z"); + $tickets = RT::Tickets->new($user_b); + $tickets->FromSQL("'CustomField.{$cf_name}' = 'tomorrow' AND id = $tid"); + is( $tickets->Count, 0, 'found no tickets' ); + + set_fixed_time("2013-02-11T23:10:00Z"); + $tickets = RT::Tickets->new($user_b); + $tickets->FromSQL("'CustomField.{$cf_name}' = 'tomorrow' AND id = $tid"); + is( $tickets->Count, 1, 'found the tickets' ); +} diff --git a/rt/t/customfields/datetime_search.t b/rt/t/customfields/datetime_search.t index 11fe3bc..6b37cf1 100644 --- a/rt/t/customfields/datetime_search.t +++ b/rt/t/customfields/datetime_search.t @@ -1,18 +1,30 @@ -#!/usr/bin/perl +use Test::MockTime qw(set_fixed_time restore_time); use warnings; use strict; -use RT::Test nodata => 1, tests => 14; +use RT::Test nodata => 1, tests => 30; RT->Config->Set( 'Timezone' => 'EST5EDT' ); # -04:00 -my $q = RT::Queue->new(RT->SystemUser); -ok( $q->Create( Name => 'DateTimeCFTest' . $$ ), 'create queue' ); +RT::Test->set_rights( + { Principal => 'Everyone', Right => [qw( + SeeQueue ShowTicket CreateTicket SeeCustomField ModifyCustomField + )] }, +); + +my $q = RT::Test->load_or_create_queue( Name => 'General' ); +ok $q && $q->id, 'loaded or created a queue'; + +my $user_m = RT::Test->load_or_create_user( Name => 'moscow', Timezone => 'Europe/Moscow' ); +ok $user_m && $user_m->id; + +my $user_b = RT::Test->load_or_create_user( Name => 'boston', Timezone => 'America/New_York' ); +ok $user_b && $user_b->id; my $cf = RT::CustomField->new(RT->SystemUser); ok( $cf->Create( - Name => 'datetime-' . $$, + Name => 'TestDateTime', Type => 'DateTime', MaxValues => 1, LookupType => RT::Ticket->CustomFieldLookupType, @@ -20,6 +32,7 @@ ok( 'create cf datetime' ); ok( $cf->AddToObject($q), 'date cf apply to queue' ); +my $cf_name = $cf->Name; my $ticket = RT::Ticket->new(RT->SystemUser); @@ -78,6 +91,23 @@ is( is( $tickets->Count, 0, 'did not find the ticket with wrong datetime: 2010-05-05' ); } +{ + my $tickets = RT::Tickets->new(RT->SystemUser); + $tickets->FromSQL( "'CF.{$cf_name}' = 'May 4 2010 7am'" ); + is( $tickets->Count, 1, 'found the ticket with = May 4 2010 7am' ); + + $tickets->FromSQL( "'CF.{$cf_name}' = 'May 4 2010 8am'" ); + is( $tickets->Count, 0, 'did not find the ticket with = May 4 2010 8am' ); + + $tickets->FromSQL( "'CF.{$cf_name}' > 'May 3 2010 7am'" ); + is( $tickets->Count, 1, 'found the ticket with > May 3 2010 7am' ); + + $tickets->FromSQL( "'CF.{$cf_name}' < 'May 4 2010 8am'" ); + is( $tickets->Count, 1, 'found the ticket with < May 4 2010 8am' ); + +} + + my $tickets = RT::Tickets->new( RT->SystemUser ); $tickets->UnLimit; while( my $ticket = $tickets->Next ) { @@ -139,3 +169,69 @@ while( my $ticket = $tickets->Next ) { ); is( $tickets->Count, 1, 'found the ticket with = 2010-06-22 01:00:01' ); } + +# set timezone in all places to UTC +{ + RT->SystemUser->UserObj->__Set(Field => 'Timezone', Value => 'UTC') + if RT->SystemUser->UserObj->Timezone; + RT->Config->Set( Timezone => 'UTC' ); +} + +# search by absolute date with '=', but date only +{ + my $ticket = RT::Ticket->new(RT->SystemUser); + my ($tid) = $ticket->Create( + Queue => $q->id, + Subject => 'Test', + 'CustomField-' . $cf->id => '2013-02-11 23:14:15', + ); + is $ticket->FirstCustomFieldValue($cf_name), '2013-02-11 23:14:15'; + + my $tickets = RT::Tickets->new($user_m); + $tickets->FromSQL("'CustomField.{$cf_name}' = '2013-02-11' AND id = $tid"); + is( $tickets->Count, 0); + + $tickets = RT::Tickets->new($user_m); + $tickets->FromSQL("'CustomField.{$cf_name}' = '2013-02-12' AND id = $tid"); + is( $tickets->Count, 1); + + $tickets = RT::Tickets->new($user_b); + $tickets->FromSQL("'CustomField.{$cf_name}' = '2013-02-11' AND id = $tid"); + is( $tickets->Count, 1); + + $tickets = RT::Tickets->new($user_b); + $tickets->FromSQL("'CustomField.{$cf_name}' = '2013-02-12' AND id = $tid"); + is( $tickets->Count, 0); +} + +# search by relative date with '=', but date only +{ + my $ticket = RT::Ticket->new(RT->SystemUser); + my ($tid) = $ticket->Create( + Queue => $q->id, + Subject => 'Test', + 'CustomField-' . $cf->id => '2013-02-11 23:14:15', + ); + is $ticket->FirstCustomFieldValue($cf_name), '2013-02-11 23:14:15'; + + set_fixed_time("2013-02-10T16:10:00Z"); + my $tickets = RT::Tickets->new($user_m); + $tickets->FromSQL("'CustomField.{$cf_name}' = 'tomorrow' AND id = $tid"); + is( $tickets->Count, 0); + + set_fixed_time("2013-02-10T23:10:00Z"); + $tickets = RT::Tickets->new($user_m); + $tickets->FromSQL("'CustomField.{$cf_name}' = 'tomorrow' AND id = $tid"); + is( $tickets->Count, 1); + + set_fixed_time("2013-02-10T23:10:00Z"); + $tickets = RT::Tickets->new($user_b); + $tickets->FromSQL("'CustomField.{$cf_name}' = 'tomorrow' AND id = $tid"); + is( $tickets->Count, 1); + + set_fixed_time("2013-02-10T02:10:00Z"); + $tickets = RT::Tickets->new($user_b); + $tickets->FromSQL("'CustomField.{$cf_name}' = 'tomorrow' AND id = $tid"); + is( $tickets->Count, 0); +} + diff --git a/rt/t/customfields/external.t b/rt/t/customfields/external.t index 0abf6ec..7354916 100644 --- a/rt/t/customfields/external.t +++ b/rt/t/customfields/external.t @@ -1,10 +1,9 @@ -#!/usr/bin/perl use warnings; use strict; use RT; -use RT::Test nodata => 1, tests => 11; +use RT::Test nodata => 1, tests => 13; sub new (*) { my $class = shift; @@ -54,3 +53,9 @@ isa_ok( $cf, 'RT::CustomField' ); is( $values->Count, $count, "count is correct" ); } +{ + my ($ret, $msg) = $cf->SetValuesClass('RT::CustomFieldValues'); + ok $ret, 'Reverting this CF as internal source values based' or diag "error: $msg"; + ($ret, $msg) = $cf->SetValuesClass('RT::CustomFieldValues::Groups'); + ok $ret, 'Reverting this CF as external source values based' or diag "error: $msg"; +} diff --git a/rt/t/customfields/ip.t b/rt/t/customfields/ip.t index f73e63f..3ab7fbd 100644 --- a/rt/t/customfields/ip.t +++ b/rt/t/customfields/ip.t @@ -1,9 +1,9 @@ -#!/usr/bin/perl use strict; use warnings; -use RT::Test tests => 73; +use RT::Test tests => undef; +use Test::Warn; my ( $baseurl, $agent ) = RT::Test->started_ok; ok( $agent->login, 'log in' ); @@ -265,7 +265,9 @@ diag "create a ticket with an IP of 10.0.0.1 and search for doesn't match '10.0. ok( $id, "created first ticket $id" ); my $tickets = RT::Tickets->new($RT::SystemUser); - $tickets->FromSQL("id=$id AND CF.{IP} NOT LIKE '10.0.0.'"); + warning_like { + $tickets->FromSQL("id=$id AND CF.{IP} NOT LIKE '10.0.0.'"); + } [qr/not a valid IPAddress/], "caught warning about valid IP address"; SKIP: { skip "partical ip parse causes ambiguity", 1; @@ -283,3 +285,6 @@ diag "test the operators in search page" if $ENV{'TEST_VERBOSE'}; ok( $op, "found 'CF.{IP}'Op" ); is_deeply( [ $op->possible_values ], [ '=', '!=', '<', '>' ], 'op values' ); } + +undef $agent; +done_testing; diff --git a/rt/t/customfields/iprange.t b/rt/t/customfields/iprange.t index 118d23c..af9a52f 100644 --- a/rt/t/customfields/iprange.t +++ b/rt/t/customfields/iprange.t @@ -1,4 +1,3 @@ -#!/usr/bin/perl use strict; use warnings; diff --git a/rt/t/customfields/iprangev6.t b/rt/t/customfields/iprangev6.t index d823dd6..3b8a4d6 100644 --- a/rt/t/customfields/iprangev6.t +++ b/rt/t/customfields/iprangev6.t @@ -1,4 +1,3 @@ -#!/usr/bin/perl use strict; use warnings; diff --git a/rt/t/customfields/ipv6.t b/rt/t/customfields/ipv6.t index 09c4d30..f97420e 100644 --- a/rt/t/customfields/ipv6.t +++ b/rt/t/customfields/ipv6.t @@ -1,9 +1,9 @@ -#!/usr/bin/perl use strict; use warnings; -use RT::Test tests => 102; +use RT::Test tests => undef; +use Test::Warn; my ( $baseurl, $agent ) = RT::Test->started_ok; ok( $agent->login, 'log in' ); @@ -242,7 +242,9 @@ diag "create a ticket with an IP of abcd:23:: and search for doesn't match 'abcd ok( $id, "created first ticket $id" ); my $tickets = RT::Tickets->new($RT::SystemUser); - $tickets->FromSQL("id=$id AND CF.{IP} NOT LIKE 'abcd:23'"); + warning_like { + $tickets->FromSQL("id=$id AND CF.{IP} NOT LIKE 'abcd:23'"); + } [qr/not a valid IPAddress/], "caught warning about IPAddress"; SKIP: { skip "partical ip parse can causes ambiguity", 1; @@ -250,3 +252,5 @@ diag "create a ticket with an IP of abcd:23:: and search for doesn't match 'abcd } } +undef $agent; +done_testing; diff --git a/rt/t/customfields/pattern.t b/rt/t/customfields/pattern.t index 7d1090f..2fccb45 100644 --- a/rt/t/customfields/pattern.t +++ b/rt/t/customfields/pattern.t @@ -1,4 +1,3 @@ -#!/usr/bin/perl use warnings; use strict; diff --git a/rt/t/customfields/single_values.t b/rt/t/customfields/single_values.t index 15a0016..42ba479 100644 --- a/rt/t/customfields/single_values.t +++ b/rt/t/customfields/single_values.t @@ -1,4 +1,3 @@ -#!/usr/bin/perl use warnings; use strict; diff --git a/rt/t/customfields/sort_order.t b/rt/t/customfields/sort_order.t index 2453a7c..ba0b654 100644 --- a/rt/t/customfields/sort_order.t +++ b/rt/t/customfields/sort_order.t @@ -1,4 +1,3 @@ -#!/usr/bin/perl -w use strict; use warnings; diff --git a/rt/t/customfields/transaction.t b/rt/t/customfields/transaction.t index 22f8459..f2e660e 100644 --- a/rt/t/customfields/transaction.t +++ b/rt/t/customfields/transaction.t @@ -1,4 +1,3 @@ -#!/usr/bin/perl use warnings; use strict; |