From e9a9a3430f86c95f73cd5b4de9f2c77f007b50ae Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 4 Jul 2024 11:27:16 +0200 Subject: [PATCH] Complete AbstractStoredObjectVoterTest.php --- .../AbstractStoredObjectVoterTest.php | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/Bundle/ChillDocStoreBundle/Tests/Security/Authorization/AbstractStoredObjectVoterTest.php b/src/Bundle/ChillDocStoreBundle/Tests/Security/Authorization/AbstractStoredObjectVoterTest.php index d5ab471ab..c384e48b9 100644 --- a/src/Bundle/ChillDocStoreBundle/Tests/Security/Authorization/AbstractStoredObjectVoterTest.php +++ b/src/Bundle/ChillDocStoreBundle/Tests/Security/Authorization/AbstractStoredObjectVoterTest.php @@ -17,10 +17,9 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; class AbstractStoredObjectVoterTest extends PHPUnit\Framework\TestCase { - private $repository; - private $security; - private $workflowDocumentService; - private $voter; + private AssociatedEntityToStoredObjectInterface $repository; + private Security $security; + private WorkflowDocumentService $workflowDocumentService; protected function setUp(): void { @@ -54,10 +53,10 @@ class AbstractStoredObjectVoterTest extends PHPUnit\Framework\TestCase private function setupMockObjects(): array { - $user = $this->createMock(User::class); + $user = new User(); $token = $this->createMock(TokenInterface::class); - $subject = $this->createMock(StoredObject::class); - $entity = $this->createMock(AccompanyingCourseDocument::class); + $subject = new StoredObject(); + $entity = new \stdClass(); return [$user, $token, $subject, $entity]; } @@ -90,9 +89,7 @@ class AbstractStoredObjectVoterTest extends PHPUnit\Framework\TestCase $this->setupMocksForVoteOnAttribute($user, $token, true, $entity, true); // The voteOnAttribute method should return True when workflow is allowed - $attributeSee = StoredObjectRoleEnum::SEE; - $attributeEdit = StoredObjectRoleEnum::EDIT; - $this->assertTrue($this->voter->voteOnAttribute($attributeSee, $subject, $token)); + self::assertTrue($voter->voteOnAttribute(StoredObjectRoleEnum::SEE, $subject, $token)); } public function testVoteOnAttributeNotAllowed(): void @@ -101,11 +98,10 @@ class AbstractStoredObjectVoterTest extends PHPUnit\Framework\TestCase // Setup mocks for voteOnAttribute method where isGranted() returns false $this->setupMocksForVoteOnAttribute($user, $token, false, $entity, true); + $voter = $this->buildStoredObjectVoter(true, $this->repository, $this->security, $this->workflowDocumentService); // The voteOnAttribute method should return True when workflow is allowed - $attributeSee = StoredObjectRoleEnum::SEE; - $attributeEdit = StoredObjectRoleEnum::EDIT; - $this->assertTrue($this->voter->voteOnAttribute($attributeSee, $subject, $token)); + self::assertFalse($voter->voteOnAttribute(StoredObjectRoleEnum::SEE, $subject, $token)); } public function testVoteOnAttributeWhenBlockedByWorkflow(): void @@ -114,10 +110,11 @@ class AbstractStoredObjectVoterTest extends PHPUnit\Framework\TestCase // Setup mocks for voteOnAttribute method $this->setupMocksForVoteOnAttribute($user, $token, true, $entity, false); + $voter = $this->buildStoredObjectVoter(true, $this->repository, $this->security, $this->workflowDocumentService); // Test voteOnAttribute method $attribute = StoredObjectRoleEnum::SEE; - $result = $this->voter->voteOnAttribute($attribute, $subject, $token); + $result = $voter->voteOnAttribute($attribute, $subject, $token); // Assert that access is denied when workflow is not allowed $this->assertFalse($result);