diff options
author | Ivan Kohler <ivan@freeside.biz> | 2012-06-07 00:56:06 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2012-06-07 00:56:06 -0700 |
commit | 43a06151e47d2c59b833cbd8c26d97865ee850b6 (patch) | |
tree | 42c51d94e7fa265461b508d061562be204ccc2c1 /rt/t | |
parent | 6587f6ba7d047ddc1686c080090afe7d53365bd4 (diff) |
starting to work...
Diffstat (limited to 'rt/t')
81 files changed, 722 insertions, 3499 deletions
diff --git a/rt/t/00-compile.t b/rt/t/00-compile.t index 7257c3e8c..43daf7075 100644 --- a/rt/t/00-compile.t +++ b/rt/t/00-compile.t @@ -2,7 +2,7 @@ use strict; use warnings; -use RT::Test nodata => 1, tests => 34; +use RT::Test nodb => 1, tests => 44; require_ok("RT"); require_ok("RT::Test"); @@ -24,20 +24,30 @@ require_ok("RT::GroupMembers"); require_ok("RT::ScripActions"); require_ok("RT::Transactions"); require_ok("RT::ScripCondition"); -require_ok("RT::Action::Generic"); +require_ok("RT::Action"); require_ok("RT::ScripConditions"); -require_ok("RT::Search::Generic"); -require_ok("RT::Search::Generic"); -require_ok("RT::Search::Generic"); -require_ok("RT::Search::Generic"); +require_ok("RT::Search"); require_ok("RT::Action::SendEmail"); require_ok("RT::CachedGroupMembers"); -require_ok("RT::Condition::Generic"); +require_ok("RT::Condition"); require_ok("RT::Interface::Web"); require_ok("RT::SavedSearch"); require_ok("RT::SavedSearches"); +require_ok("RT::Dashboard"); +require_ok("RT::Dashboard::Mailer"); +require_ok("RT::Dashboards"); require_ok("RT::Installer"); require_ok("RT::Util"); +require_ok("RT::Article"); +require_ok("RT::Articles"); +require_ok("RT::Class"); +require_ok("RT::Classes"); +require_ok("RT::ObjectClass"); +require_ok("RT::ObjectClasses"); +require_ok("RT::ObjectTopic"); +require_ok("RT::ObjectTopics"); +require_ok("RT::Topic"); +require_ok("RT::Topics"); # no the following doesn't work yet @@ -55,4 +65,3 @@ for (@files) { require_ok($_); } -1; diff --git a/rt/t/00-mason-syntax.t b/rt/t/00-mason-syntax.t index 0584f630f..1221b7d17 100644 --- a/rt/t/00-mason-syntax.t +++ b/rt/t/00-mason-syntax.t @@ -3,9 +3,8 @@ use strict; use warnings; -use RT::Test tests => 1; +use RT::Test nodb => 1; -my $ok = 1; use File::Find; find( { @@ -14,13 +13,10 @@ find( { return if /(?:\.(?:jpe?g|png|gif|rej)|\~)$/i; return if m{/\.[^/]+\.swp$}; # vim swap files return unless -f $_; - diag "testing $_" if $ENV{'TEST_VERBOSE'}; - eval { compile_file($_) } and return; - $ok = 0; - diag "error in ${File::Find::name}:\n$@"; + local ($@); + ok( eval { compile_file($_) }, "Compiled $File::Find::name ok: $@"); }, }, RT::Test::get_relocatable_dir('../share/html')); -ok($ok, "mason syntax is ok"); use HTML::Mason; use HTML::Mason::Compiler; @@ -37,7 +33,7 @@ sub compile_file { $compiler->compile( comp_source => $text, name => 'my', - $HTML::Mason::VERSION >= 1.36? (comp_path => 'my'): (), + comp_path => 'my', ); return 1; } diff --git a/rt/t/api/ace.t b/rt/t/api/ace.t deleted file mode 100644 index 4031046d9..000000000 --- a/rt/t/api/ace.t +++ /dev/null @@ -1,238 +0,0 @@ - -use strict; -use warnings; -use RT; -use RT::Test tests => 76; - - -{ - -ok(require RT::ACE); - - -} - -{ - -my $Queue = RT::Queue->new($RT::SystemUser); - -is ($Queue->AvailableRights->{'DeleteTicket'} , 'Delete tickets', "Found the delete ticket right"); -is ($RT::System->AvailableRights->{'SuperUser'}, 'Do anything and everything', "Found the superuser right"); - - - -} - -{ - -use_ok('RT::User'); -my $user_a = RT::User->new($RT::SystemUser); -$user_a->Create( Name => 'DelegationA', Privileged => 1); -ok ($user_a->Id, "Created delegation user a"); - -my $user_b = RT::User->new($RT::SystemUser); -$user_b->Create( Name => 'DelegationB', Privileged => 1); -ok ($user_b->Id, "Created delegation user b"); - - -use_ok('RT::Queue'); -my $q = RT::Queue->new($RT::SystemUser); -$q->Create(Name =>'DelegationTest'); -ok ($q->Id, "Created a delegation test queue"); - - -#------ First, we test whether a user can delegate a right that's been granted to him personally -my ($val, $msg) = $user_a->PrincipalObj->GrantRight(Object => $RT::System, Right => 'AdminOwnPersonalGroups'); -ok($val, $msg); - -($val, $msg) = $user_a->PrincipalObj->GrantRight(Object =>$q, Right => 'OwnTicket'); -ok($val, $msg); - -ok($user_a->HasRight( Object => $RT::System, Right => 'AdminOwnPersonalGroups') ,"user a has the right 'AdminOwnPersonalGroups' directly"); - -my $a_delegates = RT::Group->new($user_a); -$a_delegates->CreatePersonalGroup(Name => 'Delegates'); -ok( $a_delegates->Id ,"user a creates a personal group 'Delegates'"); -ok( $a_delegates->AddMember($user_b->PrincipalId) ,"user a adds user b to personal group 'delegates'"); - -ok( !$user_b->HasRight(Right => 'OwnTicket', Object => $q) ,"user b does not have the right to OwnTicket' in queue 'DelegationTest'"); -ok( $user_a->HasRight(Right => 'OwnTicket', Object => $q) ,"user a has the right to 'OwnTicket' in queue 'DelegationTest'"); -ok(!$user_a->HasRight( Object => $RT::System, Right => 'DelegateRights') ,"user a does not have the right 'delegate rights'"); - - -my $own_ticket_ace = RT::ACE->new($user_a); -my $user_a_equiv_group = RT::Group->new($user_a); -$user_a_equiv_group->LoadACLEquivalenceGroup($user_a->PrincipalObj); -ok ($user_a_equiv_group->Id, "Loaded the user A acl equivalence group"); -my $user_b_equiv_group = RT::Group->new($user_b); -$user_b_equiv_group->LoadACLEquivalenceGroup($user_b->PrincipalObj); -ok ($user_b_equiv_group->Id, "Loaded the user B acl equivalence group"); -$own_ticket_ace->LoadByValues( PrincipalType => 'Group', PrincipalId => $user_a_equiv_group->PrincipalId, Object=>$q, RightName => 'OwnTicket'); - -ok ($own_ticket_ace->Id, "Found the ACE we want to test with for now"); - - -($val, $msg) = $own_ticket_ace->Delegate(PrincipalId => $a_delegates->PrincipalId) ; -ok( !$val ,"user a tries and fails to delegate the right 'ownticket' in queue 'DelegationTest' to personal group 'delegates' - $msg"); - - -($val, $msg) = $user_a->PrincipalObj->GrantRight( Right => 'DelegateRights'); -ok($val, "user a is granted the right to 'delegate rights' - $msg"); - -ok($user_a->HasRight( Object => $RT::System, Right => 'DelegateRights') ,"user a has the right 'DeletgateRights'"); - -($val, $msg) = $own_ticket_ace->Delegate(PrincipalId => $a_delegates->PrincipalId) ; - -ok( $val ,"user a tries and succeeds to delegate the right 'ownticket' in queue 'DelegationTest' to personal group 'delegates' - $msg"); -ok( $user_b->HasRight(Right => 'OwnTicket', Object => $q) ,"user b has the right to own tickets in queue 'DelegationTest'"); -my $delegated_ace = RT::ACE->new($user_a); -$delegated_ace->LoadByValues ( Object => $q, RightName => 'OwnTicket', PrincipalType => 'Group', -PrincipalId => $a_delegates->PrincipalId, DelegatedBy => $user_a->PrincipalId, DelegatedFrom => $own_ticket_ace->Id); -ok ($delegated_ace->Id, "Found the delegated ACE"); - -ok( $a_delegates->DeleteMember($user_b->PrincipalId) ,"user a removes b from pg 'delegates'"); -ok( !$user_b->HasRight(Right => 'OwnTicket', Object => $q) ,"user b does not have the right to own tickets in queue 'DelegationTest'"); -ok( $a_delegates->AddMember($user_b->PrincipalId) ,"user a adds user b to personal group 'delegates'"); -ok( $user_b->HasRight(Right => 'OwnTicket', Object=> $q) ,"user b has the right to own tickets in queue 'DelegationTest'"); -ok( $delegated_ace->Delete ,"user a revokes pg 'delegates' right to 'OwnTickets' in queue 'DelegationTest'"); -ok( ! $user_b->HasRight(Right => 'OwnTicket', Object => $q) ,"user b does not have the right to own tickets in queue 'DelegationTest'"); - -($val, $msg) = $own_ticket_ace->Delegate(PrincipalId => $a_delegates->PrincipalId) ; -ok( $val ,"user a delegates pg 'delegates' right to 'OwnTickets' in queue 'DelegationTest' - $msg"); - -ok( $user_b->HasRight(Right => 'OwnTicket', Object => $q) ,"user b has the right to own tickets in queue 'DelegationTest'"); - -($val, $msg) = $user_a->PrincipalObj->RevokeRight(Object=>$q, Right => 'OwnTicket'); -ok($val, "Revoked user a's right to own tickets in queue 'DelegationTest". $msg); - -ok( !$user_a->HasRight(Right => 'OwnTicket', Object => $q) ,"user a does not have the right to own tickets in queue 'DelegationTest'"); - - ok( !$user_b->HasRight(Right => 'OwnTicket', Object => $q) ,"user b does not have the right to own tickets in queue 'DelegationTest'"); - -($val, $msg) = $user_a->PrincipalObj->GrantRight(Object=>$q, Right => 'OwnTicket'); -ok($val, $msg); - - ok( $user_a->HasRight(Right => 'OwnTicket', Object => $q) ,"user a has the right to own tickets in queue 'DelegationTest'"); - - ok( !$user_b->HasRight(Right => 'OwnTicket', Object => $q) ,"user b does not have the right to own tickets in queue 'DelegationTest'"); - -# {{{ get back to a known clean state -($val, $msg) = $user_a->PrincipalObj->RevokeRight( Object => $q, Right => 'OwnTicket'); -ok($val, "Revoked user a's right to own tickets in queue 'DelegationTest -". $msg); -ok( !$user_a->HasRight(Right => 'OwnTicket', Object => $q) ,"make sure that user a can't own tickets in queue 'DelegationTest'"); -# }}} - - -# {{{ Set up some groups and membership -my $del1 = RT::Group->new($RT::SystemUser); -($val, $msg) = $del1->CreateUserDefinedGroup(Name => 'Del1'); -ok( $val ,"create a group del1 - $msg"); - -my $del2 = RT::Group->new($RT::SystemUser); -($val, $msg) = $del2->CreateUserDefinedGroup(Name => 'Del2'); -ok( $val ,"create a group del2 - $msg"); -($val, $msg) = $del1->AddMember($del2->PrincipalId); -ok( $val,"make del2 a member of del1 - $msg"); - -my $del2a = RT::Group->new($RT::SystemUser); -($val, $msg) = $del2a->CreateUserDefinedGroup(Name => 'Del2a'); -ok( $val ,"create a group del2a - $msg"); -($val, $msg) = $del2->AddMember($del2a->PrincipalId); -ok($val ,"make del2a a member of del2 - $msg"); - -my $del2b = RT::Group->new($RT::SystemUser); -($val, $msg) = $del2b->CreateUserDefinedGroup(Name => 'Del2b'); -ok( $val ,"create a group del2b - $msg"); -($val, $msg) = $del2->AddMember($del2b->PrincipalId); -ok($val ,"make del2b a member of del2 - $msg"); - -($val, $msg) = $del2->AddMember($user_a->PrincipalId) ; -ok($val,"make 'user a' a member of del2 - $msg"); - -($val, $msg) = $del2b->AddMember($user_a->PrincipalId) ; -ok($val,"make 'user a' a member of del2b - $msg"); - -# }}} - -# {{{ Grant a right to a group and make sure that a submember can delegate the right and that it does not get yanked -# when a user is removed as a submember, when they're a submember through another path -($val, $msg) = $del1->PrincipalObj->GrantRight( Object=> $q, Right => 'OwnTicket'); -ok( $val ,"grant del1 the right to 'OwnTicket' in queue 'DelegationTest' - $msg"); - -ok( $user_a->HasRight(Right => 'OwnTicket', Object => $q) ,"make sure that user a can own tickets in queue 'DelegationTest'"); - -my $group_ace= RT::ACE->new($user_a); -$group_ace->LoadByValues( PrincipalType => 'Group', PrincipalId => $del1->PrincipalId, Object => $q, RightName => 'OwnTicket'); - -ok ($group_ace->Id, "Found the ACE we want to test with for now"); - -($val, $msg) = $group_ace->Delegate(PrincipalId => $a_delegates->PrincipalId); - -ok( $val ,"user a tries and succeeds to delegate the right 'ownticket' in queue 'DelegationTest' to personal group 'delegates' - $msg"); -ok( $user_b->HasRight(Right => 'OwnTicket', Object => $q) ,"user b has the right to own tickets in queue 'DelegationTest'"); - - -($val, $msg) = $del2b->DeleteMember($user_a->PrincipalId); -ok( $val ,"remove user a from group del2b - $msg"); -ok( $user_a->HasRight(Right => 'OwnTicket', Object => $q) ,"user a has the right to own tickets in queue 'DelegationTest'"); -ok( $user_b->HasRight(Right => 'OwnTicket', Object => $q) ,"user b has the right to own tickets in queue 'DelegationTest'"); - -# }}} - -# {{{ When a user is removed froom a group by the only path they're in there by, make sure the delegations go away -($val, $msg) = $del2->DeleteMember($user_a->PrincipalId); -ok( $val ,"remove user a from group del2 - $msg"); -ok( !$user_a->HasRight(Right => 'OwnTicket', Object => $q) ,"user a does not have the right to own tickets in queue 'DelegationTest' "); -ok( !$user_b->HasRight(Right => 'OwnTicket', Object => $q) ,"user b does not have the right to own tickets in queue 'DelegationTest' "); -# }}} - -($val, $msg) = $del2->AddMember($user_a->PrincipalId); -ok( $val ,"make user a a member of group del2 - $msg"); - -($val, $msg) = $del2->PrincipalObj->GrantRight(Object=>$q, Right => 'OwnTicket'); -ok($val, "grant the right 'own tickets' in queue 'DelegationTest' to group del2 - $msg"); - -my $del2_right = RT::ACE->new($user_a); -$del2_right->LoadByValues( PrincipalId => $del2->PrincipalId, PrincipalType => 'Group', Object => $q, RightName => 'OwnTicket'); -ok ($del2_right->Id, "Found the right"); - -($val, $msg) = $del2_right->Delegate(PrincipalId => $a_delegates->PrincipalId); -ok( $val ,"user a tries and succeeds to delegate the right 'ownticket' in queue 'DelegationTest' gotten via del2 to personal group 'delegates' - $msg"); - -# They have it via del1 and del2 -ok( $user_b->HasRight(Right => 'OwnTicket', Object => $q) ,"user b has the right to own tickets in queue 'DelegationTest'"); - - -($val, $msg) = $del2->PrincipalObj->RevokeRight(Object=>$q, Right => 'OwnTicket'); -ok($val, "revoke the right 'own tickets' in queue 'DelegationTest' to group del2 - $msg"); -ok( $user_a->HasRight(Right => 'OwnTicket', Object => $q) ,"user a does has the right to own tickets in queue 'DelegationTest' via del1"); -ok( !$user_b->HasRight(Right => 'OwnTicket', Object => $q) ,"user b does not have the right to own tickets in queue 'DelegationTest'"); - -($val, $msg) = $del2->PrincipalObj->GrantRight(Object=>$q, Right => 'OwnTicket'); -ok($val, "grant the right 'own tickets' in queue 'DelegationTest' to group del2 - $msg"); - - -$group_ace= RT::ACE->new($user_a); -$group_ace->LoadByValues( PrincipalType => 'Group', PrincipalId => $del1->PrincipalId, Object=>$q, RightName => 'OwnTicket'); - -ok ($group_ace->Id, "Found the ACE we want to test with for now"); - -($val, $msg) = $group_ace->Delegate(PrincipalId => $a_delegates->PrincipalId); - -ok( $val ,"user a tries and succeeds to delegate the right 'ownticket' in queue 'DelegationTest' to personal group 'delegates' - $msg"); - -ok( $user_b->HasRight(Right => 'OwnTicket', Object => $q) ,"user b has the right to own tickets in queue 'DelegationTest'"); - -($val, $msg) = $del2->DeleteMember($user_a->PrincipalId); -ok( $val ,"remove user a from group del2 - $msg"); - -ok( !$user_a->HasRight(Right => 'OwnTicket', Object => $q) ,"user a does not have the right to own tickets in queue 'DelegationTest'"); - -ok( !$user_b->HasRight(Right => 'OwnTicket', Object => $q) ,"user b does not have the right to own tickets in queue 'DelegationTest'"); - - - - -} - -1; diff --git a/rt/t/api/cf.t b/rt/t/api/cf.t deleted file mode 100644 index 98114c93f..000000000 --- a/rt/t/api/cf.t +++ /dev/null @@ -1,224 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings FATAL => 'all'; - -use RT::Test tests => 139; - -# 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(); -} - - -my $queue = RT::Queue->new( $RT::SystemUser ); -$queue->Create( Name => 'RecordCustomFields-'.$$ ); -ok ($queue->id, "Created the queue"); - -my $queue2 = RT::Queue->new( $RT::SystemUser ); -$queue2->Create( Name => 'RecordCustomFields2' ); - -my $ticket = RT::Ticket->new( $RT::SystemUser ); -$ticket->Create( - Queue => $queue->Id, - Requestor => 'root@localhost', - Subject => 'RecordCustomFields1', -); - -my $cfs = $ticket->CustomFields; -is( $cfs->Count, 0 ); - -# Check that record has no any CF values yet {{{ -my $cfvs = $ticket->CustomFieldValues; -is( $cfvs->Count, 0 ); -is( $ticket->FirstCustomFieldValue, undef ); - -my $local_cf1 = RT::CustomField->new( $RT::SystemUser ); -$local_cf1->Create( Name => 'RecordCustomFields1-'.$$, Type => 'SelectSingle', Queue => $queue->id ); -$local_cf1->AddValue( Name => 'RecordCustomFieldValues11' ); -$local_cf1->AddValue( Name => 'RecordCustomFieldValues12' ); - -my $local_cf2 = RT::CustomField->new( $RT::SystemUser ); -$local_cf2->Create( Name => 'RecordCustomFields2-'.$$, Type => 'SelectSingle', Queue => $queue->id ); -$local_cf2->AddValue( Name => 'RecordCustomFieldValues21' ); -$local_cf2->AddValue( Name => 'RecordCustomFieldValues22' ); - -my $global_cf3 = RT::CustomField->new( $RT::SystemUser ); -$global_cf3->Create( Name => 'RecordCustomFields3-'.$$, Type => 'SelectSingle', Queue => 0 ); -$global_cf3->AddValue( Name => 'RecordCustomFieldValues31' ); -$global_cf3->AddValue( Name => 'RecordCustomFieldValues32' ); - -my $local_cf4 = RT::CustomField->new( $RT::SystemUser ); -$local_cf4->Create( Name => 'RecordCustomFields4', Type => 'SelectSingle', Queue => $queue2->id ); -$local_cf4->AddValue( Name => 'RecordCustomFieldValues41' ); -$local_cf4->AddValue( Name => 'RecordCustomFieldValues42' ); - - -my @custom_fields = ($local_cf1, $local_cf2, $global_cf3); - - -$cfs = $ticket->CustomFields; -is( $cfs->Count, 3 ); - -# Check that record has no any CF values yet {{{ -$cfvs = $ticket->CustomFieldValues; -is( $cfvs->Count, 0 ); -is( $ticket->FirstCustomFieldValue, undef ); - -# CF with ID -1 shouldnt exist at all -$cfvs = $ticket->CustomFieldValues( -1 ); -is( $cfvs->Count, 0 ); -is( $ticket->FirstCustomFieldValue( -1 ), undef ); - -$cfvs = $ticket->CustomFieldValues( 'SomeUnexpedCustomFieldName' ); -is( $cfvs->Count, 0 ); -is( $ticket->FirstCustomFieldValue( 'SomeUnexpedCustomFieldName' ), undef ); - -for (@custom_fields) { - $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 ); -} -# }}} - -# try to add field value with fields that do not exist {{{ -my ($status, $msg) = $ticket->AddCustomFieldValue( Field => -1 , Value => 'foo' ); -ok(!$status, "shouldn't add value" ); -($status, $msg) = $ticket->AddCustomFieldValue( Field => 'SomeUnexpedCustomFieldName' , Value => 'foo' ); -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 ); - } - -} -# Add some values to our custom fields -for (@custom_fields) { - # 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" ); - } -}; - -# lets test cycle via CF id -$test_add_delete_cycle->( sub { return $_[0]->id } ); -# lets test cycle via CF object reference -$test_add_delete_cycle->( sub { return $_[0] } ); - -$ticket->AddCustomFieldValue( Field => $local_cf2->id , Value => 'Baz' ); -$ticket->AddCustomFieldValue( Field => $global_cf3->id , Value => 'Baz' ); -# now if we ask for cf values on RecordCustomFields4 we should not get any -$cfvs = $ticket->CustomFieldValues( 'RecordCustomFields4' ); -is( $cfvs->Count, 0, "No custom field values for non-Queue cf" ); -is( $ticket->FirstCustomFieldValue( 'RecordCustomFields4' ), undef, "No first custom field value for non-Queue cf" ); - -{ - my $cfname = $global_cf3->Name; - ($status, $msg) = $global_cf3->SetDisabled(1); - ok($status, "Disabled CF named $cfname"); - - my $load = RT::CustomField->new( $RT::SystemUser ); - $load->LoadByName( Name => $cfname); - ok($load->Id, "Loaded CF named $cfname"); - is($load->Id, $global_cf3->Id, "Can load disabled CFs"); - - my $dup = RT::CustomField->new( $RT::SystemUser ); - $dup->Create( Name => $cfname, Type => 'SelectSingle', Queue => 0 ); - ok($dup->Id, "Created CF with duplicate name"); - - $load->LoadByName( Name => $cfname); - is($load->Id, $dup->Id, "Loading by name gets non-disabled first"); - - $dup->SetDisabled(1); - $global_cf3->SetDisabled(0); - - $load->LoadByName( Name => $cfname); - is($load->Id, $global_cf3->Id, "Loading by name gets non-disabled first, even with order swapped"); -} - -#SKIP: { -# 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 } ); -#} - - diff --git a/rt/t/api/cf_combo_casacade.t b/rt/t/api/cf_combo_casacade.t deleted file mode 100644 index b37345a6a..000000000 --- a/rt/t/api/cf_combo_casacade.t +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/perl -use warnings; -use strict; - -use RT::Test tests => 11; - -sub fails { ok(!$_[0], "This should fail: $_[1]") } -sub works { ok($_[0], $_[1] || 'This works') } - -sub new (*) { - my $class = shift; - return $class->new($RT::SystemUser); -} - -my $q = new(RT::Queue); -works($q->Create(Name => "CF-Pattern-".$$)); - -my $cf = new(RT::CustomField); -my @cf_args = (Name => $q->Name, Type => 'Combobox', Queue => $q->id); - -works($cf->Create(@cf_args)); - -# Set some CFVs with Category markers - -my $t = new(RT::Ticket); -my ($id,undef,$msg) = $t->Create(Queue => $q->id, Subject => 'CF Test'); -works($id,$msg); - -sub add_works { - works( - $cf->AddValue(Name => $_[0], Description => $_[0], Category => $_[1]) - ); -}; - -add_works('value1', '1. Category A'); -add_works('value2'); -add_works('value3', '1.1. A-sub one'); -add_works('value4', '1.2. A-sub two'); -add_works('value5', ''); - -my $cfv = $cf->Values->First; -is($cfv->Category, '1. Category A'); -works($cfv->SetCategory('1. Category AAA')); -is($cfv->Category, '1. Category AAA'); - -1; diff --git a/rt/t/api/cf_external.t b/rt/t/api/cf_external.t deleted file mode 100644 index 076871240..000000000 --- a/rt/t/api/cf_external.t +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/perl - -use warnings; -use strict; - -use RT; -use RT::Test nodata => 1, tests => 11; - -sub new (*) { - my $class = shift; - return $class->new($RT::SystemUser); -} - -use constant VALUES_CLASS => 'RT::CustomFieldValues::Groups'; - -my $q = new( RT::Queue ); -isa_ok( $q, 'RT::Queue' ); -my ($qid) = $q->Create( Name => "CF-External-". $$ ); -ok( $qid, "created queue" ); -my %arg = ( Name => $q->Name, - Type => 'Select', - Queue => $q->id, - MaxValues => 1, - ValuesClass => VALUES_CLASS ); - -my $cf = new( RT::CustomField ); -isa_ok( $cf, 'RT::CustomField' ); - -{ - my ($cfid) = $cf->Create( %arg ); - ok( $cfid, "created cf" ); - is( $cf->ValuesClass, VALUES_CLASS, "right values class" ); - ok( $cf->IsExternalValues, "custom field has external values" ); -} - -{ - # create at least on group for the tests - my $group = RT::Group->new( $RT::SystemUser ); - my ($ret, $msg) = $group->CreateUserDefinedGroup( Name => $q->Name ); - ok $ret, 'created group' or diag "error: $msg"; -} - -{ - my $values = $cf->Values; - isa_ok( $values, VALUES_CLASS ); - ok( $values->Count, "we have values" ); - my ($failure, $count) = (0, 0); - while( my $value = $values->Next ) { - $count++; - $failure = 1 unless $value->Name; - } - ok( !$failure, "all values have name" ); - is( $values->Count, $count, "count is correct" ); -} - -exit(0); diff --git a/rt/t/api/cf_pattern.t b/rt/t/api/cf_pattern.t deleted file mode 100644 index 89db2fea5..000000000 --- a/rt/t/api/cf_pattern.t +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/perl -use warnings; -use strict; - -use RT; -use RT::Test tests => 17; - - -sub fails { ok(!$_[0], "This should fail: $_[1]") } -sub works { ok($_[0], $_[1] || 'This works') } - -sub new (*) { - my $class = shift; - return $class->new($RT::SystemUser); -} - -my $q = new(RT::Queue); -works($q->Create(Name => "CF-Pattern-".$$)); - -my $cf = new(RT::CustomField); -my @cf_args = (Name => $q->Name, Type => 'Freeform', Queue => $q->id, MaxValues => 1); - -fails($cf->Create(@cf_args, Pattern => ')))bad!regex(((')); -works($cf->Create(@cf_args, Pattern => 'good regex')); - -my $t = new(RT::Ticket); -my ($id,undef,$msg) = $t->Create(Queue => $q->id, Subject => 'CF Test'); -works($id,$msg); - -# OK, I'm thoroughly brain washed by HOP at this point now... -sub cnt { $t->CustomFieldValues($cf->id)->Count }; -sub add { $t->AddCustomFieldValue(Field => $cf->id, Value => $_[0]) }; -sub del { $t->DeleteCustomFieldValue(Field => $cf->id, Value => $_[0]) }; - -is(cnt(), 0, "No values yet"); -fails(add('not going to match')); -is(cnt(), 0, "No values yet"); -works(add('here is a good regex')); -is(cnt(), 1, "Value filled"); -fails(del('here is a good regex')); -is(cnt(), 1, "Single CF - Value _not_ deleted"); - -$cf->SetMaxValues(0); # Unlimited MaxValues - -works(del('here is a good regex')); -is(cnt(), 0, "Multiple CF - Value deleted"); - -fails($cf->SetPattern('(?{ "insert evil code here" })')); -works($cf->SetPattern('(?!)')); # reject everything -fails(add('')); -fails(add('...')); - -1; diff --git a/rt/t/api/cf_single_values.t b/rt/t/api/cf_single_values.t deleted file mode 100644 index 8e96edd44..000000000 --- a/rt/t/api/cf_single_values.t +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/perl -use warnings; -use strict; - -use RT; -use RT::Test tests => 8; - - - -my $q = RT::Queue->new($RT::SystemUser); -my ($id,$msg) =$q->Create(Name => "CF-Single-".$$); -ok($id,$msg); - -my $cf = RT::CustomField->new($RT::SystemUser); -($id,$msg) = $cf->Create(Name => 'Single-'.$$, Type => 'Select', MaxValues => '1', Queue => $q->id); -ok($id,$msg); - - -($id,$msg) =$cf->AddValue(Name => 'First'); -ok($id,$msg); - -($id,$msg) =$cf->AddValue(Name => 'Second'); -ok($id,$msg); - - -my $t = RT::Ticket->new($RT::SystemUser); -($id,undef,$msg) = $t->Create(Queue => $q->id, - Subject => 'CF Test'); - -ok($id,$msg); -is($t->CustomFieldValues($cf->id)->Count, 0, "No values yet"); -$t->AddCustomFieldValue(Field => $cf->id, Value => 'First'); -is($t->CustomFieldValues($cf->id)->Count, 1, "One now"); - -$t->AddCustomFieldValue(Field => $cf->id, Value => 'Second'); -is($t->CustomFieldValues($cf->id)->Count, 1, "Still one"); - -1; diff --git a/rt/t/api/cf_transaction.t b/rt/t/api/cf_transaction.t deleted file mode 100644 index 1ed2ab932..000000000 --- a/rt/t/api/cf_transaction.t +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/perl - -use warnings; -use strict; -use Data::Dumper; - -use RT::Test tests => 14; -use_ok('RT'); -use_ok('RT::Transactions'); - - -my $q = RT::Queue->new($RT::SystemUser); -my ($id,$msg) = $q->Create( Name => 'TxnCFTest'.$$); -ok($id,$msg); - -my $cf = RT::CustomField->new($RT::SystemUser); -($id,$msg) = $cf->Create(Name => 'Txnfreeform-'.$$, Type => 'Freeform', MaxValues => '0', LookupType => RT::Transaction->CustomFieldLookupType ); - -ok($id,$msg); - -($id,$msg) = $cf->AddToObject($q); - -ok($id,$msg); - - -my $ticket = RT::Ticket->new($RT::SystemUser); - -my $transid; -($id,$transid, $msg) = $ticket->Create(Queue => $q->id, - Subject => 'TxnCF test', - ); -ok($id,$msg); - -my $trans = RT::Transaction->new($RT::SystemUser); -$trans->Load($transid); - -is($trans->ObjectId,$id); -is ($trans->ObjectType, 'RT::Ticket'); -is ($trans->Type, 'Create'); -my $txncfs = $trans->CustomFields; -is ($txncfs->Count, 1, "We have one custom field"); -my $txn_cf = $txncfs->First; -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"); - -# TODO ok(0, "Should updating custom field values remove old values?"); diff --git a/rt/t/approval/admincc.t b/rt/t/approval/admincc.t index 7915b6a78..b43929603 100644 --- a/rt/t/approval/admincc.t +++ b/rt/t/approval/admincc.t @@ -9,7 +9,7 @@ BEGIN { use RT; -use RT::Test tests => 58; +use RT::Test tests => 62; use RT::Test::Email; RT->Config->Set( LogToScreen => 'debug' ); @@ -236,14 +236,18 @@ $m->get_ok( $approval_link ); $m_coo->get_ok( $approval_link ); $m_ceo->get_ok( $approval_link ); -$m->content_like( qr/first approval.*second approval/s, 'cto: see both approvals' ); -$m_coo->content_like( qr/first approval.*second approval/s, 'coo: see both approvals' ); -$m_ceo->content_like( qr/first approval.*second approval/s, 'ceo: see both approvals' ); +$m->content_contains('first approval', 'cto: see both approvals' ); +$m->content_contains('second approval', 'cto: see both approvals' ); + +$m_coo->content_contains('first approval', 'coo: see both approvals'); +$m_coo->content_contains('second approval', 'coo: see both approvals'); + +$m_ceo->content_contains('first approval', 'ceo: see both approvals'); +$m_ceo->content_contains('second approval', 'ceo: see both approvals'); # now let's approve the first one via cto -$m->content_like( qr/first approval.*second approval/s, 'cto can see both approvals' ); $m->submit_form( - form_number => 3, + form_name => 'Approvals', fields => { 'Approval-' . $first_approval->id . '-Action' => 'approve', }, ); @@ -257,7 +261,7 @@ $m_ceo->content_lacks( 'first approval', 'ceo: first approval is gone' ); $m_ceo->content_contains( 'second approval', 'ceo: second approval is still here' ); $m_coo->submit_form( - form_number => 3, + form_name => 'Approvals', fields => { 'Approval-' . $second_approval->id . '-Action' => 'approve', }, ); diff --git a/rt/t/approval/basic.t b/rt/t/approval/basic.t index 597459125..2d00eb56e 100644 --- a/rt/t/approval/basic.t +++ b/rt/t/approval/basic.t @@ -1,28 +1,24 @@ - use strict; use warnings; -use Test::More; +use RT::Test tests => undef; BEGIN { - eval { require Email::Abstract; require Test::Email; 1 } - or plan skip_all => 'require Email::Abstract and Test::Email'; + plan skip_all => 'Email::Abstract and Test::Email required.' + unless eval { require Email::Abstract; require Test::Email; 1 }; + plan tests => 38; } - -use RT; -use RT::Test tests => 39; use RT::Test::Email; RT->Config->Set( LogToScreen => 'debug' ); RT->Config->Set( UseTransactionBatch => 1 ); -my ($baseurl, $m) = RT::Test->started_ok; -my $q = RT::Queue->new($RT::SystemUser); +my $q = RT::Queue->new(RT->SystemUser); $q->Load('___Approvals'); $q->SetDisabled(0); my %users; for my $user_name (qw(minion cfo ceo )) { - my $user = $users{$user_name} = RT::User->new($RT::SystemUser); + my $user = $users{$user_name} = RT::User->new(RT->SystemUser); $user->Create( Name => uc($user_name), Privileged => 1, EmailAddress => $user_name.'@company.com'); @@ -61,16 +57,16 @@ Your CFO approved PO ticket {$Tickets{"TOP"}->Id} for minion. you ok with that? ENDOFCONTENT '; -my $apptemp = RT::Template->new($RT::SystemUser); +my $apptemp = RT::Template->new(RT->SystemUser); $apptemp->Create( Content => $approvals, Name => "PO Approvals", Queue => "0"); ok($apptemp->Id); -$q = RT::Queue->new($RT::SystemUser); +$q = RT::Queue->new(RT->SystemUser); $q->Create(Name => 'PO'); ok ($q->Id, "Created PO queue"); -my $scrip = RT::Scrip->new($RT::SystemUser); +my $scrip = RT::Scrip->new(RT->SystemUser); my ($sval, $smsg) =$scrip->Create( ScripCondition => 'On Create', ScripAction => 'Create Tickets', Template => 'PO Approvals', @@ -82,7 +78,7 @@ ok ($scrip->TemplateObj->Id, "Created the scrip template"); ok ($scrip->ConditionObj->Id, "Created the scrip condition"); ok ($scrip->ActionObj->Id, "Created the scrip action"); -my $t = RT::Ticket->new($RT::SystemUser); +my $t = RT::Ticket->new(RT->SystemUser); my ($tid, $ttrans, $tmsg); mail_ok { @@ -172,7 +168,7 @@ mail_ok { to => 'minion@company.com', subject => qr/Ticket Approved:/, body => qr/approved by CEO.*Its Owner may now start to act on it.*notes: And consumed they will be/s, -}, { from => qr'CEO via RT', +}, { from => qr/CEO via RT/, to => 'root@localhost', subject => qr/Ticket Approved/, body => qr/The ticket has been approved, you may now start to act on it/, diff --git a/rt/t/clicky.t b/rt/t/clicky.t deleted file mode 100644 index 8d5227e04..000000000 --- a/rt/t/clicky.t +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; -use Test::More; -use RT::Test tests => 14; -my %clicky; - -BEGIN { - - %clicky = map { $_ => 1 } grep $_, RT->Config->Get('Active_MakeClicky'); - -# this's hack: we have to use RT::Test first to get RT->Config work, this -# results in the fact that we can't plan any more - unless ( keys %clicky ) { - SKIP: { - skip "No active Make Clicky actions", 14; - } - exit 0; - } -} - -my ($baseurl, $m) = RT::Test->started_ok; - -use_ok('MIME::Entity'); - -my $CurrentUser = $RT::SystemUser; - -my $queue = new RT::Queue($CurrentUser); -$queue->Load('General') || Abort(loc("Queue could not be loaded.")); - -my $message = MIME::Entity->build( - Subject => 'test', - Data => <<END, -If you have some problems with RT you could find help -on http://wiki.bestpractical.com or subscribe to -the rt-users\@lists.bestpractical.com. - --- -Best regards. BestPractical Team. -END -); - -my $ticket = new RT::Ticket( $CurrentUser ); -my ($id) = $ticket->Create( - Subject => 'test', - Queue => $queue->Id, - MIMEObj => $message, -); -ok($id, "We created a ticket #$id"); -ok($ticket->Transactions->First->Content, "Has some content"); - -ok $m->login, 'logged in'; -ok $m->goto_ticket($id), 'opened diplay page of the ticket'; - -SKIP: { - skip "httpurl action disabled", 1 unless $clicky{'httpurl'}; - my @links = $m->find_link( - tag => 'a', - url => 'http://wiki.bestpractical.com', - text => 'Open URL', - ); - ok( scalar @links, 'found clicky link' ); -} - -SKIP: { - skip "httpurl_overwrite action disabled", 1 unless $clicky{'httpurl_overwrite'}; - my @links = $m->find_link( - tag => 'a', - url => 'http://wiki.bestpractical.com', - text => 'http://wiki.bestpractical.com', - ); - ok( scalar @links, 'found clicky link' ); -} - -{ - -my $message = MIME::Entity->build( - Type => 'text/html', - Subject => 'test', - Data => <<END, -If you have some problems with RT you could find help -on <a href="http://wiki.bestpractical.com">wiki</a> -or find known bugs on http://rt3.fsck.com --- -Best regards. BestPractical Team. -END -); - -my $ticket = new RT::Ticket($CurrentUser); -my ($id) = $ticket->Create( - Subject => 'test', - Queue => $queue->Id, - MIMEObj => $message, -); -ok( $id, "We created a ticket #$id" ); -ok( $ticket->Transactions->First->Content, "Has some content" ); - -ok $m->login, 'logged in'; -ok $m->goto_ticket($id), 'opened diplay page of the ticket'; - -SKIP: { - skip "httpurl action disabled", 2 unless $clicky{'httpurl'}; - my @links = $m->find_link( - tag => 'a', - url => 'http://wiki.bestpractical.com', - text => 'Open URL', - ); - ok( @links == 0, 'not make clicky links clicky twice' ); - - @links = $m->find_link( - tag => 'a', - url => 'http://rt3.fsck.com', - text => 'Open URL', - ); - ok( scalar @links, 'found clicky link' ); -} - -} diff --git a/rt/t/cron.t b/rt/t/cron.t deleted file mode 100644 index 29d7bd7f6..000000000 --- a/rt/t/cron.t +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/perl -w - -use strict; - -use RT; -use RT::Test tests => 18; - - -### Set up some testing data. Test the testing data because why not? - -# Create a user with rights, a queue, and some tickets. -my $user_obj = RT::User->new($RT::SystemUser); -my ($ret, $msg) = $user_obj->LoadOrCreateByEmail('tara@example.com'); -ok($ret, 'record test user creation'); -$user_obj->SetName('tara'); -$user_obj->PrincipalObj->GrantRight(Right => 'SuperUser'); -my $CurrentUser = RT::CurrentUser->new('tara'); - -# Create our template, which will be used for tests of RT::Action::Record*. - -my $template_content = 'RT-Send-Cc: tla@example.com -RT-Send-Bcc: jesse@example.com - -This is a content string with no content.'; - -my $template_obj = RT::Template->new($CurrentUser); -$template_obj->Create(Queue => '0', - Name => 'recordtest', - Description => 'testing Record actions', - Content => $template_content, - ); - -# Create a queue and some tickets. - -my $queue_obj = RT::Queue->new($CurrentUser); -($ret, $msg) = $queue_obj->Create(Name => 'recordtest', Description => 'queue for Action::Record testing'); -ok($ret, 'record test queue creation'); - -my $ticket1 = RT::Ticket->new($CurrentUser); -my ($id, $tobj, $msg2) = $ticket1->Create(Queue => $queue_obj, - Requestor => ['tara@example.com'], - Subject => 'bork bork bork', - Priority => 22, - ); -ok($id, 'record test ticket creation 1'); -my $ticket2 = RT::Ticket->new($CurrentUser); -($id, $tobj, $msg2) = $ticket2->Create(Queue => $queue_obj, - Requestor => ['root@localhost'], - Subject => 'hurdy gurdy' - ); -ok($id, 'record test ticket creation 2'); - - -### OK. Have data, will travel. - -# First test the search. - -ok(require RT::Search::FromSQL, "Search::FromSQL loaded"); -my $ticketsqlstr = "Requestor.EmailAddress = '" . $CurrentUser->EmailAddress . - "' AND Priority > '20'"; -my $search = RT::Search::FromSQL->new(Argument => $ticketsqlstr, TicketsObj => RT::Tickets->new($CurrentUser), - ); -is(ref($search), 'RT::Search::FromSQL', "search created"); -ok($search->Prepare(), "fromsql search run"); -my $counter = 0; -while(my $t = $search->TicketsObj->Next() ) { - is($t->Id(), $ticket1->Id(), "fromsql search results 1"); - $counter++; -} -is ($counter, 1, "fromsql search results 2"); - -# Right. Now test the actions. - -ok(require RT::Action::RecordComment); -ok(require RT::Action::RecordCorrespondence); - -my ($comment_act, $correspond_act); -ok($comment_act = RT::Action::RecordComment->new(TicketObj => $ticket1, TemplateObj => $template_obj, CurrentUser => $CurrentUser), "RecordComment created"); -ok($correspond_act = RT::Action::RecordCorrespondence->new(TicketObj => $ticket2, TemplateObj => $template_obj, CurrentUser => $CurrentUser), "RecordCorrespondence created"); -ok($comment_act->Prepare(), "Comment prepared"); -ok($correspond_act->Prepare(), "Correspond prepared"); -ok($comment_act->Commit(), "Comment committed"); -ok($correspond_act->Commit(), "Correspondence committed"); - -# Now test for loop suppression. -my ($trans, $desc, $transaction) = $ticket2->Comment(MIMEObj => $template_obj->MIMEObj); -my $bogus_action = RT::Action::RecordComment->new(TicketObj => $ticket1, TemplateObj => $template_obj, TransactionObj => $transaction, CurrentUser => $CurrentUser); -ok(!$bogus_action->Prepare(), "Comment aborted to prevent loop"); - -1; diff --git a/rt/t/data/configs/apache2.2+fastcgi.conf b/rt/t/data/configs/apache2.2+fastcgi.conf index 4033479bb..a4016eb42 100644 --- a/rt/t/data/configs/apache2.2+fastcgi.conf +++ b/rt/t/data/configs/apache2.2+fastcgi.conf @@ -5,12 +5,10 @@ ServerAdmin root@localhost %%LOAD_MODULES%% -FastCgiIpcDir %%TMP_DIR%% - <IfModule !mpm_netware_module> <IfModule !mpm_winnt_module> -User www-data -Group www-data +User freeside +Group freeside </IfModule> </IfModule> @@ -28,16 +26,23 @@ LogLevel debug AddDefaultCharset UTF-8 -FastCgiServer %%RT_BIN_PATH%%/mason_handler.fcgi -processes 1 -idle-timeout 180 -initial-env RT_SITE_CONFIG=%%RT_SITE_CONFIG%% +FastCgiServer %%RT_SBIN_PATH%%/rt-server.fcgi \ + -socket %%TMP_DIR%%/socket \ + -processes 1 \ + -idle-timeout 180 \ + -initial-env RT_SITE_CONFIG=%%RT_SITE_CONFIG%% \ + -initial-env RT_TESTING=1 Alias /NoAuth/images/ %%DOCUMENT_ROOT%%/NoAuth/images/ -ScriptAlias / %%RT_BIN_PATH%%/mason_handler.fcgi/ +ScriptAlias / %%RT_SBIN_PATH%%/rt-server.fcgi/ DocumentRoot "%%DOCUMENT_ROOT%%" <Location /> Order allow,deny Allow from all +%%BASIC_AUTH%% + Options +ExecCGI AddHandler fastcgi-script fcgi </Location> diff --git a/rt/t/data/configs/apache2.2+fastcgi.conf.in b/rt/t/data/configs/apache2.2+fastcgi.conf.in index 75cbadbca..3ec36dd0f 100644 --- a/rt/t/data/configs/apache2.2+fastcgi.conf.in +++ b/rt/t/data/configs/apache2.2+fastcgi.conf.in @@ -5,8 +5,6 @@ ServerAdmin root@localhost %%LOAD_MODULES%% -FastCgiIpcDir %%TMP_DIR%% - <IfModule !mpm_netware_module> <IfModule !mpm_winnt_module> User @WEB_USER@ @@ -28,16 +26,23 @@ LogLevel debug AddDefaultCharset UTF-8 -FastCgiServer %%RT_BIN_PATH%%/mason_handler.fcgi -processes 1 -idle-timeout 180 -initial-env RT_SITE_CONFIG=%%RT_SITE_CONFIG%% +FastCgiServer %%RT_SBIN_PATH%%/rt-server.fcgi \ + -socket %%TMP_DIR%%/socket \ + -processes 1 \ + -idle-timeout 180 \ + -initial-env RT_SITE_CONFIG=%%RT_SITE_CONFIG%% \ + -initial-env RT_TESTING=1 Alias /NoAuth/images/ %%DOCUMENT_ROOT%%/NoAuth/images/ -ScriptAlias / %%RT_BIN_PATH%%/mason_handler.fcgi/ +ScriptAlias / %%RT_SBIN_PATH%%/rt-server.fcgi/ DocumentRoot "%%DOCUMENT_ROOT%%" <Location /> Order allow,deny Allow from all +%%BASIC_AUTH%% + Options +ExecCGI AddHandler fastcgi-script fcgi </Location> diff --git a/rt/t/data/configs/apache2.2+mod_perl.conf b/rt/t/data/configs/apache2.2+mod_perl.conf index d1a6e9f15..a50e5b342 100644 --- a/rt/t/data/configs/apache2.2+mod_perl.conf +++ b/rt/t/data/configs/apache2.2+mod_perl.conf @@ -1,3 +1,21 @@ +<IfModule mpm_prefork_module> + StartServers 1 + MinSpareServers 1 + MaxSpareServers 1 + MaxClients 1 + MaxRequestsPerChild 0 +</IfModule> + +<IfModule mpm_worker_module> + StartServers 1 + MinSpareThreads 1 + MaxSpareThreads 1 + ThreadLimit 1 + ThreadsPerChild 1 + MaxClients 1 + MaxRequestsPerChild 0 +</IfModule> + ServerRoot %%SERVER_ROOT%% PidFile %%PID_FILE%% LockFile %%LOCK_FILE%% @@ -7,8 +25,8 @@ ServerAdmin root@localhost <IfModule !mpm_netware_module> <IfModule !mpm_winnt_module> -User www-data -Group www-data +User freeside +Group freeside </IfModule> </IfModule> @@ -26,16 +44,23 @@ LogLevel debug AddDefaultCharset UTF-8 PerlSetEnv RT_SITE_CONFIG %%RT_SITE_CONFIG%% -PerlRequire %%RT_BIN_PATH%%/webmux.pl - -RedirectMatch permanent (.*)/$ $1/index.html DocumentRoot "%%DOCUMENT_ROOT%%" -<Directory "%%DOCUMENT_ROOT%%"> +<Location /> Order allow,deny Allow from all - SetHandler perl-script - PerlResponseHandler RT::Mason -</Directory> +%%BASIC_AUTH%% + + SetHandler modperl + + PerlResponseHandler Plack::Handler::Apache2 + PerlSetVar psgi_app %%RT_SBIN_PATH%%/rt-server +</Location> + +<Perl> + $ENV{RT_TESTING}=1; + use Plack::Handler::Apache2; + Plack::Handler::Apache2->preload("%%RT_SBIN_PATH%%/rt-server"); +</Perl> diff --git a/rt/t/data/configs/apache2.2+mod_perl.conf.in b/rt/t/data/configs/apache2.2+mod_perl.conf.in index 3d28c2cca..3b1f3f618 100644 --- a/rt/t/data/configs/apache2.2+mod_perl.conf.in +++ b/rt/t/data/configs/apache2.2+mod_perl.conf.in @@ -1,3 +1,21 @@ +<IfModule mpm_prefork_module> + StartServers 1 + MinSpareServers 1 + MaxSpareServers 1 + MaxClients 1 + MaxRequestsPerChild 0 +</IfModule> + +<IfModule mpm_worker_module> + StartServers 1 + MinSpareThreads 1 + MaxSpareThreads 1 + ThreadLimit 1 + ThreadsPerChild 1 + MaxClients 1 + MaxRequestsPerChild 0 +</IfModule> + ServerRoot %%SERVER_ROOT%% PidFile %%PID_FILE%% LockFile %%LOCK_FILE%% @@ -26,16 +44,23 @@ LogLevel debug AddDefaultCharset UTF-8 PerlSetEnv RT_SITE_CONFIG %%RT_SITE_CONFIG%% -PerlRequire %%RT_BIN_PATH%%/webmux.pl - -RedirectMatch permanent (.*)/$ $1/index.html DocumentRoot "%%DOCUMENT_ROOT%%" -<Directory "%%DOCUMENT_ROOT%%"> +<Location /> Order allow,deny Allow from all - SetHandler perl-script - PerlResponseHandler RT::Mason -</Directory> +%%BASIC_AUTH%% + + SetHandler modperl + + PerlResponseHandler Plack::Handler::Apache2 + PerlSetVar psgi_app %%RT_SBIN_PATH%%/rt-server +</Location> + +<Perl> + $ENV{RT_TESTING}=1; + use Plack::Handler::Apache2; + Plack::Handler::Apache2->preload("%%RT_SBIN_PATH%%/rt-server"); +</Perl> diff --git a/rt/t/data/gnupg/emails/10-encrypted-inline-plain.txt b/rt/t/data/gnupg/emails/10-encrypted-inline-plain.txt index 93cc19516..4f3e151c3 100644 --- a/rt/t/data/gnupg/emails/10-encrypted-inline-plain.txt +++ b/rt/t/data/gnupg/emails/10-encrypted-inline-plain.txt @@ -8,7 +8,7 @@ MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; x-action=pgp-encrypted Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) -From: ternus@mit.edu (Christian Ternus) +From: rt-test@example.com -----BEGIN PGP MESSAGE----- Version: GnuPG v1.4.6 (GNU/Linux) diff --git a/rt/t/data/gnupg/emails/11-encrypted-inline-attachment.txt b/rt/t/data/gnupg/emails/11-encrypted-inline-attachment.txt index e3695f776..892433c41 100644 --- a/rt/t/data/gnupg/emails/11-encrypted-inline-attachment.txt +++ b/rt/t/data/gnupg/emails/11-encrypted-inline-attachment.txt @@ -1,6 +1,6 @@ Message-ID: <46BCDCA0.4000205@mit.edu> Date: Fri, 10 Aug 2007 17:46:08 -0400 -From: Christian Ternus <ternus@mit.edu> +From: rt-test@example.com User-Agent: Thunderbird 1.5.0.12 (X11/20070604) MIME-Version: 1.0 To: rt-recipient@example.com diff --git a/rt/t/data/gnupg/emails/12-encrypted-inline-binary.txt b/rt/t/data/gnupg/emails/12-encrypted-inline-binary.txt index e07163bcc..5c646ec79 100644 --- a/rt/t/data/gnupg/emails/12-encrypted-inline-binary.txt +++ b/rt/t/data/gnupg/emails/12-encrypted-inline-binary.txt @@ -1,6 +1,6 @@ Message-ID: <46BCDCF2.3080704@mit.edu> Date: Fri, 10 Aug 2007 17:47:30 -0400 -From: Christian Ternus <ternus@mit.edu> +From: rt-test@example.com User-Agent: Thunderbird 1.5.0.12 (X11/20070604) MIME-Version: 1.0 To: rt-recipient@example.com diff --git a/rt/t/data/gnupg/emails/13-signed-encrypted-MIME-plain.txt b/rt/t/data/gnupg/emails/13-signed-encrypted-MIME-plain.txt index f0bd624a2..a09ccec4c 100644 --- a/rt/t/data/gnupg/emails/13-signed-encrypted-MIME-plain.txt +++ b/rt/t/data/gnupg/emails/13-signed-encrypted-MIME-plain.txt @@ -9,7 +9,7 @@ Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; boundary="+nBD6E3TurpgldQp" Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) -From: ternus@mit.edu (Christian Ternus) +From: rt-test@example.com --+nBD6E3TurpgldQp diff --git a/rt/t/data/gnupg/emails/14-signed-encrypted-MIME-attachment.txt b/rt/t/data/gnupg/emails/14-signed-encrypted-MIME-attachment.txt index 8a70384a2..e6d23ea96 100644 --- a/rt/t/data/gnupg/emails/14-signed-encrypted-MIME-attachment.txt +++ b/rt/t/data/gnupg/emails/14-signed-encrypted-MIME-attachment.txt @@ -9,7 +9,7 @@ Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; boundary="N1GIdlSm9i+YlY4t" Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) -From: ternus@mit.edu (Christian Ternus) +From: rt-test@example.com --N1GIdlSm9i+YlY4t diff --git a/rt/t/data/gnupg/emails/15-signed-encrypted-MIME-binary.txt b/rt/t/data/gnupg/emails/15-signed-encrypted-MIME-binary.txt index 55f69a19d..58049e1f2 100644 --- a/rt/t/data/gnupg/emails/15-signed-encrypted-MIME-binary.txt +++ b/rt/t/data/gnupg/emails/15-signed-encrypted-MIME-binary.txt @@ -9,7 +9,7 @@ Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; boundary="QWpDgw58+k1mSFBj" Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) -From: ternus@mit.edu (Christian Ternus) +From: rt-test@example.com --QWpDgw58+k1mSFBj diff --git a/rt/t/data/gnupg/emails/16-signed-encrypted-inline-plain.txt b/rt/t/data/gnupg/emails/16-signed-encrypted-inline-plain.txt index 5686a12bf..84e49caf2 100644 --- a/rt/t/data/gnupg/emails/16-signed-encrypted-inline-plain.txt +++ b/rt/t/data/gnupg/emails/16-signed-encrypted-inline-plain.txt @@ -8,7 +8,7 @@ MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; x-action=pgp-encrypted Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) -From: ternus@mit.edu (Christian Ternus) +From: rt-test@example.com -----BEGIN PGP MESSAGE----- Version: GnuPG v1.4.6 (GNU/Linux) diff --git a/rt/t/data/gnupg/emails/18-signed-encrypted-inline-binary.txt b/rt/t/data/gnupg/emails/18-signed-encrypted-inline-binary.txt index 315ba5898..61e11e22c 100644 --- a/rt/t/data/gnupg/emails/18-signed-encrypted-inline-binary.txt +++ b/rt/t/data/gnupg/emails/18-signed-encrypted-inline-binary.txt @@ -1,6 +1,6 @@ Message-ID: <46BCDC0C.6090400@mit.edu> Date: Fri, 10 Aug 2007 17:43:40 -0400 -From: Christian Ternus <ternus@mit.edu> +From: rt-test@example.com User-Agent: Thunderbird 1.5.0.12 (X11/20070604) MIME-Version: 1.0 To: rt-recipient@example.com diff --git a/rt/t/data/gnupg/emails/19-signed-inline-plain-nested.txt b/rt/t/data/gnupg/emails/19-signed-inline-plain-nested.txt index eb763bdc1..6ed683d07 100644 --- a/rt/t/data/gnupg/emails/19-signed-inline-plain-nested.txt +++ b/rt/t/data/gnupg/emails/19-signed-inline-plain-nested.txt @@ -8,7 +8,7 @@ MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; x-action=pgp-signed Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) -From: ternus@mit.edu (Christian Ternus) +From: rt-test@example.com -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 diff --git a/rt/t/data/gnupg/emails/2-signed-MIME-plain-with-attachment.txt b/rt/t/data/gnupg/emails/2-signed-MIME-plain-with-attachment.txt index 851549c02..c658e6b69 100755 --- a/rt/t/data/gnupg/emails/2-signed-MIME-plain-with-attachment.txt +++ b/rt/t/data/gnupg/emails/2-signed-MIME-plain-with-attachment.txt @@ -9,7 +9,7 @@ Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="bKyqfOwhbdpXa4YI" Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) -From: ternus@mit.edu (Christian Ternus) +From: rt-test@example.com --bKyqfOwhbdpXa4YI diff --git a/rt/t/data/gnupg/emails/3-signed-MIME-plain-with-binary.txt b/rt/t/data/gnupg/emails/3-signed-MIME-plain-with-binary.txt index 82ef7e9f3..ed8e392b4 100755 --- a/rt/t/data/gnupg/emails/3-signed-MIME-plain-with-binary.txt +++ b/rt/t/data/gnupg/emails/3-signed-MIME-plain-with-binary.txt @@ -9,7 +9,7 @@ Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="pY3vCvL1qV+PayAL" Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) -From: ternus@mit.edu (Christian Ternus) +From: rt-test@example.com --pY3vCvL1qV+PayAL diff --git a/rt/t/data/gnupg/emails/4-signed-inline-plain.txt b/rt/t/data/gnupg/emails/4-signed-inline-plain.txt index 1dcecaedb..9240d81b0 100644 --- a/rt/t/data/gnupg/emails/4-signed-inline-plain.txt +++ b/rt/t/data/gnupg/emails/4-signed-inline-plain.txt @@ -8,7 +8,7 @@ MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; x-action=pgp-signed Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) -From: ternus@mit.edu (Christian Ternus) +From: rt-test@example.com -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 diff --git a/rt/t/data/gnupg/emails/5-signed-inline-with-attachment.txt b/rt/t/data/gnupg/emails/5-signed-inline-with-attachment.txt index 638f0fda5..763f97138 100644 --- a/rt/t/data/gnupg/emails/5-signed-inline-with-attachment.txt +++ b/rt/t/data/gnupg/emails/5-signed-inline-with-attachment.txt @@ -1,6 +1,6 @@ Message-ID: <46BCDA81.3030308@mit.edu> Date: Fri, 10 Aug 2007 17:37:05 -0400 -From: Christian Ternus <ternus@mit.edu> +From: rt-test@example.com User-Agent: Thunderbird 1.5.0.12 (X11/20070604) MIME-Version: 1.0 To: rt-recipient@example.com diff --git a/rt/t/data/gnupg/emails/6-signed-inline-with-binary.txt b/rt/t/data/gnupg/emails/6-signed-inline-with-binary.txt index 2c725aa58..d0251ccc7 100644 --- a/rt/t/data/gnupg/emails/6-signed-inline-with-binary.txt +++ b/rt/t/data/gnupg/emails/6-signed-inline-with-binary.txt @@ -1,6 +1,6 @@ Message-ID: <46BCDAE6.4090803@mit.edu> Date: Fri, 10 Aug 2007 17:38:46 -0400 -From: Christian Ternus <ternus@mit.edu> +From: rt-test@example.com User-Agent: Thunderbird 1.5.0.12 (X11/20070604) MIME-Version: 1.0 To: rt-recipient@example.com diff --git a/rt/t/data/gnupg/emails/7-encrypted-MIME-plain.txt b/rt/t/data/gnupg/emails/7-encrypted-MIME-plain.txt index 11e3b7cda..cabed5314 100644 --- a/rt/t/data/gnupg/emails/7-encrypted-MIME-plain.txt +++ b/rt/t/data/gnupg/emails/7-encrypted-MIME-plain.txt @@ -9,7 +9,7 @@ Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; boundary="YiEDa0DAkWCtVeE4" Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) -From: ternus@mit.edu (Christian Ternus) +From: rt-test@example.com --YiEDa0DAkWCtVeE4 diff --git a/rt/t/data/gnupg/emails/8-encrypted-MIME-with-attachment.txt b/rt/t/data/gnupg/emails/8-encrypted-MIME-with-attachment.txt index 3781a62e1..c28eb9843 100644 --- a/rt/t/data/gnupg/emails/8-encrypted-MIME-with-attachment.txt +++ b/rt/t/data/gnupg/emails/8-encrypted-MIME-with-attachment.txt @@ -9,7 +9,7 @@ Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; boundary="FFoLq8A0u+X9iRU8" Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) -From: ternus@mit.edu (Christian Ternus) +From: rt-test@example.com --FFoLq8A0u+X9iRU8 diff --git a/rt/t/data/gnupg/emails/9-encrypted-MIME-with-binary.txt b/rt/t/data/gnupg/emails/9-encrypted-MIME-with-binary.txt index cafc88077..1cc8f0696 100644 --- a/rt/t/data/gnupg/emails/9-encrypted-MIME-with-binary.txt +++ b/rt/t/data/gnupg/emails/9-encrypted-MIME-with-binary.txt @@ -9,7 +9,7 @@ Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; boundary="GID0FwUMdk1T2AWN" Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) -From: ternus@mit.edu (Christian Ternus) +From: rt-test@example.com --GID0FwUMdk1T2AWN diff --git a/rt/t/data/gnupg/emails/special/quoted_inline_signature.txt b/rt/t/data/gnupg/emails/special/quoted_inline_signature.txt index 131d27adc..af67b7e09 100644 --- a/rt/t/data/gnupg/emails/special/quoted_inline_signature.txt +++ b/rt/t/data/gnupg/emails/special/quoted_inline_signature.txt @@ -3,7 +3,7 @@ Subject: Test Email ID:4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline -From: root@localhost +From: rt-test@example.com Forwarded email with signature quoted. RT shouldn't bother about it. diff --git a/rt/t/delegation/cleanup_stalled.t b/rt/t/delegation/cleanup_stalled.t deleted file mode 100644 index f108eccf2..000000000 --- a/rt/t/delegation/cleanup_stalled.t +++ /dev/null @@ -1,458 +0,0 @@ -#!/usr/bin/perl -w -use strict; -use warnings; - -# Regression test suite for http://rt3.fsck.com/Ticket/Display.html?id=6184 -# and related corner cases related to cleanup of delegated ACEs when -# the delegator loses the right to delegate. This causes complexities -# due to the fact that multiple ACEs can grant different delegation -# rights to a principal, and because DelegateRights and SuperUser can -# themselves be delegated. - -# The case where the "parent" delegated ACE is removed is handled in -# the embedded regression tests in lib/RT/ACE_Overlay.pm . - - -use RT; - -use RT::Test tests => 98; - -my ($u1, $u2, $g1, $g2, $g3, $pg1, $pg2, $ace, @groups, @users, @principals); -@groups = (\$g1, \$g2, \$g3, \$pg1, \$pg2); -@users = (\$u1, \$u2); -@principals = (@groups, @users); - -my($ret, $msg); - -$u1 = RT::User->new($RT::SystemUser); -( $ret, $msg ) = $u1->LoadOrCreateByEmail('delegtest1@example.com'); -ok( $ret, "Load / Create test user 1: $msg" ); -$u1->SetPrivileged(1); -$u2 = RT::User->new($RT::SystemUser); -( $ret, $msg ) = $u2->LoadOrCreateByEmail('delegtest2@example.com'); -ok( $ret, "Load / Create test user 2: $msg" ); -$u2->SetPrivileged(1); -$g1 = RT::Group->new($RT::SystemUser); -( $ret, $msg) = $g1->LoadUserDefinedGroup('dg1'); -unless ($ret) { - ( $ret, $msg ) = $g1->CreateUserDefinedGroup( Name => 'dg1' ); -} -ok( $ret, "Load / Create test group 1: $msg" ); -$g2 = RT::Group->new($RT::SystemUser); -( $ret, $msg) = $g2->LoadUserDefinedGroup('dg2'); -unless ($ret) { - ( $ret, $msg ) = $g2->CreateUserDefinedGroup( Name => 'dg2' ); -} -ok( $ret, "Load / Create test group 2: $msg" ); -$g3 = RT::Group->new($RT::SystemUser); -( $ret, $msg) = $g3->LoadUserDefinedGroup('dg3'); -unless ($ret) { - ( $ret, $msg ) = $g3->CreateUserDefinedGroup( Name => 'dg3' ); -} -ok( $ret, "Load / Create test group 3: $msg" ); -$pg1 = RT::Group->new($RT::SystemUser); -( $ret, $msg ) = $pg1->LoadPersonalGroup( Name => 'dpg1', - User => $u1->PrincipalId ); -unless ($ret) { - ( $ret, $msg ) = $pg1->CreatePersonalGroup( Name => 'dpg1', - PrincipalId => $u1->PrincipalId ); -} -ok( $ret, "Load / Create test personal group 1: $msg" ); -$pg2 = RT::Group->new($RT::SystemUser); -( $ret, $msg ) = $pg2->LoadPersonalGroup( Name => 'dpg2', - User => $u2->PrincipalId ); -unless ($ret) { - ( $ret, $msg ) = $pg2->CreatePersonalGroup( Name => 'dpg2', - PrincipalId => $u2->PrincipalId ); -} -ok( $ret, "Load / Create test personal group 2: $msg" ); - - - -# Basic case: u has global DelegateRights through g1 and ShowConfigTab -# through g2; then u is removed from g1. - -clear_acls_and_groups(); - -( $ret, $msg ) = $g1->PrincipalObj->GrantRight( Right => 'DelegateRights' ); -ok( $ret, "Grant DelegateRights to g1: $msg" ); -( $ret, $msg ) = $g2->PrincipalObj->GrantRight( Right => 'ShowConfigTab' ); -ok( $ret, "Grant ShowConfigTab to g2: $msg" ); -( $ret, $msg ) = $g1->AddMember( $u1->PrincipalId ); -ok( $ret, "Add test user 1 to g1: $msg" ); -ok( - $u1->PrincipalObj->HasRight( - Right => 'DelegateRights', - Object => $RT::System - ), - "test user 1 has DelegateRights after joining g1" -); -( $ret, $msg ) = $g2->AddMember( $u1->PrincipalId ); -ok( $ret, "Add test user 1 to g2: $msg" ); -ok( - $u1->PrincipalObj->HasRight( - Right => 'ShowConfigTab', - Object => $RT::System - ), - "test user 1 has ShowConfigTab after joining g2" -); - -$ace = RT::ACE->new($u1); -( $ret, $msg ) = $ace->LoadByValues( - RightName => 'ShowConfigTab', - Object => $RT::System, - PrincipalType => 'Group', - PrincipalId => $g2->PrincipalId -); -ok( $ret, "Look up ACE to be delegated: $msg" ); -( $ret, $msg ) = $ace->Delegate( PrincipalId => $pg1->PrincipalId ); -ok( $ret, "Delegate ShowConfigTab to pg1: $msg" ); -ok( - $pg1->PrincipalObj->HasRight( - Right => 'ShowConfigTab', - Object => $RT::System - ), - "Test personal group 1 has ShowConfigTab right after delegation" -); - -( $ret, $msg ) = $g1->DeleteMember( $u1->PrincipalId ); -ok( $ret, "Delete test user 1 from g1: $msg" ); -ok( - not( - $pg1->PrincipalObj->HasRight( - Right => 'ShowConfigTab', - Object => $RT::System - ) - ), - "Test personal group 1 lacks ShowConfigTab right after user removed from g1" -); - -# Basic case: u has global DelegateRights through g1 and ShowConfigTab -# through g2; then DelegateRights revoked from g1. - -( $ret, $msg ) = $g1->AddMember( $u1->PrincipalId ); -ok( $ret, "Add test user 1 to g1: $msg" ); -( $ret, $msg ) = $ace->Delegate( PrincipalId => $pg1->PrincipalId ); -ok( $ret, "Delegate ShowConfigTab to pg1: $msg" ); -( $ret, $msg ) = $g1->PrincipalObj->RevokeRight( Right => 'DelegateRights' ); -ok( $ret, "Revoke DelegateRights from g1: $msg" ); -ok( - not( - $pg1->PrincipalObj->HasRight( - Right => 'ShowConfigTab', - Object => $RT::System - ) - ), - "Test personal group 1 lacks ShowConfigTab right after DelegateRights revoked from g1" -); - - - -# Corner case - restricted delegation: u has DelegateRights on pg1 -# through g1 and AdminGroup on pg1 through g2; then DelegateRights -# revoked from g1. - -clear_acls_and_groups(); - -( $ret, $msg ) = $g1->PrincipalObj->GrantRight( Right => 'DelegateRights', - Object => $pg1); -ok( $ret, "Grant DelegateRights on pg1 to g1: $msg" ); -( $ret, $msg ) = $g2->PrincipalObj->GrantRight( Right => 'AdminGroup', - Object => $pg1); -ok( $ret, "Grant AdminGroup on pg1 to g2: $msg" ); -( $ret, $msg ) = $g1->AddMember( $u1->PrincipalId ); -ok( $ret, "Add test user 1 to g1: $msg" ); -( $ret, $msg ) = $g2->AddMember( $u1->PrincipalId ); -ok( $ret, "Add test user 1 to g2: $msg" ); -ok( $u1->PrincipalObj->HasRight( - Right => 'DelegateRights', - Object => $pg1 ), - "test user 1 has DelegateRights on pg1 after joining g1" ); -ok( not( $u1->PrincipalObj->HasRight( - Right => 'DelegateRights', - Object => $RT::System )), - "Test personal group 1 lacks global DelegateRights after joining g1" ); -$ace = RT::ACE->new($u1); -( $ret, $msg ) = $ace->LoadByValues( - RightName => 'AdminGroup', - Object => $pg1, - PrincipalType => 'Group', - PrincipalId => $g2->PrincipalId -); -ok( $ret, "Look up ACE to be delegated: $msg" ); -( $ret, $msg ) = $ace->Delegate( PrincipalId => $pg1->PrincipalId ); -ok( $ret, "Delegate AdminGroup on pg1 to pg1: $msg" ); -ok( $pg1->PrincipalObj->HasRight( - Right => 'AdminGroup', - Object => $pg1 ), - "Test personal group 1 has AdminGroup right on pg1 after delegation" ); -( $ret, $msg ) = $g1->PrincipalObj->RevokeRight ( Right => 'DelegateRights', - Object => $pg1 ); -ok( $ret, "Revoke DelegateRights on pg1 from g1: $msg" ); -ok( not( $pg1->PrincipalObj->HasRight( - Right => 'AdminGroup', - Object => $pg1 )), - "Test personal group 1 lacks AdminGroup right on pg1 after DelegateRights revoked from g1" ); -( $ret, $msg ) = $g1->PrincipalObj->GrantRight( Right => 'DelegateRights', - Object => $pg1); - -# Corner case - restricted delegation: u has DelegateRights on pg1 -# through g1 and AdminGroup on pg1 through g2; then u removed from g1. - -ok( $ret, "Grant DelegateRights on pg1 to g1: $msg" ); -( $ret, $msg ) = $ace->Delegate( PrincipalId => $pg1->PrincipalId ); -ok( $ret, "Delegate AdminGroup on pg1 to pg1: $msg" ); -ok( $pg1->PrincipalObj->HasRight( - Right => 'AdminGroup', - Object => $pg1 ), - "Test personal group 1 has AdminGroup right on pg1 after delegation" ); -( $ret, $msg ) = $g1->DeleteMember( $u1->PrincipalId ); -ok( $ret, "Delete test user 1 from g1: $msg" ); -ok( not( $pg1->PrincipalObj->HasRight( - Right => 'AdminGroup', - Object => $pg1 )), - "Test personal group 1 lacks AdminGroup right on pg1 after user removed from g1" ); - -clear_acls_and_groups(); - - - -# Corner case - multiple delegation rights: u has global -# DelegateRights directly and DelegateRights on pg1 through g1, and -# AdminGroup on pg1 through g2; then u removed from g1 (delegation -# should remain); then DelegateRights revoked from u (delegation -# should not remain). - -( $ret, $msg ) = $g1->PrincipalObj->GrantRight( Right => 'DelegateRights', - Object => $pg1); -ok( $ret, "Grant DelegateRights on pg1 to g1: $msg" ); -( $ret, $msg ) = $g2->PrincipalObj->GrantRight( Right => 'AdminGroup', - Object => $pg1); -ok( $ret, "Grant AdminGroup on pg1 to g2: $msg" ); -( $ret, $msg ) = $u1->PrincipalObj->GrantRight( Right => 'DelegateRights', - Object => $RT::System); -ok( $ret, "Grant DelegateRights to user: $msg" ); -( $ret, $msg ) = $g1->AddMember( $u1->PrincipalId ); -ok( $ret, "Add test user 1 to g1: $msg" ); -( $ret, $msg ) = $g2->AddMember( $u1->PrincipalId ); -ok( $ret, "Add test user 1 to g2: $msg" ); -$ace = RT::ACE->new($u1); -( $ret, $msg ) = $ace->LoadByValues( - RightName => 'AdminGroup', - Object => $pg1, - PrincipalType => 'Group', - PrincipalId => $g2->PrincipalId -); -ok( $ret, "Look up ACE to be delegated: $msg" ); -( $ret, $msg ) = $ace->Delegate( PrincipalId => $pg1->PrincipalId ); -ok( $ret, "Delegate AdminGroup on pg1 to pg1: $msg" ); -( $ret, $msg ) = $g1->DeleteMember( $u1->PrincipalId ); -ok( $ret, "Delete test user 1 from g1: $msg" ); -ok( $pg1->PrincipalObj->HasRight(Right => 'AdminGroup', - Object => $pg1), - "Test personal group 1 retains AdminGroup right on pg1 after user removed from g1" ); -( $ret, $msg ) = $u1->PrincipalObj->RevokeRight( Right => 'DelegateRights', - Object => $RT::System ); -ok( not ($pg1->PrincipalObj->HasRight(Right => 'AdminGroup', - Object => $pg1)), - "Test personal group 1 lacks AdminGroup right on pg1 after DelegateRights revoked"); - -# Corner case - multiple delegation rights and selectivity: u has -# DelegateRights globally and on g2 directly and DelegateRights on pg1 -# through g1, and AdminGroup on pg1 through g2; then global -# DelegateRights revoked from u (delegation should remain), -# DelegateRights on g2 revoked from u (delegation should remain), and -# u removed from g1 (delegation should not remain). - -( $ret, $msg ) = $g1->AddMember( $u1->PrincipalId ); -ok( $ret, "Add test user 1 to g1: $msg" ); -( $ret, $msg ) = $u1->PrincipalObj->GrantRight( Right => 'DelegateRights', - Object => $RT::System); -ok( $ret, "Grant DelegateRights to user: $msg" ); -( $ret, $msg ) = $u1->PrincipalObj->GrantRight( Right => 'DelegateRights', - Object => $g2); -ok( $ret, "Grant DelegateRights on g2 to user: $msg" ); -( $ret, $msg ) = $ace->Delegate( PrincipalId => $pg1->PrincipalId ); -ok( $ret, "Delegate AdminGroup on pg1 to pg1: $msg" ); -( $ret, $msg ) = $u1->PrincipalObj->RevokeRight( Right => 'DelegateRights', - Object => $RT::System ); -ok( $pg1->PrincipalObj->HasRight(Right => 'AdminGroup', - Object => $pg1), - "Test personal group 1 retains AdminGroup right on pg1 after global DelegateRights revoked" ); -( $ret, $msg ) = $u1->PrincipalObj->RevokeRight( Right => 'DelegateRights', - Object => $g2 ); -ok( $pg1->PrincipalObj->HasRight(Right => 'AdminGroup', - Object => $pg1), - "Test personal group 1 retains AdminGroup right on pg1 after DelegateRights on g2 revoked" ); -( $ret, $msg ) = $g1->DeleteMember( $u1->PrincipalId ); -ok( $ret, "Delete test user 1 from g1: $msg" ); -ok( not ($pg1->PrincipalObj->HasRight(Right => 'AdminGroup', - Object => $pg1)), - "Test personal group 1 lacks AdminGroup right on pg1 after user removed from g1"); - - - -# Corner case - indirect delegation rights: u has DelegateRights -# through g1 via g3, and ShowConfigTab via g2; then g3 removed from -# g1. - -clear_acls_and_groups(); - -( $ret, $msg ) = $g1->PrincipalObj->GrantRight( Right => 'DelegateRights' ); -ok( $ret, "Grant DelegateRights to g1: $msg" ); -( $ret, $msg ) = $g2->PrincipalObj->GrantRight( Right => 'ShowConfigTab' ); -ok( $ret, "Grant ShowConfigTab to g2: $msg" ); -( $ret, $msg ) = $g1->AddMember( $g3->PrincipalId ); -ok( $ret, "Add g3 to g1: $msg" ); -( $ret, $msg ) = $g3->AddMember( $u1->PrincipalId ); -ok( $ret, "Add test user 1 to g3: $msg" ); -( $ret, $msg ) = $g2->AddMember( $u1->PrincipalId ); -ok( $ret, "Add test user 1 to g2: $msg" ); - -$ace = RT::ACE->new($u1); -( $ret, $msg ) = $ace->LoadByValues( - RightName => 'ShowConfigTab', - Object => $RT::System, - PrincipalType => 'Group', - PrincipalId => $g2->PrincipalId -); -ok( $ret, "Look up ACE to be delegated: $msg" ); -( $ret, $msg ) = $ace->Delegate( PrincipalId => $pg1->PrincipalId ); -ok( $ret, "Delegate ShowConfigTab to pg1: $msg" ); - -( $ret, $msg ) = $g1->DeleteMember( $g3->PrincipalId ); -ok( $ret, "Delete g3 from g1: $msg" ); -ok( not ($pg1->PrincipalObj->HasRight(Right => 'ShowConfigTab', - Object => $RT::System)), - "Test personal group 1 lacks ShowConfigTab right after g3 removed from g1"); - -# Corner case - indirect delegation rights: u has DelegateRights -# through g1 via g3, and ShowConfigTab via g2; then DelegateRights -# revoked from g1. - -( $ret, $msg ) = $g1->AddMember( $g3->PrincipalId ); -ok( $ret, "Add g3 to g1: $msg" ); -( $ret, $msg ) = $ace->Delegate( PrincipalId => $pg1->PrincipalId ); -ok( $ret, "Delegate ShowConfigTab to pg1: $msg" ); -( $ret, $msg ) = $g1->PrincipalObj->RevokeRight ( Right => 'DelegateRights' ); -ok( $ret, "Revoke DelegateRights from g1: $msg" ); - -ok( not ($pg1->PrincipalObj->HasRight(Right => 'ShowConfigTab', - Object => $RT::System)), - "Test personal group 1 lacks ShowConfigTab right after DelegateRights revoked from g1"); - - - -# Corner case - delegation of DelegateRights: u1 has DelegateRights -# via g1 and delegates DelegateRights to pg1; u2 has DelegateRights -# via pg1 and ShowConfigTab via g2; then u1 removed from g1. - -clear_acls_and_groups(); - -( $ret, $msg ) = $g1->PrincipalObj->GrantRight( Right => 'DelegateRights' ); -ok( $ret, "Grant DelegateRights to g1: $msg" ); -( $ret, $msg ) = $g2->PrincipalObj->GrantRight( Right => 'ShowConfigTab' ); -ok( $ret, "Grant ShowConfigTab to g2: $msg" ); -( $ret, $msg ) = $g1->AddMember( $u1->PrincipalId ); -ok( $ret, "Add test user 1 to g1: $msg" ); -$ace = RT::ACE->new($u1); -( $ret, $msg ) = $ace->LoadByValues( - RightName => 'DelegateRights', - Object => $RT::System, - PrincipalType => 'Group', - PrincipalId => $g1->PrincipalId -); -ok( $ret, "Look up ACE to be delegated: $msg" ); -( $ret, $msg ) = $ace->Delegate( PrincipalId => $pg1->PrincipalId ); -ok( $ret, "Delegate DelegateRights to pg1: $msg" ); - -( $ret, $msg ) = $pg1->AddMember( $u2->PrincipalId ); -ok( $ret, "Add test user 2 to pg1: $msg" ); -( $ret, $msg ) = $g2->AddMember( $u2->PrincipalId ); -ok( $ret, "Add test user 2 to g2: $msg" ); -$ace = RT::ACE->new($u2); -( $ret, $msg ) = $ace->LoadByValues( - RightName => 'ShowConfigTab', - Object => $RT::System, - PrincipalType => 'Group', - PrincipalId => $g2->PrincipalId -); -ok( $ret, "Look up ACE to be delegated: $msg" ); -( $ret, $msg ) = $ace->Delegate( PrincipalId => $pg2->PrincipalId ); -ok( $ret, "Delegate ShowConfigTab to pg2: $msg" ); - -ok( $pg2->PrincipalObj->HasRight(Right => 'ShowConfigTab', - Object => $RT::System), - "Test personal group 2 has ShowConfigTab right after delegation"); -( $ret, $msg ) = $g1->DeleteMember( $u1->PrincipalId ); -ok( $ret, "Delete u1 from g1: $msg" ); -ok( not ($pg2->PrincipalObj->HasRight(Right => 'ShowConfigTab', - Object => $RT::System)), - "Test personal group 2 lacks ShowConfigTab right after u1 removed from g1"); - -# Corner case - delegation of DelegateRights: u1 has DelegateRights -# via g1 and delegates DelegateRights to pg1; u2 has DelegateRights -# via pg1 and ShowConfigTab via g2; then DelegateRights revoked from -# g1. - -( $ret, $msg ) = $g1->AddMember( $u1->PrincipalId ); -ok( $ret, "Add u1 to g1: $msg" ); -$ace = RT::ACE->new($u1); -( $ret, $msg ) = $ace->LoadByValues( - RightName => 'DelegateRights', - Object => $RT::System, - PrincipalType => 'Group', - PrincipalId => $g1->PrincipalId -); -ok( $ret, "Look up ACE to be delegated: $msg" ); -( $ret, $msg ) = $ace->Delegate( PrincipalId => $pg1->PrincipalId ); -ok( $ret, "Delegate DelegateRights to pg1: $msg" ); -$ace = RT::ACE->new($u2); -( $ret, $msg ) = $ace->LoadByValues( - RightName => 'ShowConfigTab', - Object => $RT::System, - PrincipalType => 'Group', - PrincipalId => $g2->PrincipalId -); -ok( $ret, "Look up ACE to be delegated: $msg" ); -( $ret, $msg ) = $ace->Delegate( PrincipalId => $pg2->PrincipalId ); -ok( $ret, "Delegate ShowConfigTab to pg2: $msg" ); - -( $ret, $msg ) = $g1->PrincipalObj->RevokeRight ( Right => 'DelegateRights' ); -ok( $ret, "Revoke DelegateRights from g1: $msg" ); -ok( not ($pg2->PrincipalObj->HasRight(Right => 'ShowConfigTab', - Object => $RT::System)), - "Test personal group 2 lacks ShowConfigTab right after DelegateRights revoked from g1"); - - - - -####### - -sub clear_acls_and_groups { - # Revoke all rights granted to our cast - my $acl = RT::ACL->new($RT::SystemUser); - foreach (@principals) { - $acl->LimitToPrincipal(Type => $$_->PrincipalObj->PrincipalType, - Id => $$_->PrincipalObj->Id); - } - while (my $ace = $acl->Next()) { - $ace->Delete(); - } - - # Remove all group memberships - my $members = RT::GroupMembers->new($RT::SystemUser); - foreach (@groups) { - $members->LimitToMembersOfGroup( $$_->PrincipalId ); - } - while (my $member = $members->Next()) { - $member->Delete(); - } - - $acl->RedoSearch(); - is( $acl->Count() , 0, - "All principals have no rights after clearing ACLs" ); - $members->RedoSearch(); - is( $members->Count() , 0, - "All groups have no members after clearing groups" ); -} diff --git a/rt/t/delegation/revocation.t b/rt/t/delegation/revocation.t deleted file mode 100644 index 151525edf..000000000 --- a/rt/t/delegation/revocation.t +++ /dev/null @@ -1,135 +0,0 @@ -#!/usr/bin/perl -w - -use strict; -use warnings; - -use RT; - -use RT::Test tests => 22; - -my ($u1, $g1, $pg1, $pg2, $ace, @groups, @users, @principals); -@groups = (\$g1, \$pg1, \$pg2); -@users = (\$u1); -@principals = (@groups, @users); - -my($ret, $msg); - -$u1 = RT::User->new($RT::SystemUser); -( $ret, $msg ) = $u1->LoadOrCreateByEmail('delegtest1@example.com'); -ok( $ret, "Load / Create test user 1: $msg" ); -$u1->SetPrivileged(1); - -$g1 = RT::Group->new($RT::SystemUser); -( $ret, $msg) = $g1->LoadUserDefinedGroup('dg1'); -unless ($ret) { - ( $ret, $msg ) = $g1->CreateUserDefinedGroup( Name => 'dg1' ); -} -$pg1 = RT::Group->new($RT::SystemUser); -( $ret, $msg ) = $pg1->LoadPersonalGroup( Name => 'dpg1', - User => $u1->PrincipalId ); -unless ($ret) { - ( $ret, $msg ) = $pg1->CreatePersonalGroup( Name => 'dpg1', - PrincipalId => $u1->PrincipalId ); -} -ok( $ret, "Load / Create test personal group 1: $msg" ); -$pg2 = RT::Group->new($RT::SystemUser); -( $ret, $msg ) = $pg2->LoadPersonalGroup( Name => 'dpg2', - User => $u1->PrincipalId ); -unless ($ret) { - ( $ret, $msg ) = $pg2->CreatePersonalGroup( Name => 'dpg2', - PrincipalId => $u1->PrincipalId ); -} -ok( $ret, "Load / Create test personal group 2: $msg" ); - -clear_acls_and_groups(); - -( $ret, $msg ) = $u1->PrincipalObj->GrantRight( Right => 'DelegateRights' ); -ok( $ret, "Grant DelegateRights to u1: $msg" ); -( $ret, $msg ) = $g1->PrincipalObj->GrantRight( Right => 'ShowConfigTab' ); -ok( $ret, "Grant ShowConfigTab to g1: $msg" ); -( $ret, $msg ) = $g1->AddMember( $u1->PrincipalId ); -ok( $ret, "Add test user 1 to g1: $msg" ); - -$ace = RT::ACE->new($u1); -( $ret, $msg ) = $ace->LoadByValues( - RightName => 'ShowConfigTab', - Object => $RT::System, - PrincipalType => 'Group', - PrincipalId => $g1->PrincipalId -); -ok( $ret, "Look up ACE to be delegated: $msg" ); -( $ret, $msg ) = $ace->Delegate( PrincipalId => $pg1->PrincipalId ); -ok( $ret, "Delegate ShowConfigTab to pg1: $msg" ); -( $ret, $msg ) = $ace->Delegate( PrincipalId => $pg2->PrincipalId ); -ok( $ret, "Delegate ShowConfigTab to pg2: $msg" ); - -ok(( $pg1->PrincipalObj->HasRight( Right => 'ShowConfigTab', - Object => $RT::System ) and - $pg2->PrincipalObj->HasRight( Right => 'ShowConfigTab', - Object => $RT::System )), - "Test personal groups have ShowConfigTab right after delegation" ); - -( $ret, $msg ) = $g1->DeleteMember( $u1->PrincipalId ); -ok( $ret, "Delete test user 1 from g1: $msg" ); - -ok( not( $pg1->PrincipalObj->HasRight( Right => 'ShowConfigTab', - Object => $RT::System )), - "Test personal group 1 lacks ShowConfigTab after user removed from g1" ); -ok( not( $pg2->PrincipalObj->HasRight( Right => 'ShowConfigTab', - Object => $RT::System )), - "Test personal group 2 lacks ShowConfigTab after user removed from g1" ); - -( $ret, $msg ) = $g1->AddMember( $u1->PrincipalId ); -ok( $ret, "Add test user 1 to g1: $msg" ); -( $ret, $msg ) = $ace->Delegate( PrincipalId => $pg1->PrincipalId ); -ok( $ret, "Delegate ShowConfigTab to pg1: $msg" ); -( $ret, $msg ) = $ace->Delegate( PrincipalId => $pg2->PrincipalId ); -ok( $ret, "Delegate ShowConfigTab to pg2: $msg" ); - -ok(( $pg1->PrincipalObj->HasRight( Right => 'ShowConfigTab', - Object => $RT::System ) and - $pg2->PrincipalObj->HasRight( Right => 'ShowConfigTab', - Object => $RT::System )), - "Test personal groups have ShowConfigTab right after delegation" ); - -( $ret, $msg ) = $g1->PrincipalObj->RevokeRight( Right => 'ShowConfigTab' ); -ok( $ret, "Revoke ShowConfigTab from g1: $msg" ); - -ok( not( $pg1->PrincipalObj->HasRight( Right => 'ShowConfigTab', - Object => $RT::System )), - "Test personal group 1 lacks ShowConfigTab after user removed from g1" ); -ok( not( $pg2->PrincipalObj->HasRight( Right => 'ShowConfigTab', - Object => $RT::System )), - "Test personal group 2 lacks ShowConfigTab after user removed from g1" ); - - - -####### - -sub clear_acls_and_groups { - # Revoke all rights granted to our cast - my $acl = RT::ACL->new($RT::SystemUser); - foreach (@principals) { - $acl->LimitToPrincipal(Type => $$_->PrincipalObj->PrincipalType, - Id => $$_->PrincipalObj->Id); - } - while (my $ace = $acl->Next()) { - $ace->Delete(); - } - - # Remove all group memberships - my $members = RT::GroupMembers->new($RT::SystemUser); - foreach (@groups) { - $members->LimitToMembersOfGroup( $$_->PrincipalId ); - } - while (my $member = $members->Next()) { - $member->Delete(); - } - - $acl->RedoSearch(); - is( $acl->Count() , 0, - "All principals have no rights after clearing ACLs" ); - $members->RedoSearch(); - is( $members->Count() , 0, - "All groups have no members after clearing groups" ); -} diff --git a/rt/t/i18n/default.t b/rt/t/i18n/default.t index 6c9842a4c..6c26b6207 100644 --- a/rt/t/i18n/default.t +++ b/rt/t/i18n/default.t @@ -2,7 +2,7 @@ use strict; use warnings; -use RT::Test tests => 8; +use RT::Test nodata => 1; my ($baseurl, $m) = RT::Test->started_ok; $m->get_ok('/'); @@ -10,6 +10,7 @@ $m->title_is('Login'); $m->get_ok('/', { 'Accept-Language' => 'x-klingon' }); $m->title_is('Login', 'unavailable language fallback to en'); +$m->content_contains('<html lang="en">'); $m->add_header('Accept-Language' => 'zh-tw,zh;q=0.8,en-gb;q=0.5,en;q=0.3'); $m->get_ok('/'); @@ -17,3 +18,9 @@ use utf8; Encode::_utf8_on($m->{content}); $m->title_is('登入', 'Page title properly translated to chinese'); $m->content_contains('密碼','Password properly translated'); +{ + local $TODO = "We fail to correctly advertise the langauage in the <html> block"; + $m->content_contains('<html lang="zh-tw">'); +} + +undef $m; diff --git a/rt/t/maildigest/attributes.t b/rt/t/maildigest/attributes.t deleted file mode 100644 index ba2a58566..000000000 --- a/rt/t/maildigest/attributes.t +++ /dev/null @@ -1,168 +0,0 @@ -#!/usr/bin/perl -w - -use warnings; -use strict; -use RT; -use RT::Test tests => 31; -my @users = qw/ emailnormal@example.com emaildaily@example.com emailweekly@example.com emailsusp@example.com /; - -my( $ret, $msg ); -my $user_n = RT::User->new( $RT::SystemUser ); -( $ret, $msg ) = $user_n->LoadOrCreateByEmail( $users[0] ); -ok( $ret, "user with default email prefs created: $msg" ); -$user_n->SetPrivileged( 1 ); - -my $user_d = RT::User->new( $RT::SystemUser ); -( $ret, $msg ) = $user_d->LoadOrCreateByEmail( $users[1] ); -ok( $ret, "user with daily digest email prefs created: $msg" ); -# Set a username & password for testing the interface. -$user_d->SetPrivileged( 1 ); -$user_d->SetPreferences($RT::System => { %{ $user_d->Preferences( $RT::System ) || {}}, EmailFrequency => 'Daily digest'}); - - - -my $user_w = RT::User->new( $RT::SystemUser ); -( $ret, $msg ) = $user_w->LoadOrCreateByEmail( $users[2] ); -ok( $ret, "user with weekly digest email prefs created: $msg" ); -$user_w->SetPrivileged( 1 ); -$user_w->SetPreferences($RT::System => { %{ $user_w->Preferences( $RT::System ) || {}}, EmailFrequency => 'Weekly digest'}); - -my $user_s = RT::User->new( $RT::SystemUser ); -( $ret, $msg ) = $user_s->LoadOrCreateByEmail( $users[3] ); -ok( $ret, "user with suspended email prefs created: $msg" ); -$user_s->SetPreferences($RT::System => { %{ $user_s->Preferences( $RT::System ) || {}}, EmailFrequency => 'Suspended'}); -$user_s->SetPrivileged( 1 ); - - -is(RT::Config->Get('EmailFrequency' => $user_s), 'Suspended'); - -# Make a testing queue for ourselves. -my $testq = RT::Queue->new( $RT::SystemUser ); -if( $testq->ValidateName( 'EmailDigest-testqueue' ) ) { - ( $ret, $msg ) = $testq->Create( Name => 'EmailDigest-testqueue' ); - ok( $ret, "Our test queue is created: $msg" ); -} else { - $testq->Load( 'EmailDigest-testqueue' ); - ok( $testq->id, "Our test queue is loaded" ); -} - -# Allow anyone to open a ticket on the test queue. -my $everyone = RT::Group->new( $RT::SystemUser ); -( $ret, $msg ) = $everyone->LoadSystemInternalGroup( 'Everyone' ); -ok( $ret, "Loaded 'everyone' group: $msg" ); - -( $ret, $msg ) = $everyone->PrincipalObj->GrantRight( Right => 'CreateTicket', - Object => $testq ); -ok( $ret || $msg =~ /already has/, "Granted everyone CreateTicket on testq: $msg" ); - -# Make user_d an admincc for the queue. -( $ret, $msg ) = $user_d->PrincipalObj->GrantRight( Right => 'AdminQueue', - Object => $testq ); -ok( $ret || $msg =~ /already has/, "Granted dduser AdminQueue on testq: $msg" ); -( $ret, $msg ) = $testq->AddWatcher( Type => 'AdminCc', - PrincipalId => $user_d->PrincipalObj->id ); -ok( $ret || $msg =~ /already/, "dduser added as a queue watcher: $msg" ); - -# Give the others queue rights. -( $ret, $msg ) = $user_n->PrincipalObj->GrantRight( Right => 'AdminQueue', - Object => $testq ); -ok( $ret || $msg =~ /already has/, "Granted emailnormal right on testq: $msg" ); -( $ret, $msg ) = $user_w->PrincipalObj->GrantRight( Right => 'AdminQueue', - Object => $testq ); -ok( $ret || $msg =~ /already has/, "Granted emailweekly right on testq: $msg" ); -( $ret, $msg ) = $user_s->PrincipalObj->GrantRight( Right => 'AdminQueue', - Object => $testq ); -ok( $ret || $msg =~ /already has/, "Granted emailsusp right on testq: $msg" ); - -# Create a ticket with To: Cc: Bcc: fields using our four users. -my $id; -my $ticket = RT::Ticket->new( $RT::SystemUser ); -( $id, $ret, $msg ) = $ticket->Create( Queue => $testq->Name, - Requestor => [ $user_w->Name ], - Subject => 'Test ticket for RT::Extension::EmailDigest', - ); -ok( $ret, "Ticket $id created: $msg" ); - -# Make the other users ticket watchers. -( $ret, $msg ) = $ticket->AddWatcher( Type => 'Cc', - PrincipalId => $user_n->PrincipalObj->id ); -ok( $ret, "Added user_n as a ticket watcher: $msg" ); -( $ret, $msg ) = $ticket->AddWatcher( Type => 'Cc', - PrincipalId => $user_s->PrincipalObj->id ); -ok( $ret, "Added user_s as a ticket watcher: $msg" ); - -my $obj; -($id, $msg, $obj ) = $ticket->Correspond( - Content => "This is a ticket response for CC action" ); -ok( $ret, "Transaction created: $msg" ); - -# Get the deferred notifications that should result. Should be two for -# email daily, and one apiece for emailweekly and emailsusp. -my @notifications; - -my $txns = RT::Transactions->new( $RT::SystemUser ); -$txns->LimitToTicket( $ticket->id ); -my( $c_daily, $c_weekly, $c_susp ) = ( 0, 0, 0 ); -while( my $txn = $txns->Next ) { - my @daily_rcpt = $txn->DeferredRecipients( 'daily' ); - my @weekly_rcpt = $txn->DeferredRecipients('weekly' ); - my @susp_rcpt = $txn->DeferredRecipients( 'susp' ); - - $c_daily++ if @daily_rcpt; - $c_weekly++ if @weekly_rcpt; - $c_susp++ if @susp_rcpt; - - # If the transaction has content... - if( $txn->ContentObj ) { - # ...none of the deferred folk should be in the header. - my $headerstr = $txn->ContentObj->Headers; - foreach my $rcpt( @daily_rcpt, @weekly_rcpt, @susp_rcpt ) { - ok( $headerstr !~ /$rcpt/, "Deferred recipient $rcpt not found in header" ); - } - } -} - -# Finally, check to see that we got the correct number of each sort of -# deferred recipient. -is( $c_daily, 2, "correct number of daily-sent messages" ); -is( $c_weekly, 2, "correct number of weekly-sent messages" ); -is( $c_susp, 1, "correct number of suspended messages" ); - - - - - -# Now let's actually run the daily and weekly digest tool to make sure we generate those - -# the first time get the content -email_digest_like( '--mode daily --print', qr/in the last day/ ); -# The second time run it for real so we make sure that we get RT to mark the txn as sent -email_digest_like( '--mode daily', qr/maildaily\@/ ); -# now we should have nothing to do, so no content. -email_digest_like( '--mode daily --print', '' ); - -# the first time get the content -email_digest_like( '--mode weekly --print', qr/in the last seven days/ ); -# The second time run it for real so we make sure that we get RT to mark the txn as sent -email_digest_like( '--mode weekly', qr/mailweekly\@/ ); -# now we should have nothing to do, so no content. -email_digest_like( '--mode weekly --print', '' ); - -sub email_digest_like { - my $arg = shift; - my $pattern = shift; - - local $Test::Builder::Level = $Test::Builder::Level + 1; - - my $perl = $^X . ' ' . join ' ', map { "-I$_" } @INC; - open my $digester, "-|", "$perl $RT::SbinPath/rt-email-digest $arg"; - my @results = <$digester>; - my $content = join '', @results; - if ( ref $pattern && ref $pattern eq 'Regexp' ) { - like($content, $pattern); - } - else { - is( $content, $pattern ); - } - close $digester; -} diff --git a/rt/t/rtname.t b/rt/t/rtname.t deleted file mode 100644 index ef6092bb2..000000000 --- a/rt/t/rtname.t +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -use RT::Test nodata => 1, tests => 9; - -use RT::Interface::Email; - -# normal use case, regexp set to rtname -RT->Config->Set( rtname => "site" ); -RT->Config->Set( EmailSubjectTagRegex => qr/site/ ); -RT->Config->Set( rtname => undef ); -is(RT::Interface::Email::ParseTicketId("[site #123] test"), 123); -is(RT::Interface::Email::ParseTicketId("[othersite #123] test"), undef); - -# oops usecase, where the regexp is scragged -RT->Config->Set( rtname => "site" ); -RT->Config->Set( EmailSubjectTagRegex => undef ); -is(RT::Interface::Email::ParseTicketId("[site #123] test"), 123); -is(RT::Interface::Email::ParseTicketId("[othersite #123] test"), undef); - -# set to a simple regexp. NOTE: we no longer match "site" -RT->Config->Set( rtname => "site"); -RT->Config->Set( EmailSubjectTagRegex => qr/newsite/); -is(RT::Interface::Email::ParseTicketId("[site #123] test"), undef); -is(RT::Interface::Email::ParseTicketId("[newsite #123] test"), 123); - -# set to a more complex regexp -RT->Config->Set( rtname => "site" ); -RT->Config->Set( EmailSubjectTagRegex => qr/newsite|site/ ); -is(RT::Interface::Email::ParseTicketId("[site #123] test"), 123); -is(RT::Interface::Email::ParseTicketId("[newsite #123] test"), 123); -is(RT::Interface::Email::ParseTicketId("[othersite #123] test"), undef); - diff --git a/rt/t/savedsearch.t b/rt/t/savedsearch.t deleted file mode 100644 index 5798f79cb..000000000 --- a/rt/t/savedsearch.t +++ /dev/null @@ -1,185 +0,0 @@ -use strict; -use warnings; -BEGIN { $ENV{'LANG'} = 'C' } -use RT; -use RT::User; -use RT::Group; -use RT::Ticket; -use RT::Queue; - -use RT::Test tests => 27; -use_ok('RT::SavedSearch'); -use_ok('RT::SavedSearches'); - -use Test::Warn; - -# Set up some infrastructure. These calls are tested elsewhere. - -my $searchuser = RT::User->new($RT::SystemUser); -my ($ret, $msg) = $searchuser->Create(Name => 'searchuser'.$$, - Privileged => 1, - EmailAddress => "searchuser\@p$$.example.com", - RealName => 'Search user'); -ok($ret, "created searchuser: $msg"); -$searchuser->PrincipalObj->GrantRight(Right => 'LoadSavedSearch'); -$searchuser->PrincipalObj->GrantRight(Right => 'CreateSavedSearch'); -$searchuser->PrincipalObj->GrantRight(Right => 'ModifySelf'); - -# This is the group whose searches searchuser should be able to see. -my $ingroup = RT::Group->new($RT::SystemUser); -$ingroup->CreateUserDefinedGroup(Name => 'searchgroup1'.$$); -$ingroup->AddMember($searchuser->Id); -$searchuser->PrincipalObj->GrantRight(Right => 'EditSavedSearches', - Object => $ingroup); -$searchuser->PrincipalObj->GrantRight(Right => 'ShowSavedSearches', - Object => $ingroup); - -# This is the group whose searches searchuser should not be able to see. -my $outgroup = RT::Group->new($RT::SystemUser); -$outgroup->CreateUserDefinedGroup(Name => 'searchgroup2'.$$); -$outgroup->AddMember($RT::SystemUser->Id); - -my $queue = RT::Queue->new($RT::SystemUser); -$queue->Create(Name => 'SearchQueue'.$$); -$searchuser->PrincipalObj->GrantRight(Right => 'SeeQueue', Object => $queue); -$searchuser->PrincipalObj->GrantRight(Right => 'ShowTicket', Object => $queue); -$searchuser->PrincipalObj->GrantRight(Right => 'OwnTicket', Object => $queue); - - -my $ticket = RT::Ticket->new($RT::SystemUser); -$ticket->Create(Queue => $queue->Id, - Requestor => [ $searchuser->Name ], - Owner => $searchuser, - Subject => 'saved search test'); - - -# Now start the search madness. -my $curruser = RT::CurrentUser->new($searchuser); -my $format = '\' <b><a href="/Ticket/Display.html?id=__id__">__id__</a></b>/TITLE:#\', -\'<b><a href="/Ticket/Display.html?id=__id__">__Subject__</a></b>/TITLE:Subject\', -\'__Status__\', -\'__QueueName__\', -\'__OwnerName__\', -\'__Priority__\', -\'__NEWLINE__\', -\'\', -\'<small>__Requestors__</small>\', -\'<small>__CreatedRelative__</small>\', -\'<small>__ToldRelative__</small>\', -\'<small>__LastUpdatedRelative__</small>\', -\'<small>__TimeLeft__</small>\''; - -my $mysearch = RT::SavedSearch->new($curruser); -($ret, $msg) = $mysearch->Save(Privacy => 'RT::User-' . $searchuser->Id, - Type => 'Ticket', - Name => 'owned by me', - SearchParams => {'Format' => $format, - 'Query' => "Owner = '" - . $searchuser->Name - . "'"}); -ok($ret, "mysearch was created"); - - -my $groupsearch = RT::SavedSearch->new($curruser); -($ret, $msg) = $groupsearch->Save(Privacy => 'RT::Group-' . $ingroup->Id, - Type => 'Ticket', - Name => 'search queue', - SearchParams => {'Format' => $format, - 'Query' => "Queue = '" - . $queue->Name . "'"}); -ok($ret, "groupsearch was created"); - -my $othersearch = RT::SavedSearch->new($curruser); -($ret, $msg) = $othersearch->Save(Privacy => 'RT::Group-' . $outgroup->Id, - Type => 'Ticket', - Name => 'searchuser requested', - SearchParams => {'Format' => $format, - 'Query' => - "Requestor.Name LIKE 'search'"}); -ok(!$ret, "othersearch NOT created"); -like($msg, qr/Failed to load object for/, "...for the right reason"); - -$othersearch = RT::SavedSearch->new($RT::SystemUser); -($ret, $msg) = $othersearch->Save(Privacy => 'RT::Group-' . $outgroup->Id, - Type => 'Ticket', - Name => 'searchuser requested', - SearchParams => {'Format' => $format, - 'Query' => - "Requestor.Name LIKE 'search'"}); -ok($ret, "othersearch created by systemuser"); - -# Now try to load some searches. - -# This should work. -my $loadedsearch1 = RT::SavedSearch->new($curruser); -$loadedsearch1->Load('RT::User-'.$curruser->Id, $mysearch->Id); -is($loadedsearch1->Id, $mysearch->Id, "Loaded mysearch"); -like($loadedsearch1->GetParameter('Query'), qr/Owner/, - "Retrieved query of mysearch"); -# Check through the other accessor methods. -is($loadedsearch1->Privacy, 'RT::User-' . $curruser->Id, - "Privacy of mysearch correct"); -is($loadedsearch1->Name, 'owned by me', "Name of mysearch correct"); -is($loadedsearch1->Type, 'Ticket', "Type of mysearch correct"); - -# See if it can be used to search for tickets. -my $tickets = RT::Tickets->new($curruser); -$tickets->FromSQL($loadedsearch1->GetParameter('Query')); -is($tickets->Count, 1, "Found a ticket"); - -# This should fail -- wrong object. -# my $loadedsearch2 = RT::SavedSearch->new($curruser); -# $loadedsearch2->Load('RT::User-'.$curruser->Id, $groupsearch->Id); -# isnt($loadedsearch2->Id, $othersearch->Id, "Didn't load groupsearch as mine"); -# ...but this should succeed. -my $loadedsearch3 = RT::SavedSearch->new($curruser); -$loadedsearch3->Load('RT::Group-'.$ingroup->Id, $groupsearch->Id); -is($loadedsearch3->Id, $groupsearch->Id, "Loaded groupsearch"); -like($loadedsearch3->GetParameter('Query'), qr/Queue/, - "Retrieved query of groupsearch"); -# Can it get tickets? -$tickets = RT::Tickets->new($curruser); -$tickets->FromSQL($loadedsearch3->GetParameter('Query')); -is($tickets->Count, 1, "Found a ticket"); - -# This should fail -- no permission. -my $loadedsearch4 = RT::SavedSearch->new($curruser); - -warning_like { - $loadedsearch4->Load($othersearch->Privacy, $othersearch->Id); -} qr/Could not load object RT::Group-\d+ when loading search/; - -isnt($loadedsearch4->Id, $othersearch->Id, "Did not load othersearch"); - -# Try to update an existing search. -$loadedsearch1->Update( SearchParams => {'Format' => $format, - 'Query' => "Queue = '" . $queue->Name . "'" } ); -like($loadedsearch1->GetParameter('Query'), qr/Queue/, - "Updated mysearch parameter"); -is($loadedsearch1->Type, 'Ticket', "mysearch is still for tickets"); -is($loadedsearch1->Privacy, 'RT::User-'.$curruser->Id, - "mysearch still belongs to searchuser"); -like($mysearch->GetParameter('Query'), qr/Queue/, "other mysearch object updated"); - - -## Right ho. Test the pseudo-collection object. - -my $genericsearch = RT::SavedSearch->new($curruser); -$genericsearch->Save(Name => 'generic search', - Type => 'all', - SearchParams => {'Query' => "Queue = 'General'"}); - -my $ticketsearches = RT::SavedSearches->new($curruser); -$ticketsearches->LimitToPrivacy('RT::User-'.$curruser->Id, 'Ticket'); -is($ticketsearches->Count, 1, "Found searchuser's ticket searches"); - -my $allsearches = RT::SavedSearches->new($curruser); -$allsearches->LimitToPrivacy('RT::User-'.$curruser->Id); -is($allsearches->Count, 2, "Found all searchuser's searches"); - -# Delete a search. -($ret, $msg) = $genericsearch->Delete; -ok($ret, "Deleted genericsearch"); -$allsearches->LimitToPrivacy('RT::User-'.$curruser->Id); -is($allsearches->Count, 1, "Found all searchuser's searches after deletion"); - diff --git a/rt/t/shredder/00load.t b/rt/t/shredder/00load.t index 1e06261bc..21d5ef765 100644 --- a/rt/t/shredder/00load.t +++ b/rt/t/shredder/00load.t @@ -2,7 +2,7 @@ use strict; use warnings; use File::Spec; use Test::More tests => 11; -use RT::Test (); +use RT::Test nodb => 1; BEGIN { my $shredder_utils = RT::Test::get_relocatable_file('utils.pl', diff --git a/rt/t/shredder/01basics.t b/rt/t/shredder/01basics.t index 450f2df8c..99e66c786 100644 --- a/rt/t/shredder/01basics.t +++ b/rt/t/shredder/01basics.t @@ -18,11 +18,11 @@ init_db(); create_savepoint(); use RT::Tickets; -my $ticket = RT::Ticket->new( $RT::SystemUser ); +my $ticket = RT::Ticket->new( RT->SystemUser ); my ($id) = $ticket->Create( Subject => 'test', Queue => 1 ); ok( $id, "created new ticket" ); -$ticket = RT::Ticket->new( $RT::SystemUser ); +$ticket = RT::Ticket->new( RT->SystemUser ); my ($status, $msg) = $ticket->Load( $id ); ok( $id, "load ticket" ) or diag( "error: $msg" ); diff --git a/rt/t/shredder/01ticket.t b/rt/t/shredder/01ticket.t index 5625b985d..7dff16df3 100644 --- a/rt/t/shredder/01ticket.t +++ b/rt/t/shredder/01ticket.t @@ -22,13 +22,13 @@ use RT::Ticket; use RT::Tickets; { - my $ticket = RT::Ticket->new( $RT::SystemUser ); + my $ticket = RT::Ticket->new( RT->SystemUser ); my ($id) = $ticket->Create( Subject => 'test', Queue => 1 ); ok( $id, "created new ticket" ); $ticket->Delete; is( $ticket->Status, 'deleted', "successfuly changed status" ); - my $tickets = RT::Tickets->new( $RT::SystemUser ); + my $tickets = RT::Tickets->new( RT->SystemUser ); $tickets->{'allow_deleted_search'} = 1; $tickets->LimitStatus( VALUE => 'deleted' ); is( $tickets->Count, 1, "found one deleted ticket" ); @@ -40,12 +40,12 @@ use RT::Tickets; cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint"); { - my $parent = RT::Ticket->new( $RT::SystemUser ); + my $parent = RT::Ticket->new( RT->SystemUser ); my ($pid) = $parent->Create( Subject => 'test', Queue => 1 ); ok( $pid, "created new ticket" ); create_savepoint('parent_ticket'); - my $child = RT::Ticket->new( $RT::SystemUser ); + my $child = RT::Ticket->new( RT->SystemUser ); my ($cid) = $child->Create( Subject => 'test', Queue => 1 ); ok( $cid, "created new ticket" ); @@ -62,14 +62,14 @@ cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint" cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint"); { - my $parent = RT::Ticket->new( $RT::SystemUser ); + my $parent = RT::Ticket->new( RT->SystemUser ); my ($pid) = $parent->Create( Subject => 'test', Queue => 1 ); ok( $pid, "created new ticket" ); my ($status, $msg) = $parent->Delete; ok( $status, 'deleted parent ticket'); create_savepoint('parent_ticket'); - my $child = RT::Ticket->new( $RT::SystemUser ); + my $child = RT::Ticket->new( RT->SystemUser ); my ($cid) = $child->Create( Subject => 'test', Queue => 1 ); ok( $cid, "created new ticket" ); diff --git a/rt/t/shredder/02group_member.t b/rt/t/shredder/02group_member.t index b68557a8b..9f8a6c6e3 100644 --- a/rt/t/shredder/02group_member.t +++ b/rt/t/shredder/02group_member.t @@ -18,12 +18,12 @@ init_db(); ### nested membership check { create_savepoint('clean'); - my $pgroup = RT::Group->new( $RT::SystemUser ); + my $pgroup = RT::Group->new( RT->SystemUser ); my ($pgid) = $pgroup->CreateUserDefinedGroup( Name => 'Parent group' ); ok( $pgid, "created parent group" ); is( $pgroup->id, $pgid, "id is correct" ); - my $cgroup = RT::Group->new( $RT::SystemUser ); + my $cgroup = RT::Group->new( RT->SystemUser ); my ($cgid) = $cgroup->CreateUserDefinedGroup( Name => 'Child group' ); ok( $cgid, "created child group" ); is( $cgroup->id, $cgid, "id is correct" ); @@ -32,7 +32,7 @@ init_db(); ok( $status, "added child group to parent") or diag "error: $msg"; create_savepoint('bucreate'); # before user create - my $user = RT::User->new( $RT::SystemUser ); + my $user = RT::User->new( RT->SystemUser ); my $uid; ($uid, $msg) = $user->Create( Name => 'new user', Privileged => 1, Disabled => 0 ); ok( $uid, "created new user" ) or diag "error: $msg"; @@ -42,7 +42,7 @@ init_db(); ($status, $msg) = $cgroup->AddMember( $user->id ); ok( $status, "added user to child group") or diag "error: $msg"; - my $members = RT::GroupMembers->new( $RT::SystemUser ); + my $members = RT::GroupMembers->new( RT->SystemUser ); $members->Limit( FIELD => 'MemberId', VALUE => $uid ); $members->Limit( FIELD => 'GroupId', VALUE => $cgid ); is( $members->Count, 1, "find membership record" ); @@ -65,23 +65,23 @@ init_db(); { restore_savepoint('clean'); - my $user = RT::User->new( $RT::SystemUser ); + my $user = RT::User->new( RT->SystemUser ); my ($uid, $msg) = $user->Create( Name => 'new user', Privileged => 1, Disabled => 0 ); ok( $uid, "created new user" ) or diag "error: $msg"; is( $user->id, $uid, "id is correct" ); use RT::Queue; - my $queue = new RT::Queue( $RT::SystemUser ); + my $queue = RT::Queue->new( RT->SystemUser ); $queue->Load('general'); ok( $queue->id, "queue loaded succesfully" ); $user->PrincipalObj->GrantRight( Right => 'OwnTicket', Object => $queue ); use RT::Tickets; - my $ticket = RT::Ticket->new( $RT::SystemUser ); + my $ticket = RT::Ticket->new( RT->SystemUser ); my ($id) = $ticket->Create( Subject => 'test', Queue => $queue->id ); ok( $id, "created new ticket" ); - $ticket = RT::Ticket->new( $RT::SystemUser ); + $ticket = RT::Ticket->new( RT->SystemUser ); my $status; ($status, $msg) = $ticket->Load( $id ); ok( $id, "load ticket" ) or diag( "error: $msg" ); @@ -95,9 +95,9 @@ init_db(); $shredder->PutObjects( Objects => $member ); $shredder->WipeoutAll(); - $ticket = RT::Ticket->new( $RT::SystemUser ); + $ticket = RT::Ticket->new( RT->SystemUser ); ($status, $msg) = $ticket->Load( $id ); ok( $id, "load ticket" ) or diag( "error: $msg" ); - is( $ticket->Owner, $RT::Nobody->id, "owner switched back to nobody" ); - is( $ticket->OwnerGroup->MembersObj->First->MemberId, $RT::Nobody->id, "and owner role group member is nobody"); + is( $ticket->Owner, RT->Nobody->id, "owner switched back to nobody" ); + is( $ticket->OwnerGroup->MembersObj->First->MemberId, RT->Nobody->id, "and owner role group member is nobody"); } diff --git a/rt/t/shredder/02queue.t b/rt/t/shredder/02queue.t index 197cf63c8..fb5e36d6e 100644 --- a/rt/t/shredder/02queue.t +++ b/rt/t/shredder/02queue.t @@ -15,10 +15,10 @@ BEGIN { init_db(); -diag 'simple queue' if $ENV{'TEST_VERBOSE'}; +diag 'simple queue' if $ENV{TEST_VERBOSE}; { create_savepoint('clean'); - my $queue = RT::Queue->new( $RT::SystemUser ); + my $queue = RT::Queue->new( RT->SystemUser ); my ($id, $msg) = $queue->Create( Name => 'my queue' ); ok($id, 'created queue') or diag "error: $msg"; @@ -28,14 +28,14 @@ diag 'simple queue' if $ENV{'TEST_VERBOSE'}; cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint"); } -diag 'queue with scrip' if $ENV{'TEST_VERBOSE'}; +diag 'queue with scrip' if $ENV{TEST_VERBOSE}; { create_savepoint('clean'); - my $queue = RT::Queue->new( $RT::SystemUser ); + my $queue = RT::Queue->new( RT->SystemUser ); my ($id, $msg) = $queue->Create( Name => 'my queue' ); ok($id, 'created queue') or diag "error: $msg"; - my $scrip = RT::Scrip->new( $RT::SystemUser ); + my $scrip = RT::Scrip->new( RT->SystemUser ); ($id, $msg) = $scrip->Create( Description => 'my scrip', Queue => $queue->id, @@ -51,14 +51,14 @@ diag 'queue with scrip' if $ENV{'TEST_VERBOSE'}; cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint"); } -diag 'queue with template' if $ENV{'TEST_VERBOSE'}; +diag 'queue with template' if $ENV{TEST_VERBOSE}; { create_savepoint('clean'); - my $queue = RT::Queue->new( $RT::SystemUser ); + my $queue = RT::Queue->new( RT->SystemUser ); my ($id, $msg) = $queue->Create( Name => 'my queue' ); ok($id, 'created queue') or diag "error: $msg"; - my $template = RT::Template->new( $RT::SystemUser ); + my $template = RT::Template->new( RT->SystemUser ); ($id, $msg) = $template->Create( Name => 'my template', Queue => $queue->id, @@ -72,14 +72,14 @@ diag 'queue with template' if $ENV{'TEST_VERBOSE'}; cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint"); } -diag 'queue with a right granted' if $ENV{'TEST_VERBOSE'}; +diag 'queue with a right granted' if $ENV{TEST_VERBOSE}; { create_savepoint('clean'); - my $queue = RT::Queue->new( $RT::SystemUser ); + my $queue = RT::Queue->new( RT->SystemUser ); my ($id, $msg) = $queue->Create( Name => 'my queue' ); ok($id, 'created queue') or diag "error: $msg"; - my $group = RT::Group->new( $RT::SystemUser ); + my $group = RT::Group->new( RT->SystemUser ); $group->LoadSystemInternalGroup('Everyone'); ok($group->id, 'loaded group'); @@ -95,16 +95,16 @@ diag 'queue with a right granted' if $ENV{'TEST_VERBOSE'}; cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint"); } -diag 'queue with a watcher' if $ENV{'TEST_VERBOSE'}; +diag 'queue with a watcher' if $ENV{TEST_VERBOSE}; { # XXX, FIXME: if uncomment these lines then we'll get 'Bizarre...' # create_savepoint('clean'); - my $group = RT::Group->new( $RT::SystemUser ); + my $group = RT::Group->new( RT->SystemUser ); my ($id, $msg) = $group->CreateUserDefinedGroup(Name => 'my group'); ok($id, 'created group') or diag "error: $msg"; create_savepoint('bqcreate'); - my $queue = RT::Queue->new( $RT::SystemUser ); + my $queue = RT::Queue->new( RT->SystemUser ); ($id, $msg) = $queue->Create( Name => 'my queue' ); ok($id, 'created queue') or diag "error: $msg"; diff --git a/rt/t/shredder/02template.t b/rt/t/shredder/02template.t index d4c323e09..16fa61588 100644 --- a/rt/t/shredder/02template.t +++ b/rt/t/shredder/02template.t @@ -15,10 +15,10 @@ BEGIN { init_db(); -diag 'global template' if $ENV{'TEST_VERBOSE'}; +diag 'global template' if $ENV{TEST_VERBOSE}; { create_savepoint('clean'); - my $template = RT::Template->new( $RT::SystemUser ); + my $template = RT::Template->new( RT->SystemUser ); my ($id, $msg) = $template->Create( Name => 'my template', Content => "\nsome content", @@ -31,10 +31,10 @@ diag 'global template' if $ENV{'TEST_VERBOSE'}; cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint"); } -diag 'local template' if $ENV{'TEST_VERBOSE'}; +diag 'local template' if $ENV{TEST_VERBOSE}; { create_savepoint('clean'); - my $template = RT::Template->new( $RT::SystemUser ); + my $template = RT::Template->new( RT->SystemUser ); my ($id, $msg) = $template->Create( Name => 'my template', Queue => 'General', @@ -48,10 +48,10 @@ diag 'local template' if $ENV{'TEST_VERBOSE'}; cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint"); } -diag 'template used in scrip' if $ENV{'TEST_VERBOSE'}; +diag 'template used in scrip' if $ENV{TEST_VERBOSE}; { create_savepoint('clean'); - my $template = RT::Template->new( $RT::SystemUser ); + my $template = RT::Template->new( RT->SystemUser ); my ($id, $msg) = $template->Create( Name => 'my template', Queue => 'General', @@ -59,7 +59,7 @@ diag 'template used in scrip' if $ENV{'TEST_VERBOSE'}; ); ok($id, 'created template') or diag "error: $msg"; - my $scrip = RT::Scrip->new( $RT::SystemUser ); + my $scrip = RT::Scrip->new( RT->SystemUser ); ($id, $msg) = $scrip->Create( Description => 'my scrip', Queue => 'General', diff --git a/rt/t/shredder/02user.t b/rt/t/shredder/02user.t index 03abd6c69..8c8657c7d 100644 --- a/rt/t/shredder/02user.t +++ b/rt/t/shredder/02user.t @@ -17,16 +17,16 @@ init_db(); create_savepoint('clean'); -my $queue = RT::Queue->new( $RT::SystemUser ); +my $queue = RT::Queue->new( RT->SystemUser ); my ($qid) = $queue->Load( 'General' ); ok( $qid, "loaded queue" ); -my $ticket = RT::Ticket->new( $RT::SystemUser ); +my $ticket = RT::Ticket->new( RT->SystemUser ); my ($tid) = $ticket->Create( Queue => $qid, Subject => 'test' ); ok( $tid, "ticket created" ); create_savepoint('bucreate'); # berfore user create -my $user = RT::User->new( $RT::SystemUser ); +my $user = RT::User->new( RT->SystemUser ); my ($uid, $msg) = $user->Create( Name => 'new user', Privileged => 1, Disabled => 0 ); ok( $uid, "created new user" ) or diag "error: $msg"; is( $user->id, $uid, "id is correct" ); @@ -38,7 +38,7 @@ create_savepoint('aucreate'); # after user create my $resolver = sub { my %args = (@_); my $t = $args{'TargetObject'}; - my $resolver_uid = $RT::SystemUser->id; + my $resolver_uid = RT->SystemUser->id; foreach my $method ( qw(Creator LastUpdatedBy) ) { next unless $t->_Accessible( $method => 'read' ); $t->__Set( Field => $method, Value => $resolver_uid ); @@ -52,7 +52,7 @@ create_savepoint('aucreate'); # after user create { restore_savepoint('aucreate'); - my $user = RT::User->new( $RT::SystemUser ); + my $user = RT::User->new( RT->SystemUser ); $user->Load($uid); ok($user->id, "loaded user after restore"); my $shredder = shredder_new(); diff --git a/rt/t/shredder/03plugin.t b/rt/t/shredder/03plugin.t index 190f40acf..cf51e448d 100644 --- a/rt/t/shredder/03plugin.t +++ b/rt/t/shredder/03plugin.t @@ -17,7 +17,7 @@ my @PLUGINS = sort qw(Attachments Base Objects SQLDump Summary Tickets Users); use_ok('RT::Shredder::Plugin'); { - my $plugin = new RT::Shredder::Plugin; + my $plugin = RT::Shredder::Plugin->new; isa_ok($plugin, 'RT::Shredder::Plugin'); my %plugins = $plugin->List; cmp_deeply( [sort keys %plugins], [@PLUGINS], "correct plugins" ); @@ -28,7 +28,7 @@ use_ok('RT::Shredder::Plugin'); } { # reblessing on LoadByName foreach (@PLUGINS) { - my $plugin = new RT::Shredder::Plugin; + my $plugin = RT::Shredder::Plugin->new; isa_ok($plugin, 'RT::Shredder::Plugin'); my ($status, $msg) = $plugin->LoadByName( $_ ); ok($status, "loaded plugin by name") or diag("error: $msg"); @@ -36,7 +36,7 @@ use_ok('RT::Shredder::Plugin'); } } { # error checking in LoadByName - my $plugin = new RT::Shredder::Plugin; + my $plugin = RT::Shredder::Plugin->new; isa_ok($plugin, 'RT::Shredder::Plugin'); my ($status, $msg) = $plugin->LoadByName; ok(!$status, "not loaded plugin - empty name"); diff --git a/rt/t/shredder/03plugin_summary.t b/rt/t/shredder/03plugin_summary.t index 30606af41..2744531db 100644 --- a/rt/t/shredder/03plugin_summary.t +++ b/rt/t/shredder/03plugin_summary.t @@ -6,7 +6,7 @@ use warnings; use Test::Deep; use File::Spec; use Test::More tests => 4; -use RT::Test (); +use RT::Test nodb => 1; BEGIN { my $shredder_utils = RT::Test::get_relocatable_file('utils.pl', File::Spec->curdir()); @@ -15,7 +15,7 @@ BEGIN { use_ok('RT::Shredder::Plugin'); -my $plugin_obj = new RT::Shredder::Plugin; +my $plugin_obj = RT::Shredder::Plugin->new; isa_ok($plugin_obj, 'RT::Shredder::Plugin'); my ($status, $msg) = $plugin_obj->LoadByName('Summary'); ok($status, 'loaded summary plugin') or diag "error: $msg"; diff --git a/rt/t/shredder/03plugin_tickets.t b/rt/t/shredder/03plugin_tickets.t index 3d742ff83..092b57052 100644 --- a/rt/t/shredder/03plugin_tickets.t +++ b/rt/t/shredder/03plugin_tickets.t @@ -16,7 +16,7 @@ BEGIN { use_ok('RT::Shredder::Plugin::Tickets'); { - my $plugin = new RT::Shredder::Plugin::Tickets; + my $plugin = RT::Shredder::Plugin::Tickets->new; isa_ok($plugin, 'RT::Shredder::Plugin::Tickets'); is(lc $plugin->Type, 'search', 'correct type'); @@ -28,15 +28,14 @@ use_ok('RT::Ticket'); use_ok('RT::Tickets'); { # create parent and child and check functionality of 'with_linked' arg - my $parent = RT::Ticket->new( $RT::SystemUser ); + my $parent = RT::Ticket->new( RT->SystemUser ); my ($pid) = $parent->Create( Subject => 'parent', Queue => 1 ); ok( $pid, "created new ticket" ); - - my $child = RT::Ticket->new( $RT::SystemUser ); + my $child = RT::Ticket->new( RT->SystemUser ); my ($cid) = $child->Create( Subject => 'child', Queue => 1, MemberOf => $pid ); ok( $cid, "created new ticket" ); - my $plugin = new RT::Shredder::Plugin::Tickets; + my $plugin = RT::Shredder::Plugin::Tickets->new; isa_ok($plugin, 'RT::Shredder::Plugin::Tickets'); my ($status, $msg, @objs); @@ -67,18 +66,18 @@ use_ok('RT::Tickets'); cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint"); { # create parent and child and link them reqursively to check that we don't hang - my $parent = RT::Ticket->new( $RT::SystemUser ); + my $parent = RT::Ticket->new( RT->SystemUser ); my ($pid) = $parent->Create( Subject => 'parent', Queue => 1 ); ok( $pid, "created new ticket" ); - my $child = RT::Ticket->new( $RT::SystemUser ); + my $child = RT::Ticket->new( RT->SystemUser ); my ($cid) = $child->Create( Subject => 'child', Queue => 1, MemberOf => $pid ); ok( $cid, "created new ticket" ); my ($status, $msg) = $child->AddLink( Target => $pid, Type => 'DependsOn' ); ok($status, "added reqursive link") or diag "error: $msg"; - my $plugin = new RT::Shredder::Plugin::Tickets; + my $plugin = RT::Shredder::Plugin::Tickets->new; isa_ok($plugin, 'RT::Shredder::Plugin::Tickets'); my (@objs); @@ -109,18 +108,20 @@ cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint" cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint"); { # create parent and child and check functionality of 'apply_query_to_linked' arg - my $parent = RT::Ticket->new( $RT::SystemUser ); - my ($pid) = $parent->Create( Subject => 'parent', Queue => 1, Status => 'resolved' ); + my $parent = RT::Ticket->new( RT->SystemUser ); + my ($pid) = $parent->Create( Subject => 'parent', Queue => 1 ); ok( $pid, "created new ticket" ); + $parent->SetStatus('resolved'); - my $child1 = RT::Ticket->new( $RT::SystemUser ); + my $child1 = RT::Ticket->new( RT->SystemUser ); my ($cid1) = $child1->Create( Subject => 'child', Queue => 1, MemberOf => $pid ); ok( $cid1, "created new ticket" ); - my $child2 = RT::Ticket->new( $RT::SystemUser ); - my ($cid2) = $child2->Create( Subject => 'child', Queue => 1, MemberOf => $pid, Status => 'resolved' ); + my $child2 = RT::Ticket->new( RT->SystemUser ); + my ($cid2) = $child2->Create( Subject => 'child', Queue => 1, MemberOf => $pid); ok( $cid2, "created new ticket" ); + $child2->SetStatus('resolved'); - my $plugin = new RT::Shredder::Plugin::Tickets; + my $plugin = RT::Shredder::Plugin::Tickets->new; isa_ok($plugin, 'RT::Shredder::Plugin::Tickets'); my ($status, $msg) = $plugin->TestArgs( query => 'Status = "resolved"', apply_query_to_linked => 1 ); @@ -140,7 +141,7 @@ cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint" $shredder->PutObjects( Objects => \@objs ); $shredder->WipeoutAll; - my $ticket = RT::Ticket->new( $RT::SystemUser ); + my $ticket = RT::Ticket->new( RT->SystemUser ); $ticket->Load( $cid1 ); is($ticket->id, $cid1, 'loaded ticket'); diff --git a/rt/t/shredder/03plugin_users.t b/rt/t/shredder/03plugin_users.t index 45fc8a27e..4f4ecc89c 100644 --- a/rt/t/shredder/03plugin_users.t +++ b/rt/t/shredder/03plugin_users.t @@ -6,7 +6,7 @@ use warnings; use Test::Deep; use File::Spec; use Test::More tests => 9; -use RT::Test (); +use RT::Test nodb => 1; BEGIN { my $shredder_utils = RT::Test::get_relocatable_file('utils.pl', File::Spec->curdir()); @@ -18,7 +18,7 @@ my @ARGS = sort qw(limit status name member_of email replace_relations no_ticket use_ok('RT::Shredder::Plugin::Users'); { - my $plugin = new RT::Shredder::Plugin::Users; + my $plugin = RT::Shredder::Plugin::Users->new; isa_ok($plugin, 'RT::Shredder::Plugin::Users'); is(lc $plugin->Type, 'search', 'correct type'); diff --git a/rt/t/shredder/utils.pl b/rt/t/shredder/utils.pl index 54243318e..5f5c1822f 100644 --- a/rt/t/shredder/utils.pl +++ b/rt/t/shredder/utils.pl @@ -3,21 +3,15 @@ use strict; use warnings; -use File::Spec; -use File::Temp 0.19 (); -require File::Path; require File::Copy; require Cwd; +require RT::Test; BEGIN { ### after: push @INC, qw(@RT_LIB_PATH@); - push @INC, qw(/opt/rt3/local/lib /opt/rt3/lib); } use RT::Shredder; -# where to keep temporary generated test data -my $tmpdir = ''; - =head1 DESCRIPTION RT::Shredder test suite utilities @@ -95,8 +89,9 @@ sub rewrite_rtconfig config_set( '$LogStackTraces' , 'crit' ); # logging to standalone file config_set( '$LogToFile' , 'debug' ); - my $fname = File::Spec->catfile(create_tmpdir(), test_name() .".log"); + my $fname = File::Spec->catfile(RT::Test->temp_directory(), test_name() .".log"); config_set( '$LogToFileNamed' , $fname ); + config_set('@LexiconLanguages', qw(en)); } =head3 config_set @@ -127,7 +122,7 @@ in most situations. sub init_db { - create_tmpdir(); + RT::Test->bootstrap_tempdir() unless RT::Test->temp_directory(); RT::LoadConfig(); rewrite_rtconfig(); RT::InitLogging(); @@ -161,13 +156,13 @@ sub _init_db =head3 db_name Returns the absolute file path to the current DB. -It is <$tmpdir . test_name() .'.db'>. +It is <<RT::Test->temp_directory . test_name() .'.db'>>. See also the C<test_name> function. =cut -sub db_name { return File::Spec->catfile(create_tmpdir(), test_name() .".db") } +sub db_name { return File::Spec->catfile(RT::Test->temp_directory(), test_name() .".db") } =head3 connect_sqlite @@ -192,9 +187,9 @@ Creates and returns a new RT::Shredder object. sub shredder_new { - my $obj = new RT::Shredder; + my $obj = RT::Shredder->new; - my $file = File::Spec->catfile( create_tmpdir(), test_name() .'.XXXX.sql' ); + my $file = File::Spec->catfile( RT::Test->temp_directory, test_name() .'.XXXX.sql' ); $obj->AddDumpPlugin( Arguments => { file_name => $file, from_storage => 0, @@ -223,44 +218,6 @@ sub test_name return $name; } -=head2 TEMPORARY DIRECTORY - -=head3 tmpdir - -Returns the absolute path to a tmp dir used in tests. - -=cut - -sub tmpdir { - if (-d $tmpdir) { - return $tmpdir; - } else { - $tmpdir = File::Temp->newdir(TEMPLATE => 'shredderXXXXX', CLEANUP => 0); - return $tmpdir; - } -} - -=head2 create_tmpdir - -Creates a tmp dir if one doesn't exist already. Returns tmpdir path. - -=cut - -sub create_tmpdir { my $n = tmpdir(); File::Path::mkpath( [$n] ); return $n } - -=head3 cleanup_tmp - -Deletes all the tmp dir used in the tests. -See also the C<test_name> function. - -=cut - -sub cleanup_tmp -{ - my $dir = File::Spec->catdir(tmpdir(), test_name()); - return File::Path::rmtree( File::Spec->catdir( tmpdir(), test_name() )); -} - =head2 SAVEPOINTS =head3 savepoint_name @@ -273,7 +230,7 @@ Takes one argument - savepoint name, by default C<sp>. sub savepoint_name { my $name = shift || 'sp'; - return File::Spec->catfile( create_tmpdir(), test_name() .".$name.db" ); + return File::Spec->catfile( RT::Test->temp_directory, test_name() .".$name.db" ); } =head3 create_savepoint @@ -293,14 +250,9 @@ sub restore_savepoint { return __cp_db( savepoint_name( shift ) => db_name() ) } sub __cp_db { my( $orig, $dest ) = @_; - $RT::Handle->dbh->disconnect; - # DIRTY HACK: undef Handles to force reconnect - $RT::Handle = undef; - %DBIx::SearchBuilder::DBIHandle = (); - $DBIx::SearchBuilder::PrevHandle = undef; - + RT::Test::__disconnect_rt(); File::Copy::copy( $orig, $dest ) or die "Couldn't copy '$orig' => '$dest': $!"; - RT::ConnectToDatabase(); + RT::Test::__reconnect_rt(); return; } @@ -337,7 +289,7 @@ sub dump_sqlite my $res = {}; foreach my $t( @tables ) { next if lc($t) eq 'sessions'; - $res->{$t} = $dbh->selectall_hashref("SELECT * FROM $t", 'id'); + $res->{$t} = $dbh->selectall_hashref("SELECT * FROM $t".dump_sqlite_exceptions($t), 'id'); clean_dates( $res->{$t} ) if $args{'CleanDates'}; die $DBI::err if $DBI::err; } @@ -346,6 +298,27 @@ sub dump_sqlite return $res; } +=head3 dump_sqlite_exceptions + +If there are parts of the DB which can change from creating and deleting +a queue, skip them when doing the comparison. One example is the global +queue cache attribute on RT::System which will be updated on Queue creation +and can't be rolled back by the shredder. It may actually make sense for +Shredder to be updating this at some point in the future. + +=cut + +sub dump_sqlite_exceptions { + my $table = shift; + + my $special_wheres = { + attributes => " WHERE Name != 'QueueCacheNeedsUpdate'" + }; + + return $special_wheres->{lc $table}||''; + +} + =head3 dump_current_and_savepoint Returns dump of the current DB and of the named savepoint. @@ -396,7 +369,7 @@ Returns a note about debug info that you can display if tests fail. sub note_on_fail { my $name = test_name(); - my $tmpdir = tmpdir(); + my $tmpdir = RT::Test->temp_directory(); return <<END; Some tests in '$0' file failed. You can find debug info in '$tmpdir' dir. @@ -408,27 +381,9 @@ See also perldoc t/shredder/utils.pl for how to use this info. END } -=head2 OTHER - -=head3 all_were_successful - -Returns true if all tests that have already run were successful. - -=cut - -sub all_were_successful -{ - use Test::Builder; - my $Test = Test::Builder->new; - return grep( !$_, $Test->summary )? 0: 1; -} - END { - return unless -e tmpdir(); - if ( all_were_successful() ) { - cleanup_tmp(); - } else { - diag( note_on_fail() ); + if ( ! RT::Test->builder->is_passing ) { + diag( note_on_fail() ); } } diff --git a/rt/t/ticket/action_linear_escalate.t b/rt/t/ticket/action_linear_escalate.t index 38cd47ded..2a1be611d 100644 --- a/rt/t/ticket/action_linear_escalate.t +++ b/rt/t/ticket/action_linear_escalate.t @@ -34,7 +34,7 @@ my $user = RT::Test->load_or_create_user( ok $user && $user->id, 'loaded or created user'; $user->PrincipalObj->GrantRight( Right => 'SuperUser' ); -my $current_user = RT::CurrentUser->new($RT::SystemUser); +my $current_user = RT::CurrentUser->new(RT->SystemUser); ($id, $msg) = $current_user->Load($user->id); ok( $id, "Got current user? $msg" ); @@ -60,15 +60,12 @@ escalate_ticket_ok($ticket3); ok( $ticket3->LastUpdatedBy == $user->id, "Did not set LastUpdated" ); ok( $ticket3->Transactions->Last->Type =~ /Create/i, "Did not record a transaction" ); -1; - - sub create_ticket_as_ok { my $user = shift; - my $created = RT::Date->new($RT::SystemUser); + my $created = RT::Date->new(RT->SystemUser); $created->Unix(time() - ( 7 * 24 * 60**2 )); - my $due = RT::Date->new($RT::SystemUser); + my $due = RT::Date->new(RT->SystemUser); $due->Unix(time() + ( 7 * 24 * 60**2 )); my $ticket = RT::Ticket->new($user); diff --git a/rt/t/ticket/add-watchers.t b/rt/t/ticket/add-watchers.t index ae993a936..e49c694ed 100644 --- a/rt/t/ticket/add-watchers.t +++ b/rt/t/ticket/add-watchers.t @@ -45,11 +45,10 @@ # # END BPS TAGGED BLOCK }}} -use RT::Test tests => 32; +use RT::Test nodata => 1, tests => 32; use strict; use warnings; -no warnings 'once'; use RT::Queue; use RT::User; @@ -59,20 +58,20 @@ use RT::CurrentUser; # clear all global right -my $acl = RT::ACL->new($RT::SystemUser); +my $acl = RT::ACL->new(RT->SystemUser); $acl->Limit( FIELD => 'RightName', OPERATOR => '!=', VALUE => 'SuperUser' ); -$acl->LimitToObject( $RT::System ); +$acl->LimitToObject( RT->System ); while( my $ace = $acl->Next ) { $ace->Delete; } # create new queue to be sure we do not mess with rights -my $queue = RT::Queue->new($RT::SystemUser); +my $queue = RT::Queue->new(RT->SystemUser); my ($queue_id) = $queue->Create( Name => 'watcher tests '.$$); ok( $queue_id, 'queue created for watcher tests' ); # new privileged user to check rights -my $user = RT::User->new( $RT::SystemUser ); +my $user = RT::User->new( RT->SystemUser ); my ($user_id) = $user->Create( Name => 'watcher'.$$, EmailAddress => "watcher$$".'@localhost', Privileged => 1, @@ -91,7 +90,7 @@ ok( $user->HasRight( Right => 'ShowTicket', Object => $queue ), "user can sho ok( !$user->HasRight( Right => 'ModifyTicket', Object => $queue ), "user can't modify queue tickets" ); ok( !$user->HasRight( Right => 'Watch', Object => $queue ), "user can't watch queue tickets" ); -my $ticket = RT::Ticket->new( $RT::SystemUser ); +my $ticket = RT::Ticket->new( RT->SystemUser ); my ($rv, $msg) = $ticket->Create( Subject => 'watcher tests', Queue => $queue->Name ); ok( $ticket->id, "ticket created" ); diff --git a/rt/t/ticket/badlinks.t b/rt/t/ticket/badlinks.t index 408e6b67c..71ab73928 100644 --- a/rt/t/ticket/badlinks.t +++ b/rt/t/ticket/badlinks.t @@ -1,7 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use RT::Test tests => 12; +use RT::Test tests => 14; my ($baseurl, $m) = RT::Test->started_ok; ok($m->login, "Logged in"); @@ -9,7 +9,7 @@ ok($m->login, "Logged in"); my $queue = RT::Test->load_or_create_queue(Name => 'General'); ok($queue->Id, "loaded the General queue"); -my $ticket = RT::Ticket->new($RT::SystemUser); +my $ticket = RT::Ticket->new(RT->SystemUser); my ($tid, $txn, $msg) = $ticket->Create( Queue => $queue->id, Subject => 'test links', diff --git a/rt/t/ticket/batch-upload-csv.t b/rt/t/ticket/batch-upload-csv.t index 41dc78696..cedc0143a 100644 --- a/rt/t/ticket/batch-upload-csv.t +++ b/rt/t/ticket/batch-upload-csv.t @@ -8,10 +8,10 @@ use_ok('RT::Action::CreateTickets'); my $QUEUE = 'uploadtest-'.$$; -my $queue_obj = RT::Queue->new($RT::SystemUser); +my $queue_obj = RT::Queue->new(RT->SystemUser); $queue_obj->Create(Name => $QUEUE); -my $cf = RT::CustomField->new($RT::SystemUser); +my $cf = RT::CustomField->new(RT->SystemUser); my ($val,$msg) = $cf->Create(Name => 'Work Package-'.$$, Type => 'Freeform', LookupType => RT::Ticket->CustomFieldLookupType, MaxValues => 1); ok($cf->id); ok($val,$msg); @@ -32,7 +32,7 @@ ok ($action->CurrentUser->id , "WE have a current user"); $action->Parse(Content => $data); my @results = $action->CreateByTemplate(); -my $tix = RT::Tickets->new($RT::SystemUser); +my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL ("Queue = '". $QUEUE."'"); $tix->OrderBy( FIELD => 'id', ORDER => 'ASC' ); is($tix->Count, 2, '2 tickets'); @@ -45,4 +45,3 @@ is($first->FirstCustomFieldValue($cf->id), '2.0'); my $second = $tix->Next; is($second->Subject(), 'hello'); is($second->FirstCustomFieldValue($cf->id), '3.0'); -1; diff --git a/rt/t/ticket/cfsort-freeform-multiple.t b/rt/t/ticket/cfsort-freeform-multiple.t index f8f5950ef..e285d0e6f 100644 --- a/rt/t/ticket/cfsort-freeform-multiple.t +++ b/rt/t/ticket/cfsort-freeform-multiple.t @@ -1,6 +1,6 @@ #!/usr/bin/perl -use RT::Test tests => 24; +use RT::Test nodata => 1, tests => 41; use strict; use warnings; @@ -11,11 +11,11 @@ use RT::CustomField; # Test Sorting by custom fields. -diag "Create a queue to test with." if $ENV{TEST_VERBOSE}; +diag "Create a queue to test with."; my $queue_name = "CFSortQueue-$$"; my $queue; { - $queue = RT::Queue->new( $RT::SystemUser ); + $queue = RT::Queue->new( RT->SystemUser ); my ($ret, $msg) = $queue->Create( Name => $queue_name, Description => 'queue for custom field sort testing' @@ -23,11 +23,11 @@ my $queue; ok($ret, "$queue_name - test queue creation. $msg"); } -diag "create a CF\n" if $ENV{TEST_VERBOSE}; +diag "create a CF"; my $cf_name = "Order$$"; my $cf; { - $cf = RT::CustomField->new( $RT::SystemUser ); + $cf = RT::CustomField->new( RT->SystemUser ); my ($ret, $msg) = $cf->Create( Name => $cf_name, Queue => $queue->id, @@ -36,34 +36,9 @@ my $cf; ok($ret, "Custom Field Order created"); } -my ($total, @data, @tickets, @test) = (0, ()); - -sub add_tix_from_data { - my @res = (); - @data = sort { rand(100) <=> rand(100) } @data; - while (@data) { - my $t = RT::Ticket->new($RT::SystemUser); - my %args = %{ shift(@data) }; - my @values = (); - if ( exists $args{'CF'} && ref $args{'CF'} ) { - @values = @{ delete $args{'CF'} }; - } elsif ( exists $args{'CF'} ) { - @values = (delete $args{'CF'}); - } - $args{ 'CustomField-'. $cf->id } = \@values - if @values; - my $subject = join(",", sort @values) || '-'; - my ( $id, undef $msg ) = $t->Create( - %args, - Queue => $queue->id, - Subject => $subject, - ); - ok( $id, "ticket created" ) or diag("error: $msg"); - push @res, $t; - $total++; - } - return @res; -} +my (@data, @tickets, @test) = (0, ()); + + sub run_tests { my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets; @@ -73,7 +48,7 @@ sub run_tests { foreach my $order (qw(ASC DESC)) { my $error = 0; - my $tix = RT::Tickets->new( $RT::SystemUser ); + my $tix = RT::Tickets->new( RT->SystemUser ); $tix->FromSQL( $query ); $tix->OrderBy( FIELD => $test->{'Order'}, ORDER => $order ); @@ -112,11 +87,11 @@ sub run_tests { } @data = ( - { }, - { CF => ['b', 'd'] }, - { CF => ['a', 'c'] }, + { Subject => '-' }, + { Subject => 'b-d', 'CustomField-' . $cf->id => ['b', 'd'] }, + { Subject => 'a-c', 'CustomField-' . $cf->id => ['a', 'c'] }, ); -@tickets = add_tix_from_data(); +@tickets = RT::Test->create_tickets( {Queue => $queue->id, RandomOrder => 1 }, @data); @test = ( { Order => "CF.{$cf_name}" }, { Order => "CF.$queue_name.{$cf_name}" }, @@ -124,14 +99,16 @@ sub run_tests { run_tests(); @data = ( - { CF => ['m', 'a'] }, - { CF => ['m'] }, - { CF => ['m', 'o'] }, + { Subject => 'm-a', 'CustomField-' . $cf->id => ['m', 'a'] }, + { Subject => 'm', 'CustomField-' . $cf->id => ['m'] }, + { Subject => 'm-o', 'CustomField-' . $cf->id => ['m', 'o'] }, ); -@tickets = add_tix_from_data(); +@tickets = RT::Test->create_tickets( {Queue => $queue->id, RandomORder => 1 }, @data); @test = ( { Order => "CF.{$cf_name}", Query => "CF.{$cf_name} = 'm'" }, { Order => "CF.$queue_name.{$cf_name}", Query => "CF.{$cf_name} = 'm'" }, ); run_tests(); +@tickets = (); + diff --git a/rt/t/ticket/cfsort-freeform-single.t b/rt/t/ticket/cfsort-freeform-single.t index f1f506bea..35a53fb54 100644 --- a/rt/t/ticket/cfsort-freeform-single.t +++ b/rt/t/ticket/cfsort-freeform-single.t @@ -1,6 +1,6 @@ #!/usr/bin/perl -use RT::Test tests => 57; +use RT::Test nodata => 1, tests => 89; use strict; use warnings; @@ -11,11 +11,11 @@ use RT::CustomField; # Test Sorting by FreeformSingle custom field. -diag "Create a queue to test with." if $ENV{TEST_VERBOSE}; +diag "Create a queue to test with."; my $queue_name = "CFSortQueue-$$"; my $queue; { - $queue = RT::Queue->new( $RT::SystemUser ); + $queue = RT::Queue->new( RT->SystemUser ); my ($ret, $msg) = $queue->Create( Name => $queue_name, Description => 'queue for custom field sort testing' @@ -27,10 +27,10 @@ my $queue; my %CF; my $cf_name; -diag "create a CF\n" if $ENV{TEST_VERBOSE}; +diag "create a CF"; { $cf_name = $CF{'CF'}{'name'} = "Order$$"; - $CF{'CF'}{'obj'} = RT::CustomField->new( $RT::SystemUser ); + $CF{'CF'}{'obj'} = RT::CustomField->new( RT->SystemUser ); my ($ret, $msg) = $CF{'CF'}{'obj'}->Create( Name => $CF{'CF'}{'name'}, Queue => $queue->id, @@ -41,39 +41,6 @@ diag "create a CF\n" if $ENV{TEST_VERBOSE}; my ($total, @data, @tickets, @test) = (0, ()); -sub add_tix_from_data { - my @res = (); - @data = sort { rand(100) <=> rand(100) } @data; - while (@data) { - my $t = RT::Ticket->new($RT::SystemUser); - my %args = %{ shift(@data) }; - - my $subject = '-'; - foreach my $e ( grep exists $CF{$_} && defined $CF{$_}, keys %args ) { - my @values = (); - if ( ref $args{ $e } ) { - @values = @{ delete $args{ $e } }; - } else { - @values = (delete $args{ $e }); - } - $args{ 'CustomField-'. $CF{ $e }{'obj'}->id } = \@values - if @values; - $subject = join(",", sort @values) || '-' - if $e eq 'CF'; - } - - my ( $id, undef $msg ) = $t->Create( - %args, - Queue => $queue->id, - Subject => $subject, - ); - ok( $id, "ticket created" ) or diag("error: $msg"); - push @res, $t; - $total++; - } - return @res; -} - sub run_tests { my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets; foreach my $test ( @test ) { @@ -82,7 +49,7 @@ sub run_tests { foreach my $order (qw(ASC DESC)) { my $error = 0; - my $tix = RT::Tickets->new( $RT::SystemUser ); + my $tix = RT::Tickets->new( RT->SystemUser ); $tix->FromSQL( $query ); $tix->OrderBy( FIELD => $test->{'Order'}, ORDER => $order ); @@ -121,11 +88,12 @@ sub run_tests { } @data = ( - { }, - { CF => 'a' }, - { CF => 'b' }, + { Subject => '-' }, + { Subject => 'a', 'CustomField-' . $CF{CF}{obj}->id => 'a' }, + { Subject => 'b', 'CustomField-' . $CF{CF}{obj}->id => 'b' }, ); -@tickets = add_tix_from_data(); + +@tickets = RT::Test->create_tickets( { Queue => $queue->id, RandomOrder => 1 }, @data); @test = ( { Order => "CF.{$cf_name}" }, { Order => "CF.$queue_name.{$cf_name}" }, @@ -133,11 +101,11 @@ sub run_tests { run_tests(); @data = ( - { }, - { CF => 'aa' }, - { CF => 'ab' }, + { Subject => '-' }, + { Subject => 'aa', 'CustomField-' . $CF{CF}{obj}->id => 'aa' }, + { Subject => 'bb', 'CustomField-' . $CF{CF}{obj}->id => 'bb' }, ); -@tickets = add_tix_from_data(); +@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}" }, @@ -150,7 +118,7 @@ run_tests(); { Subject => 'b', CF => 'b' }, { Subject => 'c', CF => 'c' }, ); -@tickets = add_tix_from_data(); +@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}" }, @@ -159,10 +127,10 @@ run_tests(); -diag "create another CF\n" if $ENV{TEST_VERBOSE}; +diag "create another CF"; { $CF{'AnotherCF'}{'name'} = "OrderAnother$$"; - $CF{'AnotherCF'}{'obj'} = RT::CustomField->new( $RT::SystemUser ); + $CF{'AnotherCF'}{'obj'} = RT::CustomField->new( RT->SystemUser ); my ($ret, $msg) = $CF{'AnotherCF'}{'obj'}->Create( Name => $CF{'AnotherCF'}{'name'}, Queue => $queue->id, @@ -178,7 +146,7 @@ diag "create another CF\n" if $ENV{TEST_VERBOSE}; { Subject => 'b', CF => 'b', AnotherCF => 'ya' }, { Subject => 'c', CF => 'c', AnotherCF => 'xa' }, ); -@tickets = add_tix_from_data(); +@tickets = RT::Test->create_tickets( { Queue => $queue->id, RandomOrder => 1 }, @data); @test = ( { Order => "CF.{$cf_name}" }, { Order => "CF.$queue_name.{$cf_name}" }, @@ -187,5 +155,5 @@ diag "create another CF\n" if $ENV{TEST_VERBOSE}; ); run_tests(); - +@tickets = (); diff --git a/rt/t/ticket/deferred_owner.t b/rt/t/ticket/deferred_owner.t index 40172caf9..fe90d539d 100644 --- a/rt/t/ticket/deferred_owner.t +++ b/rt/t/ticket/deferred_owner.t @@ -2,7 +2,7 @@ use strict; use warnings; -use RT::Test tests => 18; +use RT::Test nodata => 1, tests => 18; use_ok('RT'); use_ok('RT::Ticket'); use Test::Warn; @@ -16,11 +16,11 @@ 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 ); +my $owner_role_group = RT::Group->new( RT->SystemUser ); $owner_role_group->LoadQueueRoleGroup( Type => 'Owner', Queue => $queue->id ); ok $owner_role_group->id, 'loaded owners role group of the queue'; -diag "check that deffering owner doesn't regress" if $ENV{'TEST_VERBOSE'}; +diag "check that deffering owner doesn't regress"; { RT::Test->set_rights( { Principal => $tester->PrincipalObj, @@ -39,14 +39,13 @@ diag "check that deffering owner doesn't regress" if $ENV{'TEST_VERBOSE'}; Owner => $tester->id, AdminCc => 'root@localhost', ); - diag $msg if $msg && $ENV{'TEST_VERBOSE'}; + diag $msg if $msg; ok $tid, "created a ticket"; is $ticket->Owner, $tester->id, 'correct owner'; like $ticket->AdminCcAddresses, qr/root\@localhost/, 'root is there'; } -diag "check that previous trick doesn't work without sufficient rights" - if $ENV{'TEST_VERBOSE'}; +diag "check that previous trick doesn't work without sufficient rights"; { RT::Test->set_rights( { Principal => $tester->PrincipalObj, @@ -61,13 +60,13 @@ diag "check that previous trick doesn't work without sufficient rights" Owner => $tester->id, AdminCc => 'root@localhost', ); - diag $msg if $msg && $ENV{'TEST_VERBOSE'}; + 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'; } -diag "check that deffering owner really works" if $ENV{'TEST_VERBOSE'}; +diag "check that deffering owner really works"; { RT::Test->set_rights( { Principal => $tester->PrincipalObj, @@ -85,13 +84,13 @@ diag "check that deffering owner really works" if $ENV{'TEST_VERBOSE'}; Owner => $tester->id, Cc => 'tester@localhost', ); - diag $msg if $msg && $ENV{'TEST_VERBOSE'}; + diag $msg if $msg; 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'; } -diag "check that deffering doesn't work without correct rights" if $ENV{'TEST_VERBOSE'}; +diag "check that deffering doesn't work without correct rights"; { RT::Test->set_rights( { Principal => $tester->PrincipalObj, @@ -110,7 +109,7 @@ diag "check that deffering doesn't work without correct rights" if $ENV{'TEST_VE ); } qr/User .* was proposed as a ticket owner but has no rights to own tickets in General/; - diag $msg if $msg && $ENV{'TEST_VERBOSE'}; + 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'; diff --git a/rt/t/ticket/link_search.t b/rt/t/ticket/link_search.t index 1bf7dc6dc..dbcf4b477 100644 --- a/rt/t/ticket/link_search.t +++ b/rt/t/ticket/link_search.t @@ -10,19 +10,19 @@ use RT::Test tests => 63; #Get the current user all loaded -my $CurrentUser = $RT::SystemUser; +my $CurrentUser = RT->SystemUser; -my $queue = new RT::Queue($CurrentUser); +my $queue = RT::Queue->new($CurrentUser); $queue->Load('General') || Abort(loc("Queue could not be loaded.")); -my $child_ticket = new RT::Ticket( $CurrentUser ); +my $child_ticket = RT::Ticket->new( $CurrentUser ); my ($childid) = $child_ticket->Create( Subject => 'test child', Queue => $queue->Id, ); ok($childid, "We created a child ticket"); -my $parent_ticket = new RT::Ticket( $CurrentUser ); +my $parent_ticket = RT::Ticket->new( $CurrentUser ); my ($parentid) = $parent_ticket->Create( Subject => 'test parent', Children => [ $childid ], @@ -155,7 +155,7 @@ while (my $t = $Collection->Next) { ok( $has{$parentid}, "The collection has our parent - $parentid"); ok( !$has{$childid}, "The collection doesn't have our child - $childid"); -my $grand_child_ticket = new RT::Ticket( $CurrentUser ); +my $grand_child_ticket = RT::Ticket->new( $CurrentUser ); my ($grand_childid) = $child_ticket->Create( Subject => 'test child', Queue => $queue->Id, @@ -163,7 +163,7 @@ my ($grand_childid) = $child_ticket->Create( ); ok($childid, "We created a grand child ticket"); -my $unlinked_ticket = new RT::Ticket( $CurrentUser ); +my $unlinked_ticket = RT::Ticket->new( $CurrentUser ); my ($unlinked_id) = $child_ticket->Create( Subject => 'test unlinked', Queue => $queue->Id, @@ -242,5 +242,3 @@ ok( $has{$parentid}, "The collection has our parent"); ok( $has{$grand_childid}, "The collection have our child"); ok( !$has{$unlinked_id}, "unlinked is not in collection"); - -1; diff --git a/rt/t/ticket/linking.t b/rt/t/ticket/linking.t index fc4761d47..1bd83d633 100644 --- a/rt/t/ticket/linking.t +++ b/rt/t/ticket/linking.t @@ -2,7 +2,8 @@ use strict; use warnings; -use RT::Test tests => '101'; +use RT::Test tests => 102; +use Test::Warn; use_ok('RT'); use_ok('RT::Ticket'); use_ok('RT::ScripConditions'); @@ -12,35 +13,36 @@ use_ok('RT::Scrips'); use_ok('RT::Scrip'); -use File::Temp qw/tempfile/; -my ($fh, $filename) = tempfile( UNLINK => 1, SUFFIX => '.rt'); +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); -my $condition = RT::ScripCondition->new( $RT::SystemUser ); +my $condition = RT::ScripCondition->new( RT->SystemUser ); $condition->Load('User Defined'); ok($condition->id); -my $action = RT::ScripAction->new( $RT::SystemUser ); +my $action = RT::ScripAction->new( RT->SystemUser ); $action->Load('User Defined'); ok($action->id); -my $template = RT::Template->new( $RT::SystemUser ); +my $template = RT::Template->new( RT->SystemUser ); $template->Load('Blank'); ok($template->id); -my $q1 = RT::Queue->new($RT::SystemUser); +my $q1 = RT::Queue->new(RT->SystemUser); my ($id,$msg) = $q1->Create(Name => "LinkTest1.$$"); ok ($id,$msg); -my $q2 = RT::Queue->new($RT::SystemUser); +my $q2 = RT::Queue->new(RT->SystemUser); ($id,$msg) = $q2->Create(Name => "LinkTest2.$$"); ok ($id,$msg); my $commit_code = <<END; open( my \$file, '<', "$filename" ) or die "couldn't open $filename"; my \$data = <\$file>; -chomp \$data; \$data += 0; close \$file; \$RT::Logger->debug("Data is \$data"); @@ -62,14 +64,14 @@ close \$file; 1; END -my $Scrips = RT::Scrips->new( $RT::SystemUser ); +my $Scrips = RT::Scrips->new( RT->SystemUser ); $Scrips->UnLimit; while ( my $Scrip = $Scrips->Next ) { $Scrip->Delete if $Scrip->Description and $Scrip->Description =~ /Add or Delete Link \d+/; } -my $scrip = RT::Scrip->new($RT::SystemUser); +my $scrip = RT::Scrip->new(RT->SystemUser); ($id,$msg) = $scrip->Create( Description => "Add or Delete Link $$", ScripCondition => $condition->id, ScripAction => $action->id, @@ -82,7 +84,7 @@ my $scrip = RT::Scrip->new($RT::SystemUser); ); ok($id, "Scrip created"); -my $u1 = RT::User->new($RT::SystemUser); +my $u1 = RT::User->new(RT->SystemUser); ($id,$msg) = $u1->Create(Name => "LinkTestUser.$$"); ok ($id,$msg); @@ -96,31 +98,31 @@ ok ($id,$msg); my $creator = RT::CurrentUser->new($u1->id); -diag('Create tickets without rights to link') if $ENV{'TEST_VERBOSE'}; +diag('Create tickets without rights to link'); { # on q2 we have no rights, yet - my $parent = RT::Ticket->new( $RT::SystemUser ); + my $parent = RT::Ticket->new( RT->SystemUser ); my ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id ); ok($id,$msg); my $child = RT::Ticket->new( $creator ); ($id,$tid,$msg) = $child->Create( Subject => 'Link test 1', Queue => $q1->id, MemberOf => $parent->id ); ok($id,$msg); - $child->CurrentUser( $RT::SystemUser ); + $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'); } -diag('Create tickets with rights checks on one end of a link') if $ENV{'TEST_VERBOSE'}; +diag('Create tickets with rights checks on one end of a link'); { # on q2 we have no rights, but use checking one only on thing RT->Config->Set( StrictLinkACL => 0 ); - my $parent = RT::Ticket->new( $RT::SystemUser ); + my $parent = RT::Ticket->new( RT->SystemUser ); my ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id ); ok($id,$msg); my $child = RT::Ticket->new( $creator ); ($id,$tid,$msg) = $child->Create( Subject => 'Link test 1', Queue => $q1->id, MemberOf => $parent->id ); ok($id,$msg); - $child->CurrentUser( $RT::SystemUser ); + $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 @@ -131,10 +133,10 @@ diag('Create tickets with rights checks on one end of a link') if $ENV{'TEST_VER ($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q1, Right => 'ModifyTicket'); ok ($id,$msg); -diag('try to add link without rights') if $ENV{'TEST_VERBOSE'}; +diag('try to add link without rights'); { # on q2 we have no rights, yet - my $parent = RT::Ticket->new( $RT::SystemUser ); + my $parent = RT::Ticket->new( RT->SystemUser ); my ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id ); ok($id,$msg); my $child = RT::Ticket->new( $creator ); @@ -143,16 +145,16 @@ diag('try to add link without rights') if $ENV{'TEST_VERBOSE'}; ($id, $msg) = $child->AddLink(Type => 'MemberOf', Target => $parent->id); ok(!$id, $msg); is(link_count($filename), undef, "scrips ok"); - $child->CurrentUser( $RT::SystemUser ); + $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'); } -diag('add link with rights only on base') if $ENV{'TEST_VERBOSE'}; +diag('add link with rights only on base'); { # on q2 we have no rights, but use checking one only on thing RT->Config->Set( StrictLinkACL => 0 ); - my $parent = RT::Ticket->new( $RT::SystemUser ); + my $parent = RT::Ticket->new( RT->SystemUser ); my ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id ); ok($id,$msg); my $child = RT::Ticket->new( $creator ); @@ -161,7 +163,7 @@ diag('add link with rights only on base') if $ENV{'TEST_VERBOSE'}; ($id, $msg) = $child->AddLink(Type => 'MemberOf', Target => $parent->id); ok($id, $msg); is(link_count($filename), 1, "scrips ok"); - $child->CurrentUser( $RT::SystemUser ); + $child->CurrentUser( RT->SystemUser ); is($child->_Links('Base')->Count, 1, 'link was created'); is($child->_Links('Target')->Count, 0, 'link was created only one'); $child->CurrentUser( $creator ); @@ -171,7 +173,7 @@ diag('add link with rights only on base') if $ENV{'TEST_VERBOSE'}; ($id, $msg) = $child->AddLink(Type => 'MemberOf', Target => $parent->id); ok(!$id, $msg); is(link_count($filename), 1, "scrips ok"); - $child->CurrentUser( $RT::SystemUser ); + $child->CurrentUser( RT->SystemUser ); $child->_Links('Base')->_DoCount; is($child->_Links('Base')->Count, 1, 'link was not deleted'); $child->CurrentUser( $creator ); @@ -181,7 +183,7 @@ diag('add link with rights only on base') if $ENV{'TEST_VERBOSE'}; ($id, $msg) = $child->DeleteLink(Type => 'MemberOf', Target => $parent->id); ok($id, $msg); is(link_count($filename), 0, "scrips ok"); - $child->CurrentUser( $RT::SystemUser ); + $child->CurrentUser( RT->SystemUser ); $child->_Links('Base')->_DoCount; is($child->_Links('Base')->Count, 0, 'link was deleted'); RT->Config->Set( StrictLinkACL => 1 ); @@ -193,14 +195,16 @@ ok($ticket->isa('RT::Ticket')); ($id,$tid, $msg) = $ticket->Create(Subject => 'Link test 1', Queue => $q1->id); ok ($id,$msg); -diag('try link to itself') if $ENV{'TEST_VERBOSE'}; +diag('try link to itself'); { - my ($id, $msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket->id); + warning_like { + ($id, $msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket->id); + } qr/Can't link a ticket to itself/; ok(!$id, $msg); is(link_count($filename), 0, "scrips ok"); } -my $ticket2 = RT::Ticket->new($RT::SystemUser); +my $ticket2 = RT::Ticket->new(RT->SystemUser); ($id, $tid, $msg) = $ticket2->Create(Subject => 'Link test 2', Queue => $q2->id); ok ($id, $msg); ($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id); @@ -214,8 +218,14 @@ ok ($id,$msg); ($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id); ok($id,$msg); is(link_count($filename), 1, "scrips ok"); -($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => -1); -ok(!$id,$msg); + +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"); @@ -301,13 +311,13 @@ RT->Config->Set( LinkTransactionsRun1Scrip => $link_scrips_orig ); RT->Config->Set( StrictLinkACL => $link_acl_checks_orig ); { - my $Scrips = RT::Scrips->new( $RT::SystemUser ); + my $Scrips = RT::Scrips->new( RT->SystemUser ); $Scrips->Limit( FIELD => 'Description', OPERATOR => 'STARTSWITH', VALUE => 'Add or Delete Link '); while ( my $s = $Scrips->Next ) { $s->Delete }; } -my $link = RT::Link->new( $RT::SystemUser ); +my $link = RT::Link->new( RT->SystemUser ); ($id,$msg) = $link->Create( Base => $ticket->URI, Target => $ticket2->URI, Type => 'MyLinkType' ); ok($id, $msg); ok($link->LocalBase == $ticket->id, "LocalBase set correctly"); @@ -375,7 +385,7 @@ ok($link->LocalBase == 0, "LocalBase set correctly"); sub link_count { my $file = shift; - open ( my $fh, '<', $file ) or die "couldn't open $file"; + open( my $fh, '<', $file ) or die "couldn't open $file"; my $data = <$fh>; close $fh; diff --git a/rt/t/ticket/merge.t b/rt/t/ticket/merge.t index 7c72fe08f..d06d54174 100644 --- a/rt/t/ticket/merge.t +++ b/rt/t/ticket/merge.t @@ -11,11 +11,11 @@ use RT::Test tests => '29'; # validate that when merging two tickets, the comments from both tickets # are integrated into the new ticket { - my $queue = RT::Queue->new($RT::SystemUser); + my $queue = RT::Queue->new(RT->SystemUser); my ($id,$msg) = $queue->Create(Name => 'MergeTest-'.rand(25)); ok ($id,$msg); - my $t1 = RT::Ticket->new($RT::SystemUser); + my $t1 = RT::Ticket->new(RT->SystemUser); my ($tid,$transid, $t1msg) =$t1->Create( Queue => $queue->Name, Subject => 'Merge test. orig', @@ -31,7 +31,7 @@ use RT::Test tests => '29'; } is($Comments,1, "our first ticket has only one Comment"); - my $t2 = RT::Ticket->new($RT::SystemUser); + my $t2 = RT::Ticket->new(RT->SystemUser); my ($t2id,$t2transid, $t2msg) =$t2->Create ( Queue => $queue->Name, Subject => 'Merge test. duplicate'); ok ($t2id, $t2msg); @@ -71,15 +71,15 @@ use RT::Test tests => '29'; # when you try to merge duplicate links on postgres, eveyrything goes to hell due to referential integrity constraints. { - my $t = RT::Ticket->new($RT::SystemUser); + my $t = RT::Ticket->new(RT->SystemUser); $t->Create(Subject => 'Main', Queue => 'general'); ok ($t->id); - my $t2 = RT::Ticket->new($RT::SystemUser); + my $t2 = RT::Ticket->new(RT->SystemUser); $t2->Create(Subject => 'Second', Queue => 'general'); ok ($t2->id); - my $t3 = RT::Ticket->new($RT::SystemUser); + my $t3 = RT::Ticket->new(RT->SystemUser); $t3->Create(Subject => 'Third', Queue => 'general'); ok ($t3->id); diff --git a/rt/t/ticket/quicksearch.t b/rt/t/ticket/quicksearch.t deleted file mode 100644 index 9ab9f21e4..000000000 --- a/rt/t/ticket/quicksearch.t +++ /dev/null @@ -1,41 +0,0 @@ - -#!/usr/bin/perl -w - -use strict; -use warnings; - -use RT::Test tests => 10; -use_ok('RT'); - - -my $q = RT::Queue->new($RT::SystemUser); -my $queue = 'SearchTests-'.$$; -$q->Create(Name => $queue); -ok ($q->id, "Created the queue"); - -my $t1 = RT::Ticket->new($RT::SystemUser); -my ( $id, undef, $msg ) = $t1->Create( - Queue => $q->id, - Subject => 'SearchTest1', - Requestor => ['search2@example.com'], -); -ok( $id, $msg ); - -use_ok("RT::Search::Googleish"); - -my $active_statuses = join( " OR ", map "Status = '$_'", RT::Queue->ActiveStatusArray()); - -my $tickets = RT::Tickets->new($RT::SystemUser); -my $quick = RT::Search::Googleish->new(Argument => "", - TicketsObj => $tickets); -my @tests = ( - "General new open root" => "( Owner = 'root' ) AND ( Queue = 'General' ) AND ( Status = 'new' OR Status = 'open' )", - "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' )"); - -while (my ($from, $to) = splice @tests, 0, 2) { - is($quick->QueryToSQL($from), $to, "<$from> -> <$to>"); -} diff --git a/rt/t/ticket/requestor-order.t b/rt/t/ticket/requestor-order.t index 4539fbdc6..bdacc460e 100644 --- a/rt/t/ticket/requestor-order.t +++ b/rt/t/ticket/requestor-order.t @@ -6,7 +6,7 @@ use_ok('RT'); use RT::Ticket; -my $q = RT::Queue->new($RT::SystemUser); +my $q = RT::Queue->new(RT->SystemUser); my $queue = 'SearchTests-'.rand(200); $q->Create(Name => $queue); @@ -15,7 +15,7 @@ my @requestors = ( ('bravo@example.com') x 6, ('alpha@example.com') x 6, (undef) x 6); my @subjects = ("first test", "second test", "third test", "fourth test", "fifth test") x 6; while (@requestors) { - my $t = RT::Ticket->new($RT::SystemUser); + my $t = RT::Ticket->new(RT->SystemUser); my ( $id, undef $msg ) = $t->Create( Queue => $q->id, Subject => shift @subjects, @@ -25,13 +25,13 @@ while (@requestors) { } { - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue'"); is($tix->Count, 30, "found thirty tickets"); } { - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND requestor = 'alpha\@example.com'"); $tix->OrderByCols({ FIELD => "Subject" }); my @subjects; @@ -60,7 +60,7 @@ sub check_emails_order } { - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND subject = 'first test' AND Requestor.EmailAddress LIKE 'example.com'"); $tix->OrderByCols({ FIELD => "Requestor.EmailAddress" }); check_emails_order($tix, 5, 'ASC'); @@ -69,7 +69,7 @@ sub check_emails_order } { - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND Subject = 'first test'"); $tix->OrderByCols({ FIELD => "Requestor.EmailAddress" }); check_emails_order($tix, 6, 'ASC'); @@ -79,7 +79,7 @@ sub check_emails_order { - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND Subject = 'first test'"); $tix->OrderByCols({ FIELD => "Requestor.EmailAddress" }); check_emails_order($tix, 6, 'ASC'); @@ -89,7 +89,7 @@ sub check_emails_order { # create ticket with group as member of the requestors group - my $t = RT::Ticket->new($RT::SystemUser); + my $t = RT::Ticket->new(RT->SystemUser); my ( $id, $msg ) = $t->Create( Queue => $q->id, Subject => "first test", @@ -97,7 +97,7 @@ sub check_emails_order ); ok( $id, "ticket created" ) or diag( "error: $msg" ); - my $g = RT::Group->new($RT::SystemUser); + my $g = RT::Group->new(RT->SystemUser); my ($gid); ($gid, $msg) = $g->CreateUserDefinedGroup(Name => '20-sort-by-requestor.t-'.rand(200)); @@ -107,7 +107,7 @@ sub check_emails_order ok($id, "added group to requestors group") or diag("error: $msg"); } - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND Subject = 'first test'"); $tix->OrderByCols({ FIELD => "Requestor.EmailAddress" }); @@ -117,7 +117,7 @@ sub check_emails_order check_emails_order($tix, 7, 'DESC'); { - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue'"); $tix->OrderByCols({ FIELD => "Requestor.EmailAddress" }); $tix->RowsPerPage(30); @@ -128,7 +128,7 @@ sub check_emails_order } { - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue'"); $tix->OrderByCols({ FIELD => "Requestor.EmailAddress" }); $tix->RowsPerPage(30); @@ -138,5 +138,3 @@ sub check_emails_order is_deeply( [grep {$_} @mails], [ sort grep {$_} @mails ], "Paging works (exclude nulls, which are db-dependant)"); } RT::Test->mailsent_ok(25); - -# vim:ft=perl: diff --git a/rt/t/ticket/scrips_batch.t b/rt/t/ticket/scrips_batch.t index f13881b65..44d7f8e34 100644 --- a/rt/t/ticket/scrips_batch.t +++ b/rt/t/ticket/scrips_batch.t @@ -2,7 +2,7 @@ use strict; use warnings; -use RT::Test tests => '19'; +use RT::Test tests => 19; use_ok('RT'); use_ok('RT::Ticket'); @@ -16,12 +16,10 @@ ok $m->login, 'logged in as root'; my $sid; { - $m->follow_link_ok( { text => 'Configuration' } ); - $m->follow_link_ok( { text => 'Queues' } ); + $m->follow_link_ok( { id => 'tools-config-queues' } ); $m->follow_link_ok( { text => $queue->Name } ); - $m->follow_link_ok( { text => 'Scrips' } ); - $m->follow_link_ok( { text => 'New scrip' } ); - $m->form_number(3); + $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'); @@ -30,19 +28,19 @@ my $sid; $m->field('Scrip-new-CustomPrepareCode' => 'return 1;'); $m->field('Scrip-new-CustomCommitCode' => 'return 1;'); $m->submit; - $m->content_like( qr/Scrip Created/ ); + $m->content_contains("Scrip Created"); - ($sid) = ($m->content =~ /Scrip\s*#(\d+)/); - my $form = $m->form_number(3); + 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'; - use File::Temp qw(tempfile); - my ($tmp_fh, $tmp_fn) = tempfile(); + my $tmp_fn = File::Spec->catfile( RT::Test->temp_directory, 'transactions' ); + open my $tmp_fh, '+>', $tmp_fn or die $!; my $code = <<END; open( my \$fh, '>', '$tmp_fn' ) or die "Couldn't open '$tmp_fn':\$!"; @@ -62,13 +60,13 @@ END $m->submit; $m->goto_create_ticket( $queue ); - $m->form_number(3); + $m->form_name('TicketCreate'); $m->submit; is_deeply parse_handle($tmp_fh), ['Create'], 'Create'; $m->follow_link_ok( { text => 'Resolve' } ); - $m->form_number(3); + $m->form_name('TicketUpdate'); $m->field( "UpdateContent" => 'resolve it' ); $m->click('SubmitTicket'); diff --git a/rt/t/ticket/search.t b/rt/t/ticket/search.t index 9cec4f753..fd0a7e08f 100644 --- a/rt/t/ticket/search.t +++ b/rt/t/ticket/search.t @@ -6,11 +6,11 @@ use strict; use warnings; -use RT::Test tests => 43; +use RT::Test nodata => 1, tests => 43; # setup the queue -my $q = RT::Queue->new($RT::SystemUser); +my $q = RT::Queue->new(RT->SystemUser); my $queue = 'SearchTests-'.$$; $q->Create(Name => $queue); ok ($q->id, "Created the queue"); @@ -19,17 +19,17 @@ ok ($q->id, "Created the queue"); # and setup the CFs # we believe the Type shouldn't matter. -my $cf = RT::CustomField->new($RT::SystemUser); +my $cf = RT::CustomField->new(RT->SystemUser); $cf->Create(Name => 'SearchTest', Type => 'Freeform', MaxValues => 0, Queue => $q->id); ok($cf->id, "Created the SearchTest CF"); my $cflabel = "CustomField-".$cf->id; -my $cf2 = RT::CustomField->new($RT::SystemUser); +my $cf2 = RT::CustomField->new(RT->SystemUser); $cf2->Create(Name => 'SearchTest2', Type => 'Freeform', MaxValues => 0, Queue => $q->id); ok($cf2->id, "Created the SearchTest2 CF"); my $cflabel2 = "CustomField-".$cf2->id; -my $cf3 = RT::CustomField->new($RT::SystemUser); +my $cf3 = RT::CustomField->new(RT->SystemUser); $cf3->Create(Name => 'SearchTest3', Type => 'Freeform', MaxValues => 0, Queue => $q->id); ok($cf3->id, "Created the SearchTest3 CF"); my $cflabel3 = "CustomField-".$cf3->id; @@ -39,16 +39,16 @@ my $cflabel3 = "CustomField-".$cf3->id; # caused spurious results on negative searches if another custom field # with the same name existed on a different queue. Hence, we make # duplicate CFs on a different queue here -my $dup = RT::Queue->new($RT::SystemUser); +my $dup = RT::Queue->new(RT->SystemUser); $dup->Create(Name => $queue . "-Copy"); ok ($dup->id, "Created the duplicate queue"); -my $dupcf = RT::CustomField->new($RT::SystemUser); +my $dupcf = RT::CustomField->new(RT->SystemUser); $dupcf->Create(Name => 'SearchTest', Type => 'Freeform', MaxValues => 0, Queue => $dup->id); ok($dupcf->id, "Created the duplicate SearchTest CF"); -$dupcf = RT::CustomField->new($RT::SystemUser); +$dupcf = RT::CustomField->new(RT->SystemUser); $dupcf->Create(Name => 'SearchTest2', Type => 'Freeform', MaxValues => 0, Queue => $dup->id); ok($dupcf->id, "Created the SearchTest2 CF"); -$dupcf = RT::CustomField->new($RT::SystemUser); +$dupcf = RT::CustomField->new(RT->SystemUser); $dupcf->Create(Name => 'SearchTest3', Type => 'Freeform', MaxValues => 0, Queue => $dup->id); ok($dupcf->id, "Created the SearchTest3 CF"); @@ -58,7 +58,7 @@ ok($dupcf->id, "Created the SearchTest3 CF"); # there's probably a way to think harder and do this with fewer -my $t1 = RT::Ticket->new($RT::SystemUser); +my $t1 = RT::Ticket->new(RT->SystemUser); my ( $id, undef $msg ) = $t1->Create( Queue => $q->id, Subject => 'SearchTest1', @@ -70,7 +70,7 @@ my ( $id, undef $msg ) = $t1->Create( ok( $id, $msg ); -my $t2 = RT::Ticket->new($RT::SystemUser); +my $t2 = RT::Ticket->new(RT->SystemUser); ( $id, undef, $msg ) = $t2->Create( Queue => $q->id, Subject => 'SearchTest2', @@ -81,7 +81,7 @@ my $t2 = RT::Ticket->new($RT::SystemUser); ); ok( $id, $msg ); -my $t3 = RT::Ticket->new($RT::SystemUser); +my $t3 = RT::Ticket->new(RT->SystemUser); ( $id, undef, $msg ) = $t3->Create( Queue => $q->id, Subject => 'SearchTest3', @@ -92,7 +92,7 @@ my $t3 = RT::Ticket->new($RT::SystemUser); ); ok( $id, $msg ); -my $t4 = RT::Ticket->new($RT::SystemUser); +my $t4 = RT::Ticket->new(RT->SystemUser); ( $id, undef, $msg ) = $t4->Create( Queue => $q->id, Subject => 'SearchTest4', @@ -103,7 +103,7 @@ my $t4 = RT::Ticket->new($RT::SystemUser); ); ok( $id, $msg ); -my $t5 = RT::Ticket->new($RT::SystemUser); +my $t5 = RT::Ticket->new(RT->SystemUser); ( $id, undef, $msg ) = $t5->Create( Queue => $q->id, # Subject => 'SearchTest5', @@ -114,7 +114,7 @@ my $t5 = RT::Ticket->new($RT::SystemUser); ); ok( $id, $msg ); -my $t6 = RT::Ticket->new($RT::SystemUser); +my $t6 = RT::Ticket->new(RT->SystemUser); ( $id, undef, $msg ) = $t6->Create( Queue => $q->id, Subject => 'SearchTest6', @@ -125,7 +125,7 @@ my $t6 = RT::Ticket->new($RT::SystemUser); ); ok( $id, $msg ); -my $t7 = RT::Ticket->new($RT::SystemUser); +my $t7 = RT::Ticket->new(RT->SystemUser); ( $id, undef, $msg ) = $t7->Create( Queue => $q->id, Subject => 'SearchTest7', @@ -137,7 +137,7 @@ my $t7 = RT::Ticket->new($RT::SystemUser); ok( $id, $msg ); # we have tickets. start searching -my $tix = RT::Tickets->new($RT::SystemUser); +my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue'"); is($tix->Count, 7, "found all the tickets") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; @@ -145,73 +145,73 @@ is($tix->Count, 7, "found all the tickets") # very simple searches. both CF and normal -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND CF.SearchTest = 'foo1'"); is($tix->Count, 1, "matched identical subject") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'foo1'"); is($tix->Count, 1, "matched LIKE subject") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND CF.SearchTest = 'foo'"); is($tix->Count, 0, "IS a regexp match") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'foo'"); is($tix->Count, 5, "matched LIKE subject") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND CF.SearchTest IS NULL"); is($tix->Count, 2, "IS null CF") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND Requestors LIKE 'search1'"); is($tix->Count, 1, "LIKE requestor") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND Requestors = 'search1\@example.com'"); is($tix->Count, 1, "IS requestor") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND Requestors LIKE 'search'"); is($tix->Count, 6, "LIKE requestor") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND Requestors IS NULL"); is($tix->Count, 1, "Search for no requestor") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND Subject = 'SearchTest1'"); is($tix->Count, 1, "IS subject") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND Subject LIKE 'SearchTest1'"); is($tix->Count, 1, "LIKE subject") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND Subject = ''"); is($tix->Count, 1, "found one ticket") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND Subject LIKE 'SearchTest'"); is($tix->Count, 6, "found two ticket") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND Subject LIKE 'qwerty'"); is($tix->Count, 0, "found zero ticket") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; @@ -221,58 +221,58 @@ is($tix->Count, 0, "found zero ticket") # various combinations -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("CF.SearchTest LIKE 'foo' AND CF.SearchTest2 LIKE 'bar1'"); is($tix->Count, 1, "LIKE cf and LIKE cf"); -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("CF.SearchTest = 'foo1' AND CF.SearchTest2 = 'bar1'"); is($tix->Count, 1, "is cf and is cf"); -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("CF.SearchTest = 'foo' AND CF.SearchTest2 LIKE 'bar1'"); is($tix->Count, 0, "is cf and like cf"); -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("CF.SearchTest LIKE 'foo' AND CF.SearchTest2 LIKE 'bar' AND CF.SearchTest3 LIKE 'qux'"); is($tix->Count, 3, "like cf and like cf and like cf"); -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("CF.SearchTest LIKE 'foo' AND CF.SearchTest2 LIKE 'bar' AND CF.SearchTest3 LIKE 'qux6'"); is($tix->Count, 1, "like cf and like cf and is cf"); -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("CF.SearchTest LIKE 'foo' AND Subject LIKE 'SearchTest'"); is($tix->Count, 4, "like cf and like subject"); -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("CF.SearchTest IS NULL AND CF.SearchTest2 = 'bar2'"); is($tix->Count, 1, "null cf and is cf"); -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND CF.SearchTest IS NULL AND CF.SearchTest2 IS NULL"); is($tix->Count, 1, "null cf and null cf"); # tests with the same CF listed twice -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("CF.{SearchTest} = 'foo1'"); is($tix->Count, 1, "is cf.{name} format"); -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("CF.SearchTest = 'foo1' OR CF.SearchTest = 'foo3'"); is($tix->Count, 2, "is cf1 or is cf1"); -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("CF.SearchTest = 'foo1' OR CF.SearchTest IS NULL"); is($tix->Count, 3, "is cf1 or null cf1"); -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("(CF.SearchTest = 'foo1' OR CF.SearchTest = 'foo3') AND (CF.SearchTest2 = 'bar1' OR CF.SearchTest2 = 'bar2')"); is($tix->Count, 1, "(is cf1 or is cf1) and (is cf2 or is cf2)"); -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("CF.SearchTest = 'foo1' OR CF.SearchTest = 'foo3' OR CF.SearchTest2 = 'bar1' OR CF.SearchTest2 = 'bar2'"); is($tix->Count, 3, "is cf1 or is cf1 or is cf2 or is cf2"); diff --git a/rt/t/ticket/search_by_cf_freeform_multiple.t b/rt/t/ticket/search_by_cf_freeform_multiple.t index be5130651..4e7cddc06 100644 --- a/rt/t/ticket/search_by_cf_freeform_multiple.t +++ b/rt/t/ticket/search_by_cf_freeform_multiple.t @@ -3,17 +3,17 @@ use strict; use warnings; -use RT::Test tests => 105; +use RT::Test nodata => 1, tests => 118; use RT::Ticket; my $q = RT::Test->load_or_create_queue( Name => 'Regression' ); ok $q && $q->id, 'loaded or created queue'; my $queue = $q->Name; -diag "create a CF\n" if $ENV{TEST_VERBOSE}; +diag "create a CF"; my ($cf_name, $cf_id, $cf) = ("Test", 0, undef); { - $cf = RT::CustomField->new( $RT::SystemUser ); + $cf = RT::CustomField->new( RT->SystemUser ); my ($ret, $msg) = $cf->Create( Name => $cf_name, Queue => $q->id, @@ -25,38 +25,10 @@ my ($cf_name, $cf_id, $cf) = ("Test", 0, undef); my ($total, @data, @tickets, %test) = (0, ()); -sub add_tix_from_data { - my @res = (); - while (@data) { - my %args = %{ shift(@data) }; - my @cf_value = $args{'Subject'} ne '-'? (split /(?=.)/, $args{'Subject'}) : (); - diag "vals: ". join ', ', @cf_value; - my $t = RT::Ticket->new($RT::SystemUser); - my ( $id, undef $msg ) = $t->Create( - Queue => $q->id, - %args, - "CustomField-$cf_id" => \@cf_value, - ); - ok( $id, "ticket created" ) or diag("error: $msg"); - - my $got = join ',', sort do { - my $vals = $t->CustomFieldValues( $cf_name ); - my @tmp; - while (my $v = $vals->Next ) { push @tmp, $v->Content } - @tmp; - }; - - is( $got, join( ',', sort @cf_value), 'correct CF values' ); - push @res, $t; - $total++; - } - return @res; -} - 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); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL( "( $query_prefix ) AND ( $key )" ); my $error = 0; @@ -79,12 +51,12 @@ sub run_tests { @data = ( { Subject => '-' }, - { Subject => 'x' }, - { Subject => 'y' }, - { Subject => 'z' }, - { Subject => 'xy' }, - { Subject => 'xz' }, - { Subject => 'yz' }, + { 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 }, @@ -142,12 +114,13 @@ sub run_tests { "'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 = add_tix_from_data(); +@tickets = RT::Test->create_tickets( { Queue => $q->id }, @data); +$total = scalar @tickets; + { - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue'"); is($tix->Count, $total, "found $total tickets"); } run_tests(); -exit 0; diff --git a/rt/t/ticket/search_by_cf_freeform_single.t b/rt/t/ticket/search_by_cf_freeform_single.t index d5ff7ec0d..278a3ce03 100644 --- a/rt/t/ticket/search_by_cf_freeform_single.t +++ b/rt/t/ticket/search_by_cf_freeform_single.t @@ -3,17 +3,17 @@ use strict; use warnings; -use RT::Test tests => 99; +use RT::Test nodata => 1, tests => 106; use RT::Ticket; my $q = RT::Test->load_or_create_queue( Name => 'Regression' ); ok $q && $q->id, 'loaded or created queue'; my $queue = $q->Name; -diag "create a CF\n" if $ENV{TEST_VERBOSE}; +diag "create a CF"; my ($cf_name, $cf_id, $cf) = ("Test", 0, undef); { - $cf = RT::CustomField->new( $RT::SystemUser ); + $cf = RT::CustomField->new( RT->SystemUser ); my ($ret, $msg) = $cf->Create( Name => $cf_name, Queue => $q->id, @@ -25,29 +25,10 @@ my ($cf_name, $cf_id, $cf) = ("Test", 0, undef); my ($total, @data, @tickets, %test) = (0, ()); -sub add_tix_from_data { - my @res = (); - while (@data) { - my %args = %{ shift(@data) }; - my $cf_value = $args{'Subject'} ne '-'? $args{'Subject'} : undef; - my $t = RT::Ticket->new($RT::SystemUser); - my ( $id, undef $msg ) = $t->Create( - Queue => $q->id, - %args, - "CustomField-$cf_id" => $cf_value, - ); - ok( $id, "ticket created" ) or diag("error: $msg"); - is( $t->FirstCustomFieldValue( $cf_name ), $cf_value, 'correct value' ); - push @res, $t; - $total++; - } - return @res; -} - 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); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL( "( $query_prefix ) AND ( $key )" ); my $error = 0; @@ -70,9 +51,9 @@ sub run_tests { @data = ( { Subject => '-' }, - { Subject => 'x' }, - { Subject => 'y' }, - { Subject => 'z' }, + { 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 }, @@ -131,12 +112,14 @@ sub run_tests { "'CF.$queue.{$cf_name}' = 'x' OR 'CF.$queue.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1 }, ); -@tickets = add_tix_from_data(); +@tickets = RT::Test->create_tickets( { Queue => $q->id }, @data); +$total = scalar @tickets; { - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue'"); is($tix->Count, $total, "found $total tickets"); } run_tests(); -exit 0; +@tickets = (); + diff --git a/rt/t/ticket/search_by_links.t b/rt/t/ticket/search_by_links.t index a8e955c8b..61b69b73e 100644 --- a/rt/t/ticket/search_by_links.t +++ b/rt/t/ticket/search_by_links.t @@ -3,35 +3,18 @@ use strict; use warnings; -use RT::Test tests => 80; +use RT::Test nodata => 1, tests => 98; use RT::Ticket; my $q = RT::Test->load_or_create_queue( Name => 'Regression' ); ok $q && $q->id, 'loaded or created queue'; -my ($total, @data, @tickets, %test) = (0, ()); - -sub add_tix_from_data { - my @res = (); - while (@data) { - my $t = RT::Ticket->new($RT::SystemUser); - my %args = %{ shift(@data) }; - $args{$_} = $res[ $args{$_} ]->id foreach grep $args{$_}, keys %RT::Ticket::LINKTYPEMAP; - my ( $id, undef $msg ) = $t->Create( - Queue => $q->id, - %args, - ); - ok( $id, "ticket created" ) or diag("error: $msg"); - push @res, $t; - $total++; - } - return @res; -} +my ($total, @tickets, %test) = (0, ()); 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); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL( "( $query_prefix ) AND ( $key )" ); my $error = 0; @@ -53,12 +36,13 @@ sub run_tests { } # simple set with "no links", "parent and child" -@data = ( +@tickets = RT::Test->create_tickets( + { Queue => $q->id }, { Subject => '-', }, { Subject => 'p', }, { Subject => 'c', MemberOf => -1 }, ); -@tickets = add_tix_from_data(); +$total += @tickets; %test = ( 'Linked IS NOT NULL' => { '-' => 0, c => 1, p => 1 }, 'Linked IS NULL' => { '-' => 1, c => 0, p => 0 }, @@ -82,14 +66,15 @@ sub run_tests { 'MemberOf != '. $tickets[1]->id => { '-' => 1, c => 0, p => 1 }, ); { - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '". $q->id ."'"); is($tix->Count, $total, "found $total tickets"); } run_tests(); # another set with tests of combinations searches -@data = ( +@tickets = RT::Test->create_tickets( + { Queue => $q->id }, { Subject => '-', }, { Subject => 'p', }, { Subject => 'rp', RefersTo => -1 }, @@ -97,7 +82,7 @@ run_tests(); { Subject => 'rc1', RefersTo => -1 }, { Subject => 'rc2', RefersTo => -2 }, ); -@tickets = add_tix_from_data(); +$total += @tickets; my $pid = $tickets[1]->id; %test = ( 'RefersTo IS NOT NULL' => { '-' => 0, c => 0, p => 0, rp => 1, rc1 => 1, rc2 => 1 }, @@ -124,9 +109,11 @@ my $pid = $tickets[1]->id; "RefersTo != $pid OR MemberOf != $pid" => { '-' => 1, c => 1, p => 1, rp => 1, rc1 => 1, rc2 => 1 }, ); { - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '". $q->id ."'"); is($tix->Count, $total, "found $total tickets"); } run_tests(); +@tickets = (); + diff --git a/rt/t/ticket/search_by_txn.t b/rt/t/ticket/search_by_txn.t index 1be6916ef..0e5f76dcd 100644 --- a/rt/t/ticket/search_by_txn.t +++ b/rt/t/ticket/search_by_txn.t @@ -11,13 +11,13 @@ use RT::Test tests => 10; my $SUBJECT = "Search test - ".$$; use_ok('RT::Tickets'); -my $tix = RT::Tickets->new($RT::SystemUser); +my $tix = RT::Tickets->new(RT->SystemUser); can_ok($tix, 'FromSQL'); $tix->FromSQL('Updated = "2005-08-05" AND Subject = "$SUBJECT"'); ok(! $tix->Count, "Searching for tickets updated on a random date finds nothing" . $tix->Count); -my $ticket = RT::Ticket->new($RT::SystemUser); +my $ticket = RT::Ticket->new(RT->SystemUser); $ticket->Create(Queue => 'General', Subject => $SUBJECT); ok ($ticket->id, "We created a ticket"); my ($id, $txnid, $txnobj) = $ticket->Comment( Content => 'A comment that happend on 2004-01-01'); diff --git a/rt/t/ticket/search_by_watcher.t b/rt/t/ticket/search_by_watcher.t index 9d94432d2..809450b56 100644 --- a/rt/t/ticket/search_by_watcher.t +++ b/rt/t/ticket/search_by_watcher.t @@ -3,224 +3,216 @@ use strict; use warnings; -use RT::Test tests => 119; +use RT::Test nodata => 1, tests => 2108; use RT::Ticket; my $q = RT::Test->load_or_create_queue( Name => 'Regression' ); ok $q && $q->id, 'loaded or created queue'; my $queue = $q->Name; -my ($total, @data, @tickets, %test) = (0, ()); - -sub add_tix_from_data { - my @res = (); - while (@data) { - my $t = RT::Ticket->new($RT::SystemUser); - my ( $id, undef $msg ) = $t->Create( - Queue => $q->id, - %{ shift(@data) }, - ); - ok( $id, "ticket created" ) or diag("error: $msg"); - push @res, $t; - $total++; +my ($total, @tickets, @test, @conditions) = (0, ()); + +sub generate_tix { + my @list = ( + [], + ['x@foo.com'], ['y@bar.com'], ['z@bar.com'], + ['x@foo.com', 'y@bar.com'], + ['y@bar.com', 'z@bar.com'], + ['x@foo.com', 'z@bar.com'], + ['x@foo.com', 'y@bar.com', 'z@bar.com'], + ); + my @data = (); + foreach my $r (@list) { + foreach my $c (@list) { + my $subject = 'r:'. (join( '', map substr($_, 0, 1), @$r ) || '-') .';'; + $subject .= 'c:'. (join( '', map substr($_, 0, 1), @$c ) || '-') .';'; + + push @data, { + Subject => $subject, + Requestor => $r, + Cc => $c, + }; + } } - return @res; + return RT::Test->create_tickets( { Queue => $q->id }, @data ); } 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; + while ( my ($query, $checks) = splice @test, 0, 2 ) { + run_test( $query, %$checks ); } } -@data = ( - { Subject => 'xy', Requestor => ['x@example.com', 'y@example.com'] }, - { Subject => 'x', Requestor => 'x@example.com' }, - { Subject => 'y', Requestor => 'y@example.com' }, - { Subject => '-', }, - { Subject => 'z', Requestor => 'z@example.com' }, -); -%test = ( - 'Requestor = "x@example.com"' => { xy => 1, x => 1, y => 0, '-' => 0, z => 0 }, - 'Requestor != "x@example.com"' => { xy => 0, x => 0, y => 1, '-' => 1, z => 1 }, - - 'Requestor = "y@example.com"' => { xy => 1, x => 0, y => 1, '-' => 0, z => 0 }, - 'Requestor != "y@example.com"' => { xy => 0, x => 1, y => 0, '-' => 1, z => 1 }, +sub run_test { + my ($query, %checks) = @_; - 'Requestor LIKE "@example.com"' => { xy => 1, x => 1, y => 1, '-' => 0, z => 1 }, - 'Requestor NOT LIKE "@example.com"' => { xy => 0, x => 0, y => 0, '-' => 1, z => 0 }, + my $tix = RT::Tickets->new(RT->SystemUser); + $tix->FromSQL($query); + my $error = 0; - 'Requestor IS NULL' => { xy => 0, x => 0, y => 0, '-' => 1, z => 0 }, - 'Requestor IS NOT NULL' => { xy => 1, x => 1, y => 1, '-' => 0, z => 1 }, + my $count = 0; + $count++ foreach grep $_, values %checks; + is($tix->Count, $count, "found correct number of ticket(s) by '$query'") or $error = 1; -# this test is a todo, we run it later -# 'Requestor = "x@example.com" AND Requestor = "y@example.com"' => { xy => 1, x => 0, y => 0, '-' => 0, z => 0 }, - 'Requestor = "x@example.com" OR Requestor = "y@example.com"' => { xy => 1, x => 1, y => 1, '-' => 0, z => 0 }, - - 'Requestor != "x@example.com" AND Requestor != "y@example.com"' => { xy => 0, x => 0, y => 0, '-' => 1, z => 1 }, - 'Requestor != "x@example.com" OR Requestor != "y@example.com"' => { xy => 0, x => 1, y => 1, '-' => 1, z => 1 }, - - 'Requestor = "x@example.com" AND Requestor != "y@example.com"' => { xy => 0, x => 1, y => 0, '-' => 0, z => 0 }, - 'Requestor = "x@example.com" OR Requestor != "y@example.com"' => { xy => 1, x => 1, y => 0, '-' => 1, z => 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; - 'Requestor != "x@example.com" AND Requestor = "y@example.com"' => { xy => 0, x => 0, y => 1, '-' => 0, z => 0 }, - 'Requestor != "x@example.com" OR Requestor = "y@example.com"' => { xy => 1, x => 0, y => 1, '-' => 1, z => 1 }, -); -@tickets = add_tix_from_data(); -{ - my $tix = RT::Tickets->new($RT::SystemUser); - $tix->FromSQL("Queue = '$queue'"); - is($tix->Count, $total, "found $total tickets"); + diag "Wrong SQL query for '$query':". $tix->BuildSelectQuery if $error; } -run_tests(); - -# mixing searches by watchers with other conditions -# http://rt3.fsck.com/Ticket/Display.html?id=9322 -%test = ( - 'Subject LIKE "x" AND Requestor = "y@example.com"' => - { xy => 1, x => 0, y => 0, '-' => 0, z => 0 }, - 'Subject NOT LIKE "x" AND Requestor = "y@example.com"' => - { xy => 0, x => 0, y => 1, '-' => 0, z => 0 }, - 'Subject LIKE "x" AND Requestor != "y@example.com"' => - { xy => 0, x => 1, y => 0, '-' => 0, z => 0 }, - 'Subject NOT LIKE "x" AND Requestor != "y@example.com"' => - { xy => 0, x => 0, y => 0, '-' => 1, z => 1 }, - - 'Subject LIKE "x" OR Requestor = "y@example.com"' => - { xy => 1, x => 1, y => 1, '-' => 0, z => 0 }, - 'Subject NOT LIKE "x" OR Requestor = "y@example.com"' => - { xy => 1, x => 0, y => 1, '-' => 1, z => 1 }, - 'Subject LIKE "x" OR Requestor != "y@example.com"' => - { xy => 1, x => 1, y => 0, '-' => 1, z => 1 }, - 'Subject NOT LIKE "x" OR Requestor != "y@example.com"' => - { xy => 0, x => 1, y => 1, '-' => 1, z => 1 }, - -# group of cases when user doesn't exist in DB at all - 'Subject LIKE "x" AND Requestor = "not-exist@example.com"' => - { xy => 0, x => 0, y => 0, '-' => 0, z => 0 }, - 'Subject NOT LIKE "x" AND Requestor = "not-exist@example.com"' => - { xy => 0, x => 0, y => 0, '-' => 0, z => 0 }, - 'Subject LIKE "x" AND Requestor != "not-exist@example.com"' => - { xy => 1, x => 1, y => 0, '-' => 0, z => 0 }, - 'Subject NOT LIKE "x" AND Requestor != "not-exist@example.com"' => - { xy => 0, x => 0, y => 1, '-' => 1, z => 1 }, -# 'Subject LIKE "x" OR Requestor = "not-exist@example.com"' => -# { xy => 1, x => 1, y => 0, '-' => 0, z => 0 }, -# 'Subject NOT LIKE "x" OR Requestor = "not-exist@example.com"' => -# { xy => 0, x => 0, y => 1, '-' => 1, z => 1 }, - 'Subject LIKE "x" OR Requestor != "not-exist@example.com"' => - { xy => 1, x => 1, y => 1, '-' => 1, z => 1 }, - 'Subject NOT LIKE "x" OR Requestor != "not-exist@example.com"' => - { xy => 1, x => 1, y => 1, '-' => 1, z => 1 }, - - 'Subject LIKE "z" AND (Requestor = "x@example.com" OR Requestor = "y@example.com")' => - { xy => 0, x => 0, y => 0, '-' => 0, z => 0 }, - 'Subject NOT LIKE "z" AND (Requestor = "x@example.com" OR Requestor = "y@example.com")' => - { xy => 1, x => 1, y => 1, '-' => 0, z => 0 }, - 'Subject LIKE "z" OR (Requestor = "x@example.com" OR Requestor = "y@example.com")' => - { xy => 1, x => 1, y => 1, '-' => 0, z => 1 }, - 'Subject NOT LIKE "z" OR (Requestor = "x@example.com" OR Requestor = "y@example.com")' => - { xy => 1, x => 1, y => 1, '-' => 1, z => 0 }, -); -run_tests(); - -TODO: { - local $TODO = "we can't generate this query yet"; - %test = ( - 'Requestor = "x@example.com" AND Requestor = "y@example.com"' - => { xy => 1, x => 0, y => 0, '-' => 0, z => 0 }, - 'Subject LIKE "x" OR Requestor = "not-exist@example.com"' => - { xy => 1, x => 1, y => 0, '-' => 0, z => 0 }, - 'Subject NOT LIKE "x" OR Requestor = "not-exist@example.com"' => - { xy => 0, x => 0, y => 1, '-' => 1, z => 1 }, + +sub run_auto_tests { + { + my @atmp = @conditions; + while ( my ($query, $cb) = splice @atmp, 0, 2 ) { + my %checks = (); + foreach my $ticket ( @tickets ) { + my $s = $ticket->Subject; + $checks{ $s } = $cb->($s); + } + run_test($query, %checks); + } + } + my @queries = ( + '? AND ?' => sub { $_[0] and $_[1] }, + '? OR ?' => sub { $_[0] or $_[1] }, ); - run_tests(); + while ( my ($template, $t_cb) = splice @queries, 0, 2 ) { + my @atmp = @conditions; + while ( my ($a, $a_cb) = splice @atmp, 0, 2 ) { + my @btmp = @conditions; + while ( my ($b, $b_cb) = splice @btmp, 0, 2 ) { + next if $a eq $b; + + my %checks = (); + foreach my $ticket ( @tickets ) { + my $s = $ticket->Subject; + $checks{ $s } = $t_cb->( scalar $a_cb->($s), scalar $b_cb->($s) ); + } + + my $query = $template; + foreach my $tmp ($a, $b) { + $query =~ s/\?/$tmp/; + } + + run_test( $query, %checks ); + } } + } +# XXX: It +# @queries = ( +# '? AND ? AND ?' => sub { $_[0] and $_[1] and $_[2] }, +# '(? OR ?) AND ?' => sub { return (($_[0] or $_[1]) and $_[2]) }, +# '? OR (? AND ?)' => sub { $_[0] or ($_[1] and $_[2]) }, +# '(? AND ?) OR ?' => sub { ($_[0] and $_[1]) or $_[2] }, +# '? AND (? OR ?)' => sub { $_[0] and ($_[1] or $_[2]) }, +# '? OR ? OR ?' => sub { $_[0] or $_[1] or $_[2] }, +# ); +# while ( my ($template, $t_cb) = splice @queries, 0, 2 ) { +# my @atmp = @conditions; +# while ( my ($a, $a_cb) = splice @atmp, 0, 2 ) { +# my @btmp = @conditions; +# while ( my ($b, $b_cb) = splice @btmp, 0, 2 ) { +# next if $a eq $b; +# my @ctmp = @conditions; +# while ( my ($c, $c_cb) = splice @ctmp, 0, 2 ) { +# next if $a eq $c; +# next if $b eq $c; +# +# my %checks = (); +# foreach my $ticket ( @tickets ) { +# my $s = $ticket->Subject; +# $checks{ $s } = $t_cb->( scalar $a_cb->($s), scalar $b_cb->($s), scalar $c_cb->($s) ); +# } +# +# my $query = $template; +# foreach my $tmp ($a, $b, $c) { +# $query =~ s/\?/$tmp/; +# } +# +# run_test( $query, %checks ); +# } } } +# } + } -@data = ( - { Subject => 'xy', Cc => ['x@example.com'], Requestor => [ 'y@example.com' ] }, - { Subject => 'x-', Cc => ['x@example.com'], Requestor => [] }, - { Subject => '-y', Cc => [], Requestor => [ 'y@example.com' ] }, - { Subject => '-', }, - { Subject => 'zz', Cc => ['z@example.com'], Requestor => [ 'z@example.com' ] }, - { Subject => 'z-', Cc => ['z@example.com'], Requestor => [] }, - { Subject => '-z', Cc => [], Requestor => [ 'z@example.com' ] }, -); -%test = ( - 'Cc = "x@example.com" AND Requestor = "y@example.com"' => - { xy => 1, 'x-' => 0, '-y' => 0, '-' => 0, zz => 0, 'z-' => 0, '-z' => 0 }, - 'Cc = "x@example.com" OR Requestor = "y@example.com"' => - { xy => 1, 'x-' => 1, '-y' => 1, '-' => 0, zz => 0, 'z-' => 0, '-z' => 0 }, - - 'Cc != "x@example.com" AND Requestor = "y@example.com"' => - { xy => 0, 'x-' => 0, '-y' => 1, '-' => 0, zz => 0, 'z-' => 0, '-z' => 0 }, - 'Cc != "x@example.com" OR Requestor = "y@example.com"' => - { xy => 1, 'x-' => 0, '-y' => 1, '-' => 1, zz => 1, 'z-' => 1, '-z' => 1 }, - - 'Cc IS NULL AND Requestor = "y@example.com"' => - { xy => 0, 'x-' => 0, '-y' => 1, '-' => 0, zz => 0, 'z-' => 0, '-z' => 0 }, - 'Cc IS NULL OR Requestor = "y@example.com"' => - { xy => 1, 'x-' => 0, '-y' => 1, '-' => 1, zz => 0, 'z-' => 0, '-z' => 1 }, - - 'Cc IS NOT NULL AND Requestor = "y@example.com"' => - { xy => 1, 'x-' => 0, '-y' => 0, '-' => 0, zz => 0, 'z-' => 0, '-z' => 0 }, - 'Cc IS NOT NULL OR Requestor = "y@example.com"' => - { xy => 1, 'x-' => 1, '-y' => 1, '-' => 0, zz => 1, 'z-' => 1, '-z' => 0 }, +@conditions = ( + 'Cc = "not@exist"' => sub { 0 }, + 'Cc != "not@exist"' => sub { 1 }, + 'Cc IS NULL' => sub { $_[0] =~ 'c:-;' }, + 'Cc IS NOT NULL' => sub { $_[0] !~ 'c:-;' }, + 'Cc = "x@foo.com"' => sub { $_[0] =~ /c:[^;]*x/ }, + 'Cc != "x@foo.com"' => sub { $_[0] !~ /c:[^;]*x/ }, + 'Cc LIKE "@bar.com"' => sub { $_[0] =~ /c:[^;]*(?:y|z)/ }, +# TODO: +# 'Cc NOT LIKE "@bar.com"' => sub { $_[0] !~ /y|z/ }, + + 'Requestor = "not@exist"' => sub { 0 }, + 'Requestor != "not@exist"' => sub { 1 }, + 'Requestor IS NULL' => sub { $_[0] =~ 'r:-;' }, + 'Requestor IS NOT NULL' => sub { $_[0] !~ 'r:-;' }, + 'Requestor = "x@foo.com"' => sub { $_[0] =~ /r:[^;]*x/ }, + 'Requestor != "x@foo.com"' => sub { $_[0] !~ /r:[^;]*x/ }, + 'Requestor LIKE "@bar.com"' => sub { $_[0] =~ /r:[^;]*(?:y|z)/ }, +# TODO: +# 'Requestor NOT LIKE "@bar.com"' => sub { $_[0] !~ /y|z/ }, + + 'Watcher = "not@exist"' => sub { 0 }, + 'Watcher != "not@exist"' => sub { 1 }, +# TODO: +# 'Watcher IS NULL' => sub { $_[0] eq 'r:-;c:-;' }, +# 'Watcher IS NOT NULL' => sub { $_[0] ne 'r:-;c:-;' }, + 'Watcher = "x@foo.com"' => sub { $_[0] =~ /x/ }, +# 'Watcher != "x@foo.com"' => sub { $_[0] !~ /x/ }, + 'Watcher LIKE "@bar.com"' => sub { $_[0] =~ /(?:y|z)/ }, +# TODO: +# 'Watcher NOT LIKE "@bar.com"' => sub { $_[0] !~ /y|z/ }, + + 'Subject LIKE "ne"' => sub { 0 }, + 'Subject NOT LIKE "ne"' => sub { 1 }, + 'Subject = "r:x;c:y;"' => sub { $_[0] eq 'r:x;c:y;' }, + 'Subject LIKE "x"' => sub { $_[0] =~ 'x' }, ); -@tickets = add_tix_from_data(); + +@tickets = generate_tix(); +$total += scalar @tickets; { - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue'"); is($tix->Count, $total, "found $total tickets"); } -run_tests(); - +run_auto_tests(); # owner is special watcher because reference is duplicated in two places, # owner was an ENUM field now it's WATCHERFIELD, but should support old # style ENUM searches for backward compatibility my $nobody = RT::Nobody(); { - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND Owner = '". $nobody->id ."'"); ok($tix->Count, "found ticket(s)"); } { - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND Owner = '". $nobody->Name ."'"); ok($tix->Count, "found ticket(s)"); } { - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND Owner != '". $nobody->id ."'"); is($tix->Count, 0, "found ticket(s)"); } { - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND Owner != '". $nobody->Name ."'"); is($tix->Count, 0, "found ticket(s)"); } { - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND Owner.Name LIKE 'nob'"); ok($tix->Count, "found ticket(s)"); } @@ -229,22 +221,20 @@ my $nobody = RT::Nobody(); # create ticket and force type to not a 'ticket' value # bug #6898@rt3.fsck.com # and http://marc.theaimsgroup.com/?l=rt-devel&m=112662934627236&w=2 - @data = ( { Subject => 'not a ticket' } ); - my($t) = add_tix_from_data(); + my($t) = RT::Test->create_tickets( { Queue => $q->id }, { Subject => 'not a ticket' } ); $t->_Set( Field => 'Type', Value => 'not a ticket', CheckACL => 0, RecordTransaction => 0, ); - $total--; - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND Owner = 'Nobody'"); is($tix->Count, $total, "found ticket(s)"); } { - my $everyone = RT::Group->new( $RT::SystemUser ); + my $everyone = RT::Group->new( RT->SystemUser ); $everyone->LoadSystemInternalGroup('Everyone'); ok($everyone->id, "loaded 'everyone' group"); my($id, $msg) = $everyone->PrincipalObj->GrantRight( Right => 'OwnTicket', @@ -252,23 +242,23 @@ my $nobody = RT::Nobody(); ); ok($id, "granted OwnTicket right to Everyone on '$queue'") or diag("error: $msg"); - my $u = RT::User->new( $RT::SystemUser ); - $u->LoadOrCreateByEmail('alpha@example.com'); + my $u = RT::User->new( RT->SystemUser ); + $u->LoadOrCreateByEmail('alpha@e.com'); ok($u->id, "loaded user"); - @data = ( { Subject => '4', Owner => $u->id } ); - my($t) = add_tix_from_data(); - is( $t->Owner, $u->id, "created ticket with custom owner" ); + my($t) = RT::Test->create_tickets( + { Queue => $q->id }, { Subject => '4', Owner => $u->id }, + ); my $u_alpha_id = $u->id; - $u = RT::User->new( $RT::SystemUser ); - $u->LoadOrCreateByEmail('bravo@example.com'); + $u = RT::User->new( RT->SystemUser ); + $u->LoadOrCreateByEmail('bravo@e.com'); ok($u->id, "loaded user"); - @data = ( { Subject => '5', Owner => $u->id } ); - ($t) = add_tix_from_data(); - is( $t->Owner, $u->id, "created ticket with custom owner" ); + ($t) = RT::Test->create_tickets( + { Queue => $q->id }, { Subject => '5', Owner => $u->id }, + ); my $u_bravo_id = $u->id; - my $tix = RT::Tickets->new($RT::SystemUser); + my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND ( Owner = '$u_alpha_id' OR Owner = '$u_bravo_id' )" @@ -276,5 +266,5 @@ my $nobody = RT::Nobody(); is($tix->Count, 2, "found ticket(s)"); } +@tickets = (); -exit(0) diff --git a/rt/t/ticket/search_long_cf_values.t b/rt/t/ticket/search_long_cf_values.t index f9cc7b5a2..6ce8505d6 100644 --- a/rt/t/ticket/search_long_cf_values.t +++ b/rt/t/ticket/search_long_cf_values.t @@ -6,24 +6,24 @@ use strict; use warnings; -use RT::Test tests => 10; +use RT::Test nodata => 1, tests => 10; # setup the queue -my $q = RT::Queue->new($RT::SystemUser); +my $q = RT::Queue->new(RT->SystemUser); my $queue = 'SearchTests-'.$$; $q->Create(Name => $queue); ok ($q->id, "Created the queue"); # setup the CF -my $cf = RT::CustomField->new($RT::SystemUser); +my $cf = RT::CustomField->new(RT->SystemUser); $cf->Create(Name => 'SearchTest', Type => 'Freeform', MaxValues => 0, Queue => $q->id); ok($cf->id, "Created the SearchTest CF"); my $cflabel = "CustomField-".$cf->id; # setup some tickets -my $t1 = RT::Ticket->new($RT::SystemUser); +my $t1 = RT::Ticket->new(RT->SystemUser); my ( $id, undef $msg ) = $t1->Create( Queue => $q->id, Subject => 'SearchTest1', @@ -33,7 +33,7 @@ my ( $id, undef $msg ) = $t1->Create( ok( $id, $msg ); -my $t2 = RT::Ticket->new($RT::SystemUser); +my $t2 = RT::Ticket->new(RT->SystemUser); ( $id, undef, $msg ) = $t2->Create( Queue => $q->id, Subject => 'SearchTest2', @@ -42,7 +42,7 @@ my $t2 = RT::Ticket->new($RT::SystemUser); ); ok( $id, $msg ); -my $t3 = RT::Ticket->new($RT::SystemUser); +my $t3 = RT::Ticket->new(RT->SystemUser); ( $id, undef, $msg ) = $t3->Create( Queue => $q->id, Subject => 'SearchTest3', @@ -52,27 +52,27 @@ my $t3 = RT::Ticket->new($RT::SystemUser); ok( $id, $msg ); # we have tickets. start searching -my $tix = RT::Tickets->new($RT::SystemUser); +my $tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'foo'"); is($tix->Count, 1, "matched short string foo") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'bar'"); is($tix->Count, 2, "matched long+short string bar") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND ( CF.SearchTest LIKE 'foo' OR CF.SearchTest LIKE 'bar' )"); is($tix->Count, 3, "matched short string foo or long+short string bar") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND CF.SearchTest NOT LIKE 'foo' AND CF.SearchTest LIKE 'bar'"); is($tix->Count, 2, "not matched short string foo and matched long+short string bar") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; -$tix = RT::Tickets->new($RT::SystemUser); +$tix = RT::Tickets->new(RT->SystemUser); $tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'foo' AND CF.SearchTest NOT LIKE 'bar'"); is($tix->Count, 1, "matched short string foo and not matched long+short string bar") or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery; diff --git a/rt/t/ticket/sort-by-custom-ownership.t b/rt/t/ticket/sort-by-custom-ownership.t index 9739c5aec..b06e9a00a 100644 --- a/rt/t/ticket/sort-by-custom-ownership.t +++ b/rt/t/ticket/sort-by-custom-ownership.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use RT; -use RT::Test tests => 7; +use RT::Test nodata => 1, tests => 7; use strict; @@ -19,7 +19,7 @@ my($ret,$msg); # ---- Create a queue to test with. my $queue = "PAWSortQueue-$$"; -my $queue_obj = RT::Queue->new($RT::SystemUser); +my $queue_obj = RT::Queue->new(RT->SystemUser); ($ret, $msg) = $queue_obj->Create(Name => $queue, Description => 'queue for custom field sort testing'); ok($ret, "$queue test queue creation. $msg"); @@ -27,18 +27,18 @@ ok($ret, "$queue test queue creation. $msg"); # ---- Create some users -my $me = RT::User->new($RT::SystemUser); +my $me = RT::User->new(RT->SystemUser); ($ret, $msg) = $me->Create(Name => "Me$$", EmailAddress => $$.'create-me-1@example.com'); ($ret, $msg) = $me->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'OwnTicket'); ($ret, $msg) = $me->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'SeeQueue'); ($ret, $msg) = $me->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'ShowTicket'); -my $you = RT::User->new($RT::SystemUser); +my $you = RT::User->new(RT->SystemUser); ($ret, $msg) = $you->Create(Name => "You$$", EmailAddress => $$.'create-you-1@example.com'); ($ret, $msg) = $you->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'OwnTicket'); ($ret, $msg) = $you->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'SeeQueue'); ($ret, $msg) = $you->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'ShowTicket'); -my $nobody = RT::User->new($RT::SystemUser); +my $nobody = RT::User->new(RT->SystemUser); $nobody->Load('nobody'); @@ -54,7 +54,7 @@ my @tickets = ( [qw[6 55], $nobody], ); for (@tickets) { - my $t = RT::Ticket->new($RT::SystemUser); + my $t = RT::Ticket->new(RT->SystemUser); $t->Create( Queue => $queue_obj->Id, Subject => $_->[0], Owner => $_->[2]->Id, @@ -76,8 +76,8 @@ sub check_order { # The real tests start here -my $cme = new RT::CurrentUser( $me ); -my $metx = new RT::Tickets( $cme ); +my $cme = RT::CurrentUser->new( $me ); +my $metx = RT::Tickets->new( $cme ); # Make sure we can sort in both directions on a queue specific field. $metx->FromSQL(qq[queue="$queue"] ); $metx->OrderBy( FIELD => "Custom.Ownership", ORDER => 'ASC' ); @@ -90,8 +90,8 @@ check_order( $metx, reverse qw[2 1 6 5 4 3]); -my $cyou = new RT::CurrentUser( $you ); -my $youtx = new RT::Tickets( $cyou ); +my $cyou = RT::CurrentUser->new( $you ); +my $youtx = RT::Tickets->new( $cyou ); # Make sure we can sort in both directions on a queue specific field. $youtx->FromSQL(qq[queue="$queue"] ); $youtx->OrderBy( FIELD => "Custom.Ownership", ORDER => 'ASC' ); diff --git a/rt/t/ticket/sort-by-queue.t b/rt/t/ticket/sort-by-queue.t index df6e1ad0f..bf2934bc2 100644 --- a/rt/t/ticket/sort-by-queue.t +++ b/rt/t/ticket/sort-by-queue.t @@ -1,6 +1,6 @@ #!/usr/bin/perl -use RT::Test tests => 8; +use RT::Test nodata => 1, tests => 12; use strict; use warnings; @@ -14,12 +14,12 @@ use RT::CustomField; ######################################################### -diag "Create queues to test with." if $ENV{TEST_VERBOSE}; +diag "Create queues to test with."; my @qids; my @queues; # create them in reverse order to avoid false positives foreach my $name ( qw(sort-by-queue-Z sort-by-queue-A) ) { - my $queue = RT::Queue->new( $RT::SystemUser ); + my $queue = RT::Queue->new( RT->SystemUser ); my ($ret, $msg) = $queue->Create( Name => $name ."-$$", Description => 'queue to test sorting by queue' @@ -29,21 +29,7 @@ foreach my $name ( qw(sort-by-queue-Z sort-by-queue-A) ) { push @qids, $queue->id; } -my ($total, @data, @tickets, @test) = (0, ()); - -sub add_tix_from_data { - my @res = (); - @data = sort { rand(100) <=> rand(100) } @data; - while (@data) { - my $t = RT::Ticket->new($RT::SystemUser); - my %args = %{ shift(@data) }; - my ( $id, undef, $msg ) = $t->Create( %args ); - ok( $id, "ticket created" ) or diag("error: $msg"); - push @res, $t; - $total++; - } - return @res; -} +my ($total, @tickets, @test) = (0, ()); sub run_tests { my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets; @@ -53,7 +39,7 @@ sub run_tests { foreach my $order (qw(ASC DESC)) { my $error = 0; - my $tix = RT::Tickets->new( $RT::SystemUser ); + my $tix = RT::Tickets->new( RT->SystemUser ); $tix->FromSQL( $query ); $tix->OrderBy( FIELD => $test->{'Order'}, ORDER => $order ); @@ -88,13 +74,14 @@ sub run_tests { } } -@data = ( +@tickets = RT::Test->create_tickets( + { RandomOrder => 1 }, { Queue => $qids[0], Subject => 'z' }, { Queue => $qids[1], Subject => 'a' }, ); -@tickets = add_tix_from_data(); @test = ( { Order => "Queue" }, ); run_tests(); +@tickets = (); diff --git a/rt/t/ticket/sort-by-user.t b/rt/t/ticket/sort-by-user.t index f9b1602f1..10d43de37 100644 --- a/rt/t/ticket/sort-by-user.t +++ b/rt/t/ticket/sort-by-user.t @@ -1,6 +1,6 @@ #!/usr/bin/perl -use RT::Test tests => 32; +use RT::Test nodata => 1, tests => 52; use strict; use warnings; @@ -14,11 +14,11 @@ use RT::CustomField; # we sort by user name ######################################################### -diag "Create a queue to test with." if $ENV{TEST_VERBOSE}; +diag "Create a queue to test with."; my $queue_name = "OwnerSortQueue$$"; my $queue; { - $queue = RT::Queue->new( $RT::SystemUser ); + $queue = RT::Queue->new( RT->SystemUser ); my ($ret, $msg) = $queue->Create( Name => $queue_name, Description => 'queue for custom field sort testing' @@ -31,7 +31,7 @@ my @users; # create them in reverse order to avoid false positives foreach my $u (qw(Z A)) { my $name = $u ."-user-to-test-ordering-$$"; - my $user = RT::User->new( $RT::SystemUser ); + my $user = RT::User->new( RT->SystemUser ); my ($uid) = $user->Create( Name => $name, Privileged => 1, @@ -47,32 +47,8 @@ foreach my $u (qw(Z A)) { push @uids, $user->id; } -my ($total, @data, @tickets, @test) = (0, ()); +my (@data, @tickets, @test) = (0, ()); -sub add_tix_from_data { - my @res = (); - @data = sort { rand(100) <=> rand(100) } @data; - while (@data) { - my $t = RT::Ticket->new($RT::SystemUser); - my %args = %{ shift(@data) }; - - my ( $id, undef, $msg ) = $t->Create( %args, Queue => $queue->id ); - if ( $args{'Owner'} ) { - is $t->Owner, $args{'Owner'}, "owner is correct"; - } - if ( $args{'Creator'} ) { - is $t->Creator, $args{'Creator'}, "creator is correct"; - } - # hackish, but simpler - if ( $args{'LastUpdatedBy'} ) { - $t->__Set( Field => 'LastUpdatedBy', Value => $args{'LastUpdatedBy'} ); - } - ok( $id, "ticket created" ) or diag("error: $msg"); - push @res, $t; - $total++; - } - return @res; -} sub run_tests { my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets; @@ -82,7 +58,7 @@ sub run_tests { foreach my $order (qw(ASC DESC)) { my $error = 0; - my $tix = RT::Tickets->new( $RT::SystemUser ); + my $tix = RT::Tickets->new( RT->SystemUser ); $tix->FromSQL( $query ); $tix->OrderBy( FIELD => $test->{'Order'}, ORDER => $order ); @@ -122,7 +98,9 @@ sub run_tests { { Subject => 'Z', Owner => $uids[0] }, { Subject => 'A', Owner => $uids[1] }, ); -@tickets = add_tix_from_data(); + +@tickets = RT::Test->create_tickets( { Queue => $queue->id }, @data ); + @test = ( { Order => "Owner" }, ); @@ -133,7 +111,7 @@ run_tests(); { Subject => 'Z', Creator => $uids[0] }, { Subject => 'A', Creator => $uids[1] }, ); -@tickets = add_tix_from_data(); +@tickets = RT::Test->create_tickets( { Queue => $queue->id }, @data ); @test = ( { Order => "Creator" }, ); @@ -144,9 +122,10 @@ run_tests(); { Subject => 'Z', LastUpdatedBy => $uids[0] }, { Subject => 'A', LastUpdatedBy => $uids[1] }, ); -@tickets = add_tix_from_data(); +@tickets = RT::Test->create_tickets( { Queue => $queue->id }, @data ); @test = ( { Order => "LastUpdatedBy" }, ); run_tests(); +@tickets = (); diff --git a/rt/t/ticket/sort_by_cf.t b/rt/t/ticket/sort_by_cf.t index 69274add9..65704da62 100644 --- a/rt/t/ticket/sort_by_cf.t +++ b/rt/t/ticket/sort_by_cf.t @@ -1,6 +1,6 @@ #!/usr/bin/perl -use RT::Test tests => 21; +use RT::Test nodata => 1, tests => 21; RT::Init(); use strict; @@ -19,7 +19,7 @@ my($ret,$msg); # ---- Create a queue to test with. my $queue = "CFSortQueue-$$"; -my $queue_obj = RT::Queue->new( $RT::SystemUser ); +my $queue_obj = RT::Queue->new( RT->SystemUser ); ($ret, $msg) = $queue_obj->Create( Name => $queue, Description => 'queue for custom field sort testing' @@ -28,10 +28,10 @@ ok($ret, "$queue test queue creation. $msg"); # ---- Create some custom fields. We're not currently using all of # them to test with, but the more the merrier. -my $cfO = RT::CustomField->new($RT::SystemUser); -my $cfA = RT::CustomField->new($RT::SystemUser); -my $cfB = RT::CustomField->new($RT::SystemUser); -my $cfC = RT::CustomField->new($RT::SystemUser); +my $cfO = RT::CustomField->new(RT->SystemUser); +my $cfA = RT::CustomField->new(RT->SystemUser); +my $cfB = RT::CustomField->new(RT->SystemUser); +my $cfC = RT::CustomField->new(RT->SystemUser); ($ret, $msg) = $cfO->Create( Name => 'Order', Queue => 0, @@ -61,7 +61,7 @@ ok($ret, "Custom Field Charlie created"); # ----- Create some tickets to test with. Assign them some values to # make it easy to sort with. -my $t1 = RT::Ticket->new($RT::SystemUser); +my $t1 = RT::Ticket->new(RT->SystemUser); $t1->Create( Queue => $queue_obj->Id, Subject => 'One', ); @@ -70,7 +70,7 @@ $t1->AddCustomFieldValue(Field => $cfA->Id, Value => '2'); $t1->AddCustomFieldValue(Field => $cfB->Id, Value => '1'); $t1->AddCustomFieldValue(Field => $cfC->Id, Value => 'BBB'); -my $t2 = RT::Ticket->new($RT::SystemUser); +my $t2 = RT::Ticket->new(RT->SystemUser); $t2->Create( Queue => $queue_obj->Id, Subject => 'Two', ); @@ -93,7 +93,7 @@ sub check_order { } # The real tests start here -my $tx = new RT::Tickets( $RT::SystemUser ); +my $tx = RT::Tickets->new( RT->SystemUser ); # Make sure we can sort in both directions on a queue specific field. @@ -102,7 +102,7 @@ $tx->OrderBy( FIELD => "CF.${queue}.{Charlie}", ORDER => 'DES' ); is($tx->Count,2 ,"We found 2 tickets when looking for cf charlie"); check_order( $tx, 1, 2); -$tx = new RT::Tickets( $RT::SystemUser ); +$tx = RT::Tickets->new( RT->SystemUser ); $tx->FromSQL(qq[queue="$queue"] ); $tx->OrderBy( FIELD => "CF.${queue}.{Charlie}", ORDER => 'ASC' ); is($tx->Count,2, "We found two tickets when sorting by cf charlie without limiting to it" ); @@ -111,20 +111,20 @@ check_order( $tx, 2, 1); # When ordering by _global_ CustomFields, if more than one queue has a # CF named Charlie, things will go bad. So, these results are uniqued # in Tickets_Overlay. -$tx = new RT::Tickets( $RT::SystemUser ); +$tx = RT::Tickets->new( RT->SystemUser ); $tx->FromSQL(qq[queue="$queue"] ); $tx->OrderBy( FIELD => "CF.{Charlie}", ORDER => 'DESC' ); is($tx->Count,2); check_order( $tx, 1, 2); -$tx = new RT::Tickets( $RT::SystemUser ); +$tx = RT::Tickets->new( RT->SystemUser ); $tx->FromSQL(qq[queue="$queue"] ); $tx->OrderBy( FIELD => "CF.{Charlie}", ORDER => 'ASC' ); is($tx->Count,2); check_order( $tx, 2, 1); # Add a new ticket, to test sorting on multiple columns. -my $t3 = RT::Ticket->new($RT::SystemUser); +my $t3 = RT::Ticket->new(RT->SystemUser); $t3->Create( Queue => $queue_obj->Id, Subject => 'Three', ); @@ -133,7 +133,7 @@ $t3->AddCustomFieldValue(Field => $cfA->Id, Value => '3'); $t3->AddCustomFieldValue(Field => $cfB->Id, Value => '2'); $t3->AddCustomFieldValue(Field => $cfC->Id, Value => 'AAA'); -$tx = new RT::Tickets( $RT::SystemUser ); +$tx = RT::Tickets->new( RT->SystemUser ); $tx->FromSQL(qq[queue="$queue"] ); $tx->OrderByCols( { FIELD => "CF.${queue}.{Charlie}", ORDER => 'ASC' }, @@ -142,7 +142,7 @@ $tx->OrderByCols( is($tx->Count,3); check_order( $tx, 3, 2, 1); -$tx = new RT::Tickets( $RT::SystemUser ); +$tx = RT::Tickets->new( RT->SystemUser ); $tx->FromSQL(qq[queue="$queue"] ); $tx->OrderByCols( { FIELD => "CF.${queue}.{Charlie}", ORDER => 'DES' }, @@ -153,7 +153,7 @@ check_order( $tx, 1, 2, 3); # Reverse the order of the secondary column, which changes the order # of the first two tickets. -$tx = new RT::Tickets( $RT::SystemUser ); +$tx = RT::Tickets->new( RT->SystemUser ); $tx->FromSQL(qq[queue="$queue"] ); $tx->OrderByCols( { FIELD => "CF.${queue}.{Charlie}", ORDER => 'ASC' }, @@ -162,7 +162,7 @@ $tx->OrderByCols( is($tx->Count,3); check_order( $tx, 2, 3, 1); -$tx = new RT::Tickets( $RT::SystemUser ); +$tx = RT::Tickets->new( RT->SystemUser ); $tx->FromSQL(qq[queue="$queue"] ); $tx->OrderByCols( { FIELD => "CF.${queue}.{Charlie}", ORDER => 'DES' }, diff --git a/rt/t/validator/group_members.t b/rt/t/validator/group_members.t index f27a1f177..781801426 100644 --- a/rt/t/validator/group_members.t +++ b/rt/t/validator/group_members.t @@ -9,7 +9,7 @@ sub load_or_create_group { my $name = shift; my %args = (@_); - my $group = RT::Group->new( $RT::SystemUser ); + my $group = RT::Group->new( RT->SystemUser ); $group->LoadUserDefinedGroup( $name ); unless ( $group->id ) { my ($id, $msg) = $group->CreateUserDefinedGroup( diff --git a/rt/t/web/dashboard_with_deleted_saved_search.t b/rt/t/web/dashboard_with_deleted_saved_search.t deleted file mode 100644 index 328095aaf..000000000 --- a/rt/t/web/dashboard_with_deleted_saved_search.t +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - -use RT::Test tests => 18; -my ( $url, $m ) = RT::Test->started_ok; -ok( $m->login, 'logged in' ); - -# create a saved search -$m->get_ok( $url . "/Search/Build.html?Query=" . 'id=1' ); - -$m->submit_form( - form_name => 'BuildQuery', - fields => { SavedSearchDescription => 'foo', }, - button => 'SavedSearchSave', -); - -my ( $search_uri, $user_id, $search_id ) = - $m->content =~ /value="(RT::User-(\d+)-SavedSearch-(\d+))"/; -$m->submit_form( - form_name => 'BuildQuery', - fields => { SavedSearchLoad => $search_uri }, - button => 'SavedSearchSave', -); - -$m->content_like( qr/name="SavedSearchDelete"\s+value="Delete"/, - 'found Delete button' ); -$m->content_like( - qr/name="SavedSearchDescription"\s+value="foo"/, - 'found Description input with the value filled' -); - -# create a dashboard with the created search - -$m->get_ok( $url . "/Dashboards/Modify.html?Create=1" ); -$m->submit_form( - form_name => 'ModifyDashboard', - fields => { Name => 'bar' }, -); - -$m->content_like( qr/Saved dashboard bar/i, 'dashboard saved' ); -my $dashboard_queries_link = $m->find_link( text_regex => qr/Queries/ ); -my ( $dashboard_id ) = $dashboard_queries_link->url =~ /id=(\d+)/; - -$m->get_ok( $url . "/Dashboards/Queries.html?id=$dashboard_id" ); - -$m->content_lacks( 'value="Update"', 'no update button' ); - -$m->submit_form( - form_name => 'Dashboard-Searches-body', - fields => - { 'Searches-body-Available' => "search-$search_id-RT::User-$user_id" }, - button => 'add', -); - -$m->content_like( qr/Dashboard updated/i, 'added search foo to dashboard bar' ); - -# delete the created search - -$m->get_ok( $url . "/Search/Build.html?Query=" . 'id=1' ); -$m->submit_form( - form_name => 'BuildQuery', - fields => { SavedSearchLoad => $search_uri }, -); -$m->submit_form( - form_name => 'BuildQuery', - button => 'SavedSearchDelete', -); - -$m->content_lacks( $search_uri, 'deleted search foo' ); - -# here is what we really want to test - -$m->get_ok( $url . "/Dashboards/Queries.html?id=$dashboard_id" ); -$m->content_like( qr/Deleted queries/i, 'found deleted message' ); - -# Update button shows so we can update the deleted search easily -$m->content_contains( 'value="Update"', 'found update button' ); - -$m->submit_form( - form_name => 'Dashboard-Searches-body', - button => 'update', -); - -$m->content_unlike( qr/Deleted queries/i, 'deleted message is gone' ); -$m->content_lacks( 'value="Update"', 'update button is gone too' ); - -$m->get_warnings; # we'll get a lot of warnings because the deleted search - diff --git a/rt/t/web/dashboards.t b/rt/t/web/dashboards.t deleted file mode 100644 index a816eb35c..000000000 --- a/rt/t/web/dashboards.t +++ /dev/null @@ -1,250 +0,0 @@ -#!/usr/bin/perl -w -use strict; - -use RT::Test tests => 109; -my ($baseurl, $m) = RT::Test->started_ok; - -my $url = $m->rt_base_url; - -my $user_obj = RT::User->new($RT::SystemUser); -my ($ret, $msg) = $user_obj->LoadOrCreateByEmail('customer@example.com'); -ok($ret, 'ACL test user creation'); -$user_obj->SetName('customer'); -$user_obj->SetPrivileged(1); -($ret, $msg) = $user_obj->SetPassword('customer'); -$user_obj->PrincipalObj->GrantRight(Right => 'ModifySelf'); -my $currentuser = RT::CurrentUser->new($user_obj); - -my $onlooker = RT::User->new($RT::SystemUser); -($ret, $msg) = $onlooker->LoadOrCreateByEmail('onlooker@example.com'); -ok($ret, 'ACL test user creation'); -$onlooker->SetName('onlooker'); -$onlooker->SetPrivileged(1); -($ret, $msg) = $onlooker->SetPassword('onlooker'); - -my $queue = RT::Queue->new($RT::SystemUser); -$queue->Create(Name => 'SearchQueue'.$$); - -for my $user ($user_obj, $onlooker) { - $user->PrincipalObj->GrantRight(Right => 'ModifySelf'); - for my $right (qw/SeeQueue ShowTicket OwnTicket/) { - $user->PrincipalObj->GrantRight(Right => $right, Object => $queue); - } -} - -ok $m->login(customer => 'customer'), "logged in"; - -$m->get_ok($url."Dashboards/index.html"); -$m->content_lacks('<a href="/Dashboards/Modify.html?Create=1">New</a>', - "No 'new dashboard' link because we have no CreateOwnDashboard"); - -$m->no_warnings_ok; - -$m->get_ok($url."Dashboards/Modify.html?Create=1"); -$m->content_contains("Permission denied"); -$m->content_lacks("Save Changes"); - -$m->warning_like(qr/Permission denied/, "got a permission denied warning"); - -$user_obj->PrincipalObj->GrantRight(Right => 'ModifyOwnDashboard', Object => $RT::System); - -# Modify itself is no longer good enough, you need Create -$m->get_ok($url."Dashboards/Modify.html?Create=1"); -$m->content_contains("Permission denied"); -$m->content_lacks("Save Changes"); - -$m->warning_like(qr/Permission denied/, "got a permission denied warning"); - -$user_obj->PrincipalObj->GrantRight(Right => 'CreateOwnDashboard', Object => $RT::System); - -$m->get_ok($url."Dashboards/Modify.html?Create=1"); -$m->content_lacks("Permission denied"); -$m->content_contains("Create"); - -$m->get_ok($url."Dashboards/index.html"); -$m->content_contains("New", "'New' link because we now have ModifyOwnDashboard"); - -$m->follow_link_ok({text => "New"}); -$m->form_name('ModifyDashboard'); -$m->field("Name" => 'different dashboard'); -$m->content_lacks('Delete', "Delete button hidden because we are creating"); -$m->click_button(value => 'Create'); -$m->content_lacks("No permission to create dashboards"); -$m->content_contains("Saved dashboard different dashboard"); -$m->content_lacks('Delete', "Delete button hidden because we lack DeleteOwnDashboard"); - -$m->get_ok($url."Dashboards/index.html"); -$m->content_lacks("different dashboard", "we lack SeeOwnDashboard"); - -$user_obj->PrincipalObj->GrantRight(Right => 'SeeOwnDashboard', Object => $RT::System); - -$m->get_ok($url."Dashboards/index.html"); -$m->content_contains("different dashboard", "we now have SeeOwnDashboard"); -$m->content_lacks("Permission denied"); - -$m->follow_link_ok({text => "different dashboard"}); -$m->content_contains("Basics"); -$m->content_contains("Queries"); -$m->content_lacks("Subscription", "we don't have the SubscribeDashboard right"); - -$m->follow_link_ok({text => "Basics"}); -$m->content_contains("Modify the dashboard different dashboard"); - -$m->follow_link_ok({text => "Queries"}); -$m->content_contains("Modify the queries of dashboard different dashboard"); -$m->form_name('Dashboard-Searches-body'); -$m->field('Searches-body-Available' => ["search-2-RT::System-1"]); -$m->click_button(name => 'add'); -$m->content_contains("Dashboard updated"); - -my $dashboard = RT::Dashboard->new($currentuser); -my ($id) = $m->content =~ /name="id" value="(\d+)"/; -ok($id, "got an ID, $id"); -$dashboard->LoadById($id); -is($dashboard->Name, "different dashboard"); - -is($dashboard->Privacy, 'RT::User-' . $user_obj->Id, "correct privacy"); -is($dashboard->PossibleHiddenSearches, 0, "all searches are visible"); - -my @searches = $dashboard->Searches; -is(@searches, 1, "one saved search in the dashboard"); -like($searches[0]->Name, qr/newest unowned tickets/, "correct search name"); - -$m->form_name('Dashboard-Searches-body'); -$m->field('Searches-body-Available' => ["search-1-RT::System-1"]); -$m->click_button(name => 'add'); -$m->content_contains("Dashboard updated"); - -RT::Record->FlushCache if RT::Record->can('FlushCache'); -$dashboard = RT::Dashboard->new($currentuser); -$dashboard->LoadById($id); - -@searches = $dashboard->Searches; -is(@searches, 2, "two saved searches in the dashboard"); -like($searches[0]->Name, qr/newest unowned tickets/, "correct existing search name"); -like($searches[1]->Name, qr/highest priority tickets I own/, "correct new search name"); - -my $ticket = RT::Ticket->new($RT::SystemUser); -$ticket->Create( - Queue => $queue->Id, - Requestor => [ $user_obj->Name ], - Owner => $user_obj, - Subject => 'dashboard test', -); - -$m->follow_link_ok({text => 'different dashboard'}); -$m->content_contains("50 highest priority tickets I own"); -$m->content_contains("50 newest unowned tickets"); -$m->content_lacks("Bookmarked Tickets"); -$m->content_contains("dashboard test", "ticket subject"); - -$m->get_ok("/Dashboards/$id/This fragment left intentionally blank"); -$m->content_contains("50 highest priority tickets I own"); -$m->content_contains("50 newest unowned tickets"); -$m->content_lacks("Bookmarked Tickets"); -$m->content_contains("dashboard test", "ticket subject"); - -$m->get_ok("/Dashboards/Subscription.html?DashboardId=$id"); -$m->form_name('SubscribeDashboard'); -$m->click_button(name => 'Save'); -$m->content_contains("Permission denied"); -$m->warning_like(qr/Unable to subscribe to dashboard.*Permission denied/, "got a permission denied warning when trying to subscribe to a dashboard"); - -RT::Record->FlushCache if RT::Record->can('FlushCache'); -is($user_obj->Attributes->Named('Subscription'), 0, "no subscriptions"); - -$user_obj->PrincipalObj->GrantRight(Right => 'SubscribeDashboard', Object => $RT::System); - -$m->get_ok("/Dashboards/Modify.html?id=$id"); -$m->follow_link_ok({text => "Subscription"}); -$m->content_contains("Subscribe to dashboard different dashboard"); -$m->content_contains("Unowned Tickets"); -$m->content_contains("My Tickets"); -$m->content_lacks("Bookmarked Tickets", "only dashboard queries show up"); - -$m->form_name('SubscribeDashboard'); -$m->click_button(name => 'Save'); -$m->content_lacks("Permission denied"); -$m->content_contains("Subscribed to dashboard different dashboard"); - -RT::Record->FlushCache if RT::Record->can('FlushCache'); -TODO: { - local $TODO = "some kind of caching is still happening (it works if I remove the check above)"; - is($user_obj->Attributes->Named('Subscription'), 1, "we have a subscription"); -}; - -$m->get_ok("/Dashboards/Modify.html?id=$id"); -$m->follow_link_ok({text => "Subscription"}); -$m->content_contains("Modify the subscription to dashboard different dashboard"); - -$m->get_ok("/Dashboards/Modify.html?id=$id&Delete=1"); -$m->content_contains("Permission denied", "unable to delete dashboard because we lack DeleteOwnDashboard"); - -$m->warning_like(qr/Couldn't delete dashboard.*Permission denied/, "got a permission denied warning when trying to delete the dashboard"); - -$user_obj->PrincipalObj->GrantRight(Right => 'DeleteOwnDashboard', Object => $RT::System); - -$m->get_ok("/Dashboards/Modify.html?id=$id"); -$m->content_contains('Delete', "Delete button shows because we have DeleteOwnDashboard"); - -$m->form_name('ModifyDashboard'); -$m->click_button(name => 'Delete'); -$m->content_contains("Deleted dashboard $id"); - -$m->get("/Dashboards/Modify.html?id=$id"); -$m->content_lacks("different dashboard", "dashboard was deleted"); -$m->content_contains("Failed to load dashboard $id"); - -$m->warning_like(qr/Failed to load dashboard.*Couldn't find row/, "the dashboard was deleted"); - -$user_obj->PrincipalObj->GrantRight(Right => "SuperUser", Object => $RT::System); - -# now test that we warn about searches others can't see -# first create a personal saved search... -$m->get_ok($url."Search/Build.html"); -$m->follow_link_ok({text => 'Advanced'}); -$m->form_with_fields('Query'); -$m->field(Query => "id > 0"); -$m->submit; - -$m->form_with_fields('SavedSearchDescription'); -$m->field(SavedSearchDescription => "personal search"); -$m->click_button(name => "SavedSearchSave"); - -# then the system-wide dashboard -$m->get_ok($url."Dashboards/Modify.html?Create=1"); - -$m->form_name('ModifyDashboard'); -$m->field("Name" => 'system dashboard'); -$m->field("Privacy" => 'RT::System-1'); -$m->content_lacks('Delete', "Delete button hidden because we are creating"); -$m->click_button(value => 'Create'); -$m->content_lacks("No permission to create dashboards"); -$m->content_contains("Saved dashboard system dashboard"); - -$m->follow_link_ok({text => 'Queries'}); - -$m->form_name('Dashboard-Searches-body'); -$m->field('Searches-body-Available' => ['search-7-RT::User-22']); # XXX: :( :( -$m->click_button(name => 'add'); -$m->content_contains("Dashboard updated"); - -$m->content_contains("The following queries may not be visible to all users who can see this dashboard."); - -$m->follow_link_ok({text => 'system dashboard'}); -$m->content_contains("personal search", "saved search shows up"); -$m->content_contains("dashboard test", "matched ticket shows up"); - -# make sure the onlooker can't see the search... -$onlooker->PrincipalObj->GrantRight(Right => 'SeeDashboard', Object => $RT::System); - -my $omech = RT::Test::Web->new; -ok $omech->login(onlooker => 'onlooker'), "logged in"; -$omech->get_ok("/Dashboards"); - -$omech->follow_link_ok({text => 'system dashboard'}); -$omech->content_lacks("personal search", "saved search doesn't show up"); -$omech->content_lacks("dashboard test", "matched ticket doesn't show up"); - -$m->warning_like(qr/User .* tried to load container user /, "can't see other users' personal searches"); - diff --git a/rt/t/web/gnupg-outgoing.t b/rt/t/web/gnupg-outgoing.t deleted file mode 100644 index a46833c6c..000000000 --- a/rt/t/web/gnupg-outgoing.t +++ /dev/null @@ -1,363 +0,0 @@ -#!/usr/bin/perl -w -use strict; -use warnings; - -use RT::Test tests => 492; - -plan skip_all => 'GnuPG required.' - unless eval 'use GnuPG::Interface; 1'; -plan skip_all => 'gpg executable is required.' - unless RT::Test->find_executable('gpg'); - - -use RT::Action::SendEmail; -use File::Temp qw(tempdir); - -RT::Test->set_mail_catcher; - -use_ok('RT::Crypt::GnuPG'); - -RT->Config->Set( GnuPG => - Enable => 1, - OutgoingMessagesFormat => 'RFC', -); - -RT->Config->Set( GnuPGOptions => - homedir => scalar tempdir( CLEANUP => 1 ), - passphrase => 'rt-test', - 'no-permission-warning' => undef, - 'trust-model' => 'always', -); -RT->Config->Set( 'MailPlugins' => 'Auth::MailFrom', 'Auth::GnuPG' ); - -RT::Test->import_gnupg_key('rt-recipient@example.com'); -RT::Test->import_gnupg_key('rt-test@example.com', 'public'); - -my $queue = RT::Test->load_or_create_queue( - Name => 'Regression', - CorrespondAddress => 'rt-recipient@example.com', - CommentAddress => 'rt-recipient@example.com', -); -ok $queue && $queue->id, 'loaded or created queue'; - -RT::Test->set_rights( - Principal => 'Everyone', - Right => ['CreateTicket', 'ShowTicket', 'SeeQueue', 'ReplyToTicket', 'ModifyTicket'], -); - -my ($baseurl, $m) = RT::Test->started_ok; -ok $m->login, 'logged in'; - -my @variants = ( - {}, - { Sign => 1 }, - { Encrypt => 1 }, - { Sign => 1, Encrypt => 1 }, -); - -# collect emails -my %mail = ( - plain => [], - signed => [], - encrypted => [], - signed_encrypted => [], -); - -diag "check in read-only mode that queue's props influence create/update ticket pages" if $ENV{TEST_VERBOSE}; -{ - foreach my $variant ( @variants ) { - set_queue_crypt_options( %$variant ); - $m->goto_create_ticket( $queue ); - $m->form_name('TicketCreate'); - if ( $variant->{'Encrypt'} ) { - ok $m->value('Encrypt', 2), "encrypt tick box is checked"; - } else { - ok !$m->value('Encrypt', 2), "encrypt tick box is unchecked"; - } - if ( $variant->{'Sign'} ) { - ok $m->value('Sign', 2), "sign tick box is checked"; - } else { - ok !$m->value('Sign', 2), "sign tick box is unchecked"; - } - } - - # to avoid encryption/signing during create - set_queue_crypt_options(); - - my $ticket = RT::Ticket->new( $RT::SystemUser ); - my ($id) = $ticket->Create( - Subject => 'test', - Queue => $queue->id, - Requestor => 'rt-test@example.com', - ); - ok $id, 'ticket created'; - - foreach my $variant ( @variants ) { - set_queue_crypt_options( %$variant ); - $m->goto_ticket( $id ); - $m->follow_link_ok({text => 'Reply'}, '-> reply'); - $m->form_number(3); - if ( $variant->{'Encrypt'} ) { - ok $m->value('Encrypt', 2), "encrypt tick box is checked"; - } else { - ok !$m->value('Encrypt', 2), "encrypt tick box is unchecked"; - } - if ( $variant->{'Sign'} ) { - ok $m->value('Sign', 2), "sign tick box is checked"; - } else { - ok !$m->value('Sign', 2), "sign tick box is unchecked"; - } - } -} - -# create a ticket for each combination -foreach my $queue_set ( @variants ) { - set_queue_crypt_options( %$queue_set ); - foreach my $ticket_set ( @variants ) { - create_a_ticket( %$ticket_set ); - } -} - -my $tid; -{ - my $ticket = RT::Ticket->new( $RT::SystemUser ); - ($tid) = $ticket->Create( - Subject => 'test', - Queue => $queue->id, - Requestor => 'rt-test@example.com', - ); - ok $tid, 'ticket created'; -} - -# again for each combination add a reply message -foreach my $queue_set ( @variants ) { - set_queue_crypt_options( %$queue_set ); - foreach my $ticket_set ( @variants ) { - update_ticket( $tid, %$ticket_set ); - } -} - - -# ------------------------------------------------------------------------------ -# now delete all keys from the keyring and put back secret/pub pair for rt-test@ -# and only public key for rt-recipient@ so we can verify signatures and decrypt -# like we are on another side recieve emails -# ------------------------------------------------------------------------------ - -unlink $_ foreach glob( RT->Config->Get('GnuPGOptions')->{'homedir'} ."/*" ); -RT::Test->import_gnupg_key('rt-recipient@example.com', 'public'); -RT::Test->import_gnupg_key('rt-test@example.com'); - -$queue = RT::Test->load_or_create_queue( - Name => 'Regression', - CorrespondAddress => 'rt-test@example.com', - CommentAddress => 'rt-test@example.com', -); -ok $queue && $queue->id, 'changed props of the queue'; - -foreach my $mail ( map cleanup_headers($_), @{ $mail{'plain'} } ) { - my ($status, $id) = RT::Test->send_via_mailgate($mail); - is ($status >> 8, 0, "The mail gateway exited normally"); - ok ($id, "got id of a newly created ticket - $id"); - - my $tick = RT::Ticket->new( $RT::SystemUser ); - $tick->Load( $id ); - ok ($tick->id, "loaded ticket #$id"); - - my $txn = $tick->Transactions->First; - my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef}; - - ok !$msg->GetHeader('X-RT-Privacy'), "RT's outgoing mail has no crypto"; - is $msg->GetHeader('X-RT-Incoming-Encryption'), 'Not encrypted', - "RT's outgoing mail looks not encrypted"; - ok !$msg->GetHeader('X-RT-Incoming-Signature'), - "RT's outgoing mail looks not signed"; - - like $msg->Content, qr/Some content/, "RT's mail includes copy of ticket text"; -} - -foreach my $mail ( map cleanup_headers($_), @{ $mail{'signed'} } ) { - my ($status, $id) = RT::Test->send_via_mailgate($mail); - is ($status >> 8, 0, "The mail gateway exited normally"); - ok ($id, "got id of a newly created ticket - $id"); - - my $tick = RT::Ticket->new( $RT::SystemUser ); - $tick->Load( $id ); - ok ($tick->id, "loaded ticket #$id"); - - my $txn = $tick->Transactions->First; - my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef}; - - is $msg->GetHeader('X-RT-Privacy'), 'PGP', - "RT's outgoing mail has crypto"; - is $msg->GetHeader('X-RT-Incoming-Encryption'), 'Not encrypted', - "RT's outgoing mail looks not encrypted"; - like $msg->GetHeader('X-RT-Incoming-Signature'), - qr/<rt-recipient\@example.com>/, - "RT's outgoing mail looks signed"; - - like $attachments[0]->Content, qr/Some content/, - "RT's mail includes copy of ticket text"; -} - -foreach my $mail ( map cleanup_headers($_), @{ $mail{'encrypted'} } ) { - my ($status, $id) = RT::Test->send_via_mailgate($mail); - is ($status >> 8, 0, "The mail gateway exited normally"); - ok ($id, "got id of a newly created ticket - $id"); - - my $tick = RT::Ticket->new( $RT::SystemUser ); - $tick->Load( $id ); - ok ($tick->id, "loaded ticket #$id"); - - my $txn = $tick->Transactions->First; - my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef}; - - is $msg->GetHeader('X-RT-Privacy'), 'PGP', - "RT's outgoing mail has crypto"; - is $msg->GetHeader('X-RT-Incoming-Encryption'), 'Success', - "RT's outgoing mail looks encrypted"; - ok !$msg->GetHeader('X-RT-Incoming-Signature'), - "RT's outgoing mail looks not signed"; - - like $attachments[0]->Content, qr/Some content/, - "RT's mail includes copy of ticket text"; -} - -foreach my $mail ( map cleanup_headers($_), @{ $mail{'signed_encrypted'} } ) { - my ($status, $id) = RT::Test->send_via_mailgate($mail); - is ($status >> 8, 0, "The mail gateway exited normally"); - ok ($id, "got id of a newly created ticket - $id"); - - my $tick = RT::Ticket->new( $RT::SystemUser ); - $tick->Load( $id ); - ok ($tick->id, "loaded ticket #$id"); - - my $txn = $tick->Transactions->First; - my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef}; - - is $msg->GetHeader('X-RT-Privacy'), 'PGP', - "RT's outgoing mail has crypto"; - is $msg->GetHeader('X-RT-Incoming-Encryption'), 'Success', - "RT's outgoing mail looks encrypted"; - like $msg->GetHeader('X-RT-Incoming-Signature'), - qr/<rt-recipient\@example.com>/, - "RT's outgoing mail looks signed"; - - like $attachments[0]->Content, qr/Some content/, - "RT's mail includes copy of ticket text"; -} - -sub create_a_ticket { - my %args = (@_); - - RT::Test->clean_caught_mails; - - $m->goto_create_ticket( $queue ); - $m->form_name('TicketCreate'); - $m->field( Subject => 'test' ); - $m->field( Requestors => 'rt-test@example.com' ); - $m->field( Content => 'Some content' ); - - foreach ( qw(Sign Encrypt) ) { - if ( $args{ $_ } ) { - $m->tick( $_ => 1 ); - } else { - $m->untick( $_ => 1 ); - } - } - - $m->submit; - is $m->status, 200, "request successful"; - - unlike($m->content, qr/unable to sign outgoing email messages/); - - $m->get_ok('/'); # ensure that the mail has been processed - - my @mail = RT::Test->fetch_caught_mails; - check_text_emails( \%args, @mail ); -} - -sub update_ticket { - my $tid = shift; - my %args = (@_); - - RT::Test->clean_caught_mails; - - ok $m->goto_ticket( $tid ), "UI -> ticket #$tid"; - $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' ); - $m->form_number(3); - $m->field( UpdateContent => 'Some content' ); - - foreach ( qw(Sign Encrypt) ) { - if ( $args{ $_ } ) { - $m->tick( $_ => 1 ); - } else { - $m->untick( $_ => 1 ); - } - } - - $m->click('SubmitTicket'); - is $m->status, 200, "request successful"; - $m->content_like(qr/Message recorded/, 'Message recorded') or diag $m->content; - - $m->get_ok('/'); # ensure that the mail has been processed - - my @mail = RT::Test->fetch_caught_mails; - check_text_emails( \%args, @mail ); -} - -sub check_text_emails { - my %args = %{ shift @_ }; - my @mail = @_; - - ok scalar @mail, "got some mail"; - for my $mail (@mail) { - if ( $args{'Encrypt'} ) { - unlike $mail, qr/Some content/, "outgoing email was encrypted"; - } else { - like $mail, qr/Some content/, "outgoing email was not encrypted"; - } - if ( $args{'Sign'} && $args{'Encrypt'} ) { - like $mail, qr/BEGIN PGP MESSAGE/, 'outgoing email was signed'; - } elsif ( $args{'Sign'} ) { - like $mail, qr/SIGNATURE/, 'outgoing email was signed'; - } else { - unlike $mail, qr/SIGNATURE/, 'outgoing email was not signed'; - } - } - if ( $args{'Sign'} && $args{'Encrypt'} ) { - push @{ $mail{'signed_encrypted'} }, @mail; - } elsif ( $args{'Sign'} ) { - push @{ $mail{'signed'} }, @mail; - } elsif ( $args{'Encrypt'} ) { - push @{ $mail{'encrypted'} }, @mail; - } else { - push @{ $mail{'plain'} }, @mail; - } -} - -sub cleanup_headers { - my $mail = shift; - # strip id from subject to create new ticket - $mail =~ s/^(Subject:)\s*\[.*?\s+#\d+\]\s*/$1 /m; - # strip several headers - foreach my $field ( qw(Message-ID X-RT-Original-Encoding RT-Originator RT-Ticket X-RT-Loop-Prevention) ) { - $mail =~ s/^$field:.*?\n(?! |\t)//gmsi; - } - return $mail; -} - -sub set_queue_crypt_options { - my %args = @_; - $m->get_ok("/Admin/Queues/Modify.html?id=". $queue->id); - $m->form_with_fields('Sign', 'Encrypt'); - foreach my $opt ('Sign', 'Encrypt') { - if ( $args{$opt} ) { - $m->tick($opt => 1); - } else { - $m->untick($opt => 1); - } - } - $m->submit; -} - |