mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Complete AbstractStoredObjectVoterTest.php
This commit is contained in:
parent
c648a560cc
commit
e9a9a3430f
@ -17,10 +17,9 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
|||||||
|
|
||||||
class AbstractStoredObjectVoterTest extends PHPUnit\Framework\TestCase
|
class AbstractStoredObjectVoterTest extends PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
private $repository;
|
private AssociatedEntityToStoredObjectInterface $repository;
|
||||||
private $security;
|
private Security $security;
|
||||||
private $workflowDocumentService;
|
private WorkflowDocumentService $workflowDocumentService;
|
||||||
private $voter;
|
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
@ -54,10 +53,10 @@ class AbstractStoredObjectVoterTest extends PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
private function setupMockObjects(): array
|
private function setupMockObjects(): array
|
||||||
{
|
{
|
||||||
$user = $this->createMock(User::class);
|
$user = new User();
|
||||||
$token = $this->createMock(TokenInterface::class);
|
$token = $this->createMock(TokenInterface::class);
|
||||||
$subject = $this->createMock(StoredObject::class);
|
$subject = new StoredObject();
|
||||||
$entity = $this->createMock(AccompanyingCourseDocument::class);
|
$entity = new \stdClass();
|
||||||
|
|
||||||
return [$user, $token, $subject, $entity];
|
return [$user, $token, $subject, $entity];
|
||||||
}
|
}
|
||||||
@ -90,9 +89,7 @@ class AbstractStoredObjectVoterTest extends PHPUnit\Framework\TestCase
|
|||||||
$this->setupMocksForVoteOnAttribute($user, $token, true, $entity, true);
|
$this->setupMocksForVoteOnAttribute($user, $token, true, $entity, true);
|
||||||
|
|
||||||
// The voteOnAttribute method should return True when workflow is allowed
|
// The voteOnAttribute method should return True when workflow is allowed
|
||||||
$attributeSee = StoredObjectRoleEnum::SEE;
|
self::assertTrue($voter->voteOnAttribute(StoredObjectRoleEnum::SEE, $subject, $token));
|
||||||
$attributeEdit = StoredObjectRoleEnum::EDIT;
|
|
||||||
$this->assertTrue($this->voter->voteOnAttribute($attributeSee, $subject, $token));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testVoteOnAttributeNotAllowed(): void
|
public function testVoteOnAttributeNotAllowed(): void
|
||||||
@ -101,11 +98,10 @@ class AbstractStoredObjectVoterTest extends PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
// Setup mocks for voteOnAttribute method where isGranted() returns false
|
// Setup mocks for voteOnAttribute method where isGranted() returns false
|
||||||
$this->setupMocksForVoteOnAttribute($user, $token, false, $entity, true);
|
$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
|
// The voteOnAttribute method should return True when workflow is allowed
|
||||||
$attributeSee = StoredObjectRoleEnum::SEE;
|
self::assertFalse($voter->voteOnAttribute(StoredObjectRoleEnum::SEE, $subject, $token));
|
||||||
$attributeEdit = StoredObjectRoleEnum::EDIT;
|
|
||||||
$this->assertTrue($this->voter->voteOnAttribute($attributeSee, $subject, $token));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testVoteOnAttributeWhenBlockedByWorkflow(): void
|
public function testVoteOnAttributeWhenBlockedByWorkflow(): void
|
||||||
@ -114,10 +110,11 @@ class AbstractStoredObjectVoterTest extends PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
// Setup mocks for voteOnAttribute method
|
// Setup mocks for voteOnAttribute method
|
||||||
$this->setupMocksForVoteOnAttribute($user, $token, true, $entity, false);
|
$this->setupMocksForVoteOnAttribute($user, $token, true, $entity, false);
|
||||||
|
$voter = $this->buildStoredObjectVoter(true, $this->repository, $this->security, $this->workflowDocumentService);
|
||||||
|
|
||||||
// Test voteOnAttribute method
|
// Test voteOnAttribute method
|
||||||
$attribute = StoredObjectRoleEnum::SEE;
|
$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
|
// Assert that access is denied when workflow is not allowed
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user