diff options
author | Wouter J <waldio.webdesign@gmail.com> | 2015-09-28 10:20:11 +0200 |
---|---|---|
committer | Wouter J <waldio.webdesign@gmail.com> | 2015-09-28 10:20:11 +0200 |
commit | 123c8df26a95bfb86c1dacea02778b1aa8432fbe (patch) | |
tree | 997ed4d9b41ac45cc8131d4411f1b6eb23e5b68a /Core/Tests | |
parent | 8ba7579a2fe5b384f10c20427e08bade4baf980d (diff) | |
download | symfony-security-123c8df26a95bfb86c1dacea02778b1aa8432fbe.zip symfony-security-123c8df26a95bfb86c1dacea02778b1aa8432fbe.tar.gz symfony-security-123c8df26a95bfb86c1dacea02778b1aa8432fbe.tar.bz2 |
Fix tests in 2.8
Diffstat (limited to 'Core/Tests')
-rw-r--r-- | Core/Tests/Authorization/Voter/AbstractVoterTest.php | 54 |
1 files changed, 42 insertions, 12 deletions
diff --git a/Core/Tests/Authorization/Voter/AbstractVoterTest.php b/Core/Tests/Authorization/Voter/AbstractVoterTest.php index fc79d72..0fddd88 100644 --- a/Core/Tests/Authorization/Voter/AbstractVoterTest.php +++ b/Core/Tests/Authorization/Voter/AbstractVoterTest.php @@ -54,13 +54,48 @@ class AbstractVoterTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message); } + + /** + * @dataProvider getTests + * @group legacy + */ + public function testVoteLegacy(array $attributes, $expectedVote, $object, $message) + { + $voter = new AbstractVoterTest_LegacyVoter(); + + $this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message); + } + + /** + * @group legacy + * @expectedException \BadMethodCallException + */ + public function testNoOverriddenMethodsThrowsException() + { + $voter = new AbstractVoterTest_NothingImplementedVoter(); + $voter->vote($this->token, new \stdClass(), array('EDIT')); + } } class AbstractVoterTest_Voter extends AbstractVoter { + protected function voteOnAttribute($attribute, $object, TokenInterface $token) + { + return 'EDIT' === $attribute; + } + + protected function supports($attribute, $class) + { + return $this->isClassInstanceOf($class, 'stdClass') + && in_array($attribute, array('EDIT', 'CREATE')); + } +} + +class AbstractVoterTest_LegacyVoter extends AbstractVoter +{ protected function getSupportedClasses() { - return array('stdClass'); + return array('AbstractVoterTest_Object'); } protected function getSupportedAttributes() @@ -68,28 +103,23 @@ class AbstractVoterTest_Voter extends AbstractVoter return array('EDIT', 'CREATE'); } - protected function voteOnAttribute($attribute, $object, TokenInterface $token) + protected function isGranted($attribute, $object, $user = null) { - return $attribute === 'foo'; + return 'EDIT' === $attribute; } } -class DeprecatedVoterFixture extends AbstractVoter +class AbstractVoterTest_NothingImplementedVoter extends AbstractVoter { protected function getSupportedClasses() { - return array( - 'Symfony\Component\Security\Core\Tests\Authorization\Voter\ObjectFixture', - ); + return array('AbstractVoterTest_Object'); } protected function getSupportedAttributes() { - return array('foo', 'bar', 'baz'); + return array('EDIT', 'CREATE'); } - protected function isGranted($attribute, $object, $user = null) - { - return 'EDIT' === $attribute; - } + // this is a bad voter that hasn't overridden isGranted or voteOnAttribute } |