VoterDisablingTest.php 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace JMS\SecurityExtraBundle\Tests\Functional;
  3. class VoterDisablingTest extends BaseTestCase
  4. {
  5. /**
  6. * @runInSeparateProcess
  7. */
  8. public function testDisableAllVoters()
  9. {
  10. $client = $this->createClient(array('config' => 'all_voters_disabled.yml'));
  11. $client->insulate();
  12. $adm = self::$kernel->getContainer()->get('security.access.decision_manager');
  13. $this->assertEquals(1, count($voters = $this->getField($adm, 'voters')));
  14. $this->assertInstanceOf('JMS\SecurityExtraBundle\Security\Authorization\Expression\LazyLoadingExpressionVoter', $voters[0]);
  15. }
  16. /**
  17. * @runInSeparateProcess
  18. */
  19. public function testDefault()
  20. {
  21. $client = $this->createClient(array('config' => 'default.yml'));
  22. $client->insulate();
  23. $adm = self::$kernel->getContainer()->get('security.access.decision_manager');
  24. $this->assertEquals(2, count($voters = $this->getField($adm, 'voters')));
  25. $this->assertInstanceOf('Symfony\Component\Security\Core\Authorization\Voter\RoleVoter', $voters[0]);
  26. $this->assertInstanceOf('Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter', $voters[1]);
  27. }
  28. /**
  29. * @runInSeparateProcess
  30. */
  31. public function testSomeVotersDisabled()
  32. {
  33. $client = $this->createClient(array('config' => 'some_voters_disabled.yml'));
  34. $client->insulate();
  35. $adm = self::$kernel->getContainer()->get('security.access.decision_manager');
  36. $this->assertEquals(1, count($voters = $this->getField($adm, 'voters')));
  37. $this->assertInstanceOf('Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter', $voters[0]);
  38. }
  39. private function getField($obj, $field)
  40. {
  41. $ref = new \ReflectionProperty($obj, $field);
  42. $ref->setAccessible(true);
  43. return $ref->getValue($obj);
  44. }
  45. }