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/api | |
parent | 6587f6ba7d047ddc1686c080090afe7d53365bd4 (diff) |
starting to work...
Diffstat (limited to 'rt/t/api')
-rw-r--r-- | rt/t/api/ace.t | 238 | ||||
-rw-r--r-- | rt/t/api/cf.t | 224 | ||||
-rw-r--r-- | rt/t/api/cf_combo_casacade.t | 46 | ||||
-rw-r--r-- | rt/t/api/cf_external.t | 56 | ||||
-rw-r--r-- | rt/t/api/cf_pattern.t | 53 | ||||
-rw-r--r-- | rt/t/api/cf_single_values.t | 38 | ||||
-rw-r--r-- | rt/t/api/cf_transaction.t | 60 |
7 files changed, 0 insertions, 715 deletions
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?"); |