diff options
author | Ivan Kohler <ivan@freeside.biz> | 2015-07-09 22:32:26 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2015-07-09 22:32:26 -0700 |
commit | 026dc7ad72ba972f230b6709e31fa64397d75ad4 (patch) | |
tree | c5af1a7ac9154744afc3660e9a9405892f2bb50b /rt/t/customfields | |
parent | 07b4bc84d1078f7390221d766cdb3142513db4b0 (diff) | |
parent | 1c538bfabc2cd31f27067505f0c3d1a46cba6ef0 (diff) |
merge RT 4.2.11 and Header changes to disable RT javascript, RT#34237
Diffstat (limited to 'rt/t/customfields')
-rw-r--r-- | rt/t/customfields/access_via_queue.t | 7 | ||||
-rw-r--r-- | rt/t/customfields/api.t | 172 | ||||
-rw-r--r-- | rt/t/customfields/date_search.t | 27 | ||||
-rw-r--r-- | rt/t/customfields/datetime_search.t | 28 | ||||
-rw-r--r-- | rt/t/customfields/external.t | 8 | ||||
-rw-r--r-- | rt/t/customfields/ip.t | 10 | ||||
-rw-r--r-- | rt/t/customfields/iprange.t | 6 | ||||
-rw-r--r-- | rt/t/customfields/iprangev6.t | 2 | ||||
-rw-r--r-- | rt/t/customfields/ipv6.t | 6 | ||||
-rw-r--r-- | rt/t/customfields/sort_order.t | 2 | ||||
-rw-r--r-- | rt/t/customfields/transaction.t | 17 | ||||
-rw-r--r-- | rt/t/customfields/transaction_searching.t | 140 |
12 files changed, 305 insertions, 120 deletions
diff --git a/rt/t/customfields/access_via_queue.t b/rt/t/customfields/access_via_queue.t index a059d69ee..300e777b8 100644 --- a/rt/t/customfields/access_via_queue.t +++ b/rt/t/customfields/access_via_queue.t @@ -28,11 +28,8 @@ my $tester = RT::Test->load_or_create_user( ); ok $tester && $tester->id, 'loaded or created user'; -my $cc_role = RT::Group->new( $queue->CurrentUser ); -$cc_role->LoadQueueRoleGroup( Type => 'Cc', Queue => $queue->id ); - -my $owner_role = RT::Group->new( $queue->CurrentUser ); -$owner_role->LoadQueueRoleGroup( Type => 'Owner', Queue => $queue->id ); +my $cc_role = $queue->RoleGroup( 'Cc' ); +my $owner_role = $queue->RoleGroup( 'Owner' ); ok( RT::Test->set_rights( { Principal => $tester, Right => [qw(SeeQueue ShowTicket CreateTicket ReplyToTicket Watch OwnTicket TakeTicket)] }, diff --git a/rt/t/customfields/api.t b/rt/t/customfields/api.t index 2e1c07986..a50ca770c 100644 --- a/rt/t/customfields/api.t +++ b/rt/t/customfields/api.t @@ -5,12 +5,12 @@ use warnings FATAL => 'all'; use RT::Test nodata => 1, tests => 145; use Test::Warn; -# Before we get going, ditch all object_cfs; this will remove +# Before we get going, ditch all object_cfs; this will remove # all custom fields systemwide; my $object_cfs = RT::ObjectCustomFields->new(RT->SystemUser); $object_cfs->UnLimit(); while (my $ocf = $object_cfs->Next) { - $ocf->Delete(); + $ocf->Delete(); } @@ -23,9 +23,9 @@ $queue2->Create( Name => 'RecordCustomFields2' ); my $ticket = RT::Ticket->new( RT->SystemUser ); $ticket->Create( - Queue => $queue->Id, - Requestor => 'root@localhost', - Subject => 'RecordCustomFields1', + Queue => $queue->Id, + Requestor => 'root@localhost', + Subject => 'RecordCustomFields1', ); my $cfs = $ticket->CustomFields; @@ -86,13 +86,13 @@ warning_like { } qr{Couldn't load custom field}; for (@custom_fields) { - $cfvs = $ticket->CustomFieldValues( $_->id ); - is( $cfvs->Count, 0 ); + $cfvs = $ticket->CustomFieldValues( $_->id ); + is( $cfvs->Count, 0 ); - $cfvs = $ticket->CustomFieldValues( $_->Name ); - is( $cfvs->Count, 0 ); - is( $ticket->FirstCustomFieldValue( $_->id ), undef ); - is( $ticket->FirstCustomFieldValue( $_->Name ), undef ); + $cfvs = $ticket->CustomFieldValues( $_->Name ); + is( $cfvs->Count, 0 ); + is( $ticket->FirstCustomFieldValue( $_->id ), undef ); + is( $ticket->FirstCustomFieldValue( $_->Name ), undef ); } # try to add field value with fields that do not exist {{{ @@ -103,84 +103,84 @@ ok(!$status, "shouldn't add value" ); SKIP: { - skip "TODO: We want fields that are not allowed to set unexpected values", 10; - for (@custom_fields) { - ($status, $msg) = $ticket->AddCustomFieldValue( Field => $_ , Value => 'SomeUnexpectedCFValue' ); - ok( !$status, 'value doesn\'t exist'); - - ($status, $msg) = $ticket->AddCustomFieldValue( Field => $_->id , Value => 'SomeUnexpectedCFValue' ); - ok( !$status, 'value doesn\'t exist'); - - ($status, $msg) = $ticket->AddCustomFieldValue( Field => $_->Name , Value => 'SomeUnexpectedCFValue' ); - ok( !$status, 'value doesn\'t exist'); - } - - # Let check that we did not add value to be sure - # using only FirstCustomFieldValue sub because - # we checked other variants allready - for (@custom_fields) { - is( $ticket->FirstCustomFieldValue( $_->id ), undef ); - } - + skip "TODO: We want fields that are not allowed to set unexpected values", 10; + for (@custom_fields) { + ($status, $msg) = $ticket->AddCustomFieldValue( Field => $_ , Value => 'SomeUnexpectedCFValue' ); + ok( !$status, 'value doesn\'t exist'); + + ($status, $msg) = $ticket->AddCustomFieldValue( Field => $_->id , Value => 'SomeUnexpectedCFValue' ); + ok( !$status, 'value doesn\'t exist'); + + ($status, $msg) = $ticket->AddCustomFieldValue( Field => $_->Name , Value => 'SomeUnexpectedCFValue' ); + ok( !$status, 'value doesn\'t exist'); + } + + # Let check that we did not add value to be sure + # using only FirstCustomFieldValue sub because + # we checked other variants allready + for (@custom_fields) { + is( $ticket->FirstCustomFieldValue( $_->id ), undef ); + } + } # Add some values to our custom fields for (@custom_fields) { - # this should be tested elsewhere - $_->AddValue( Name => 'Foo' ); - $_->AddValue( Name => 'Bar' ); + # this should be tested elsewhere + $_->AddValue( Name => 'Foo' ); + $_->AddValue( Name => 'Bar' ); } my $test_add_delete_cycle = sub { - my $cb = shift; - for (@custom_fields) { - ($status, $msg) = $ticket->AddCustomFieldValue( Field => $cb->($_) , Value => 'Foo' ); - ok( $status, "message: $msg"); - } - - # does it exist? - $cfvs = $ticket->CustomFieldValues; - is( $cfvs->Count, 3, "We found all three custom fields on our ticket" ); - for (@custom_fields) { - $cfvs = $ticket->CustomFieldValues( $_->id ); - is( $cfvs->Count, 1 , "we found one custom field when searching by id"); - - $cfvs = $ticket->CustomFieldValues( $_->Name ); - is( $cfvs->Count, 1 , " We found one custom field when searching by name for " . $_->Name); - is( $ticket->FirstCustomFieldValue( $_->id ), 'Foo' , "first value by id is foo"); - is( $ticket->FirstCustomFieldValue( $_->Name ), 'Foo' , "first value by name is foo"); - } - # because our CFs are SingleValue then new value addition should override - for (@custom_fields) { - ($status, $msg) = $ticket->AddCustomFieldValue( Field => $_ , Value => 'Bar' ); - ok( $status, "message: $msg"); - } - $cfvs = $ticket->CustomFieldValues; - is( $cfvs->Count, 3 ); - for (@custom_fields) { - $cfvs = $ticket->CustomFieldValues( $_->id ); - is( $cfvs->Count, 1 ); - - $cfvs = $ticket->CustomFieldValues( $_->Name ); - is( $cfvs->Count, 1 ); - is( $ticket->FirstCustomFieldValue( $_->id ), 'Bar' ); - is( $ticket->FirstCustomFieldValue( $_->Name ), 'Bar' ); - } - # delete it - for (@custom_fields ) { - ($status, $msg) = $ticket->DeleteCustomFieldValue( Field => $_ , Value => 'Bar' ); - ok( $status, "Deleted a custom field value 'Bar' for field ".$_->id.": $msg"); - } - $cfvs = $ticket->CustomFieldValues; - is( $cfvs->Count, 0, "The ticket (".$ticket->id.") no longer has any custom field values" ); - for (@custom_fields) { - $cfvs = $ticket->CustomFieldValues( $_->id ); - is( $cfvs->Count, 0, $ticket->id." has no values for cf ".$_->id ); - - $cfvs = $ticket->CustomFieldValues( $_->Name ); - is( $cfvs->Count, 0 , $ticket->id." has no values for cf '".$_->Name. "'" ); - is( $ticket->FirstCustomFieldValue( $_->id ), undef , "There is no first custom field value when loading by id" ); - is( $ticket->FirstCustomFieldValue( $_->Name ), undef, "There is no first custom field value when loading by Name" ); - } + my $cb = shift; + for (@custom_fields) { + ($status, $msg) = $ticket->AddCustomFieldValue( Field => $cb->($_) , Value => 'Foo' ); + ok( $status, "message: $msg"); + } + + # does it exist? + $cfvs = $ticket->CustomFieldValues; + is( $cfvs->Count, 3, "We found all three custom fields on our ticket" ); + for (@custom_fields) { + $cfvs = $ticket->CustomFieldValues( $_->id ); + is( $cfvs->Count, 1 , "we found one custom field when searching by id"); + + $cfvs = $ticket->CustomFieldValues( $_->Name ); + is( $cfvs->Count, 1 , " We found one custom field when searching by name for " . $_->Name); + is( $ticket->FirstCustomFieldValue( $_->id ), 'Foo' , "first value by id is foo"); + is( $ticket->FirstCustomFieldValue( $_->Name ), 'Foo' , "first value by name is foo"); + } + # because our CFs are SingleValue then new value addition should override + for (@custom_fields) { + ($status, $msg) = $ticket->AddCustomFieldValue( Field => $_ , Value => 'Bar' ); + ok( $status, "message: $msg"); + } + $cfvs = $ticket->CustomFieldValues; + is( $cfvs->Count, 3 ); + for (@custom_fields) { + $cfvs = $ticket->CustomFieldValues( $_->id ); + is( $cfvs->Count, 1 ); + + $cfvs = $ticket->CustomFieldValues( $_->Name ); + is( $cfvs->Count, 1 ); + is( $ticket->FirstCustomFieldValue( $_->id ), 'Bar' ); + is( $ticket->FirstCustomFieldValue( $_->Name ), 'Bar' ); + } + # delete it + for (@custom_fields ) { + ($status, $msg) = $ticket->DeleteCustomFieldValue( Field => $_ , Value => 'Bar' ); + ok( $status, "Deleted a custom field value 'Bar' for field ".$_->id.": $msg"); + } + $cfvs = $ticket->CustomFieldValues; + is( $cfvs->Count, 0, "The ticket (".$ticket->id.") no longer has any custom field values" ); + for (@custom_fields) { + $cfvs = $ticket->CustomFieldValues( $_->id ); + is( $cfvs->Count, 0, $ticket->id." has no values for cf ".$_->id ); + + $cfvs = $ticket->CustomFieldValues( $_->Name ); + is( $cfvs->Count, 0 , $ticket->id." has no values for cf '".$_->Name. "'" ); + is( $ticket->FirstCustomFieldValue( $_->id ), undef , "There is no first custom field value when loading by id" ); + is( $ticket->FirstCustomFieldValue( $_->Name ), undef, "There is no first custom field value when loading by Name" ); + } }; # lets test cycle via CF id @@ -224,10 +224,10 @@ warning_like { } #SKIP: { -# skip "TODO: should we add CF values to objects via CF Name?", 48; +# skip "TODO: should we add CF values to objects via CF Name?", 48; # names are not unique - # lets test cycle via CF Name -# $test_add_delete_cycle->( sub { return $_[0]->Name } ); + # lets test cycle via CF Name +# $test_add_delete_cycle->( sub { return $_[0]->Name } ); #} diff --git a/rt/t/customfields/date_search.t b/rt/t/customfields/date_search.t index 2a8e6ce7a..e9a5a5e76 100644 --- a/rt/t/customfields/date_search.t +++ b/rt/t/customfields/date_search.t @@ -3,7 +3,7 @@ use Test::MockTime qw(set_fixed_time restore_time); use warnings; use strict; -use RT::Test nodata => 1, tests => 21; +use RT::Test nodata => 1, tests => undef; RT::Test->set_rights( { Principal => 'Everyone', Right => [qw( @@ -16,9 +16,11 @@ 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; +$user_m = RT::CurrentUser->new( $user_m ); my $user_b = RT::Test->load_or_create_user( Name => 'boston', Timezone => 'America/New_York' ); ok $user_b && $user_b->id; +$user_b = RT::CurrentUser->new( $user_b ); my $cf = RT::CustomField->new(RT->SystemUser); ok( @@ -132,6 +134,28 @@ 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' ); } +{ + my $tickets = RT::Tickets->new(RT->SystemUser); + $tickets->LimitCustomField( + CUSTOMFIELD => $cf->id, + OPERATOR => 'IS', + VALUE => 'NULL', + ); + + is( $tickets->Count, 0, 'did not find the ticket with date IS NULL' ); +} + +{ + my $tickets = RT::Tickets->new(RT->SystemUser); + $tickets->LimitCustomField( + CUSTOMFIELD => $cf->id, + OPERATOR => 'IS NOT', + VALUE => 'NULL', + ); + + is( $tickets->Count, 1, 'did find the ticket with date IS NOT NULL' ); +} + # relative search by users in different TZs { my $ticket = RT::Ticket->new(RT->SystemUser); @@ -162,3 +186,4 @@ is( $ticket->CustomFieldValues->First->Content, '2010-05-04', 'date in db is' ); is( $tickets->Count, 1, 'found the tickets' ); } +done_testing; diff --git a/rt/t/customfields/datetime_search.t b/rt/t/customfields/datetime_search.t index 6b37cf1bc..2eaa0e629 100644 --- a/rt/t/customfields/datetime_search.t +++ b/rt/t/customfields/datetime_search.t @@ -3,7 +3,7 @@ use Test::MockTime qw(set_fixed_time restore_time); use warnings; use strict; -use RT::Test nodata => 1, tests => 30; +use RT::Test nodata => 1, tests => undef; RT->Config->Set( 'Timezone' => 'EST5EDT' ); # -04:00 RT::Test->set_rights( @@ -17,9 +17,11 @@ 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; +$user_m = RT::CurrentUser->new( $user_m ); my $user_b = RT::Test->load_or_create_user( Name => 'boston', Timezone => 'America/New_York' ); ok $user_b && $user_b->id; +$user_b = RT::CurrentUser->new( $user_b ); my $cf = RT::CustomField->new(RT->SystemUser); ok( @@ -204,6 +206,29 @@ while( my $ticket = $tickets->Next ) { is( $tickets->Count, 0); } +{ + my $tickets = RT::Tickets->new(RT->SystemUser); + $tickets->LimitCustomField( + CUSTOMFIELD => $cf->id, + OPERATOR => 'IS', + VALUE => 'NULL', + ); + + is( $tickets->Count, 0, 'did not find the ticket with date IS NULL' ); +} + +{ + my $tickets = RT::Tickets->new(RT->SystemUser); + $tickets->LimitCustomField( + CUSTOMFIELD => $cf->id, + OPERATOR => 'IS NOT', + VALUE => 'NULL', + ); + + is( $tickets->Count, 2, 'did find the ticket with date IS NOT NULL' ); +} + + # search by relative date with '=', but date only { my $ticket = RT::Ticket->new(RT->SystemUser); @@ -235,3 +260,4 @@ while( my $ticket = $tickets->Next ) { is( $tickets->Count, 0); } +done_testing; diff --git a/rt/t/customfields/external.t b/rt/t/customfields/external.t index 73549166a..4b84144ee 100644 --- a/rt/t/customfields/external.t +++ b/rt/t/customfields/external.t @@ -3,7 +3,7 @@ use warnings; use strict; use RT; -use RT::Test nodata => 1, tests => 13; +use RT::Test nodata => 1, tests => undef; sub new (*) { my $class = shift; @@ -51,6 +51,10 @@ isa_ok( $cf, 'RT::CustomField' ); } ok( !$failure, "all values have name" ); is( $values->Count, $count, "count is correct" ); + is( $values->CustomFieldObject->id, $cf->id, "Values stored the CF id" ); + is( $values->CustomFieldObject, $cf, "Values stored the identical CF object" ); + is( $values->First->CustomFieldObj->id, $cf->id, "A value stored the CF id" ); + is( $values->First->CustomFieldObj, $cf, "A value stored the identical CF object" ); } { @@ -59,3 +63,5 @@ isa_ok( $cf, 'RT::CustomField' ); ($ret, $msg) = $cf->SetValuesClass('RT::CustomFieldValues::Groups'); ok $ret, 'Reverting this CF as external source values based' or diag "error: $msg"; } + +done_testing; diff --git a/rt/t/customfields/ip.t b/rt/t/customfields/ip.t index 37afcb71d..35a245c5e 100644 --- a/rt/t/customfields/ip.t +++ b/rt/t/customfields/ip.t @@ -26,7 +26,7 @@ my $cf; diag "load and check basic properties of the IP CF" if $ENV{'TEST_VERBOSE'}; { my $cfs = RT::CustomFields->new($RT::SystemUser); - $cfs->Limit( FIELD => 'Name', VALUE => 'IP' ); + $cfs->Limit( FIELD => 'Name', VALUE => 'IP', CASESENSITIVE => 0 ); is( $cfs->Count, 1, "found one CF with name 'IP'" ); $cf = $cfs->First; @@ -269,8 +269,8 @@ diag "create a ticket with an IP of 10.0.0.1 and search for doesn't match '10.0. $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; + TODO: { + local $TODO = "partial ip parse causes ambiguity"; is( $tickets->Count, 0, "should not have found the ticket" ); } } @@ -281,8 +281,8 @@ diag "test the operators in search page" if $ENV{'TEST_VERBOSE'}; $agent->get_ok( $baseurl . "/Search/Build.html?Query=Queue='General'" ); $agent->content_contains('CF.{IP}', 'got CF.{IP}'); my $form = $agent->form_name('BuildQuery'); - my $op = $form->find_input("'CF.{IP}'Op"); - ok( $op, "found 'CF.{IP}'Op" ); + my $op = $form->find_input("CF.{IP}Op"); + ok( $op, "found CF.{IP}Op" ); is_deeply( [ $op->possible_values ], [ '=', '!=', '<', '>' ], 'op values' ); } diff --git a/rt/t/customfields/iprange.t b/rt/t/customfields/iprange.t index 4bccd9ac1..2a323a352 100644 --- a/rt/t/customfields/iprange.t +++ b/rt/t/customfields/iprange.t @@ -21,7 +21,7 @@ my $cf; diag "load and check basic properties of the IP CF" if $ENV{'TEST_VERBOSE'}; { my $cfs = RT::CustomFields->new( $RT::SystemUser ); - $cfs->Limit( FIELD => 'Name', VALUE => 'IP' ); + $cfs->Limit( FIELD => 'Name', VALUE => 'IP', CASESENSITIVE => 0 ); is( $cfs->Count, 1, "found one CF with name 'IP'" ); $cf = $cfs->First; @@ -461,8 +461,8 @@ diag "test the operators in search page" if $ENV{'TEST_VERBOSE'}; $agent->get_ok( $baseurl . "/Search/Build.html?Query=Queue='General'" ); $agent->content_contains('CF.{IP}', 'got CF.{IP}'); my $form = $agent->form_name('BuildQuery'); - my $op = $form->find_input("'CF.{IP}'Op"); - ok( $op, "found 'CF.{IP}'Op" ); + my $op = $form->find_input("CF.{IP}Op"); + ok( $op, "found CF.{IP}Op" ); is_deeply( [ $op->possible_values ], [ '=', '!=', '<', '>' ], 'op values' ); } diff --git a/rt/t/customfields/iprangev6.t b/rt/t/customfields/iprangev6.t index 84fec16a0..445df333c 100644 --- a/rt/t/customfields/iprangev6.t +++ b/rt/t/customfields/iprangev6.t @@ -21,7 +21,7 @@ my $cf; diag "load and check basic properties of the IP CF" if $ENV{'TEST_VERBOSE'}; { my $cfs = RT::CustomFields->new( $RT::SystemUser ); - $cfs->Limit( FIELD => 'Name', VALUE => 'IP' ); + $cfs->Limit( FIELD => 'Name', VALUE => 'IP', CASESENSITIVE => 0 ); is( $cfs->Count, 1, "found one CF with name 'IP'" ); $cf = $cfs->First; diff --git a/rt/t/customfields/ipv6.t b/rt/t/customfields/ipv6.t index 3b02ef9d7..24f7c2a48 100644 --- a/rt/t/customfields/ipv6.t +++ b/rt/t/customfields/ipv6.t @@ -26,7 +26,7 @@ my $cf; diag "load and check basic properties of the IP CF" if $ENV{'TEST_VERBOSE'}; { my $cfs = RT::CustomFields->new($RT::SystemUser); - $cfs->Limit( FIELD => 'Name', VALUE => 'IP' ); + $cfs->Limit( FIELD => 'Name', VALUE => 'IP', CASESENSITIVE => 0 ); is( $cfs->Count, 1, "found one CF with name 'IP'" ); $cf = $cfs->First; @@ -246,8 +246,8 @@ diag "create a ticket with an IP of abcd:23:: and search for doesn't match 'abcd $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; + TODO: { + local $TODO = "partial ip parse can causes ambiguity"; is( $tickets->Count, 0, "should not have found the ticket" ); } } diff --git a/rt/t/customfields/sort_order.t b/rt/t/customfields/sort_order.t index ba0b654be..24e047ebf 100644 --- a/rt/t/customfields/sort_order.t +++ b/rt/t/customfields/sort_order.t @@ -50,7 +50,7 @@ diag "reorder CFs: C, A and B"; { $m->get( '/Admin/Queues/' ); $m->follow_link_ok( {text => $queue->id} ); - $m->follow_link_ok( {id => 'page-ticket-custom-fields'} ); + $m->follow_link_ok( {id => 'page-custom-fields-tickets'} ); my @tmp = ($m->content =~ /(CF [ABC])/g); is_deeply(\@tmp, ['CF B', 'CF A', 'CF C']); diff --git a/rt/t/customfields/transaction.t b/rt/t/customfields/transaction.t index f2e660ee2..47435bc87 100644 --- a/rt/t/customfields/transaction.t +++ b/rt/t/customfields/transaction.t @@ -3,7 +3,7 @@ use warnings; use strict; use Data::Dumper; -use RT::Test nodata => 1, tests => 14; +use RT::Test nodata => 1, tests => 13; use_ok('RT'); use_ok('RT::Transactions'); @@ -43,17 +43,8 @@ is ($txn_cf->id, $cf->id, "It's the right custom field"); my $values = $trans->CustomFieldValues($txn_cf->id); is ($values->Count, 0, "It has no values"); -# Old API -my %cf_updates = ( 'CustomField-'.$cf->id => 'Testing'); -$trans->UpdateCustomFields( ARGSRef => \%cf_updates); - - $values = $trans->CustomFieldValues($txn_cf->id); -is ($values->Count, 1, "It has one value"); - -# New API - -$trans->UpdateCustomFields( 'CustomField-'.$cf->id => 'Test two'); - $values = $trans->CustomFieldValues($txn_cf->id); -is ($values->Count, 2, "it has two values"); +$trans->UpdateCustomFields( 'CustomField-'.$cf->id => 'Test'); +$values = $trans->CustomFieldValues($txn_cf->id); +is ($values->Count, 1, "it has a value"); # TODO ok(0, "Should updating custom field values remove old values?"); diff --git a/rt/t/customfields/transaction_searching.t b/rt/t/customfields/transaction_searching.t new file mode 100644 index 000000000..0958b5ea6 --- /dev/null +++ b/rt/t/customfields/transaction_searching.t @@ -0,0 +1,140 @@ +use strict; +use warnings; + +use RT::Test tests => 'no_declare'; + +my $initialdata = RT::Test::get_relocatable_file("transaction-cfs" => "..", "data", "initialdata"); +my ($rv, $msg) = RT->DatabaseHandle->InsertData( $initialdata, undef, disconnect_after => 0 ); +ok($rv, "Inserted test data from $initialdata") + or diag "Error: $msg"; + +create_tickets( + Spam => { }, + Coffee => { Billable => "No", }, + Phone => { Billable => "Yes", Who => ["Telecom", "Information Technology"], When => "2013-06-25", Location => "Geology" }, + Stacks => { Billable => "Yes", Who => "Library", When => "2013-06-01" }, + Benches => { Billable => "Yes", Location => "Outdoors" }, +); + +# Sanity check +results_are("CF.Location IS NOT NULL", [qw( Phone Benches )]); +results_are("CF.Location IS NULL", [qw( Spam Coffee Stacks )]); + +# TODO: Ideal behaviour of TxnCF IS NULL not yet determined +#results_are("TxnCF.Billable IS NULL", [qw( Spam )]); + +results_are("TxnCF.Billable IS NOT NULL", [qw( Coffee Phone Stacks Benches )]); +results_are("TxnCF.Billable = 'No'", [qw( Coffee )]); +results_are("TxnCF.Billable = 'Yes'", [qw( Phone Stacks Benches )]); +results_are("TxnCF.Billable = 'Yes' AND CF.Location IS NOT NULL", [qw( Phone Benches )]); +results_are("TxnCF.Billable = 'Yes' AND CF.Location = 'Outdoors'", [qw( Benches )]); +results_are("TxnCF.Billable = 'Yes' AND CF.Location LIKE 'o'", [qw( Phone Benches )]); + +results_are("TxnCF.Who = 'Telecom' OR TxnCF.Who = 'Library'", [qw( Phone Stacks )]); + +# TODO: Negative searching finds tickets with at least one txn doesn't have the value +#results_are("TxnCF.Who != 'Library'", [qw( Spam Coffee Phone Benches )]); + +results_are("TxnCF.When > '2013-06-24'", [qw( Phone )]); +results_are("TxnCF.When < '2013-06-24'", [qw( Stacks )]); +results_are("TxnCF.When >= '2013-06-01' and TxnCF.When <= '2013-06-30'", [qw( Phone Stacks )]); + +results_are("TxnCF.Who LIKE 'e'", [qw( Phone )]); + +# TODO: Negative searching finds tickets with at least one txn doesn't have the value +#results_are("TxnCF.Who NOT LIKE 'e'", [qw( Spam Coffee Stacks Benches )]); + +results_are("TxnCF.Who NOT LIKE 'e' and TxnCF.Who IS NOT NULL", [qw( Stacks )]); + + +# Multiple CFs with same name applied to different queues +clear_tickets(); +create_tickets( + BlueNone => { Queue => "Blues" }, + PurpleNone => { Queue => "Purples" }, + + Blue => { Queue => "Blues", Color => "Blue" }, + Purple => { Queue => "Purples", Color => "Purple" }, +); + +# Queue-specific txn CFs +results_are("TxnCF.Blues.{Color} = 'Blue'", [qw( Blue )]); +results_are("TxnCF.Blues.{Color} = 'Purple'", []); + +# Multiple transaction CFs by name +results_are("TxnCF.{Color} IS NOT NULL", [qw( Blue Purple )]); +results_are("TxnCF.{Color} = 'Blue'", [qw( Blue )]); +results_are("TxnCF.{Color} = 'Purple'", [qw( Purple )]); +results_are("TxnCF.{Color} LIKE 'e'", [qw( Blue Purple )]); + +done_testing; + +sub results_are { + local $Test::Builder::Level = $Test::Builder::Level + 1; + + my $query = shift; + my $expected = shift; + my %expected = map { $_ => 1 } @$expected; + my @unexpected; + + my $tickets = RT::Tickets->new(RT->SystemUser); + my ($ok, $msg) = $tickets->FromSQL($query); + ok($ok, "Searched: $query") + or return diag $msg; + for my $t (@{$tickets->ItemsArrayRef || []}) { + if (delete $expected{$t->Subject}) { + ok(1, "Found expected ticket ".$t->Subject); + } else { + push @unexpected, $t->Subject; + } + } + ok(0, "Didn't find expected ticket $_") + for grep $expected{$_}, @$expected; + ok(0, "Found unexpected tickets: ".join ", ", @unexpected) + if @unexpected; +} + +sub create_tickets { + my %ticket = @_; + for my $subject (sort keys %ticket) { + my %data = %{$ticket{$subject}}; + my $location = delete $data{Location}; + my $queue = delete $data{Queue} || "General"; + + my $ticket = RT::Ticket->new( RT->SystemUser ); + my ($ok, $msg) = $ticket->Create( + Queue => $queue, + Subject => $subject, + ); + ok($ticket->id, "Created ticket: $msg") or next; + + if ($location) { + ($ok, $msg) = $ticket->AddCustomFieldValue( Field => "Location", Value => $location ); + ok($ok, "Added Location: $msg") or next; + } + + my ($txnid, $txnmsg, $txn) = $ticket->Correspond( Content => "test transaction" ); + unless ($txnid) { + RT->Logger->error("Unable to correspond on ticket $ok: $txnmsg"); + next; + } + for my $name (sort keys %data) { + my $values = ref $data{$name} ? $data{$name} : [$data{$name}]; + for my $v (@$values) { + ($ok, $msg) = $txn->_AddCustomFieldValue( + Field => $name, + Value => $v, + RecordTransaction => 0 + ); + ok($ok, "Added txn CF $name value '$v'") + or diag $msg; + } + } + } +} + +sub clear_tickets { + my $tickets = RT::Tickets->new( RT->SystemUser ); + $tickets->FromSQL("id > 0"); + $_->SetStatus("deleted") for @{$tickets->ItemsArrayRef}; +} |