Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BuilderTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class BuilderTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $_aclFactoryMock;
16 
20  protected $_aclMock;
21 
25  protected $_ruleLoader;
26 
30  protected $_roleLoader;
31 
35  protected $_resourceLoader;
36 
40  protected $_model;
41 
42  protected function setUp()
43  {
44  $this->_aclMock = new \Magento\Framework\Acl();
45  $this->_aclFactoryMock = $this->createMock(\Magento\Framework\AclFactory::class);
46  $this->_aclFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->_aclMock));
47  $this->_roleLoader = $this->createMock(\Magento\Framework\Acl\Loader\DefaultLoader::class);
48  $this->_ruleLoader = $this->createMock(\Magento\Framework\Acl\Loader\DefaultLoader::class);
49  $this->_resourceLoader = $this->createMock(\Magento\Framework\Acl\Loader\DefaultLoader::class);
50  $this->_model = new \Magento\Framework\Acl\Builder(
51  $this->_aclFactoryMock,
52  $this->_roleLoader,
53  $this->_resourceLoader,
54  $this->_ruleLoader
55  );
56  }
57 
59  {
60  $this->_ruleLoader->expects($this->once())->method('populateAcl')->with($this->equalTo($this->_aclMock));
61 
62  $this->_roleLoader->expects($this->once())->method('populateAcl')->with($this->equalTo($this->_aclMock));
63 
64  $this->_resourceLoader->expects($this->once())->method('populateAcl')->with($this->equalTo($this->_aclMock));
65 
66  $this->assertEquals($this->_aclMock, $this->_model->getAcl());
67  }
68 
70  {
71  $this->assertEquals($this->_aclMock, $this->_model->getAcl());
72  $this->assertEquals($this->_aclMock, $this->_model->getAcl());
73  }
74 
78  public function testGetAclRethrowsException()
79  {
80  $this->_aclFactoryMock->expects(
81  $this->once()
82  )->method(
83  'create'
84  )->will(
85  $this->throwException(new \InvalidArgumentException())
86  );
87  $this->_model->getAcl();
88  }
89 
90  public function testResetRuntimeAcl()
91  {
92  $this->assertInstanceOf(Builder::class, $this->_model->resetRuntimeAcl());
93  }
94 }