AclSecurityHandlerTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /*
  3. * This file is part of the Sonata package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Tests\Admin\Security\Acl\Permission;
  11. use Sonata\AdminBundle\Security\Handler\AclSecurityHandler;
  12. class AclSecurityHandlerTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testAcl()
  15. {
  16. $securityContext = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
  17. $securityContext->expects($this->any())
  18. ->method('isGranted')
  19. ->will($this->returnValue(true));
  20. $handler = new AclSecurityHandler($securityContext);
  21. $this->assertTrue($handler->isGranted(array('TOTO')));
  22. $this->assertTrue($handler->isGranted('TOTO'));
  23. $securityContext = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
  24. $securityContext->expects($this->any())
  25. ->method('isGranted')
  26. ->will($this->returnValue(false));
  27. $handler = new AclSecurityHandler($securityContext);
  28. $this->assertFalse($handler->isGranted(array('TOTO')));
  29. $this->assertFalse($handler->isGranted('TOTO'));
  30. }
  31. public function testBuildInformation()
  32. {
  33. $informations = array(
  34. 'EDIT' => array('EDIT')
  35. );
  36. $securityContext = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
  37. $admin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');
  38. $admin->expects($this->once())
  39. ->method('getCode')
  40. ->will($this->returnValue('test'));
  41. $admin->expects($this->once())
  42. ->method('getSecurityInformation')
  43. ->will($this->returnValue($informations));
  44. $handler = new AclSecurityHandler($securityContext);
  45. $results = $handler->buildSecurityInformation($admin);
  46. $this->assertArrayHasKey('ROLE_TEST_EDIT', $results);
  47. }
  48. }