From de9d547fea5fde254cdb930cc8c3ff527ef1c190 Mon Sep 17 00:00:00 2001 From: Danilo Cabello Date: Wed, 19 Jun 2013 18:11:11 +0000 Subject: [PATCH 1/2] Flexible RoleSecurityIdentity now checks for interface instead of a class --- .../Acl/Domain/RoleSecurityIdentity.php | 4 +-- .../Acl/Domain/RoleSecurityIdentityTest.php | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Security/Acl/Domain/RoleSecurityIdentity.php b/src/Symfony/Component/Security/Acl/Domain/RoleSecurityIdentity.php index 0d3d0d2ca2b14..2c7db29cbae48 100644 --- a/src/Symfony/Component/Security/Acl/Domain/RoleSecurityIdentity.php +++ b/src/Symfony/Component/Security/Acl/Domain/RoleSecurityIdentity.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Security\Acl\Domain; use Symfony\Component\Security\Acl\Model\SecurityIdentityInterface; -use Symfony\Component\Security\Core\Role\Role; +use Symfony\Component\Security\Core\Role\RoleInterface; /** * A SecurityIdentity implementation for roles @@ -30,7 +30,7 @@ final class RoleSecurityIdentity implements SecurityIdentityInterface */ public function __construct($role) { - if ($role instanceof Role) { + if ($role instanceof RoleInterface) { $role = $role->getRole(); } diff --git a/src/Symfony/Component/Security/Tests/Acl/Domain/RoleSecurityIdentityTest.php b/src/Symfony/Component/Security/Tests/Acl/Domain/RoleSecurityIdentityTest.php index 341f33ca48167..59bea2c8e5257 100644 --- a/src/Symfony/Component/Security/Tests/Acl/Domain/RoleSecurityIdentityTest.php +++ b/src/Symfony/Component/Security/Tests/Acl/Domain/RoleSecurityIdentityTest.php @@ -13,6 +13,7 @@ use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity; use Symfony\Component\Security\Core\Role\Role; +use Symfony\Component\Security\Core\Role\RoleInterface; use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity; class RoleSecurityIdentityTest extends \PHPUnit_Framework_TestCase @@ -50,6 +51,32 @@ public function getCompareData() array(new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity(new Role('ROLE_FOO')), true), array(new RoleSecurityIdentity('ROLE_USER'), new RoleSecurityIdentity('ROLE_FOO'), false), array(new RoleSecurityIdentity('ROLE_FOO'), new UserSecurityIdentity('ROLE_FOO', 'Foo'), false), + array(new RoleSecurityIdentity('ROLE_FOO'), new UserSecurityIdentity('ROLE_FOO', 'Foo'), false), + array(new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity(new MyRole('ROLE_FOO')), true), + array(new RoleSecurityIdentity('ROLE_USER'), new RoleSecurityIdentity(new MyRole('ROLE_FOO')), false), ); } } + +class MyRole implements RoleInterface +{ + private $role; + + /** + * Constructor. + * + * @param string $role The role name + */ + public function __construct($role) + { + $this->role = (string) $role; + } + + /** + * {@inheritdoc} + */ + public function getRole() + { + return $this->role; + } +} From b52a8f8bcd9f3bd7acca9a43a26ba90bad11c0ad Mon Sep 17 00:00:00 2001 From: Danilo Cabello Date: Thu, 20 Jun 2013 03:45:29 +0000 Subject: [PATCH 2/2] Remove duplicated test (one line on data provider) --- .../Security/Tests/Acl/Domain/RoleSecurityIdentityTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Component/Security/Tests/Acl/Domain/RoleSecurityIdentityTest.php b/src/Symfony/Component/Security/Tests/Acl/Domain/RoleSecurityIdentityTest.php index 59bea2c8e5257..f275034952f60 100644 --- a/src/Symfony/Component/Security/Tests/Acl/Domain/RoleSecurityIdentityTest.php +++ b/src/Symfony/Component/Security/Tests/Acl/Domain/RoleSecurityIdentityTest.php @@ -51,7 +51,6 @@ public function getCompareData() array(new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity(new Role('ROLE_FOO')), true), array(new RoleSecurityIdentity('ROLE_USER'), new RoleSecurityIdentity('ROLE_FOO'), false), array(new RoleSecurityIdentity('ROLE_FOO'), new UserSecurityIdentity('ROLE_FOO', 'Foo'), false), - array(new RoleSecurityIdentity('ROLE_FOO'), new UserSecurityIdentity('ROLE_FOO', 'Foo'), false), array(new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity(new MyRole('ROLE_FOO')), true), array(new RoleSecurityIdentity('ROLE_USER'), new RoleSecurityIdentity(new MyRole('ROLE_FOO')), false), );