From 1180bee93b286e40f9090fb9742fccaa9005a6bd Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Tue, 1 Jul 2014 15:20:42 +0200 Subject: [PATCH] Revert "Added VirtualResource" This reverts commit 808d06d00599f323c5f09908e0dac2cd612c9fbf. --- src/Model/ClassResource.php | 2 +- src/Model/VirtualResource.php | 52 ------------------- tests/Integration/AbstractIntegrationTest.php | 7 +-- ...assResourceTest.php => ClassScopeTest.php} | 4 +- tests/Integration/VirtualResourceTest.php | 46 ---------------- tests/Unit/Model/ClassResourceTest.php | 8 --- tests/Unit/Model/VirtualResourceTest.php | 36 ------------- 7 files changed, 4 insertions(+), 151 deletions(-) delete mode 100644 src/Model/VirtualResource.php rename tests/Integration/{ClassResourceTest.php => ClassScopeTest.php} (96%) delete mode 100644 tests/Integration/VirtualResourceTest.php delete mode 100644 tests/Unit/Model/VirtualResourceTest.php diff --git a/src/Model/ClassResource.php b/src/Model/ClassResource.php index 61075c4..eca1dc0 100644 --- a/src/Model/ClassResource.php +++ b/src/Model/ClassResource.php @@ -9,7 +9,7 @@ * * @author Matthieu Napoli */ -class ClassResource implements ResourceInterface, CascadingResource +final class ClassResource implements ResourceInterface, CascadingResource { /** * @var string diff --git a/src/Model/VirtualResource.php b/src/Model/VirtualResource.php deleted file mode 100644 index e596b2f..0000000 --- a/src/Model/VirtualResource.php +++ /dev/null @@ -1,52 +0,0 @@ - - */ -class VirtualResource implements ResourceInterface -{ - /** - * @var string - */ - private $name; - - /** - * @var int|null - */ - private $id; - - /** - * @param string $name - * @param int|null $id - */ - public function __construct($name, $id = null) - { - $this->name = (string) $name; - $this->id = $id; - } - - public function getResourceId() - { - return new ResourceId($this->name, $this->id); - } - - /** - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * @return int|null - */ - public function getId() - { - return $this->id; - } -} diff --git a/tests/Integration/AbstractIntegrationTest.php b/tests/Integration/AbstractIntegrationTest.php index b1c5196..64bb4b6 100644 --- a/tests/Integration/AbstractIntegrationTest.php +++ b/tests/Integration/AbstractIntegrationTest.php @@ -12,7 +12,6 @@ use MyCLabs\ACL\ACL; use MyCLabs\ACL\Doctrine\ACLSetup; use MyCLabs\ACL\Model\ClassResource; -use MyCLabs\ACL\Model\VirtualResource; use Tests\MyCLabs\ACL\Integration\Model\Actions; abstract class AbstractIntegrationTest extends \PHPUnit_Framework_TestCase @@ -94,11 +93,7 @@ private function configureACL() 'AccountAdmin' => [ 'resourceType' => Issues\Issue10\Account::class, 'actions' => Actions::all() - ], - 'BackendAdmin' => [ - 'resource' => new VirtualResource('backend'), - 'actions' => new Actions([Actions::VIEW]), - ], + ] ]; $setup->registerRoles($roles, $this->acl); diff --git a/tests/Integration/ClassResourceTest.php b/tests/Integration/ClassScopeTest.php similarity index 96% rename from tests/Integration/ClassResourceTest.php rename to tests/Integration/ClassScopeTest.php index 5085971..79bfaff 100644 --- a/tests/Integration/ClassResourceTest.php +++ b/tests/Integration/ClassScopeTest.php @@ -8,11 +8,11 @@ use Tests\MyCLabs\ACL\Integration\Model\User; /** - * Tests authorizations applied on class resources (i.e. all entities of type X). + * Tests authorizations applied at class scope (i.e. all entities of type X). * * @coversNothing */ -class ClassResourceTest extends AbstractIntegrationTest +class ClassScopeTest extends AbstractIntegrationTest { /** * Check when adding the role and all entities are already created and flushed diff --git a/tests/Integration/VirtualResourceTest.php b/tests/Integration/VirtualResourceTest.php deleted file mode 100644 index 3952f35..0000000 --- a/tests/Integration/VirtualResourceTest.php +++ /dev/null @@ -1,46 +0,0 @@ -em->persist($user1); - $user2 = new User(); - $this->em->persist($user2); - - $this->em->flush(); - - $resource = new VirtualResource('backend'); - - $this->assertFalse($this->acl->isAllowed($user1, Actions::VIEW, $resource)); - $this->assertFalse($this->acl->isAllowed($user1, Actions::EDIT, $resource)); - $this->assertFalse($this->acl->isAllowed($user2, Actions::VIEW, $resource)); - - $this->acl->grant($user1, 'BackendAdmin'); - - $this->assertTrue($this->acl->isAllowed($user1, Actions::VIEW, $resource)); - $this->assertFalse($this->acl->isAllowed($user1, Actions::EDIT, $resource)); - $this->assertFalse($this->acl->isAllowed($user2, Actions::VIEW, $resource)); - - $this->acl->revoke($user1, 'BackendAdmin'); - - $this->assertFalse($this->acl->isAllowed($user1, Actions::VIEW, $resource)); - $this->assertFalse($this->acl->isAllowed($user1, Actions::EDIT, $resource)); - $this->assertFalse($this->acl->isAllowed($user2, Actions::VIEW, $resource)); - } -} diff --git a/tests/Unit/Model/ClassResourceTest.php b/tests/Unit/Model/ClassResourceTest.php index 6214f4c..64a28b7 100644 --- a/tests/Unit/Model/ClassResourceTest.php +++ b/tests/Unit/Model/ClassResourceTest.php @@ -18,14 +18,6 @@ public function testGetClass() $this->assertEquals('foo', $resource->getClass()); } - public function testGetResourceId() - { - $resource = new ClassResource('foo'); - - $this->assertEquals('foo', $resource->getResourceId()->getName()); - $this->assertNull($resource->getResourceId()->getId()); - } - public function testParentResources() { $em = $this->getMock(EntityManager::class, [], [], '', false); diff --git a/tests/Unit/Model/VirtualResourceTest.php b/tests/Unit/Model/VirtualResourceTest.php deleted file mode 100644 index 2c7d066..0000000 --- a/tests/Unit/Model/VirtualResourceTest.php +++ /dev/null @@ -1,36 +0,0 @@ -assertEquals('foo', $resource->getName()); - } - - public function testGetId() - { - $resource = new VirtualResource('foo', 1); - - $this->assertEquals(1, $resource->getId()); - } - - public function testGetResourceId() - { - $resource = new VirtualResource('foo'); - $this->assertEquals('foo', $resource->getResourceId()->getName()); - $this->assertNull($resource->getResourceId()->getId()); - - $resource = new VirtualResource('foo', 1); - $this->assertEquals('foo', $resource->getResourceId()->getName()); - $this->assertEquals(1, $resource->getResourceId()->getId()); - } -}