Skip to content

Commit

Permalink
[Security] Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mTorres committed Sep 15, 2014
1 parent ba21854 commit 938ae4b
Showing 1 changed file with 42 additions and 0 deletions.
Expand Up @@ -65,6 +65,48 @@ public function testStrategies($strategy, $voters, $allowIfAllAbstainDecisions,
$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(
Expand Down

0 comments on commit 938ae4b

Please sign in to comment.