BuilderTest.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Acl\Test\Unit;
  7. use Magento\Framework\Acl\Builder;
  8. class BuilderTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \PHPUnit_Framework_MockObject_MockObject
  12. */
  13. protected $_aclFactoryMock;
  14. /**
  15. * @var \PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $_aclMock;
  18. /**
  19. * @var \PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $_ruleLoader;
  22. /**
  23. * @var \PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $_roleLoader;
  26. /**
  27. * @var \PHPUnit_Framework_MockObject_MockObject
  28. */
  29. protected $_resourceLoader;
  30. /**
  31. * @var \Magento\Framework\Acl\Builder
  32. */
  33. protected $_model;
  34. protected function setUp()
  35. {
  36. $this->_aclMock = new \Magento\Framework\Acl();
  37. $this->_aclFactoryMock = $this->createMock(\Magento\Framework\AclFactory::class);
  38. $this->_aclFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->_aclMock));
  39. $this->_roleLoader = $this->createMock(\Magento\Framework\Acl\Loader\DefaultLoader::class);
  40. $this->_ruleLoader = $this->createMock(\Magento\Framework\Acl\Loader\DefaultLoader::class);
  41. $this->_resourceLoader = $this->createMock(\Magento\Framework\Acl\Loader\DefaultLoader::class);
  42. $this->_model = new \Magento\Framework\Acl\Builder(
  43. $this->_aclFactoryMock,
  44. $this->_roleLoader,
  45. $this->_resourceLoader,
  46. $this->_ruleLoader
  47. );
  48. }
  49. public function testGetAclUsesLoadersProvidedInConfigurationToPopulateAclIfCacheIsEmpty()
  50. {
  51. $this->_ruleLoader->expects($this->once())->method('populateAcl')->with($this->equalTo($this->_aclMock));
  52. $this->_roleLoader->expects($this->once())->method('populateAcl')->with($this->equalTo($this->_aclMock));
  53. $this->_resourceLoader->expects($this->once())->method('populateAcl')->with($this->equalTo($this->_aclMock));
  54. $this->assertEquals($this->_aclMock, $this->_model->getAcl());
  55. }
  56. public function testGetAclReturnsAclStoredInCache()
  57. {
  58. $this->assertEquals($this->_aclMock, $this->_model->getAcl());
  59. $this->assertEquals($this->_aclMock, $this->_model->getAcl());
  60. }
  61. /**
  62. * @expectedException \LogicException
  63. */
  64. public function testGetAclRethrowsException()
  65. {
  66. $this->_aclFactoryMock->expects(
  67. $this->once()
  68. )->method(
  69. 'create'
  70. )->will(
  71. $this->throwException(new \InvalidArgumentException())
  72. );
  73. $this->_model->getAcl();
  74. }
  75. public function testResetRuntimeAcl()
  76. {
  77. $this->assertInstanceOf(Builder::class, $this->_model->resetRuntimeAcl());
  78. }
  79. }