|
|
@@ -4,7 +4,7 @@ namespace App\Tests\Unit\Security\Voter;
|
|
|
|
|
|
use App\Entity\Access\Access;
|
|
|
use App\Entity\Person\Person;
|
|
|
-use App\Security\Voter\AbstractVoter;
|
|
|
+use App\Security\Voter\EntityVoter\AbstractEntityVoter;
|
|
|
use App\Service\Access\Utils;
|
|
|
use App\Service\Security\InternalRequestsService;
|
|
|
use App\Service\Security\SwitchUser;
|
|
|
@@ -14,7 +14,7 @@ use PHPUnit\Framework\TestCase;
|
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
|
|
|
|
|
-class TestableAbstractVoter extends AbstractVoter {
|
|
|
+class TestableAbstractEntityVoter extends AbstractEntityVoter {
|
|
|
public const READ = 'READ';
|
|
|
public const EDIT = 'EDIT';
|
|
|
public const CREATE = 'CREATE';
|
|
|
@@ -77,8 +77,8 @@ class AbstractVoterTest extends TestCase
|
|
|
private ?string $initialInternalRequestToken = null;
|
|
|
|
|
|
private function saveInitialCondition() {
|
|
|
- $this->initialEntityClass = TestableAbstractVoter::getEntityClass();
|
|
|
- $this->initialAllowedOperations = TestableAbstractVoter::getAllowedOperations();
|
|
|
+ $this->initialEntityClass = TestableAbstractEntityVoter::getEntityClass();
|
|
|
+ $this->initialAllowedOperations = TestableAbstractEntityVoter::getAllowedOperations();
|
|
|
$this->initialSwitchHeader = $_SERVER['HTTP_X_SWITCH_USER'] ?? null;
|
|
|
$this->initialRemoteAddr = $_SERVER['REMOTE_ADDR'] ?? null;
|
|
|
$this->initialInternalRequestToken = $_SERVER['HTTP_INTERNAL_REQUESTS_TOKEN'] ?? null;
|
|
|
@@ -87,8 +87,8 @@ class AbstractVoterTest extends TestCase
|
|
|
|
|
|
private function reinitialize() {
|
|
|
// Reinitialize the TestableAbstractVoter static properties
|
|
|
- TestableAbstractVoter::setEntityClass($this->initialEntityClass);
|
|
|
- TestableAbstractVoter::setAllowedOperations($this->initialAllowedOperations);
|
|
|
+ TestableAbstractEntityVoter::setEntityClass($this->initialEntityClass);
|
|
|
+ TestableAbstractEntityVoter::setAllowedOperations($this->initialAllowedOperations);
|
|
|
|
|
|
// Reinitialize the global variables
|
|
|
if ($this->initialSwitchHeader !== null) {
|
|
|
@@ -123,8 +123,8 @@ class AbstractVoterTest extends TestCase
|
|
|
$this->reinitialize();
|
|
|
}
|
|
|
|
|
|
- private function makeAbstractVoterMockFor(string $methodName): MockObject | TestableAbstractVoter {
|
|
|
- return $this->getMockBuilder(TestableAbstractVoter::class)
|
|
|
+ private function makeAbstractVoterMockFor(string $methodName): MockObject | TestableAbstractEntityVoter {
|
|
|
+ return $this->getMockBuilder(TestableAbstractEntityVoter::class)
|
|
|
->setConstructorArgs([
|
|
|
$this->security,
|
|
|
$this->accessUtils,
|
|
|
@@ -137,57 +137,57 @@ class AbstractVoterTest extends TestCase
|
|
|
}
|
|
|
|
|
|
public function testSupports(): void {
|
|
|
- TestableAbstractVoter::setEntityClass(Access::class);
|
|
|
+ TestableAbstractEntityVoter::setEntityClass(Access::class);
|
|
|
|
|
|
$abstractVoter = $this->makeAbstractVoterMockFor('supports');
|
|
|
|
|
|
$access = new Access();
|
|
|
|
|
|
$this->assertTrue(
|
|
|
- $abstractVoter->supports(TestableAbstractVoter::READ, $access)
|
|
|
+ $abstractVoter->supports(TestableAbstractEntityVoter::READ, $access)
|
|
|
);
|
|
|
$this->assertTrue(
|
|
|
- $abstractVoter->supports(TestableAbstractVoter::EDIT, $access)
|
|
|
+ $abstractVoter->supports(TestableAbstractEntityVoter::EDIT, $access)
|
|
|
);
|
|
|
$this->assertTrue(
|
|
|
- $abstractVoter->supports(TestableAbstractVoter::CREATE, $access)
|
|
|
+ $abstractVoter->supports(TestableAbstractEntityVoter::CREATE, $access)
|
|
|
);
|
|
|
$this->assertTrue(
|
|
|
- $abstractVoter->supports(TestableAbstractVoter::DELETE, $access)
|
|
|
+ $abstractVoter->supports(TestableAbstractEntityVoter::DELETE, $access)
|
|
|
);
|
|
|
}
|
|
|
|
|
|
public function testSupportsNotSupportedClass(): void {
|
|
|
- TestableAbstractVoter::setEntityClass(Access::class);
|
|
|
+ TestableAbstractEntityVoter::setEntityClass(Access::class);
|
|
|
|
|
|
$abstractVoter = $this->makeAbstractVoterMockFor('supports');
|
|
|
|
|
|
$person = new Person();
|
|
|
|
|
|
$this->assertFalse(
|
|
|
- $abstractVoter->supports(TestableAbstractVoter::READ, $person)
|
|
|
+ $abstractVoter->supports(TestableAbstractEntityVoter::READ, $person)
|
|
|
);
|
|
|
}
|
|
|
|
|
|
public function testSupportsNotAllowedOperation(): void {
|
|
|
- TestableAbstractVoter::setEntityClass(Access::class);
|
|
|
- TestableAbstractVoter::setAllowedOperations([TestableAbstractVoter::READ]);
|
|
|
+ TestableAbstractEntityVoter::setEntityClass(Access::class);
|
|
|
+ TestableAbstractEntityVoter::setAllowedOperations([TestableAbstractEntityVoter::READ]);
|
|
|
|
|
|
$abstractVoter = $this->makeAbstractVoterMockFor('supports');
|
|
|
|
|
|
$access = new Access();
|
|
|
|
|
|
$this->assertTrue(
|
|
|
- $abstractVoter->supports(TestableAbstractVoter::READ, $access)
|
|
|
+ $abstractVoter->supports(TestableAbstractEntityVoter::READ, $access)
|
|
|
);
|
|
|
$this->assertFalse(
|
|
|
- $abstractVoter->supports(TestableAbstractVoter::EDIT, $access)
|
|
|
+ $abstractVoter->supports(TestableAbstractEntityVoter::EDIT, $access)
|
|
|
);
|
|
|
$this->assertFalse(
|
|
|
- $abstractVoter->supports(TestableAbstractVoter::CREATE, $access)
|
|
|
+ $abstractVoter->supports(TestableAbstractEntityVoter::CREATE, $access)
|
|
|
);
|
|
|
$this->assertFalse(
|
|
|
- $abstractVoter->supports(TestableAbstractVoter::DELETE, $access)
|
|
|
+ $abstractVoter->supports(TestableAbstractEntityVoter::DELETE, $access)
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -198,7 +198,7 @@ class AbstractVoterTest extends TestCase
|
|
|
$this->expectExceptionMessage('Setup the self::$entityClass property, or override the supports() method');
|
|
|
|
|
|
$access = new Access();
|
|
|
- $abstractVoter->supports(TestableAbstractVoter::READ, $access);
|
|
|
+ $abstractVoter->supports(TestableAbstractEntityVoter::READ, $access);
|
|
|
}
|
|
|
|
|
|
public function testVoteOnAttributeRead(): void {
|
|
|
@@ -213,7 +213,7 @@ class AbstractVoterTest extends TestCase
|
|
|
$abstractVoter->expects(self::never())->method('canDelete');
|
|
|
|
|
|
$this->assertTrue(
|
|
|
- $abstractVoter->voteOnAttribute(TestableAbstractVoter::READ, $subject, $token)
|
|
|
+ $abstractVoter->voteOnAttribute(TestableAbstractEntityVoter::READ, $subject, $token)
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -229,7 +229,7 @@ class AbstractVoterTest extends TestCase
|
|
|
$abstractVoter->expects(self::never())->method('canDelete');
|
|
|
|
|
|
$this->assertTrue(
|
|
|
- $abstractVoter->voteOnAttribute(TestableAbstractVoter::EDIT, $subject, $token)
|
|
|
+ $abstractVoter->voteOnAttribute(TestableAbstractEntityVoter::EDIT, $subject, $token)
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -245,7 +245,7 @@ class AbstractVoterTest extends TestCase
|
|
|
$abstractVoter->expects(self::never())->method('canDelete');
|
|
|
|
|
|
$this->assertTrue(
|
|
|
- $abstractVoter->voteOnAttribute(TestableAbstractVoter::CREATE, $subject, $token)
|
|
|
+ $abstractVoter->voteOnAttribute(TestableAbstractEntityVoter::CREATE, $subject, $token)
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -261,7 +261,7 @@ class AbstractVoterTest extends TestCase
|
|
|
$abstractVoter->expects(self::once())->method('canDelete')->with($subject)->willReturn(true);
|
|
|
|
|
|
$this->assertTrue(
|
|
|
- $abstractVoter->voteOnAttribute(TestableAbstractVoter::DELETE, $subject, $token)
|
|
|
+ $abstractVoter->voteOnAttribute(TestableAbstractEntityVoter::DELETE, $subject, $token)
|
|
|
);
|
|
|
}
|
|
|
|