RoleHierarchyVoterTest.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. namespace Symfony\Tests\Component\Security\Authorization\Voter;
  10. use Symfony\Component\Security\Authorization\Voter\RoleHierarchyVoter;
  11. use Symfony\Component\Security\Authorization\Voter\VoterInterface;
  12. use Symfony\Component\Security\Role\RoleHierarchy;
  13. require_once __DIR__.'/RoleVoterTest.php';
  14. class RoleHierarchyVoterTest extends RoleVoterTest
  15. {
  16. /**
  17. * @dataProvider getVoteTests
  18. */
  19. public function testVote($roles, $attributes, $expected)
  20. {
  21. $voter = new RoleHierarchyVoter(new RoleHierarchy(array('ROLE_FOO' => array('ROLE_FOOBAR'))));
  22. $this->assertSame($expected, $voter->vote($this->getToken($roles), null, $attributes));
  23. }
  24. public function getVoteTests()
  25. {
  26. return array_merge(parent::getVoteTests(), array(
  27. array(array('ROLE_FOO'), array('ROLE_FOOBAR'), VoterInterface::ACCESS_GRANTED),
  28. ));
  29. }
  30. }