diff options
author | WouterJ <waldio.webdesign@gmail.com> | 2015-06-30 14:43:35 +0200 |
---|---|---|
committer | Fabien Potencier <fabien.potencier@gmail.com> | 2015-09-25 13:42:48 +0200 |
commit | 0189f2b2191ba9cec13b7e53265824943d12700f (patch) | |
tree | abcb096d81cac5b45ccde09e21bc0b9450cb7b77 /Core/Tests/Authorization | |
parent | 4a5dea2861a51b6b0f3c07dc541d9449882c44e1 (diff) | |
download | symfony-security-0189f2b2191ba9cec13b7e53265824943d12700f.zip symfony-security-0189f2b2191ba9cec13b7e53265824943d12700f.tar.gz symfony-security-0189f2b2191ba9cec13b7e53265824943d12700f.tar.bz2 |
[Security] Deprecated supportsAttribute and supportsClass methods
Diffstat (limited to 'Core/Tests/Authorization')
3 files changed, 111 insertions, 0 deletions
diff --git a/Core/Tests/Authorization/AccessDecisionManagerTest.php b/Core/Tests/Authorization/AccessDecisionManagerTest.php index bd876c7..08bbc58 100644 --- a/Core/Tests/Authorization/AccessDecisionManagerTest.php +++ b/Core/Tests/Authorization/AccessDecisionManagerTest.php @@ -16,6 +16,9 @@ use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; class AccessDecisionManagerTest extends \PHPUnit_Framework_TestCase { + /** + * @group legacy + */ public function testSupportsClass() { $manager = new AccessDecisionManager(array( @@ -31,6 +34,9 @@ class AccessDecisionManagerTest extends \PHPUnit_Framework_TestCase $this->assertFalse($manager->supportsClass('FooClass')); } + /** + * @group legacy + */ public function testSupportsAttribute() { $manager = new AccessDecisionManager(array( diff --git a/Core/Tests/Authorization/Voter/AbstractVoterTest.php b/Core/Tests/Authorization/Voter/AbstractVoterTest.php new file mode 100644 index 0000000..23ac6db --- /dev/null +++ b/Core/Tests/Authorization/Voter/AbstractVoterTest.php @@ -0,0 +1,72 @@ +<?php + +namespace Symfony\Component\Security\Core\Tests\Authorization\Voter; + +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; +use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter; +use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; + +class AbstractVoterTest_Voter extends AbstractVoter +{ + protected function voteOnAttribute($attribute, $object, TokenInterface $token) + { + return 'EDIT' === $attribute; + } + + protected function supports($attribute, $class) + { + return $this->isClassInstanceOf($class, 'AbstractVoterTest_Object') + && in_array($attribute, array('EDIT', 'CREATE')); + } +} + +class AbstractVoterTest extends \PHPUnit_Framework_TestCase +{ + protected $voter; + protected $object; + protected $token; + + protected function setUp() + { + $this->voter = new AbstractVoterTest_Voter(); + $this->object = $this->getMock('AbstractVoterTest_Object'); + $this->token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'); + } + + public function testAttributeAndClassSupported() + { + $this->assertEquals(VoterInterface::ACCESS_GRANTED, $this->voter->vote($this->token, $this->object, array('EDIT')), 'ACCESS_GRANTED if attribute grants access'); + $this->assertEquals(VoterInterface::ACCESS_DENIED, $this->voter->vote($this->token, $this->object, array('CREATE')), 'ACESS_DENIED if attribute denies access'); + } + + public function testOneAttributeSupported() + { + $this->assertEquals(VoterInterface::ACCESS_GRANTED, $this->voter->vote($this->token, $this->object, array('DELETE', 'EDIT')), 'ACCESS_GRANTED if supported attribute grants access'); + $this->assertEquals(VoterInterface::ACCESS_DENIED, $this->voter->vote($this->token, $this->object, array('DELETE', 'CREATE')), 'ACCESS_DENIED if supported attribute denies access'); + } + + public function testOneAttributeGrantsAccess() + { + $this->assertEquals(VoterInterface::ACCESS_GRANTED, $this->voter->vote($this->token, $this->object, array('CREATE', 'EDIT')), 'ACCESS_GRANTED'); + } + + public function testNoAttributeSupported() + { + $this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $this->voter->vote($this->token, $this->object, array('DELETE')), 'ACCESS_ABSTAIN'); + } + + public function testClassNotSupported() + { + $this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $this->voter->vote($this->token, $this->getMock('AbstractVoterTest_Object1'), array('EDIT')), 'ACCESS_ABSTAIN'); + } + + public function testNullObject() + { + $this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $this->voter->vote($this->token, null, array('EDIT')), 'ACCESS_ABSTAIN'); + } + + public function testNoAttributes() + { + $this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $this->voter->vote($this->token, $this->object, array()), 'ACCESS_ABSTAIN'); + } +} diff --git a/Core/Tests/Authorization/Voter/LegacyAbstractVoterTest.php b/Core/Tests/Authorization/Voter/LegacyAbstractVoterTest.php new file mode 100644 index 0000000..3a0cf1e --- /dev/null +++ b/Core/Tests/Authorization/Voter/LegacyAbstractVoterTest.php @@ -0,0 +1,33 @@ +<?php + +namespace Symfony\Component\Security\Core\Tests\Authorization\Voter; + +use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter; + +class LegacyAbstractVoterTest_Voter extends AbstractVoter +{ + protected function getSupportedClasses() + { + return array('AbstractVoterTest_Object'); + } + + protected function getSupportedAttributes() + { + return array('EDIT', 'CREATE'); + } + + protected function isGranted($attribute, $object, $user = null) + { + return 'EDIT' === $attribute; + } +} + +class LegacyAbstractVoterTest extends AbstractVoterTest +{ + protected function setUp() + { + parent::setUp(); + + $this->voter = new LegacyAbstractVoterTest_Voter(); + } +} |