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/ticket | |
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/ticket')
-rw-r--r-- | rt/t/ticket/action_linear_escalate.t | 2 | ||||
-rw-r--r-- | rt/t/ticket/add-watchers.t | 22 | ||||
-rw-r--r-- | rt/t/ticket/cfsort-freeform-single.t | 269 | ||||
-rw-r--r-- | rt/t/ticket/circular_links.t | 45 | ||||
-rw-r--r-- | rt/t/ticket/deferred_owner.t | 21 | ||||
-rw-r--r-- | rt/t/ticket/linking.t | 36 | ||||
-rw-r--r-- | rt/t/ticket/merge.t | 45 | ||||
-rw-r--r-- | rt/t/ticket/scrips_batch.t | 41 | ||||
-rw-r--r-- | rt/t/ticket/search.t | 31 | ||||
-rw-r--r-- | rt/t/ticket/search_by_cf_freeform_multiple.t | 225 | ||||
-rw-r--r-- | rt/t/ticket/search_by_cf_freeform_single.t | 231 | ||||
-rw-r--r-- | rt/t/ticket/search_by_watcher_group.t | 75 | ||||
-rw-r--r-- | rt/t/ticket/simple_search.t (renamed from rt/t/ticket/googleish_search.t) | 8 | ||||
-rw-r--r-- | rt/t/ticket/time-worked.t | 80 |
14 files changed, 747 insertions, 384 deletions
diff --git a/rt/t/ticket/action_linear_escalate.t b/rt/t/ticket/action_linear_escalate.t index 0d1ff8a..8c158aa 100644 --- a/rt/t/ticket/action_linear_escalate.t +++ b/rt/t/ticket/action_linear_escalate.t @@ -19,7 +19,7 @@ ok $q && $q->id, 'loaded or created queue'; my $gecos = RT::Test->load_or_create_user( Name => 'gecos', Password => 'password', - Gecos => ($^O eq 'MSWin32') ? Win32::LoginName() : (getpwuid($<))[0], + Gecos => (getpwuid($<))[0], ); ok $gecos && $gecos->id, 'loaded or created gecos user'; diff --git a/rt/t/ticket/add-watchers.t b/rt/t/ticket/add-watchers.t index 11b3a84..12b0bb3 100644 --- a/rt/t/ticket/add-watchers.t +++ b/rt/t/ticket/add-watchers.t @@ -1,4 +1,4 @@ -use RT::Test nodata => 1, tests => 32; +use RT::Test nodata => 1, tests => 34; use strict; use warnings; @@ -15,7 +15,7 @@ my $acl = RT::ACL->new(RT->SystemUser); $acl->Limit( FIELD => 'RightName', OPERATOR => '!=', VALUE => 'SuperUser' ); $acl->LimitToObject( RT->System ); while( my $ace = $acl->Next ) { - $ace->Delete; + $ace->Delete; } # create new queue to be sure we do not mess with rights @@ -25,11 +25,12 @@ ok( $queue_id, 'queue created for watcher tests' ); # new privileged user to check rights my $user = RT::User->new( RT->SystemUser ); -my ($user_id) = $user->Create( Name => 'watcher'.$$, - EmailAddress => "watcher$$".'@localhost', - Privileged => 1, - Password => 'qwe123', - ); +my ($user_id) = $user->Create( + Name => 'watcher'.$$, + EmailAddress => "watcher$$".'@localhost', + Privileged => 1, + Password => 'qwe123', +); my $cu= RT::CurrentUser->new($user); # make sure user can see tickets in the queue @@ -86,6 +87,13 @@ ok( $rv, "user can add self as Cc by username" ); ($rv, $msg) = $ticket2->AddWatcher( Type => 'Requestor', Email => $user->Name ); ok( $rv, "user can add self as Requestor by username" ); +# Add an email address with a phrase +($rv, $msg) = $ticket->AddWatcher( Type => 'Cc', Email => q["Foo Bar" <foo@example.com>] ); +ok $rv, "Added email address with phrase" or diag $msg; + +my $foo = RT::Test->load_or_create_user( EmailAddress => 'foo@example.com' ); +is $foo->RealName, "Foo Bar", "RealName matches"; + # Queue watcher tests $principal->RevokeRight( Right => 'Watch' , Object => $queue ); ok( !$user->HasRight( Right => 'Watch', Object => $queue ), "user queue watch right revoked" ); diff --git a/rt/t/ticket/cfsort-freeform-single.t b/rt/t/ticket/cfsort-freeform-single.t index ae109e9..262f84a 100644 --- a/rt/t/ticket/cfsort-freeform-single.t +++ b/rt/t/ticket/cfsort-freeform-single.t @@ -1,158 +1,169 @@ -use RT::Test nodata => 1, tests => 89; - use strict; use warnings; -use RT::Tickets; -use RT::Queue; -use RT::CustomField; - -# Test Sorting by FreeformSingle custom field. +use RT::Test nodata => 1, tests => undef; -diag "Create a queue to test with."; -my $queue_name = "CFSortQueue-$$"; -my $queue; -{ - $queue = RT::Queue->new( RT->SystemUser ); - my ($ret, $msg) = $queue->Create( - Name => $queue_name, - Description => 'queue for custom field sort testing' - ); - ok($ret, "$queue test queue creation. $msg"); -} +my $queue = RT::Test->load_or_create_queue( Name => "sorting" ); +ok $queue && $queue->id, "Created queue"; +my $queue_name = $queue->Name; # CFs for testing, later we create another one -my %CF; -my $cf_name; - +my $cf; +my $cf_name = "ordering"; diag "create a CF"; { - $cf_name = $CF{'CF'}{'name'} = "Order$$"; - $CF{'CF'}{'obj'} = RT::CustomField->new( RT->SystemUser ); - my ($ret, $msg) = $CF{'CF'}{'obj'}->Create( - Name => $CF{'CF'}{'name'}, + $cf = RT::CustomField->new( RT->SystemUser ); + my ($ret, $msg) = $cf->Create( + Name => $cf_name, Queue => $queue->id, Type => 'FreeformSingle', ); - ok($ret, "Custom Field $CF{'CF'}{'name'} created"); -} - -my ($total, @data, @tickets, @test) = (0, ()); - -sub run_tests { - my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets; - foreach my $test ( @test ) { - my $query = join " AND ", map "( $_ )", grep defined && length, - $query_prefix, $test->{'Query'}; - - foreach my $order (qw(ASC DESC)) { - my $error = 0; - my $tix = RT::Tickets->new( RT->SystemUser ); - $tix->FromSQL( $query ); - $tix->OrderBy( FIELD => $test->{'Order'}, ORDER => $order ); - - ok($tix->Count, "found ticket(s)") - or $error = 1; - - my ($order_ok, $last) = (1, $order eq 'ASC'? '-': 'zzzzzz'); - my $last_id = $tix->Last->id; - while ( my $t = $tix->Next ) { - my $tmp; - next if $t->id == $last_id and $t->Subject eq "-"; # Nulls are allowed to come last, in Pg - - if ( $order eq 'ASC' ) { - $tmp = ((split( /,/, $last))[0] cmp (split( /,/, $t->Subject))[0]); - } else { - $tmp = -((split( /,/, $last))[-1] cmp (split( /,/, $t->Subject))[-1]); - } - if ( $tmp > 0 ) { - $order_ok = 0; last; - } - $last = $t->Subject; - } - - ok( $order_ok, "$order order of tickets is good" ) - or $error = 1; - - if ( $error ) { - diag "Wrong SQL query:". $tix->BuildSelectQuery; - $tix->GotoFirstItem; - while ( my $t = $tix->Next ) { - diag sprintf "%02d - %s", $t->id, $t->Subject; - } - } - } - } + ok($ret, "Custom Field created"); } -@data = ( - { Subject => '-' }, - { Subject => 'a', 'CustomField-' . $CF{CF}{obj}->id => 'a' }, - { Subject => 'b', 'CustomField-' . $CF{CF}{obj}->id => 'b' }, -); - -@tickets = RT::Test->create_tickets( { Queue => $queue->id, RandomOrder => 1 }, @data); -@test = ( - { Order => "CF.{$cf_name}" }, - { Order => "CF.$queue_name.{$cf_name}" }, -); -run_tests(); - -@data = ( - { Subject => '-' }, - { Subject => 'aa', 'CustomField-' . $CF{CF}{obj}->id => 'aa' }, - { Subject => 'bb', 'CustomField-' . $CF{CF}{obj}->id => 'bb' }, -); -@tickets = RT::Test->create_tickets( { Queue => $queue->id, RandomOrder => 1 }, @data); -@test = ( - { Query => "CF.{$cf_name} LIKE 'a'", Order => "CF.{$cf_name}" }, - { Query => "CF.{$cf_name} LIKE 'a'", Order => "CF.$queue_name.{$cf_name}" }, -); -run_tests(); - -@data = ( - { Subject => '-', }, - { Subject => 'a', CF => 'a' }, - { Subject => 'b', CF => 'b' }, - { Subject => 'c', CF => 'c' }, -); -@tickets = RT::Test->create_tickets( { Queue => $queue->id, RandomOrder => 1 }, @data); -@test = ( - { Query => "CF.{$cf_name} != 'c'", Order => "CF.{$cf_name}" }, - { Query => "CF.{$cf_name} != 'c'", Order => "CF.$queue_name.{$cf_name}" }, +run_tests( + [ + { Subject => '-' }, + { Subject => 'aa', 'CustomField-' . $cf->id => 'aa' }, + { Subject => 'bb', 'CustomField-' . $cf->id => 'bb' }, + { Subject => 'cc', 'CustomField-' . $cf->id => 'cc' }, + ], + { Count => 4, Order => "CF.{$cf_name}" }, + { Count => 4, Order => "CF.$queue_name.{$cf_name}" }, + { Query => "CF.{$cf_name} LIKE 'a'", Count => 1, Order => "CF.{$cf_name}" }, + { Query => "CF.{$cf_name} LIKE 'a'", Count => 1, Order => "CF.$queue_name.{$cf_name}" }, + { Query => "CF.{$cf_name} != 'cc'", Count => 3, Order => "CF.{$cf_name}" }, + { Query => "CF.{$cf_name} != 'cc'", Count => 3, Order => "CF.$queue_name.{$cf_name}" }, ); -run_tests(); +my $other_cf; +my $other_name = "othercf"; diag "create another CF"; { - $CF{'AnotherCF'}{'name'} = "OrderAnother$$"; - $CF{'AnotherCF'}{'obj'} = RT::CustomField->new( RT->SystemUser ); - my ($ret, $msg) = $CF{'AnotherCF'}{'obj'}->Create( - Name => $CF{'AnotherCF'}{'name'}, + $other_cf = RT::CustomField->new( RT->SystemUser ); + my ($ret, $msg) = $other_cf->Create( + Name => $other_name, Queue => $queue->id, Type => 'FreeformSingle', ); - ok($ret, "Custom Field $CF{'AnotherCF'}{'name'} created"); + ok($ret, "Other Custom Field created"); } -# test that order is not affect by other fields (had such problem) -@data = ( - { Subject => '-', }, - { Subject => 'a', CF => 'a', AnotherCF => 'za' }, - { Subject => 'b', CF => 'b', AnotherCF => 'ya' }, - { Subject => 'c', CF => 'c', AnotherCF => 'xa' }, +# Test that order is not affected by other CFs +run_tests( + [ + { Subject => '-', }, + { Subject => 'aa', "CustomField-" . $cf->id => 'aa', "CustomField-" . $other_cf->id => 'za' }, + { Subject => 'bb', "CustomField-" . $cf->id => 'bb', "CustomField-" . $other_cf->id => 'ya' }, + { Subject => 'cc', "CustomField-" . $cf->id => 'cc', "CustomField-" . $other_cf->id => 'xa' }, + ], + { Count => 4, Order => "CF.{$cf_name}" }, + { Count => 4, Order => "CF.$queue_name.{$cf_name}" }, + { Query => "CF.{$cf_name} LIKE 'a'", Count => 1, Order => "CF.{$cf_name}" }, + { Query => "CF.{$cf_name} LIKE 'a'", Count => 1, Order => "CF.$queue_name.{$cf_name}" }, + { Query => "CF.{$cf_name} != 'cc'", Count => 3, Order => "CF.{$cf_name}" }, + { Query => "CF.{$cf_name} != 'cc'", Count => 3, Order => "CF.$queue_name.{$cf_name}" }, + { Query => "CF.{$other_name} != 'za'", Count => 3, Order => "CF.{$cf_name}" }, + { Query => "CF.{$other_name} != 'za'", Count => 3, Order => "CF.$queue_name.{$cf_name}" }, ); -@tickets = RT::Test->create_tickets( { Queue => $queue->id, RandomOrder => 1 }, @data); -@test = ( - { Order => "CF.{$cf_name}" }, - { Order => "CF.$queue_name.{$cf_name}" }, - { Query => "CF.{$cf_name} != 'c'", Order => "CF.{$cf_name}" }, - { Query => "CF.{$cf_name} != 'c'", Order => "CF.$queue_name.{$cf_name}" }, + +# And then add a CF with a duplicate name, on a different queue +{ + my $other_queue = RT::Test->load_or_create_queue( Name => "other_queue" ); + ok $other_queue && $other_queue->id, "Created queue"; + + my $dup = RT::CustomField->new( RT->SystemUser ); + my ($ret, $msg) = $dup->Create( + Name => $cf_name, + Queue => $other_queue->id, + Type => 'FreeformSingle', + ); + ok($ret, "Custom Field created"); +} + +my $cf_id = $cf->id; +run_tests( + [ + { Subject => '-', }, + { Subject => 'aa', "CustomField-" . $cf->id => 'aa', "CustomField-" . $other_cf->id => 'za' }, + { Subject => 'bb', "CustomField-" . $cf->id => 'bb', "CustomField-" . $other_cf->id => 'ya' }, + { Subject => 'cc', "CustomField-" . $cf->id => 'cc', "CustomField-" . $other_cf->id => 'xa' }, + ], + { Count => 4, Order => "CF.{$cf_name}" }, + { Count => 4, Order => "CF.$queue_name.{$cf_name}" }, + { Query => "CF.{$cf_id} LIKE 'a'", Count => 1, Order => "CF.{$cf_name}" }, + { Query => "CF.{$cf_id} LIKE 'a'", Count => 1, Order => "CF.$queue_name.{$cf_name}" }, + { Query => "CF.{$cf_id} != 'cc'", Count => 3, Order => "CF.{$cf_name}" }, + { Query => "CF.{$cf_id} != 'cc'", Count => 3, Order => "CF.$queue_name.{$cf_name}" }, + { Query => "CF.$queue_name.{$cf_name} LIKE 'a'", Count => 1, Order => "CF.{$cf_name}" }, + { Query => "CF.$queue_name.{$cf_name} LIKE 'a'", Count => 1, Order => "CF.$queue_name.{$cf_name}" }, + { Query => "CF.$queue_name.{$cf_name} != 'cc'", Count => 3, Order => "CF.{$cf_name}" }, + { Query => "CF.$queue_name.{$cf_name} != 'cc'", Count => 3, Order => "CF.$queue_name.{$cf_name}" }, + { Query => "CF.{$other_name} != 'za'", Count => 3, Order => "CF.{$cf_name}" }, + { Query => "CF.{$other_name} != 'za'", Count => 3, Order => "CF.$queue_name.{$cf_name}" }, + + { Query => "CF.{$cf_id} != 'cc'", Count => 3, Order => "CF.{$cf_id}" }, + { Query => "CF.{$cf_id} != 'cc'", Count => 3, Order => "CF.$queue_name.{$cf_id}" }, + { Query => "CF.$queue_name.{$cf_name} != 'cc'", Count => 3, Order => "CF.{$cf_id}" }, + { Query => "CF.$queue_name.{$cf_name} != 'cc'", Count => 3, Order => "CF.$queue_name.{$cf_id}" }, + { Query => "CF.{$other_name} != 'za'", Count => 3, Order => "CF.{$cf_id}" }, + { Query => "CF.{$other_name} != 'za'", Count => 3, Order => "CF.$queue_name.{$cf_id}" }, ); -run_tests(); -@tickets = (); +sub run_tests { + my $tickets = shift; + my @tickets = RT::Test->create_tickets( { Queue => $queue->id, RandomOrder => 1 }, @{ $tickets }); + my $base_query = join(" OR ", map {"id = ".$_->id} @tickets) || "id > 0"; + + my @tests = @_; + for my $test ( @tests ) { + $test->{'Query'} ||= "id > 0"; + my $query = "( $base_query ) AND " . $test->{'Query'}; + for my $order (qw(ASC DESC)) { + subtest $test->{'Query'} . " ORDER BY ".$test->{'Order'}. " $order" => sub { + my $error = 0; + my $tix = RT::Tickets->new( RT->SystemUser ); + $tix->FromSQL( $query ); + $tix->OrderBy( FIELD => $test->{'Order'}, ORDER => $order ); + + is($tix->Count, $test->{'Count'}, "found right number of tickets (".$test->{Count}.")") + or $error = 1; + + my ($order_ok, $last) = (1, $order eq 'ASC'? '-': 'zzzzzz'); + if ($tix->Count) { + my $last_id = $tix->Last->id; + while ( my $t = $tix->Next ) { + my $tmp; + next if $t->id == $last_id and $t->Subject eq "-"; # Nulls are allowed to come last, in Pg + + if ( $order eq 'ASC' ) { + $tmp = ((split( /,/, $last))[0] cmp (split( /,/, $t->Subject))[0]); + } else { + $tmp = -((split( /,/, $last))[-1] cmp (split( /,/, $t->Subject))[-1]); + } + if ( $tmp > 0 ) { + $order_ok = 0; last; + } + $last = $t->Subject; + } + } + + ok( $order_ok, "$order order of tickets is good" ) + or $error = 1; + + if ( $error ) { + diag "Wrong SQL query:". $tix->BuildSelectQuery; + $tix->GotoFirstItem; + while ( my $t = $tix->Next ) { + diag sprintf "%02d - %s", $t->id, $t->Subject; + } + } + }; + } + } +} +done_testing; diff --git a/rt/t/ticket/circular_links.t b/rt/t/ticket/circular_links.t new file mode 100644 index 0000000..b6695fe --- /dev/null +++ b/rt/t/ticket/circular_links.t @@ -0,0 +1,45 @@ +use strict; +use warnings; + +use RT::Test tests => undef; + +my ( $foo, $bar, $baz ) = RT::Test->create_tickets( + { Queue => 'General' }, + { Subject => 'foo' }, + { Subject => 'bar' }, + { Subject => 'baz' } +); + +diag "test circular DependsOn"; +my ( $status, $msg ) = $foo->AddLink( Type => 'DependsOn', Target => $bar->id ); +ok( $status, "foo depends on bar" ); +( $status, $msg ) = $foo->AddLink( Type => 'DependsOn', Base => $bar->id ); +ok( !$status, "foo can't be depended on bar" ); +( $status, $msg ) = $bar->AddLink( Type => 'DependsOn', Target => $foo->id ); +ok( !$status, "bar can't depend on foo back" ); +( $status, $msg ) = $bar->AddLink( Type => 'DependsOn', Target => $baz->id ); +ok( $status, "bar depends on baz" ); +( $status, $msg ) = $baz->AddLink( Type => 'DependsOn', Target => $foo->id ); +ok( !$status, "baz can't depend on foo back" ); + + +diag "test circular MemberOf"; +( $status, $msg ) = $foo->AddLink( Type => 'MemberOf', Target => $bar->id ); +ok( $status, "foo is a member of bar" ); +( $status, $msg ) = $foo->AddLink( Type => 'MemberOf', Base => $bar->id ); +ok( !$status, "foo can't have member bar" ); +( $status, $msg ) = $bar->AddLink( Type => 'MemberOf', Target => $foo->id ); +ok( !$status, "bar can't be a member of foo" ); +( $status, $msg ) = $bar->AddLink( Type => 'MemberOf', Target => $baz->id ); +ok( $status, "baz is a member of bar" ); +( $status, $msg ) = $baz->AddLink( Type => 'DependsOn', Target => $foo->id ); +ok( !$status, "baz can't be a member of foo" ); + + +diag "test circular RefersTo"; +( $status, $msg ) = $foo->AddLink( Type => 'RefersTo', Target => $bar->id ); +ok( $status, "foo refers to bar" ); +( $status, $msg ) = $foo->AddLink( Type => 'RefersTo', Base => $bar->id ); +ok( $status, "foo can be referred to by bar" ); + +done_testing; diff --git a/rt/t/ticket/deferred_owner.t b/rt/t/ticket/deferred_owner.t index fe90d53..a0aa350 100644 --- a/rt/t/ticket/deferred_owner.t +++ b/rt/t/ticket/deferred_owner.t @@ -1,10 +1,7 @@ - use strict; use warnings; -use RT::Test nodata => 1, tests => 18; -use_ok('RT'); -use_ok('RT::Ticket'); +use RT::Test nodata => 1, tests => undef; use Test::Warn; @@ -16,8 +13,7 @@ ok $tester && $tester->id, 'loaded or created user'; my $queue = RT::Test->load_or_create_queue( Name => 'General' ); ok $queue && $queue->id, 'loaded or created queue'; -my $owner_role_group = RT::Group->new( RT->SystemUser ); -$owner_role_group->LoadQueueRoleGroup( Type => 'Owner', Queue => $queue->id ); +my $owner_role_group = $queue->RoleGroup( 'Owner' ); ok $owner_role_group->id, 'loaded owners role group of the queue'; diag "check that deffering owner doesn't regress"; @@ -63,7 +59,7 @@ diag "check that previous trick doesn't work without sufficient rights"; diag $msg if $msg; ok $tid, "created a ticket"; is $ticket->Owner, $tester->id, 'correct owner'; - unlike $ticket->AdminCcAddresses, qr/root\@localhost/, 'root is there'; + unlike $ticket->AdminCcAddresses, qr/root\@localhost/, 'root is not there'; } diag "check that deffering owner really works"; @@ -88,6 +84,9 @@ diag "check that deffering owner really works"; ok $tid, "created a ticket"; like $ticket->CcAddresses, qr/tester\@localhost/, 'tester is in the cc list'; is $ticket->Owner, $tester->id, 'tester is also owner'; + my $owners = $ticket->OwnerGroup->MembersObj; + is $owners->Count, 1, 'one record in owner group'; + is $owners->First->MemberObj->Id, $tester->id, 'and it is tester'; } diag "check that deffering doesn't work without correct rights"; @@ -112,8 +111,10 @@ diag "check that deffering doesn't work without correct rights"; diag $msg if $msg; ok $tid, "created a ticket"; like $ticket->CcAddresses, qr/tester\@localhost/, 'tester is in the cc list'; - isnt $ticket->Owner, $tester->id, 'tester is also owner'; + is $ticket->Owner, RT->Nobody->id, 'nobody is the owner'; + my $owners = $ticket->OwnerGroup->MembersObj; + is $owners->Count, 1, 'one record in owner group'; + is $owners->First->MemberObj->Id, RT->Nobody->id, 'and it is nobody'; } - - +done_testing; diff --git a/rt/t/ticket/linking.t b/rt/t/ticket/linking.t index 1bd83d6..9eaf939 100644 --- a/rt/t/ticket/linking.t +++ b/rt/t/ticket/linking.t @@ -17,9 +17,6 @@ my $filename = File::Spec->catfile( RT::Test->temp_directory, 'link_count' ); open my $fh, '>', $filename or die $!; close $fh; -my $link_scrips_orig = RT->Config->Get( 'LinkTransactionsRun1Scrip' ); -RT->Config->Set( 'LinkTransactionsRun1Scrip', 1 ); - my $link_acl_checks_orig = RT->Config->Get( 'StrictLinkACL' ); RT->Config->Set( 'StrictLinkACL', 1); @@ -125,8 +122,8 @@ diag('Create tickets with rights checks on one end of a link'); $child->CurrentUser( RT->SystemUser ); is($child->_Links('Base')->Count, 1, 'link was created'); is($child->_Links('Target')->Count, 0, 'link was created only one'); - # no scrip run on second ticket accroding to config option - is(link_count($filename), undef, "scrips ok"); + # only one scrip run (on second ticket) since this is on a ticket Create txn + is(link_count($filename), 1, "scrips ok"); RT->Config->Set( StrictLinkACL => 1 ); } @@ -144,7 +141,7 @@ diag('try to add link without rights'); ok($id,$msg); ($id, $msg) = $child->AddLink(Type => 'MemberOf', Target => $parent->id); ok(!$id, $msg); - is(link_count($filename), undef, "scrips ok"); + is(link_count($filename), 0, "scrips ok"); $child->CurrentUser( RT->SystemUser ); is($child->_Links('Base')->Count, 0, 'link was not created, no permissions'); is($child->_Links('Target')->Count, 0, 'link was not create, no permissions'); @@ -162,7 +159,7 @@ diag('add link with rights only on base'); ok($id,$msg); ($id, $msg) = $child->AddLink(Type => 'MemberOf', Target => $parent->id); ok($id, $msg); - is(link_count($filename), 1, "scrips ok"); + is(link_count($filename), 2, "scrips ok"); $child->CurrentUser( RT->SystemUser ); is($child->_Links('Base')->Count, 1, 'link was created'); is($child->_Links('Target')->Count, 0, 'link was created only one'); @@ -170,9 +167,9 @@ diag('add link with rights only on base'); # turn off feature and try to delete link, we should fail RT->Config->Set( StrictLinkACL => 1 ); - ($id, $msg) = $child->AddLink(Type => 'MemberOf', Target => $parent->id); + ($id, $msg) = $child->DeleteLink(Type => 'MemberOf', Target => $parent->id); ok(!$id, $msg); - is(link_count($filename), 1, "scrips ok"); + is(link_count($filename), 0, "scrips ok"); $child->CurrentUser( RT->SystemUser ); $child->_Links('Base')->_DoCount; is($child->_Links('Base')->Count, 1, 'link was not deleted'); @@ -182,7 +179,7 @@ diag('add link with rights only on base'); RT->Config->Set( StrictLinkACL => 0 ); ($id, $msg) = $child->DeleteLink(Type => 'MemberOf', Target => $parent->id); ok($id, $msg); - is(link_count($filename), 0, "scrips ok"); + is(link_count($filename), -2, "scrips ok"); $child->CurrentUser( RT->SystemUser ); $child->_Links('Base')->_DoCount; is($child->_Links('Base')->Count, 0, 'link was deleted'); @@ -217,18 +214,17 @@ ok ($id,$msg); ok ($id,$msg); ($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id); ok($id,$msg); -is(link_count($filename), 1, "scrips ok"); +is(link_count($filename), 2, "scrips ok"); warnings_like { ($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => -1); } [ qr/Could not determine a URI scheme for -1/, - qr/Couldn't resolve '-1' into a URI/, ]; ($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id); ok($id,$msg); -is(link_count($filename), 1, "scrips ok"); +is(link_count($filename), 0, "scrips ok"); # already added my $transactions = $ticket2->Transactions; $transactions->Limit( FIELD => 'Type', VALUE => 'AddLink' ); @@ -238,21 +234,19 @@ is( $transactions->First->NewValue , $ticket->URI ); ($id,$msg) = $ticket->DeleteLink(Type => 'RefersTo', Target => $ticket2->id); ok($id,$msg); -is(link_count($filename), 0, "scrips ok"); +is(link_count($filename), -2, "scrips ok"); $transactions = $ticket2->Transactions; $transactions->Limit( FIELD => 'Type', VALUE => 'DeleteLink' ); is( $transactions->Count, 1, "Transaction found in other ticket" ); is( $transactions->First->Field , 'ReferredToBy'); is( $transactions->First->OldValue , $ticket->URI ); -RT->Config->Set( LinkTransactionsRun1Scrip => 0 ); - ($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id); ok($id,$msg); is(link_count($filename), 2, "scrips ok"); ($id,$msg) =$ticket->DeleteLink(Type => 'RefersTo', Target => $ticket2->id); ok($id,$msg); -is(link_count($filename), 0, "scrips ok"); +is(link_count($filename), -2, "scrips ok"); # tests for silent behaviour ($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id, Silent => 1); @@ -287,7 +281,7 @@ is(link_count($filename), 1, "scrips ok"); } ($id,$msg) =$ticket->DeleteLink(Type => 'RefersTo', Target => $ticket2->id, SilentBase => 1); ok($id,$msg); -is(link_count($filename), 0, "scrips ok"); +is(link_count($filename), -1, "scrips ok"); ($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id, SilentTarget => 1); ok($id,$msg); @@ -303,11 +297,10 @@ is(link_count($filename), 1, "scrips ok"); } ($id,$msg) =$ticket->DeleteLink(Type => 'RefersTo', Target => $ticket2->id, SilentTarget => 1); ok($id,$msg); -is(link_count($filename), 0, "scrips ok"); +is(link_count($filename), -1, "scrips ok"); # restore -RT->Config->Set( LinkTransactionsRun1Scrip => $link_scrips_orig ); RT->Config->Set( StrictLinkACL => $link_acl_checks_orig ); { @@ -388,8 +381,9 @@ sub link_count { open( my $fh, '<', $file ) or die "couldn't open $file"; my $data = <$fh>; close $fh; + truncate($file, 0); - return undef unless $data; + return 0 unless defined $data; chomp $data; return $data + 0; } diff --git a/rt/t/ticket/merge.t b/rt/t/ticket/merge.t index 2484b65..99c723b 100644 --- a/rt/t/ticket/merge.t +++ b/rt/t/ticket/merge.t @@ -4,7 +4,7 @@ use warnings; use RT; -use RT::Test tests => '29'; +use RT::Test tests => '44'; # validate that when merging two tickets, the comments from both tickets @@ -134,3 +134,46 @@ ok $user && $user->id, 'loaded or created user'; ($status,$msg) = $t->MergeInto($t2->id); ok($status, "Merged tickets: $msg"); } + +# check Time* fields after merge +{ + my @tickets; + my @values = ( + { Worked => 11, Estimated => 17, Left => 6 }, + { Worked => 7, Estimated => 12, Left => 5 }, + ); + + for my $i (0 .. 1) { + my $t = RT::Ticket->new(RT->SystemUser); + $t->Create( Queue => 'general'); + ok ($t->id); + push @tickets, $t; + + foreach my $field ( keys %{ $values[ $i ] } ) { + my $method = "SetTime$field"; + my ($status, $msg) = $t->$method( $values[ $i ]{ $field } ); + ok $status, "changed $field on the ticket" + or diag "error: $msg"; + } + } + + my ($status, $msg) = $tickets[1]->MergeInto($tickets[0]->id); + ok($status,$msg); + + my $t = RT::Ticket->new(RT->SystemUser); + $t->Load( $tickets[0]->id ); + foreach my $field ( keys %{ $values[0] } ) { + my $method = "Time$field"; + my $expected = 0; + $expected += $_->{ $field } foreach @values; + is $t->$method, $expected, "correct value"; + + my $from_history = 0; + my $txns = $t->Transactions; + while ( my $txn = $txns->Next ) { + next unless $txn->Type eq 'Set' && $txn->Field eq $method; + $from_history += $txn->NewValue - $txn->OldValue; + } + is $from_history, $expected, "history is correct"; + } +} diff --git a/rt/t/ticket/scrips_batch.t b/rt/t/ticket/scrips_batch.t index 44d7f8e..0a996ce 100644 --- a/rt/t/ticket/scrips_batch.t +++ b/rt/t/ticket/scrips_batch.t @@ -16,28 +16,33 @@ ok $m->login, 'logged in as root'; my $sid; { - $m->follow_link_ok( { id => 'tools-config-queues' } ); + $m->follow_link_ok( { id => 'admin-queues' } ); $m->follow_link_ok( { text => $queue->Name } ); $m->follow_link_ok( { id => 'page-scrips-create'}); - $m->form_name('ModifyScrip'); - $m->field('Scrip-new-Description' => 'test'); - $m->select('Scrip-new-ScripCondition' => 'On Transaction'); - $m->select('Scrip-new-ScripAction' => 'User Defined'); - $m->select('Scrip-new-Template' => 'Global template: Blank'); - $m->select('Scrip-new-Stage' => 'TransactionBatch'); - $m->field('Scrip-new-CustomPrepareCode' => 'return 1;'); - $m->field('Scrip-new-CustomCommitCode' => 'return 1;'); - $m->submit; - $m->content_contains("Scrip Created"); + $m->form_name('CreateScrip'); + $m->field('Description' => 'test'); + $m->select('ScripCondition' => 'On Transaction'); + $m->select('ScripAction' => 'User Defined'); + $m->select('Template' => 'Blank'); + $m->select('Stage' => 'Batch'); + $m->field('CustomPrepareCode' => 'return 1;'); + $m->field('CustomCommitCode' => 'return 1;'); + $m->click('Create'); + $m->content_contains("Scrip Created"); my $form = $m->form_name('ModifyScrip'); $sid = $form->value('id'); - is $m->value("Scrip-$sid-Description"), 'test', 'correct description'; - is value_name($form, "Scrip-$sid-ScripCondition"), 'On Transaction', 'correct condition'; - is value_name($form, "Scrip-$sid-ScripAction"), 'User Defined', 'correct action'; - is value_name($form, "Scrip-$sid-Template"), 'Global template: Blank', 'correct template'; - is value_name($form, "Scrip-$sid-Stage"), 'TransactionBatch', 'correct stage'; + is $m->value("Description"), 'test', 'correct description'; + is value_name($form, "ScripCondition"), 'On Transaction', 'correct condition'; + is value_name($form, "ScripAction"), 'User Defined', 'correct action'; + is value_name($form, "Template"), 'Blank', 'correct template'; + + { + my $rec = RT::ObjectScrip->new( RT->SystemUser ); + $rec->LoadByCols( Scrip => $sid, ObjectId => $queue->id ); + is $rec->Stage, 'TransactionBatch', "correct stage"; + } my $tmp_fn = File::Spec->catfile( RT::Test->temp_directory, 'transactions' ); open my $tmp_fh, '+>', $tmp_fn or die $!; @@ -56,8 +61,8 @@ foreach my \$txn ( \@\$batch ) { return 1; END - $m->field( "Scrip-$sid-CustomCommitCode" => $code ); - $m->submit; + $m->field( "CustomCommitCode" => $code ); + $m->click('Update'); $m->goto_create_ticket( $queue ); $m->form_name('TicketCreate'); diff --git a/rt/t/ticket/search.t b/rt/t/ticket/search.t index 852241f..a43433f 100644 --- a/rt/t/ticket/search.t +++ b/rt/t/ticket/search.t @@ -283,4 +283,35 @@ like($tix->BuildSelectCountQuery, qr/\bNULL\b/, "Contains upper-case NULL"); unlike($tix->BuildSelectCountQuery, qr/\bnull\b/, "Lacks lower-case NULL"); +# tests for searching by queue lifecycle +$tix = RT::Tickets->new(RT->SystemUser); +$tix->FromSQL('Lifecycle="default"'); +is($tix->Count,7,"We found all 7 tickets in a queue with the default lifecycle"); + +$tix = RT::Tickets->new(RT->SystemUser); +$tix->FromSQL('Lifecycle ="approvals" OR Lifecycle="default"'); +is($tix->Count,7,"We found 7 tickets in a queue with a lifecycle of default or approvals"); + +$tix = RT::Tickets->new(RT->SystemUser); +$tix->FromSQL('Lifecycle ="approvals" AND Lifecycle="default"'); +is($tix->Count,0,"We found 0 tickets in a queue with a lifecycle of default AND approvals...(because that's impossible"); + +$tix = RT::Tickets->new(RT->SystemUser); +$tix->FromSQL('Queue="'.$queue.'" AND Lifecycle="default"'); +is($tix->Count,7,"We found 7 tickets in $queue with a lifecycle of default"); + + +$tix = RT::Tickets->new(RT->SystemUser); +$tix->FromSQL('Lifecycle !="approvals"'); +is($tix->Count,7,"We found 7 tickets in a queue with a lifecycle other than approvals"); + +$tix = RT::Tickets->new(RT->SystemUser); +$tix->FromSQL('Lifecycle!="default"'); +is($tix->Count,0,"We found 0 tickets in a queue with a lifecycle other than default"); + +$tix = RT::Tickets->new(RT->SystemUser); +$tix->FromSQL('Lifecycle="approvals"'); +is($tix->Count,0,"We found 0 tickets in a queue with the approvals lifecycle"); + + done_testing; diff --git a/rt/t/ticket/search_by_cf_freeform_multiple.t b/rt/t/ticket/search_by_cf_freeform_multiple.t index 1b4f092..1324abd 100644 --- a/rt/t/ticket/search_by_cf_freeform_multiple.t +++ b/rt/t/ticket/search_by_cf_freeform_multiple.t @@ -2,8 +2,7 @@ use strict; use warnings; -use RT::Test nodata => 1, tests => 118; -use RT::Ticket; +use RT::Test nodata => 1, tests => undef; my $q = RT::Test->load_or_create_queue( Name => 'Regression' ); ok $q && $q->id, 'loaded or created queue'; @@ -22,104 +21,136 @@ my ($cf_name, $cf_id, $cf) = ("Test", 0, undef); $cf_id = $cf->id; } -my ($total, @data, @tickets, %test) = (0, ()); +my $ylong = "y" x 300; +subtest "Creating tickets" => sub { + RT::Test->create_tickets( { Queue => $q->id }, + { Subject => '-' }, + { Subject => 'x', "CustomField-$cf_id" => 'x', }, + { Subject => 'y', "CustomField-$cf_id" => 'y', }, + { Subject => 'z', "CustomField-$cf_id" => 'z', }, + { Subject => 'xy', "CustomField-$cf_id" => [ 'x', 'y' ], }, + { Subject => 'xz', "CustomField-$cf_id" => [ 'x', 'z' ], }, + { Subject => 'yz', "CustomField-$cf_id" => [ 'y', 'z' ], }, + { Subject => 'x_ylong', "CustomField-$cf_id" => [ 'x', $ylong ], }, + { Subject => 'ylong', "CustomField-$cf_id" => $ylong, }, + ); +}; + +my @tests = ( + "CF.{$cf_id} IS NULL" => { '-' => 1, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 0, ylong => 0 }, + "CF.{$cf_id}.Content IS NULL" => { '-' => 1, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 1, ylong => 1 }, + "CF.{$cf_id}.LargeContent IS NULL" => { '-' => 1, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 0 }, + "'CF.{$cf_name}' IS NULL" => { '-' => 1, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 0, ylong => 0 }, + "'CF.{$cf_name}.Content' IS NULL" => { '-' => 1, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 1, ylong => 1 }, + "'CF.{$cf_name}.LargeContent' IS NULL" => { '-' => 1, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 0 }, + "'CF.$queue.{$cf_id}' IS NULL" => { '-' => 1, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 0, ylong => 0 }, + "'CF.$queue.{$cf_name}' IS NULL" => { '-' => 1, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 0, ylong => 0 }, + + "CF.{$cf_id} IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 1 }, + "CF.{$cf_id}.Content IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 0 }, + "CF.{$cf_id}.LargeContent IS NOT NULL" => { '-' => 0, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 1, ylong => 1 }, + "'CF.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 1 }, + "'CF.{$cf_name}.Content' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 0 }, + "'CF.{$cf_name}.LargeContent' IS NOT NULL" => { '-' => 0, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 1, ylong => 1 }, + "'CF.$queue.{$cf_id}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 1 }, + "'CF.$queue.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 1 }, + + "CF.{$cf_id} = 'x'" => { '-' => 0, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0, x_ylong => 1, ylong => 0 }, + "CF.{$cf_id}.Content = 'x'" => { '-' => 0, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0, x_ylong => 1, ylong => 0 }, + "CF.{$cf_id}.LargeContent = 'x'" => { '-' => 0, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 0, ylong => 0 }, + "CF.{$cf_id} = '$ylong'" => { '-' => 0, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 1, ylong => 1 }, + "CF.{$cf_id}.Content = '$ylong'" => { '-' => 0, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 0, ylong => 0 }, + "CF.{$cf_id}.LargeContent = '$ylong'" => { '-' => 0, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 1, ylong => 1 }, + "CF.{$cf_id} LIKE 'yyy'" => { '-' => 0, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 1, ylong => 1 }, + "CF.{$cf_id}.Content LIKE 'yyy'" => { '-' => 0, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 0, ylong => 0 }, + "CF.{$cf_id}.LargeContent LIKE 'yyy'" => { '-' => 0, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 1, ylong => 1 }, + "'CF.{$cf_name}' = 'x'" => { '-' => 0, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0, x_ylong => 1, ylong => 0 }, + "'CF.{$cf_name}.Content' = 'x'" => { '-' => 0, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0, x_ylong => 1, ylong => 0 }, + "'CF.{$cf_name}.LargeContent' = 'x'" => { '-' => 0, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 0, ylong => 0 }, + "'CF.$queue.{$cf_id}' = 'x'" => { '-' => 0, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0, x_ylong => 1, ylong => 0 }, + "'CF.$queue.{$cf_name}' = 'x'" => { '-' => 0, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0, x_ylong => 1, ylong => 0 }, + + "CF.{$cf_id} != 'x'" => { '-' => 1, x => 0, y => 1, z => 1, xy => 0, xz => 0, yz => 1, x_ylong => 0, ylong => 1 }, + "CF.{$cf_id}.Content != 'x'" => { '-' => 1, x => 0, y => 1, z => 1, xy => 0, xz => 0, yz => 1, x_ylong => 0, ylong => 1 }, + "CF.{$cf_id}.LargeContent != 'x'" => { '-' => 1, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 1 }, + "CF.{$cf_id} != '$ylong'" => { '-' => 1, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 0, ylong => 0 }, + "CF.{$cf_id}.Content != '$ylong'" => { '-' => 1, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 1 }, + "CF.{$cf_id}.LargeContent != '$ylong'" => { '-' => 1, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 0, ylong => 0 }, +"TODO: CF.{$cf_id} NOT LIKE 'yyy'" => { '-' => 1, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 0, ylong => 0 }, + "CF.{$cf_id}.Content NOT LIKE 'yyy'" => { '-' => 1, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 1 }, + "CF.{$cf_id}.LargeContent NOT LIKE 'yyy'" => { '-' => 1, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 0, ylong => 0 }, + "'CF.{$cf_name}' != 'x'" => { '-' => 1, x => 0, y => 1, z => 1, xy => 0, xz => 0, yz => 1, x_ylong => 0, ylong => 1 }, + "'CF.{$cf_name}.Content' != 'x'" => { '-' => 1, x => 0, y => 1, z => 1, xy => 0, xz => 0, yz => 1, x_ylong => 0, ylong => 1 }, + "'CF.{$cf_name}.LargeContent' != 'x'" => { '-' => 1, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 1 }, + "'CF.$queue.{$cf_id}' != 'x'" => { '-' => 1, x => 0, y => 1, z => 1, xy => 0, xz => 0, yz => 1, x_ylong => 0, ylong => 1 }, + "'CF.$queue.{$cf_name}' != 'x'" => { '-' => 1, x => 0, y => 1, z => 1, xy => 0, xz => 0, yz => 1, x_ylong => 0, ylong => 1 }, + + "CF.{$cf_id} = 'x' OR CF.{$cf_id} = 'y'" => { '-' => 0, x => 1, y => 1, z => 0, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 0 }, + "'CF.{$cf_name}' = 'x' OR 'CF.{$cf_name}' = 'y'" => { '-' => 0, x => 1, y => 1, z => 0, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 0 }, + "'CF.$queue.{$cf_id}' = 'x' OR 'CF.$queue.{$cf_id}' = 'y'" => { '-' => 0, x => 1, y => 1, z => 0, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 0 }, + "'CF.$queue.{$cf_name}' = 'x' OR 'CF.$queue.{$cf_name}' = 'y'" => { '-' => 0, x => 1, y => 1, z => 0, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 0 }, + + "CF.{$cf_id} = 'x' AND CF.{$cf_id} = 'y'" => { '-' => 0, x => 0, y => 0, z => 0, xy => 1, xz => 0, yz => 0, x_ylong => 0, ylong => 0 }, + "'CF.{$cf_name}' = 'x' AND 'CF.{$cf_name}' = 'y'" => { '-' => 0, x => 0, y => 0, z => 0, xy => 1, xz => 0, yz => 0, x_ylong => 0, ylong => 0 }, + "'CF.$queue.{$cf_id}' = 'x' AND 'CF.$queue.{$cf_id}' = 'y'" => { '-' => 0, x => 0, y => 0, z => 0, xy => 1, xz => 0, yz => 0, x_ylong => 0, ylong => 0 }, + "'CF.$queue.{$cf_name}' = 'x' AND 'CF.$queue.{$cf_name}' = 'y'" => { '-' => 0, x => 0, y => 0, z => 0, xy => 1, xz => 0, yz => 0, x_ylong => 0, ylong => 0 }, + + "CF.{$cf_id} != 'x' AND CF.{$cf_id} != 'y'" => { '-' => 1, x => 0, y => 0, z => 1, xy => 0, xz => 0, yz => 0, x_ylong => 0, ylong => 1 }, + "'CF.{$cf_name}' != 'x' AND 'CF.{$cf_name}' != 'y'" => { '-' => 1, x => 0, y => 0, z => 1, xy => 0, xz => 0, yz => 0, x_ylong => 0, ylong => 1 }, + "'CF.$queue.{$cf_id}' != 'x' AND 'CF.$queue.{$cf_id}' != 'y'" => { '-' => 1, x => 0, y => 0, z => 1, xy => 0, xz => 0, yz => 0, x_ylong => 0, ylong => 1 }, + "'CF.$queue.{$cf_name}' != 'x' AND 'CF.$queue.{$cf_name}' != 'y'" => { '-' => 1, x => 0, y => 0, z => 1, xy => 0, xz => 0, yz => 0, x_ylong => 0, ylong => 1 }, + + "CF.{$cf_id} = 'x' AND CF.{$cf_id} IS NULL" => { '-' => 0, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 0, ylong => 0 }, + "'CF.{$cf_name}' = 'x' AND 'CF.{$cf_name}' IS NULL" => { '-' => 0, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 0, ylong => 0 }, + "'CF.$queue.{$cf_id}' = 'x' AND 'CF.$queue.{$cf_id}' IS NULL" => { '-' => 0, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 0, ylong => 0 }, + "'CF.$queue.{$cf_name}' = 'x' AND 'CF.$queue.{$cf_name}' IS NULL" => { '-' => 0, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0, x_ylong => 0, ylong => 0 }, + + "CF.{$cf_id} = 'x' OR CF.{$cf_id} IS NULL" => { '-' => 1, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0, x_ylong => 1, ylong => 0 }, + "'CF.{$cf_name}' = 'x' OR 'CF.{$cf_name}' IS NULL" => { '-' => 1, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0, x_ylong => 1, ylong => 0 }, + "'CF.$queue.{$cf_id}' = 'x' OR 'CF.$queue.{$cf_id}' IS NULL" => { '-' => 1, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0, x_ylong => 1, ylong => 0 }, + "'CF.$queue.{$cf_name}' = 'x' OR 'CF.$queue.{$cf_name}' IS NULL" => { '-' => 1, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0, x_ylong => 1, ylong => 0 }, + + "CF.{$cf_id} = 'x' AND CF.{$cf_id} IS NOT NULL" => { '-' => 0, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0, x_ylong => 1, ylong => 0 }, + "'CF.{$cf_name}' = 'x' AND 'CF.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0, x_ylong => 1, ylong => 0 }, + "'CF.$queue.{$cf_id}' = 'x' AND 'CF.$queue.{$cf_id}' IS NOT NULL" => { '-' => 0, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0, x_ylong => 1, ylong => 0 }, + "'CF.$queue.{$cf_name}' = 'x' AND 'CF.$queue.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0, x_ylong => 1, ylong => 0 }, + + "CF.{$cf_id} = 'x' OR CF.{$cf_id} IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 1 }, + "'CF.{$cf_name}' = 'x' OR 'CF.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 1 }, + "'CF.$queue.{$cf_id}' = 'x' OR 'CF.$queue.{$cf_id}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 1 }, + "'CF.$queue.{$cf_name}' = 'x' OR 'CF.$queue.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1, x_ylong => 1, ylong => 1 }, +); +run_tests(@tests); + sub run_tests { - my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets; - foreach my $key ( sort keys %test ) { - my $tix = RT::Tickets->new(RT->SystemUser); - $tix->FromSQL( "( $query_prefix ) AND ( $key )" ); - - my $error = 0; - - my $count = 0; - $count++ foreach grep $_, values %{ $test{$key} }; - is($tix->Count, $count, "found correct number of ticket(s) by '$key'") or $error = 1; - - my $good_tickets = ($tix->Count == $count); - while ( my $ticket = $tix->Next ) { - next if $test{$key}->{ $ticket->Subject }; - diag $ticket->Subject ." ticket has been found when it's not expected"; - $good_tickets = 0; - } - ok( $good_tickets, "all tickets are good with '$key'" ) or $error = 1; - - diag "Wrong SQL query for '$key':". $tix->BuildSelectQuery if $error; + my @tests = @_; + while (@tests) { + my $query = shift @tests; + my %results = %{ shift @tests }; + local $TODO = "Not implemented correctly" if $query =~ s/^TODO:\s*//; + subtest $query => sub { + my $tix = RT::Tickets->new(RT->SystemUser); + $tix->FromSQL( "$query" ); + + my $error = 0; + + my $count = 0; + $count++ foreach grep $_, values %results; + is($tix->Count, $count, "found correct number of ticket(s)") or $error = 1; + + my $good_tickets = ($tix->Count == $count); + while ( my $ticket = $tix->Next ) { + next if $results{ $ticket->Subject }; + diag $ticket->Subject ." ticket has been found when it's not expected"; + $good_tickets = 0; + } + ok( $good_tickets, "all tickets are good" ) or $error = 1; + + diag "Wrong SQL: ". $tix->BuildSelectQuery if $error; + }; } } -@data = ( - { Subject => '-' }, - { Subject => 'x', "CustomField-$cf_id" => 'x', }, - { Subject => 'y', "CustomField-$cf_id" => 'y', }, - { Subject => 'z', "CustomField-$cf_id" => 'z', }, - { Subject => 'xy', "CustomField-$cf_id" => [ 'x', 'y' ], }, - { Subject => 'xz', "CustomField-$cf_id" => [ 'x', 'z' ], }, - { Subject => 'yz', "CustomField-$cf_id" => [ 'y', 'z' ], }, -); -%test = ( - "CF.{$cf_id} IS NULL" => { '-' => 1, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0 }, - "'CF.{$cf_name}' IS NULL" => { '-' => 1, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0 }, - "'CF.$queue.{$cf_id}' IS NULL" => { '-' => 1, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0 }, - "'CF.$queue.{$cf_name}' IS NULL" => { '-' => 1, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0 }, - - "CF.{$cf_id} IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1 }, - "'CF.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1 }, - "'CF.$queue.{$cf_id}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1 }, - "'CF.$queue.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1 }, - - "CF.{$cf_id} = 'x'" => { '-' => 0, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0 }, - "'CF.{$cf_name}' = 'x'" => { '-' => 0, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0 }, - "'CF.$queue.{$cf_id}' = 'x'" => { '-' => 0, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0 }, - "'CF.$queue.{$cf_name}' = 'x'" => { '-' => 0, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0 }, - - "CF.{$cf_id} != 'x'" => { '-' => 1, x => 0, y => 1, z => 1, xy => 0, xz => 0, yz => 1 }, - "'CF.{$cf_name}' != 'x'" => { '-' => 1, x => 0, y => 1, z => 1, xy => 0, xz => 0, yz => 1 }, - "'CF.$queue.{$cf_id}' != 'x'" => { '-' => 1, x => 0, y => 1, z => 1, xy => 0, xz => 0, yz => 1 }, - "'CF.$queue.{$cf_name}' != 'x'" => { '-' => 1, x => 0, y => 1, z => 1, xy => 0, xz => 0, yz => 1 }, - - "CF.{$cf_id} = 'x' OR CF.{$cf_id} = 'y'" => { '-' => 0, x => 1, y => 1, z => 0, xy => 1, xz => 1, yz => 1 }, - "'CF.{$cf_name}' = 'x' OR 'CF.{$cf_name}' = 'y'" => { '-' => 0, x => 1, y => 1, z => 0, xy => 1, xz => 1, yz => 1 }, - "'CF.$queue.{$cf_id}' = 'x' OR 'CF.$queue.{$cf_id}' = 'y'" => { '-' => 0, x => 1, y => 1, z => 0, xy => 1, xz => 1, yz => 1 }, - "'CF.$queue.{$cf_name}' = 'x' OR 'CF.$queue.{$cf_name}' = 'y'" => { '-' => 0, x => 1, y => 1, z => 0, xy => 1, xz => 1, yz => 1 }, - - "CF.{$cf_id} = 'x' AND CF.{$cf_id} = 'y'" => { '-' => 0, x => 0, y => 0, z => 0, xy => 1, xz => 0, yz => 0 }, - "'CF.{$cf_name}' = 'x' AND 'CF.{$cf_name}' = 'y'" => { '-' => 0, x => 0, y => 0, z => 0, xy => 1, xz => 0, yz => 0 }, - "'CF.$queue.{$cf_id}' = 'x' AND 'CF.$queue.{$cf_id}' = 'y'" => { '-' => 0, x => 0, y => 0, z => 0, xy => 1, xz => 0, yz => 0 }, - "'CF.$queue.{$cf_name}' = 'x' AND 'CF.$queue.{$cf_name}' = 'y'" => { '-' => 0, x => 0, y => 0, z => 0, xy => 1, xz => 0, yz => 0 }, - - "CF.{$cf_id} != 'x' AND CF.{$cf_id} != 'y'" => { '-' => 1, x => 0, y => 0, z => 1, xy => 0, xz => 0, yz => 0 }, - "'CF.{$cf_name}' != 'x' AND 'CF.{$cf_name}' != 'y'" => { '-' => 1, x => 0, y => 0, z => 1, xy => 0, xz => 0, yz => 0 }, - "'CF.$queue.{$cf_id}' != 'x' AND 'CF.$queue.{$cf_id}' != 'y'" => { '-' => 1, x => 0, y => 0, z => 1, xy => 0, xz => 0, yz => 0 }, - "'CF.$queue.{$cf_name}' != 'x' AND 'CF.$queue.{$cf_name}' != 'y'" => { '-' => 1, x => 0, y => 0, z => 1, xy => 0, xz => 0, yz => 0 }, - - "CF.{$cf_id} = 'x' AND CF.{$cf_id} IS NULL" => { '-' => 0, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0 }, - "'CF.{$cf_name}' = 'x' AND 'CF.{$cf_name}' IS NULL" => { '-' => 0, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0 }, - "'CF.$queue.{$cf_id}' = 'x' AND 'CF.$queue.{$cf_id}' IS NULL" => { '-' => 0, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0 }, - "'CF.$queue.{$cf_name}' = 'x' AND 'CF.$queue.{$cf_name}' IS NULL" => { '-' => 0, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0 }, - - "CF.{$cf_id} = 'x' OR CF.{$cf_id} IS NULL" => { '-' => 1, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0 }, - "'CF.{$cf_name}' = 'x' OR 'CF.{$cf_name}' IS NULL" => { '-' => 1, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0 }, - "'CF.$queue.{$cf_id}' = 'x' OR 'CF.$queue.{$cf_id}' IS NULL" => { '-' => 1, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0 }, - "'CF.$queue.{$cf_name}' = 'x' OR 'CF.$queue.{$cf_name}' IS NULL" => { '-' => 1, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0 }, - - "CF.{$cf_id} = 'x' AND CF.{$cf_id} IS NOT NULL" => { '-' => 0, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0 }, - "'CF.{$cf_name}' = 'x' AND 'CF.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0 }, - "'CF.$queue.{$cf_id}' = 'x' AND 'CF.$queue.{$cf_id}' IS NOT NULL" => { '-' => 0, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0 }, - "'CF.$queue.{$cf_name}' = 'x' AND 'CF.$queue.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 0, z => 0, xy => 1, xz => 1, yz => 0 }, - - "CF.{$cf_id} = 'x' OR CF.{$cf_id} IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1 }, - "'CF.{$cf_name}' = 'x' OR 'CF.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1 }, - "'CF.$queue.{$cf_id}' = 'x' OR 'CF.$queue.{$cf_id}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1 }, - "'CF.$queue.{$cf_name}' = 'x' OR 'CF.$queue.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1 }, -); -@tickets = RT::Test->create_tickets( { Queue => $q->id }, @data); -$total = scalar @tickets; - -{ - my $tix = RT::Tickets->new(RT->SystemUser); - $tix->FromSQL("Queue = '$queue'"); - is($tix->Count, $total, "found $total tickets"); -} -run_tests(); +done_testing; diff --git a/rt/t/ticket/search_by_cf_freeform_single.t b/rt/t/ticket/search_by_cf_freeform_single.t index f8462a9..0463412 100644 --- a/rt/t/ticket/search_by_cf_freeform_single.t +++ b/rt/t/ticket/search_by_cf_freeform_single.t @@ -2,8 +2,7 @@ use strict; use warnings; -use RT::Test nodata => 1, tests => 106; -use RT::Ticket; +use RT::Test nodata => 1, tests => undef; my $q = RT::Test->load_or_create_queue( Name => 'Regression' ); ok $q && $q->id, 'loaded or created queue'; @@ -22,103 +21,143 @@ my ($cf_name, $cf_id, $cf) = ("Test", 0, undef); $cf_id = $cf->id; } -my ($total, @data, @tickets, %test) = (0, ()); +my $other_q = RT::Test->load_or_create_queue( Name => 'Other' ); +ok $other_q && $other_q->id, 'loaded or created queue'; + +my $ylong = 'y' x 300; +subtest "Creating tickets" => sub { + RT::Test->create_tickets( { Queue => $q->id }, + { Subject => '-' }, + { Subject => "other", Queue => $other_q->id }, + { Subject => 'x', "CustomField-$cf_id" => 'x', }, + { Subject => 'y', "CustomField-$cf_id" => 'y', }, + { Subject => 'z', "CustomField-$cf_id" => 'z', }, + { Subject => 'ylong', "CustomField-$cf_id" => $ylong, }, + ); +}; + +my @tests = ( + "CF.{$cf_id} IS NULL" => { '-' => 1, other => 1, x => 0, y => 0, z => 0, ylong => 0 }, + "CF.{$cf_id}.Content IS NULL" => { '-' => 1, other => 1, x => 0, y => 0, z => 0, ylong => 1 }, + "CF.{$cf_id}.LargeContent IS NULL" => { '-' => 1, other => 1, x => 1, y => 1, z => 1, ylong => 0 }, + "'CF.{$cf_name}' IS NULL" => { '-' => 1, other => 1, x => 0, y => 0, z => 0, ylong => 0 }, + "'CF.{$cf_name}.Content' IS NULL" => { '-' => 1, other => 1, x => 0, y => 0, z => 0, ylong => 1 }, + "'CF.{$cf_name}.LargeContent' IS NULL" => { '-' => 1, other => 1, x => 1, y => 1, z => 1, ylong => 0 }, + "'CF.$queue.{$cf_id}' IS NULL" => { '-' => 1, other => 1, x => 0, y => 0, z => 0, ylong => 0 }, + "'CF.$queue.{$cf_name}' IS NULL" => { '-' => 1, other => 1, x => 0, y => 0, z => 0, ylong => 0 }, + + "CF.{$cf_id} IS NOT NULL" => { '-' => 0, other => 0, x => 1, y => 1, z => 1, ylong => 1 }, + "CF.{$cf_id}.Content IS NOT NULL" => { '-' => 0, other => 0, x => 1, y => 1, z => 1, ylong => 0 }, + "CF.{$cf_id}.LargeContent IS NOT NULL" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 1 }, + "'CF.{$cf_name}' IS NOT NULL" => { '-' => 0, other => 0, x => 1, y => 1, z => 1, ylong => 1 }, + "'CF.{$cf_name}.Content' IS NOT NULL" => { '-' => 0, other => 0, x => 1, y => 1, z => 1, ylong => 0 }, + "'CF.{$cf_name}.LargeContent' IS NOT NULL" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 1 }, + "'CF.$queue.{$cf_id}' IS NOT NULL" => { '-' => 0, other => 0, x => 1, y => 1, z => 1, ylong => 1 }, + "'CF.$queue.{$cf_name}' IS NOT NULL" => { '-' => 0, other => 0, x => 1, y => 1, z => 1, ylong => 1 }, + + "CF.{$cf_id} = 'x'" => { '-' => 0, other => 0, x => 1, y => 0, z => 0, ylong => 0 }, + "CF.{$cf_id}.Content = 'x'" => { '-' => 0, other => 0, x => 1, y => 0, z => 0, ylong => 0 }, + "CF.{$cf_id}.LargeContent = 'x'" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 0 }, + "CF.{$cf_id} = '$ylong'" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 1 }, + "CF.{$cf_id}.Content = '$ylong'" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 0 }, + "CF.{$cf_id}.LargeContent = '$ylong'" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 1 }, + "CF.{$cf_id} LIKE 'yyy'" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 1 }, + "CF.{$cf_id}.Content LIKE 'yyy'" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 0 }, + "CF.{$cf_id}.LargeContent LIKE 'yyy'" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 1 }, + "'CF.{$cf_name}' = 'x'" => { '-' => 0, other => 0, x => 1, y => 0, z => 0, ylong => 0 }, + "'CF.{$cf_name}.Content' = 'x'" => { '-' => 0, other => 0, x => 1, y => 0, z => 0, ylong => 0 }, + "'CF.{$cf_name}.LargeContent' = 'x'" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 0 }, + "'CF.$queue.{$cf_id}' = 'x'" => { '-' => 0, other => 0, x => 1, y => 0, z => 0, ylong => 0 }, + "'CF.$queue.{$cf_id}.Content' = 'x'" => { '-' => 0, other => 0, x => 1, y => 0, z => 0, ylong => 0 }, + "'CF.$queue.{$cf_id}.LargeContent' = 'x'" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 0 }, + "'CF.$queue.{$cf_name}' = 'x'" => { '-' => 0, other => 0, x => 1, y => 0, z => 0, ylong => 0 }, + "'CF.$queue.{$cf_name}.Content' = 'x'" => { '-' => 0, other => 0, x => 1, y => 0, z => 0, ylong => 0 }, + "'CF.$queue.{$cf_name}.LargeContent' = 'x'" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 0 }, + + "CF.{$cf_id} != 'x'" => { '-' => 1, other => 1, x => 0, y => 1, z => 1, ylong => 1 }, + "CF.{$cf_id}.Content != 'x'" => { '-' => 1, other => 1, x => 0, y => 1, z => 1, ylong => 1 }, + "CF.{$cf_id}.LargeContent != 'x'" => { '-' => 1, other => 1, x => 1, y => 1, z => 1, ylong => 1 }, + "CF.{$cf_id} != '$ylong'" => { '-' => 1, other => 1, x => 1, y => 1, z => 1, ylong => 0 }, + "CF.{$cf_id}.Content != '$ylong'" => { '-' => 1, other => 1, x => 1, y => 1, z => 1, ylong => 1 }, + "CF.{$cf_id}.LargeContent != '$ylong'" => { '-' => 1, other => 1, x => 1, y => 1, z => 1, ylong => 0 }, + "CF.{$cf_id} NOT LIKE 'yyy'" => { '-' => 1, other => 1, x => 1, y => 1, z => 1, ylong => 0 }, + "CF.{$cf_id}.Content NOT LIKE 'yyy'" => { '-' => 1, other => 1, x => 1, y => 1, z => 1, ylong => 1 }, + "CF.{$cf_id}.LargeContent NOT LIKE 'yyy'" => { '-' => 1, other => 1, x => 1, y => 1, z => 1, ylong => 0 }, + "'CF.{$cf_name}' != 'x'" => { '-' => 1, other => 1, x => 0, y => 1, z => 1, ylong => 1 }, + "'CF.{$cf_name}.Content' != 'x'" => { '-' => 1, other => 1, x => 0, y => 1, z => 1, ylong => 1 }, + "'CF.{$cf_name}.LargeContent' != 'x'" => { '-' => 1, other => 1, x => 1, y => 1, z => 1, ylong => 1 }, + "'CF.$queue.{$cf_id}' != 'x'" => { '-' => 1, other => 1, x => 0, y => 1, z => 1, ylong => 1 }, + "'CF.$queue.{$cf_id}.Content' != 'x'" => { '-' => 1, other => 1, x => 0, y => 1, z => 1, ylong => 1 }, + "'CF.$queue.{$cf_id}.LargeContent' != 'x'" => { '-' => 1, other => 1, x => 1, y => 1, z => 1, ylong => 1 }, + "'CF.$queue.{$cf_name}' != 'x'" => { '-' => 1, other => 1, x => 0, y => 1, z => 1, ylong => 1 }, + "'CF.$queue.{$cf_name}.Content' != 'x'" => { '-' => 1, other => 1, x => 0, y => 1, z => 1, ylong => 1 }, + "'CF.$queue.{$cf_name}.LargeContent' != 'x'" => { '-' => 1, other => 1, x => 1, y => 1, z => 1, ylong => 1 }, + + "CF.{$cf_id} = 'x' OR CF.{$cf_id} = 'y'" => { '-' => 0, other => 0, x => 1, y => 1, z => 0, ylong => 0 }, + "'CF.{$cf_name}' = 'x' OR 'CF.{$cf_name}' = 'y'" => { '-' => 0, other => 0, x => 1, y => 1, z => 0, ylong => 0 }, + "'CF.$queue.{$cf_id}' = 'x' OR 'CF.$queue.{$cf_id}' = 'y'" => { '-' => 0, other => 0, x => 1, y => 1, z => 0, ylong => 0 }, + "'CF.$queue.{$cf_name}' = 'x' OR 'CF.$queue.{$cf_name}' = 'y'" => { '-' => 0, other => 0, x => 1, y => 1, z => 0, ylong => 0 }, + + "CF.{$cf_id} = 'x' AND CF.{$cf_id} = 'y'" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 0 }, + "'CF.{$cf_name}' = 'x' AND 'CF.{$cf_name}' = 'y'" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 0 }, + "'CF.$queue.{$cf_id}' = 'x' AND 'CF.$queue.{$cf_id}' = 'y'" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 0 }, + "'CF.$queue.{$cf_name}' = 'x' AND 'CF.$queue.{$cf_name}' = 'y'" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 0 }, + + "CF.{$cf_id} != 'x' AND CF.{$cf_id} != 'y'" => { '-' => 1, other => 1, x => 0, y => 0, z => 1, ylong => 1 }, + "'CF.{$cf_name}' != 'x' AND 'CF.{$cf_name}' != 'y'" => { '-' => 1, other => 1, x => 0, y => 0, z => 1, ylong => 1 }, + "'CF.$queue.{$cf_id}' != 'x' AND 'CF.$queue.{$cf_id}' != 'y'" => { '-' => 1, other => 1, x => 0, y => 0, z => 1, ylong => 1 }, + "'CF.$queue.{$cf_name}' != 'x' AND 'CF.$queue.{$cf_name}' != 'y'" => { '-' => 1, other => 1, x => 0, y => 0, z => 1, ylong => 1 }, + + "CF.{$cf_id} = 'x' AND CF.{$cf_id} IS NULL" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 0 }, + "'CF.{$cf_name}' = 'x' AND 'CF.{$cf_name}' IS NULL" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 0 }, + "'CF.$queue.{$cf_id}' = 'x' AND 'CF.$queue.{$cf_id}' IS NULL" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 0 }, + "'CF.$queue.{$cf_name}' = 'x' AND 'CF.$queue.{$cf_name}' IS NULL" => { '-' => 0, other => 0, x => 0, y => 0, z => 0, ylong => 0 }, + + "CF.{$cf_id} = 'x' OR CF.{$cf_id} IS NULL" => { '-' => 1, other => 1, x => 1, y => 0, z => 0, ylong => 0 }, + "'CF.{$cf_name}' = 'x' OR 'CF.{$cf_name}' IS NULL" => { '-' => 1, other => 1, x => 1, y => 0, z => 0, ylong => 0 }, + "'CF.$queue.{$cf_id}' = 'x' OR 'CF.$queue.{$cf_id}' IS NULL" => { '-' => 1, other => 1, x => 1, y => 0, z => 0, ylong => 0 }, + "'CF.$queue.{$cf_name}' = 'x' OR 'CF.$queue.{$cf_name}' IS NULL" => { '-' => 1, other => 1, x => 1, y => 0, z => 0, ylong => 0 }, + + "CF.{$cf_id} = 'x' AND CF.{$cf_id} IS NOT NULL" => { '-' => 0, other => 0, x => 1, y => 0, z => 0, ylong => 0 }, + "'CF.{$cf_name}' = 'x' AND 'CF.{$cf_name}' IS NOT NULL" => { '-' => 0, other => 0, x => 1, y => 0, z => 0, ylong => 0 }, + "'CF.$queue.{$cf_id}' = 'x' AND 'CF.$queue.{$cf_id}' IS NOT NULL" => { '-' => 0, other => 0, x => 1, y => 0, z => 0, ylong => 0 }, + "'CF.$queue.{$cf_name}' = 'x' AND 'CF.$queue.{$cf_name}' IS NOT NULL" => { '-' => 0, other => 0, x => 1, y => 0, z => 0, ylong => 0 }, + + "CF.{$cf_id} = 'x' OR CF.{$cf_id} IS NOT NULL" => { '-' => 0, other => 0, x => 1, y => 1, z => 1, ylong => 1 }, + "'CF.{$cf_name}' = 'x' OR 'CF.{$cf_name}' IS NOT NULL" => { '-' => 0, other => 0, x => 1, y => 1, z => 1, ylong => 1 }, + "'CF.$queue.{$cf_id}' = 'x' OR 'CF.$queue.{$cf_id}' IS NOT NULL" => { '-' => 0, other => 0, x => 1, y => 1, z => 1, ylong => 1 }, + "'CF.$queue.{$cf_name}' = 'x' OR 'CF.$queue.{$cf_name}' IS NOT NULL" => { '-' => 0, other => 0, x => 1, y => 1, z => 1, ylong => 1 }, +); +run_tests(@tests); + sub run_tests { - my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets; - foreach my $key ( sort keys %test ) { - my $tix = RT::Tickets->new(RT->SystemUser); - $tix->FromSQL( "( $query_prefix ) AND ( $key )" ); - - my $error = 0; - - my $count = 0; - $count++ foreach grep $_, values %{ $test{$key} }; - is($tix->Count, $count, "found correct number of ticket(s) by '$key'") or $error = 1; - - my $good_tickets = ($tix->Count == $count); - while ( my $ticket = $tix->Next ) { - next if $test{$key}->{ $ticket->Subject }; - diag $ticket->Subject ." ticket has been found when it's not expected"; - $good_tickets = 0; - } - ok( $good_tickets, "all tickets are good with '$key'" ) or $error = 1; - - diag "Wrong SQL query for '$key':". $tix->BuildSelectQuery if $error; + my @tests = @_; + while (@tests) { + my $query = shift @tests; + my %results = %{ shift @tests }; + subtest $query => sub { + my $tix = RT::Tickets->new(RT->SystemUser); + $tix->FromSQL( "$query" ); + + my $error = 0; + + my $count = 0; + $count++ foreach grep $_, values %results; + is($tix->Count, $count, "found correct number of ticket(s)") or $error = 1; + + my $good_tickets = ($tix->Count == $count); + while ( my $ticket = $tix->Next ) { + next if $results{ $ticket->Subject }; + diag $ticket->Subject ." ticket has been found when it's not expected"; + $good_tickets = 0; + } + ok( $good_tickets, "all tickets are good" ) or $error = 1; + + diag "Wrong SQL: ". $tix->BuildSelectQuery if $error; + }; } } -@data = ( - { Subject => '-' }, - { Subject => 'x', "CustomField-$cf_id" => 'x', }, - { Subject => 'y', "CustomField-$cf_id" => 'y', }, - { Subject => 'z', "CustomField-$cf_id" => 'z', }, -); -%test = ( - "CF.{$cf_id} IS NULL" => { '-' => 1, x => 0, y => 0, z => 0 }, - "'CF.{$cf_name}' IS NULL" => { '-' => 1, x => 0, y => 0, z => 0 }, - "'CF.$queue.{$cf_id}' IS NULL" => { '-' => 1, x => 0, y => 0, z => 0 }, - "'CF.$queue.{$cf_name}' IS NULL" => { '-' => 1, x => 0, y => 0, z => 0 }, - - "CF.{$cf_id} IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1 }, - "'CF.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1 }, - "'CF.$queue.{$cf_id}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1 }, - "'CF.$queue.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1 }, - - "CF.{$cf_id} = 'x'" => { '-' => 0, x => 1, y => 0, z => 0 }, - "'CF.{$cf_name}' = 'x'" => { '-' => 0, x => 1, y => 0, z => 0 }, - "'CF.$queue.{$cf_id}' = 'x'" => { '-' => 0, x => 1, y => 0, z => 0 }, - "'CF.$queue.{$cf_name}' = 'x'" => { '-' => 0, x => 1, y => 0, z => 0 }, - - "CF.{$cf_id} != 'x'" => { '-' => 1, x => 0, y => 1, z => 1 }, - "'CF.{$cf_name}' != 'x'" => { '-' => 1, x => 0, y => 1, z => 1 }, - "'CF.$queue.{$cf_id}' != 'x'" => { '-' => 1, x => 0, y => 1, z => 1 }, - "'CF.$queue.{$cf_name}' != 'x'" => { '-' => 1, x => 0, y => 1, z => 1 }, - - "CF.{$cf_id} = 'x' OR CF.{$cf_id} = 'y'" => { '-' => 0, x => 1, y => 1, z => 0 }, - "'CF.{$cf_name}' = 'x' OR 'CF.{$cf_name}' = 'y'" => { '-' => 0, x => 1, y => 1, z => 0 }, - "'CF.$queue.{$cf_id}' = 'x' OR 'CF.$queue.{$cf_id}' = 'y'" => { '-' => 0, x => 1, y => 1, z => 0 }, - "'CF.$queue.{$cf_name}' = 'x' OR 'CF.$queue.{$cf_name}' = 'y'" => { '-' => 0, x => 1, y => 1, z => 0 }, - - "CF.{$cf_id} = 'x' AND CF.{$cf_id} = 'y'" => { '-' => 0, x => 0, y => 0, z => 0 }, - "'CF.{$cf_name}' = 'x' AND 'CF.{$cf_name}' = 'y'" => { '-' => 0, x => 0, y => 0, z => 0 }, - "'CF.$queue.{$cf_id}' = 'x' AND 'CF.$queue.{$cf_id}' = 'y'" => { '-' => 0, x => 0, y => 0, z => 0 }, - "'CF.$queue.{$cf_name}' = 'x' AND 'CF.$queue.{$cf_name}' = 'y'" => { '-' => 0, x => 0, y => 0, z => 0 }, - - "CF.{$cf_id} != 'x' AND CF.{$cf_id} != 'y'" => { '-' => 1, x => 0, y => 0, z => 1 }, - "'CF.{$cf_name}' != 'x' AND 'CF.{$cf_name}' != 'y'" => { '-' => 1, x => 0, y => 0, z => 1 }, - "'CF.$queue.{$cf_id}' != 'x' AND 'CF.$queue.{$cf_id}' != 'y'" => { '-' => 1, x => 0, y => 0, z => 1 }, - "'CF.$queue.{$cf_name}' != 'x' AND 'CF.$queue.{$cf_name}' != 'y'" => { '-' => 1, x => 0, y => 0, z => 1 }, - - "CF.{$cf_id} = 'x' AND CF.{$cf_id} IS NULL" => { '-' => 0, x => 0, y => 0, z => 0 }, - "'CF.{$cf_name}' = 'x' AND 'CF.{$cf_name}' IS NULL" => { '-' => 0, x => 0, y => 0, z => 0 }, - "'CF.$queue.{$cf_id}' = 'x' AND 'CF.$queue.{$cf_id}' IS NULL" => { '-' => 0, x => 0, y => 0, z => 0 }, - "'CF.$queue.{$cf_name}' = 'x' AND 'CF.$queue.{$cf_name}' IS NULL" => { '-' => 0, x => 0, y => 0, z => 0 }, - - "CF.{$cf_id} = 'x' OR CF.{$cf_id} IS NULL" => { '-' => 1, x => 1, y => 0, z => 0 }, - "'CF.{$cf_name}' = 'x' OR 'CF.{$cf_name}' IS NULL" => { '-' => 1, x => 1, y => 0, z => 0 }, - "'CF.$queue.{$cf_id}' = 'x' OR 'CF.$queue.{$cf_id}' IS NULL" => { '-' => 1, x => 1, y => 0, z => 0 }, - "'CF.$queue.{$cf_name}' = 'x' OR 'CF.$queue.{$cf_name}' IS NULL" => { '-' => 1, x => 1, y => 0, z => 0 }, - - "CF.{$cf_id} = 'x' AND CF.{$cf_id} IS NOT NULL" => { '-' => 0, x => 1, y => 0, z => 0 }, - "'CF.{$cf_name}' = 'x' AND 'CF.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 0, z => 0 }, - "'CF.$queue.{$cf_id}' = 'x' AND 'CF.$queue.{$cf_id}' IS NOT NULL" => { '-' => 0, x => 1, y => 0, z => 0 }, - "'CF.$queue.{$cf_name}' = 'x' AND 'CF.$queue.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 0, z => 0 }, - - "CF.{$cf_id} = 'x' OR CF.{$cf_id} IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1 }, - "'CF.{$cf_name}' = 'x' OR 'CF.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1 }, - "'CF.$queue.{$cf_id}' = 'x' OR 'CF.$queue.{$cf_id}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1 }, - "'CF.$queue.{$cf_name}' = 'x' OR 'CF.$queue.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1 }, - -); -@tickets = RT::Test->create_tickets( { Queue => $q->id }, @data); -$total = scalar @tickets; -{ - my $tix = RT::Tickets->new(RT->SystemUser); - $tix->FromSQL("Queue = '$queue'"); - is($tix->Count, $total, "found $total tickets"); -} -run_tests(); - -@tickets = (); +done_testing; diff --git a/rt/t/ticket/search_by_watcher_group.t b/rt/t/ticket/search_by_watcher_group.t new file mode 100644 index 0000000..9c522d5 --- /dev/null +++ b/rt/t/ticket/search_by_watcher_group.t @@ -0,0 +1,75 @@ +use strict; +use warnings; + +use RT::Test tests => undef; + +use Test::Warn; + +my $q = RT::Test->load_or_create_queue( Name => 'General' ); +ok $q && $q->id, 'loaded or created queue'; +my $queue = $q->Name; + + +my $group; +{ + $group = RT::Group->new( RT->SystemUser ); + my ($id, $msg) = $group->CreateUserDefinedGroup( Name => 'Test' ); + ok $id, "$msg"; +} + +my $root = RT::Test->load_or_create_user( Name => 'root', MemberOf => $group->id ); +ok $root && $root->id; + +RT::Test->create_tickets( + { Queue => $q, }, + { Subject => '-', }, + { Subject => 'o', Owner => $root->id }, + { Subject => 'r', Requestor => $root->id }, + { Subject => 'c', Cc => $root->id }, + { Subject => 'a', AdminCc => $root->id }, +); + +run_tests( + 'OwnerGroup = "Test"' => { '-' => 0, o => 1, r => 0, c => 0, a => 0 }, + 'RequestorGroup = "Test"' => { '-' => 0, o => 0, r => 1, c => 0, a => 0 }, + 'CCGroup = "Test"' => { '-' => 0, o => 0, r => 0, c => 1, a => 0 }, + 'AdminCCGroup = "Test"' => { '-' => 0, o => 0, r => 0, c => 0, a => 1 }, + 'WatcherGroup = "Test"' => { '-' => 0, o => 1, r => 1, c => 1, a => 1 }, +); + +warning_like { + my $tickets = RT::Tickets->new( RT->SystemUser ); + my ($status, $msg) = $tickets->FromSQL('OwnerGroup != "Test"'); + ok !$status, "incorrect op: $msg"; +} qr{Invalid OwnerGroup Op: !=}; + +done_testing(); + +sub run_tests { + my @test = @_; + while ( my ($query, $checks) = splice @test, 0, 2 ) { + run_test( $query, %$checks ); + } +} + +sub run_test { + my ($query, %checks) = @_; + + my $tix = RT::Tickets->new(RT->SystemUser); + $tix->FromSQL($query); + my $error = 0; + + my $count = 0; + $count++ foreach grep $_, values %checks; + is($tix->Count, $count, "found correct number of ticket(s) by '$query'") or $error = 1; + + my $good_tickets = ($tix->Count == $count); + while ( my $ticket = $tix->Next ) { + next if $checks{ $ticket->Subject }; + diag $ticket->Subject ." ticket has been found when it's not expected"; + $good_tickets = 0; + } + ok( $good_tickets, "all tickets are good with '$query'" ) or $error = 1; + + diag "Wrong SQL query for '$query':". $tix->BuildSelectQuery if $error; +} diff --git a/rt/t/ticket/googleish_search.t b/rt/t/ticket/simple_search.t index d372801..02bf733 100644 --- a/rt/t/ticket/googleish_search.t +++ b/rt/t/ticket/simple_search.t @@ -20,12 +20,12 @@ my ( $id, undef, $msg ) = $t1->Create( ); ok( $id, $msg ); -use_ok("RT::Search::Googleish"); +use_ok("RT::Search::Simple"); my $active_statuses = join( " OR ", map "Status = '$_'", RT::Queue->ActiveStatusArray()); my $tickets = RT::Tickets->new(RT->SystemUser); -my $quick = RT::Search::Googleish->new(Argument => "", +my $quick = RT::Search::Simple->new(Argument => "", TicketsObj => $tickets); my @tests = ( "General new open root" => "( Owner = 'root' ) AND ( Queue = 'General' ) AND ( Status = 'new' OR Status = 'open' )", @@ -34,8 +34,8 @@ my @tests = ( "fulltext:jesse" => "( Content LIKE 'jesse' ) AND ( $active_statuses )", $queue => "( Queue = '$queue' ) AND ( $active_statuses )", "root $queue" => "( Owner = 'root' ) AND ( Queue = '$queue' ) AND ( $active_statuses )", - "notauser $queue" => "( Queue = '$queue' ) AND ( $active_statuses ) AND ( Subject LIKE 'notauser' )", - "notauser $queue root" => "( Owner = 'root' ) AND ( Queue = '$queue' ) AND ( $active_statuses ) AND ( Subject LIKE 'notauser' )"); + "notauser $queue" => "( Subject LIKE 'notauser' ) AND ( Queue = '$queue' ) AND ( $active_statuses )", + "notauser $queue root" => "( Subject LIKE 'notauser' ) AND ( Owner = 'root' ) AND ( Queue = '$queue' ) AND ( $active_statuses )"); while (my ($from, $to) = splice @tests, 0, 2) { is($quick->QueryToSQL($from), $to, "<$from> -> <$to>"); diff --git a/rt/t/ticket/time-worked.t b/rt/t/ticket/time-worked.t new file mode 100644 index 0000000..3e87242 --- /dev/null +++ b/rt/t/ticket/time-worked.t @@ -0,0 +1,80 @@ +use strict; +use warnings; + +use RT::Test tests => 27; + +my $queue = RT::Test->load_or_create_queue( Name => 'General' ); +ok $queue && $queue->id, "loaded or created a queue"; + +note 'set on Create'; +{ + my $ticket = RT::Test->create_ticket( + Queue => $queue->id, TimeWorked => 10, + ); + is $ticket->TimeWorked, 10, 'correct value'; + + my $txn = RT::Transaction->new( RT->SystemUser ); + $txn->LoadByCols( + ObjectType => 'RT::Ticket', ObjectId => $ticket->id, + Type => 'Create', + ); + ok $txn->id, 'found transaction'; + is $txn->TimeTaken, 10, 'correct value'; +} + +note 'set on Comment'; +{ + my $ticket = RT::Test->create_ticket( Queue => $queue->id ); + ok !$ticket->TimeWorked, 'correct value'; + $ticket->Comment( Content => 'test', TimeTaken => 10 ); + is $ticket->TimeWorked, 10, 'correct value'; + + my $txn = RT::Transaction->new( RT->SystemUser ); + $txn->LoadByCols( + ObjectType => 'RT::Ticket', ObjectId => $ticket->id, + Type => 'Comment', + ); + ok $txn->id, 'found transaction'; + is $txn->TimeTaken, 10, 'correct value'; +} + +note 'update'; +{ + my $ticket = RT::Test->create_ticket( Queue => $queue->id ); + ok !$ticket->TimeWorked, 'correct value'; + $ticket->SetTimeWorked( 10 ); + is $ticket->TimeWorked, 10, 'correct value'; + + my $txn = RT::Transaction->new( RT->SystemUser ); + $txn->LoadByCols( + ObjectType => 'RT::Ticket', ObjectId => $ticket->id, + Type => 'Set', Field => 'TimeWorked', + ); + ok $txn->id, 'found transaction'; + is $txn->TimeTaken, 10, 'correct value'; +} + +note 'on Merge'; +{ + my $ticket = RT::Test->create_ticket( + Queue => $queue->id, TimeWorked => 7, + ); + { + my $tmp = RT::Test->create_ticket( + Queue => $queue->id, TimeWorked => 13, + ); + my ($status, $msg) = $tmp->MergeInto( $ticket->id ); + ok $status, "merged tickets"; + } + $ticket->Load( $ticket->id ); + is $ticket->TimeWorked, 20, 'correct value'; +} + +sub dump_txns { + my $ticket = shift; + my $txns = $ticket->Transactions; + while ( my $txn = $txns->Next ) { + diag sprintf "#%d\t%s\t%s\t%d", map $txn->$_() // '', qw(id Type Field TimeTaken); + } +} + |