summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Torres <torres.marc@gmail.com>2014-09-08 16:52:38 +0200
committerMarc Torres <torres.marc@gmail.com>2014-09-15 19:24:27 +0200
commit4368c75cbeb587fede098da5a6c5c705fe19f238 (patch)
tree7c13e0b4bd182463be7302aaf7fa9edee5741497
parenteea4a9bdfa0930002b9a4de65e3e6e7fd95941a1 (diff)
downloadsymfony-security-4368c75cbeb587fede098da5a6c5c705fe19f238.zip
symfony-security-4368c75cbeb587fede098da5a6c5c705fe19f238.tar.gz
symfony-security-4368c75cbeb587fede098da5a6c5c705fe19f238.tar.bz2
[Security] Added more tests
-rw-r--r--Tests/Core/Authorization/AccessDecisionManagerTest.php42
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(