mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
Implement test on AbstractStoredObjectVoter
To avoid having to duplicate tests, a test is written\ for the abstract voter.
This commit is contained in:
parent
254122d125
commit
d1653a074b
@ -5,15 +5,17 @@ namespace Chill\DocStoreBundle\Tests\Security\Authorization;
|
|||||||
use Chill\DocStoreBundle\Entity\AccompanyingCourseDocument;
|
use Chill\DocStoreBundle\Entity\AccompanyingCourseDocument;
|
||||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||||
use Chill\DocStoreBundle\Repository\AccompanyingCourseDocumentRepository;
|
use Chill\DocStoreBundle\Repository\AccompanyingCourseDocumentRepository;
|
||||||
|
use Chill\DocStoreBundle\Repository\AssociatedEntityToStoredObjectInterface;
|
||||||
use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter;
|
use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter;
|
||||||
use Chill\DocStoreBundle\Security\Authorization\StoredObjectRoleEnum;
|
use Chill\DocStoreBundle\Security\Authorization\StoredObjectRoleEnum;
|
||||||
|
use Chill\DocStoreBundle\Security\Authorization\StoredObjectVoters\AbstractStoredObjectVoter;
|
||||||
use Chill\DocStoreBundle\Service\WorkflowDocumentService;
|
use Chill\DocStoreBundle\Service\WorkflowDocumentService;
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use ChillDocStoreBundle\Security\Authorization\StoredObjectVoters\AccompanyingCourseStoredObjectVoter;
|
use ChillDocStoreBundle\Security\Authorization\StoredObjectVoters\AccompanyingCourseStoredObjectVoter;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||||
|
|
||||||
class AccompanyingCourseStoredObjectVoterTest extends PHPUnit\Framework\TestCase
|
class AbstractStoredObjectVoterTest extends PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
private $repository;
|
private $repository;
|
||||||
private $security;
|
private $security;
|
||||||
@ -26,11 +28,28 @@ class AccompanyingCourseStoredObjectVoterTest extends PHPUnit\Framework\TestCase
|
|||||||
$this->security = $this->createMock(Security::class);
|
$this->security = $this->createMock(Security::class);
|
||||||
$this->workflowDocumentService = $this->createMock(WorkflowDocumentService::class);
|
$this->workflowDocumentService = $this->createMock(WorkflowDocumentService::class);
|
||||||
|
|
||||||
$this->voter = new AccompanyingCourseStoredObjectVoter(
|
// Anonymous class extending the abstract class
|
||||||
$this->repository,
|
$this->voter = new class($this->repository, $this->security, $this->workflowDocumentService) extends AbstractStoredObjectVoter {
|
||||||
$this->security,
|
protected function attributeToRole($attribute): string
|
||||||
$this->workflowDocumentService
|
{
|
||||||
);
|
return AccompanyingCourseDocumentVoter::SEE_DETAILS;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getRepository(): AssociatedEntityToStoredObjectInterface
|
||||||
|
{
|
||||||
|
// TODO: Implement getRepository() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getClass(): string
|
||||||
|
{
|
||||||
|
// TODO: Implement getClass() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function canBeAssociatedWithWorkflow(): bool
|
||||||
|
{
|
||||||
|
// TODO: Implement canBeAssociatedWithWorkflow() method.
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setupMockObjects(): array
|
private function setupMockObjects(): array
|
||||||
@ -94,7 +113,7 @@ class AccompanyingCourseStoredObjectVoterTest extends PHPUnit\Framework\TestCase
|
|||||||
list($user, $token, $subject, $entity) = $this->setupMockObjects();
|
list($user, $token, $subject, $entity) = $this->setupMockObjects();
|
||||||
|
|
||||||
// Setup mocks for voteOnAttribute method
|
// Setup mocks for voteOnAttribute method
|
||||||
$this->setupMocksForVoteOnAttribute($user, $token, $subject, $entity, false);
|
$this->setupMocksForVoteOnAttribute($user, $token, true, $entity, false);
|
||||||
|
|
||||||
// Test voteOnAttribute method
|
// Test voteOnAttribute method
|
||||||
$attribute = StoredObjectRoleEnum::SEE;
|
$attribute = StoredObjectRoleEnum::SEE;
|
||||||
@ -103,4 +122,16 @@ class AccompanyingCourseStoredObjectVoterTest extends PHPUnit\Framework\TestCase
|
|||||||
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAbstractStoredObjectVoter(): void
|
||||||
|
{
|
||||||
|
$voter = new class extends AbstractStoredObjectVoter {
|
||||||
|
// Implement abstract methods here
|
||||||
|
public function someMethod() {
|
||||||
|
// method implementation
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Run tests on $voter
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user