Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractCompositeTest.php
Go to the documentation of this file.
1 <?php
7 
10 
11 class AbstractCompositeTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $_model;
17 
21  protected $_storeManagerMock;
22 
26  protected $_iteratorMock;
27 
31  protected $moduleManagerMock;
32 
36  private $elementVisibilityMock;
37 
43  protected $_testData = [
44  'id' => 'elementId',
45  'label' => 'Element Label',
46  'someAttribute' => 'Some attribute value',
47  'children' => ['someGroup' => []],
48  ];
49 
50  protected function setUp()
51  {
52  $this->elementVisibilityMock = $this->getMockBuilder(ElementVisibilityInterface::class)
53  ->getMockForAbstractClass();
54  $this->_iteratorMock = $this->createMock(\Magento\Config\Model\Config\Structure\Element\Iterator::class);
55  $this->_storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManager::class);
56  $this->moduleManagerMock = $this->createMock(\Magento\Framework\Module\Manager::class);
57  $this->_model = $this->getMockForAbstractClass(
58  \Magento\Config\Model\Config\Structure\Element\AbstractComposite::class,
59  [$this->_storeManagerMock, $this->moduleManagerMock, $this->_iteratorMock]
60  );
61  $objectManagerHelper = new ObjectManagerHelper($this);
62  $objectManagerHelper->setBackwardCompatibleProperty(
63  $this->_model,
64  'elementVisibility',
65  $this->elementVisibilityMock,
66  \Magento\Config\Model\Config\Structure\AbstractElement::class
67  );
68  }
69 
70  protected function tearDown()
71  {
72  unset($this->_iteratorMock);
73  unset($this->_storeManagerMock);
74  unset($this->_model);
75  }
76 
78  {
79  $this->_iteratorMock->expects(
80  $this->once()
81  )->method(
82  'setElements'
83  )->with(
84  ['someGroup' => []],
85  'scope'
86  );
87  $this->_model->setData($this->_testData, 'scope');
88  }
89 
91  {
92  $this->_iteratorMock->expects($this->once())->method('setElements')->with([], 'scope');
93  $this->_model->setData([], 'scope');
94  }
95 
97  {
98  $this->assertFalse($this->_model->hasChildren());
99  }
100 
102  {
103  $this->_iteratorMock->expects($this->once())->method('current')->will($this->returnValue(true));
104  $this->_iteratorMock->expects($this->once())->method('valid')->will($this->returnValue(true));
105  $this->assertTrue($this->_model->hasChildren());
106  }
107 
109  {
110  $this->_storeManagerMock->expects($this->once())->method('isSingleStoreMode')->will($this->returnValue(true));
111  $this->_iteratorMock->expects($this->once())->method('current')->will($this->returnValue(true));
112  $this->_iteratorMock->expects($this->once())->method('valid')->will($this->returnValue(true));
113  $this->_model->setData(['showInDefault' => 'true'], 'default');
114  $this->assertTrue($this->_model->isVisible());
115  }
116 
118  {
119  $this->_storeManagerMock->expects($this->once())->method('isSingleStoreMode')->will($this->returnValue(true));
120  $this->_model->setData(['showInDefault' => 'true', 'frontend_model' => 'Model_Name'], 'default');
121  $this->assertTrue($this->_model->isVisible());
122  }
123 
125  {
126  $this->_storeManagerMock->expects($this->once())->method('isSingleStoreMode')->will($this->returnValue(true));
127  $this->_model->setData(['showInDefault' => 'true'], 'default');
128  $this->assertFalse($this->_model->isVisible());
129  }
130 }