Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UiComponentTest.php
Go to the documentation of this file.
1 <?php
11 
19 use Magento\Framework\Config\DataInterfaceFactory;
24 
25 class UiComponentTest extends \PHPUnit\Framework\TestCase
26 {
30  protected $model;
31 
35  protected $helper;
36 
40  private $dataConfigFactory;
41 
45  private $dataConfig;
46 
50  private $readerPool;
51 
55  protected $context;
56 
57  protected function setUp()
58  {
59  $this->helper = $this->getMockBuilder(Helper::class)
60  ->setMethods(['scheduleStructure'])
61  ->disableOriginalConstructor()
62  ->getMock();
63  $this->context = $this->getMockBuilder(Context::class)
64  ->setMethods(['getScheduledStructure', 'setElementToIfconfigList'])
65  ->disableOriginalConstructor()
66  ->getMock();
67  $this->dataConfigFactory = $this->getMockBuilder(DataInterfaceFactory::class)
68  ->disableOriginalConstructor()
69  ->setMethods(['create'])
70  ->getMock();
71  $this->dataConfig = $this->getMockBuilder(DataInterface::class)
72  ->disableOriginalConstructor()
73  ->getMock();
74  $this->readerPool = $this->getMockBuilder(ReaderPool::class)
75  ->disableOriginalConstructor()
76  ->getMock();
77  $objectManager = new ObjectManager($this);
78  $condition = $objectManager->getObject(Condition::class);
79  $this->model = new UiComponent($this->helper, $condition, $this->dataConfigFactory, $this->readerPool);
80  }
81 
82  public function testGetSupportedNodes()
83  {
85  $this->assertEquals($data, $this->model->getSupportedNodes());
86  }
87 
93  public function testInterpret($element)
94  {
95  $scheduleStructure = $this->getMockBuilder(ScheduledStructure::class)
96  ->disableOriginalConstructor()
97  ->getMock();
98  $this->context->expects($this->any())->method('getScheduledStructure')->will(
99  $this->returnValue($scheduleStructure)
100  );
101  $this->helper->expects($this->any())->method('scheduleStructure')->with(
102  $scheduleStructure,
103  $element,
104  $element->getParent()
105  )->willReturn($element->getAttribute('name'));
106 
107  $scheduleStructure->expects($this->once())->method('setStructureElementData')->with(
108  $element->getAttribute('name'),
109  [
110  'attributes' => [
111  'group' => '',
112  'component' => 'listing',
113  'aclResource' => 'test_acl',
114  'visibilityConditions' => [
115  'ifconfig' => [
116  'name' => ConfigCondition::class,
117  'arguments' => [
118  'configPath' => 'config_path'
119  ],
120  ],
121  'acl' => [
122  'name' => AclCondition::class,
123  'arguments' => [
124  'acl' => 'test_acl'
125  ],
126  ],
127  ],
128  ],
129  ]
130  );
131  $this->dataConfigFactory->expects($this->once())
132  ->method('create')
133  ->with(['componentName' => $element->getAttribute('name')])
134  ->willReturn($this->dataConfig);
135  $xml = '<?xml version="1.0"?>'
136  . '<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
137  . '<block/>'
138  . '</layout>';
139  $this->dataConfig->expects($this->once())
140  ->method('get')
141  ->with($element->getAttribute('name'))
142  ->willReturn([
143  'children' => [
144  'testComponent' => [
145  'arguments' => [
146  'block' => [
147  'layout' => $xml
148  ]
149  ]
150  ]
151  ]
152  ]);
153 
154  $this->readerPool->expects($this->once())
155  ->method('interpret')
156  ->with($this->context, $this->isInstanceOf(Element::class));
157 
158  $this->model->interpret($this->context, $element);
159  }
160 
164  public function interpretDataProvider()
165  {
166  return [
167  [
168  $this->getElement(
169  '<uiComponent
170  name="cms_block_listing"
171  aclResource="test_acl"
172  component="listing"
173  ifconfig="config_path"
174  ><visibilityCondition name="test_name" className="name"></visibilityCondition></uiComponent>',
175  'uiComponent'
176  ),
177  ]
178  ];
179  }
180 
186  protected function getElement($xml, $elementType)
187  {
188  $xml = simplexml_load_string(
189  '<parent_element>' . $xml . '</parent_element>',
190  Element::class
191  );
192  return $xml->{$elementType};
193  }
194 }
$objectManager
Definition: bootstrap.php:17
$element
Definition: element.phtml:12