AuthenticatedVoterTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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\AuthenticatedVoter;
  11. use Symfony\Component\Security\Authorization\Voter\VoterInterface;
  12. use Symfony\Component\Security\Role\Role;
  13. class AuthenticatedVoterTest extends \PHPUnit_Framework_TestCase
  14. {
  15. /**
  16. * @dataProvider getVoteTests
  17. */
  18. public function testVote($authenticated, $attributes, $expected)
  19. {
  20. $voter = new AuthenticatedVoter();
  21. $this->assertSame($expected, $voter->vote($this->getToken($authenticated), null, $attributes));
  22. }
  23. public function getVoteTests()
  24. {
  25. return array(
  26. array(true, array(), VoterInterface::ACCESS_ABSTAIN),
  27. array(true, array('FOO'), VoterInterface::ACCESS_ABSTAIN),
  28. array(false, array(), VoterInterface::ACCESS_ABSTAIN),
  29. array(false, array('FOO'), VoterInterface::ACCESS_ABSTAIN),
  30. array(true, array('IS_AUTHENTICATED_ANONYMOUSLY'), VoterInterface::ACCESS_GRANTED),
  31. array(false, array('IS_AUTHENTICATED_ANONYMOUSLY'), VoterInterface::ACCESS_GRANTED),
  32. array(true, array('IS_AUTHENTICATED_FULLY'), VoterInterface::ACCESS_GRANTED),
  33. array(false, array('IS_AUTHENTICATED_FULLY'), VoterInterface::ACCESS_DENIED),
  34. );
  35. }
  36. protected function getToken($authenticated)
  37. {
  38. if ($authenticated) {
  39. return $this->getMock('Symfony\Component\Security\Authentication\Token\TokenInterface');
  40. } else {
  41. return $this->getMock('Symfony\Component\Security\Authentication\Token\AnonymousToken', null, array('', ''));
  42. }
  43. }
  44. }