diff options
author | Marc Torres <torres.marc@gmail.com> | 2014-09-08 16:52:38 +0200 |
---|---|---|
committer | Marc Torres <torres.marc@gmail.com> | 2014-09-15 19:24:27 +0200 |
commit | 4368c75cbeb587fede098da5a6c5c705fe19f238 (patch) | |
tree | 7c13e0b4bd182463be7302aaf7fa9edee5741497 | |
parent | eea4a9bdfa0930002b9a4de65e3e6e7fd95941a1 (diff) | |
download | symfony-security-4368c75cbeb587fede098da5a6c5c705fe19f238.zip symfony-security-4368c75cbeb587fede098da5a6c5c705fe19f238.tar.gz symfony-security-4368c75cbeb587fede098da5a6c5c705fe19f238.tar.bz2 |
[Security] Added more tests
-rw-r--r-- | Tests/Core/Authorization/AccessDecisionManagerTest.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Tests/Core/Authorization/AccessDecisionManagerTest.php b/Tests/Core/Authorization/AccessDecisionManagerTest.php index b99423f..0300cb4 100644 --- a/Tests/Core/Authorization/AccessDecisionManagerTest.php +++ b/Tests/Core/Authorization/AccessDecisionManagerTest.php @@ -65,6 +65,48 @@ class AccessDecisionManagerTest extends \PHPUnit_Framework_TestCase $this->assertSame($expected, $manager->decide($token, array('ROLE_FOO'))); } + /** + * @dataProvider getStrategiesWith2RolesTests + */ + public function testStrategiesWith2Roles($token, $strategy, $voter, $expected) + { + $manager = new AccessDecisionManager(array($voter), $strategy); + + $this->assertSame($expected, $manager->decide($token, array('ROLE_FOO', 'ROLE_BAR'))); + } + + public function getStrategiesWith2RolesTests() + { + $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'); + + return array( + array($token, 'affirmative', $this->getVoter(VoterInterface::ACCESS_DENIED), false), + array($token, 'affirmative', $this->getVoter(VoterInterface::ACCESS_GRANTED), true), + + array($token, 'consensus', $this->getVoter(VoterInterface::ACCESS_DENIED), false), + array($token, 'consensus', $this->getVoter(VoterInterface::ACCESS_GRANTED), true), + + array($token, 'unanimous', $this->getVoterFor2Roles($token, VoterInterface::ACCESS_DENIED, VoterInterface::ACCESS_DENIED), false), + array($token, 'unanimous', $this->getVoterFor2Roles($token, VoterInterface::ACCESS_DENIED, VoterInterface::ACCESS_GRANTED), false), + array($token, 'unanimous', $this->getVoterFor2Roles($token, VoterInterface::ACCESS_GRANTED, VoterInterface::ACCESS_DENIED), false), + array($token, 'unanimous', $this->getVoterFor2Roles($token, VoterInterface::ACCESS_GRANTED, VoterInterface::ACCESS_GRANTED), true), + ); + } + + protected function getVoterFor2Roles($token, $vote1, $vote2) + { + $voter = $this->getMock('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface'); + $voter->expects($this->exactly(2)) + ->method('vote') + ->will($this->returnValueMap(array( + array($token, null, array("ROLE_FOO"),$vote1), + array($token, null, array("ROLE_BAR"),$vote2), + ))) + ; + + return $voter; + } + public function getStrategyTests() { return array( |