RT 4.0.19
[freeside.git] / rt / t / api / rights.t
index a1795ca..5cf3a00 100644 (file)
@@ -1,66 +1,14 @@
-#!/usr/bin/perl -w
-# BEGIN BPS TAGGED BLOCK {{{
-# 
-# COPYRIGHT:
-#  
-# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC 
-#                                          <jesse.com>
-# 
-# (Except where explicitly superseded by other copyright notices)
-# 
-# 
-# LICENSE:
-# 
-# This work is made available to you under the terms of Version 2 of
-# the GNU General Public License. A copy of that license should have
-# been provided with this software, but in any event can be snarfed
-# from www.gnu.org.
-# 
-# This work is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-# 
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 or visit their web page on the internet at
-# http://www.gnu.org/copyleft/gpl.html.
-# 
-# 
-# CONTRIBUTION SUBMISSION POLICY:
-# 
-# (The following paragraph is not intended to limit the rights granted
-# to you to modify and distribute this software under the terms of
-# the GNU General Public License and is only of importance to you if
-# you choose to contribute your changes and enhancements to the
-# community by submitting them to Best Practical Solutions, LLC.)
-# 
-# By intentionally submitting any modifications, corrections or
-# derivatives to this work, or any other work intended for use with
-# Request Tracker, to Best Practical Solutions, LLC, you confirm that
-# you are the copyright holder for those contributions and you grant
-# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
-# royalty-free, perpetual, license to use, copy, create derivative
-# works based on those contributions, and sublicense and distribute
-# those contributions and any derivatives thereof.
-# 
-# END BPS TAGGED BLOCK }}}
-
-use RT::Test nodata => 1, tests => 30;
+use RT::Test nodata => 1, tests => 38;
 
 use strict;
 use warnings;
 
+use Test::Warn;
+
+sub reset_rights { RT::Test->set_rights }
+
 # clear all global right
-{
-    my $acl = RT::ACL->new(RT->SystemUser);
-    $acl->Limit( FIELD => 'RightName', OPERATOR => '!=', VALUE => 'SuperUser' );
-    $acl->LimitToObject( $RT::System );
-    while( my $ace = $acl->Next ) {
-            $ace->Delete;
-    }
-}
+reset_rights;
 
 my $queue = RT::Test->load_or_create_queue( Name => 'Regression' );
 ok $queue && $queue->id, 'loaded or created queue';
@@ -195,3 +143,38 @@ my $ticket2;
         "user is not AdminCc and can't modify ticket2 (same question different answer)"
     );
 }
+
+my $queue2 = RT::Test->load_or_create_queue( Name => 'Rights' );
+ok $queue2 && $queue2->id, 'loaded or created queue';
+
+my $user2 = RT::Test->load_or_create_user(
+    Name => 'user2', Password => 'password',
+);
+ok $user2 && $user2->id, 'Created user: ' . $user2->Name . ' with id ' . $user2->Id;
+
+warning_like {
+    ok( !$user2->HasRight( Right => 'Foo', Object => $queue2 ),
+        "HasRight false for invalid right Foo"
+    );
+} qr/Invalid right\. Couldn't canonicalize right 'Foo'/,
+    'Got warning on invalid right';
+
+
+note "Right name canonicalization";
+{
+    reset_rights;
+    my ($ok, $msg) = $user->PrincipalObj->GrantRight(
+        Right   => "showticket",
+        Object  => RT->System,
+    );
+    ok $ok, "Granted showticket: $msg";
+    ok $user->HasRight( Right => "ShowTicket", Object => RT->System ), "HasRight ShowTicket";
+
+    reset_rights;
+    ($ok, $msg) = $user->PrincipalObj->GrantRight(
+        Right   => "ShowTicket",
+        Object  => RT->System,
+    );
+    ok $ok, "Granted ShowTicket: $msg";
+    ok $user->HasRight( Right => "showticket", Object => RT->System ), "HasRight showticket";
+}