ObjectAclManipulatorTest.php 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project 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\Util;
  11. use Prophecy\Argument;
  12. use Sonata\AdminBundle\Tests\Fixtures\Util\DummyObjectAclManipulator;
  13. use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
  14. /**
  15. * @author Grégoire Paris <postmaster@greg0ire.fr>
  16. */
  17. class ObjectAclManipulatorTest extends \PHPUnit_Framework_TestCase
  18. {
  19. protected function setUp()
  20. {
  21. $this->output = $this->prophesize('Symfony\Component\Console\Output\OutputInterface');
  22. $this->admin = $this->prophesize('Sonata\AdminBundle\Admin\AdminInterface');
  23. $this->oids = new \ArrayIterator(array(
  24. $this->prophesize('Symfony\Component\Security\Acl\Model\ObjectIdentityInterface')->reveal(),
  25. $this->prophesize('Symfony\Component\Security\Acl\Model\ObjectIdentityInterface')->reveal(),
  26. ));
  27. $this->securityIdentity = new UserSecurityIdentity('Michael', 'stdClass');
  28. }
  29. public function testConfigureAclsIgnoresNonAclSecurityHandlers()
  30. {
  31. $this->admin->getSecurityHandler()->shouldBeCalled();
  32. $this->admin->getCode()->shouldBeCalled()->willReturn('test');
  33. $this->output->writeln(Argument::allof(
  34. Argument::containingString('ignoring'),
  35. Argument::containingString('test')
  36. ))->shouldBeCalled();
  37. $manipulator = new DummyObjectAclManipulator();
  38. $this->assertSame(
  39. array(0, 0),
  40. $manipulator->configureAcls(
  41. $this->output->reveal(),
  42. $this->admin->reveal(),
  43. $this->oids,
  44. $this->securityIdentity
  45. )
  46. );
  47. }
  48. public function testConfigureAcls()
  49. {
  50. $securityHandler = $this->prophesize('Sonata\AdminBundle\Security\Handler\AclSecurityHandlerInterface');
  51. $acls = $this->prophesize('SplObjectStorage');
  52. $acls->contains(Argument::type('Symfony\Component\Security\Acl\Model\ObjectIdentityInterface'))
  53. ->shouldBeCalled()
  54. ->willReturn(false, true);
  55. $acl = $this->prophesize('Symfony\Component\Security\Acl\Model\AclInterface')->reveal();
  56. $acls->offsetGet(Argument::Type('Symfony\Component\Security\Acl\Model\ObjectIdentityInterface'))
  57. ->shouldBeCalled()
  58. ->willReturn($acl);
  59. $securityHandler->findObjectAcls($this->oids)->shouldBeCalled()->willReturn($acls->reveal());
  60. $securityHandler->createAcl(Argument::type(
  61. 'Symfony\Component\Security\Acl\Model\ObjectIdentityInterface'
  62. ))->shouldBeCalled()->willReturn($acl);
  63. $securityHandler->addObjectOwner($acl, Argument::type(
  64. 'Symfony\Component\Security\Acl\Domain\UserSecurityIdentity'
  65. ))->shouldBeCalled();
  66. $securityHandler->buildSecurityInformation($this->admin)->shouldBeCalled()->willReturn(array());
  67. $securityHandler->addObjectClassAces($acl, array())->shouldBeCalled();
  68. $securityHandler->updateAcl($acl)->shouldBeCalled()->willThrow(new \Exception('test exception'));
  69. $this->output->writeln(Argument::allof(
  70. Argument::containingString('ignoring'),
  71. Argument::containingString('test exception')
  72. ))->shouldBeCalled();
  73. $this->admin->getSecurityHandler()->shouldBeCalled()->willReturn($securityHandler->reveal());
  74. $manipulator = new DummyObjectAclManipulator();
  75. $this->assertSame(
  76. array(1, 1),
  77. $manipulator->configureAcls(
  78. $this->output->reveal(),
  79. $this->admin->reveal(),
  80. $this->oids,
  81. $this->securityIdentity
  82. )
  83. );
  84. }
  85. }