[Rt-commit] r10014 - in rtir/branches/2.3-EXPERIMENTAL: t/constituency

ruz at bestpractical.com ruz at bestpractical.com
Wed Dec 19 14:39:26 EST 2007


Author: ruz
Date: Wed Dec 19 14:39:26 2007
New Revision: 10014

Modified:
   rtir/branches/2.3-EXPERIMENTAL/lib/RT/IR.pm
   rtir/branches/2.3-EXPERIMENTAL/t/constituency/basics.t

Log:
* fix constituency defaulting, add more tests

Modified: rtir/branches/2.3-EXPERIMENTAL/lib/RT/IR.pm
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/lib/RT/IR.pm	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/lib/RT/IR.pm	Wed Dec 19 14:39:26 2007
@@ -220,13 +220,13 @@
 
     my @values;
 
-    my $queues = RT::Queues->new( $queue->CurrentUser );
+    my $queues = RT::Queues->new( $RT::SystemUser );
     $queues->Limit( FIELD => 'Name', OPERATOR => 'STARTSWITH', VALUE => "$name - " );
     while ( my $pqueue = $queues->Next ) {
-        next unless $pqueue->CurrentUserHasRight( "ShowTicket" );
+        next unless $pqueue->HasRight( Principal => $queue->CurrentUser, Right => "ShowTicket" );
         push @values, substr $pqueue->__Value('Name'), length("$name - ");
     }
-    my $default = RT->Config->Get('_RTIR_Constituency_default');
+    my $default = RT->Config->Get('_RTIR_Constituency_default') || '';
     return $default if grep lc $_ eq lc $default, @values;
     return shift @values;
 }

Modified: rtir/branches/2.3-EXPERIMENTAL/t/constituency/basics.t
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/t/constituency/basics.t	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/t/constituency/basics.t	Wed Dec 19 14:39:26 2007
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 110;
+use Test::More tests => 122;
 require "t/rtir-test.pl";
 
 use_ok('RT::IR');
@@ -108,12 +108,17 @@
     }
 }
 
-my $eduhandler = RT::Test->load_or_create_user( Name => 'eduhandler' );
+my $eduhandler = RT::Test->load_or_create_user( Name => 'eduhandler', Password => 'eduhandler' );
 ok $eduhandler->id, "Created eduhandler";
 
-my $govhandler = RT::Test->load_or_create_user( Name => 'govhandler' );
+my $govhandler = RT::Test->load_or_create_user( Name => 'govhandler', Password => 'govhandler' );
 ok $govhandler->id, "Created govhandler";
 
+my $ir_queue = RT::Test->load_or_create_queue(
+    Name => 'Incident Reports',
+);
+ok $ir_queue->id, "loaded or created queue";
+
 my $govqueue = RT::Test->load_or_create_queue(
     Name => 'Incident Reports - GOVNET',
     CorrespondAddress => 'govnet at example.com',
@@ -126,25 +131,24 @@
 );
 ok $eduqueue->id, "loaded or created queue";
 
+ok( RT::Test->add_rights(
+    { Principal => 'Privileged', Right => [qw(ModifyCustomField SeeCustomField)], },
+    { Principal => $govhandler, Object => $ir_queue, Right => [qw(SeeQueue CreateTicket)] },
+    { Principal => $eduhandler, Object => $ir_queue, Right => [qw(SeeQueue CreateTicket)] },
+    { Principal => $eduhandler, Object => $eduqueue, Right => [qw(ShowTicket CreateTicket OwnTicket)] },
+    { Principal => $govhandler, Object => $govqueue, Right => [qw(ShowTicket CreateTicket OwnTicket)] },
+    { Principal => $eduhandler, Object => $govqueue, Right => [qw(OwnTicket)] },
+    { Principal => $govhandler, Object => $eduqueue, Right => [qw(OwnTicket)] },
+), 'set rights');
+
 diag "Grant govhandler the right to see tickets in Incident Reports - GOVNET" if $ENV{'TEST_VERBOSE'};
 { 
-    my ($val,$msg)  = $govhandler->PrincipalObj->GrantRight(Right => 'ShowTicket', Object => $govqueue);
-    ok $val || $msg =~ /That principal already has that right/, $msg;
-
     ok($govqueue->HasRight(Principal => $govhandler, Right => 'ShowTicket'), "Govhnadler can see govtix"); 
     ok(!$govqueue->HasRight(Principal => $eduhandler, Right => 'ShowTicket'), "eduhandler can not see gov tix"); 
-}
-
-
-diag "Grant eduhandler the right to see tickets in Incident Reports - EDUNET" if $ENV{'TEST_VERBOSE'};
-{ 
-    my ($val,$msg) = $eduhandler->PrincipalObj->GrantRight(Right => 'ShowTicket', Object => $eduqueue);
-    ok $val || $msg =~ /That principal already has that right/, $msg;
     ok($eduqueue->HasRight(Principal => $eduhandler, Right => 'ShowTicket'), "For the eduqueue, eduhandler can see tix"); 
     ok(!$eduqueue->HasRight(Principal => $govhandler, Right => 'ShowTicket'), "For the eduqueue, govhandler can not seetix"); 
 }
 
-
 diag "Create an incident report with a default constituency of EDUNET" if $ENV{'TEST_VERBOSE'};
 
 
@@ -228,3 +232,26 @@
 ok($from =~ /govnet/, "The from address pciked up the gov address");
 
 }
+
+diag "check defaults";
+{
+    $agent->login('eduhandler', 'eduhandler');
+    my $ir_id = create_ir(
+        $agent, { Subject => "test" },
+    );
+    my $ticket = RT::Ticket->new($RT::SystemUser);
+    $ticket->Load($ir_id);
+    is( $ticket->FirstCustomFieldValue('_RTIR_Constituency'), 'EDUNET', 'correct value' );
+}
+
+diag "check defaults";
+{
+    $agent->login('govhandler', 'govhandler');
+    my $ir_id = create_ir(
+        $agent, { Subject => "test" },
+    );
+    my $ticket = RT::Ticket->new($RT::SystemUser);
+    $ticket->Load($ir_id);
+    is( $ticket->FirstCustomFieldValue('_RTIR_Constituency'), 'GOVNET', 'correct value' );
+}
+


More information about the Rt-commit mailing list