Skip to content

Commit 4bc4d1e

Browse files
committed
MAGETWO-65470: The visibility conditions improvements
1 parent 173a258 commit 4bc4d1e

File tree

7 files changed

+96
-67
lines changed

7 files changed

+96
-67
lines changed

lib/internal/Magento/Framework/View/Layout/GeneratorPool.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ protected function buildStructure(ScheduledStructure $scheduledStructure, Data\S
119119
}
120120
foreach ($scheduledStructure->getElements() as $name => $data) {
121121
list(, $data) = $data;
122-
if (
123-
array_key_exists('visibilityConditions', $data['attributes']) &&
124-
!empty($data['attributes']['visibilityConditions'])
125-
) {
122+
if ($this->visibilityConditionsExistsIn($data)) {
126123
$condition = $this->conditionFactory->create($data['attributes']['visibilityConditions']);
127124
if (!$condition->isVisible($data['attributes']['visibilityConditions'])) {
128125
$this->removeElement($scheduledStructure, $structure, $name);
@@ -227,4 +224,16 @@ protected function moveElementInStructure(
227224
$scheduledStructure->unsetElementFromBrokenParentList($element);
228225
return $this;
229226
}
227+
228+
/**
229+
* @param array $data
230+
*
231+
* @return bool
232+
*/
233+
protected function visibilityConditionsExistsIn(array $data)
234+
{
235+
return isset($data['attributes']) &&
236+
array_key_exists('visibilityConditions', $data['attributes']) &&
237+
!empty($data['attributes']['visibilityConditions']);
238+
}
230239
}

lib/internal/Magento/Framework/View/Layout/Reader/UiComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class UiComponent implements ReaderInterface
2525
*
2626
* @var array
2727
*/
28-
protected $attributes = ['group', 'component', 'aclResource', 'visibilityCondition'];
28+
protected $attributes = ['group', 'component', 'aclResource'];
2929

3030
/**
3131
* @var Helper

lib/internal/Magento/Framework/View/Layout/etc/elements.xsd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@
213213
<xs:sequence minOccurs="0" maxOccurs="unbounded">
214214
<xs:element ref="action" minOccurs="0" maxOccurs="unbounded"/>
215215
<xs:element ref="arguments" minOccurs="0" maxOccurs="1"/>
216-
<xs:element name="visibilityCondition" type="visibilityConditionType" minOccurs="0" maxOccurs="unbounded"/>
217216
<xs:element ref="block" minOccurs="0" maxOccurs="unbounded"/>
218217
<xs:element ref="container" minOccurs="0" maxOccurs="unbounded"/>
219218
<xs:element ref="referenceBlock" minOccurs="0" maxOccurs="unbounded"/>

lib/internal/Magento/Framework/View/Test/Unit/Layout/GeneratorPoolTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function testProcess($schedule, $expectedSchedule)
137137
*/
138138
$this->assertContains($elementName, $schedule['structure']);
139139
$scheduledStructure->unsetStructureElement($elementName);
140-
$scheduledStructure->setElement($elementName, []);
140+
$scheduledStructure->setElement($elementName, ['block', []]);
141141
$structure->createStructuralElement($elementName, 'block', 'someClass');
142142
});
143143

@@ -171,7 +171,10 @@ public function processDataProvider()
171171
],
172172
],
173173
'expectedScheduledElements' => [
174-
'first.element' => [], 'second.element' => [], 'third.element' => [], 'sort.element' => []
174+
'first.element' => ['block', []],
175+
'second.element' => ['block', []],
176+
'third.element' => ['block', []],
177+
'sort.element' => ['block', []],
175178
],
176179
],
177180
];

lib/internal/Magento/Framework/View/Test/Unit/Layout/Reader/BlockTest.php

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
*/
1010
namespace Magento\Framework\View\Test\Unit\Layout\Reader;
1111

12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1213
use Magento\Framework\View\Layout\Reader\Block;
14+
use Magento\Framework\View\Layout\Reader\Visibility\Condition;
1315

1416
class BlockTest extends \PHPUnit_Framework_TestCase
1517
{
@@ -93,7 +95,7 @@ protected function setUp()
9395
* @param string $literal
9496
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $scheduleStructureCount
9597
* @param string $ifconfigValue
96-
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $ifconfigCondition
98+
* @param array $expectedConditions
9799
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $getCondition
98100
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $setCondition
99101
* @param string $aclKey
@@ -105,18 +107,14 @@ public function testProcessBlock(
105107
$literal,
106108
$scheduleStructureCount,
107109
$ifconfigValue,
108-
$ifconfigCondition,
110+
$expectedConditions,
109111
$getCondition,
110112
$setCondition,
111113
$aclKey,
112114
$aclValue
113115
) {
114116
$this->context->expects($this->once())->method('getScheduledStructure')
115117
->will($this->returnValue($this->scheduledStructure));
116-
117-
$this->scheduledStructure->expects($ifconfigCondition)
118-
->method('setElementToIfconfigList')
119-
->with($literal, $ifconfigValue, 'scope');
120118
$this->scheduledStructure->expects($getCondition)
121119
->method('getStructureElementData')
122120
->with($literal, [])
@@ -136,7 +134,8 @@ public function testProcessBlock(
136134
Block::ATTRIBUTE_TEMPLATE => '',
137135
Block::ATTRIBUTE_TTL => '',
138136
Block::ATTRIBUTE_DISPLAY => '',
139-
Block::ATTRIBUTE_ACL => $aclValue
137+
Block::ATTRIBUTE_ACL => $aclValue,
138+
'visibilityConditions' => $expectedConditions,
140139
],
141140
'actions' => [
142141
['someMethod', [], 'action_config_path', 'scope'],
@@ -154,12 +153,14 @@ public function testProcessBlock(
154153
. '</' . $literal . '>',
155154
$literal
156155
);
157-
156+
$objectManager = new ObjectManager($this);
157+
$condition = $objectManager->getObject(Condition::class);
158158
/** @var \Magento\Framework\View\Layout\Reader\Block $block */
159159
$block = $this->getBlock(
160160
[
161161
'helper' => $helper,
162162
'readerPool' => $this->readerPool,
163+
'conditionReader' => $condition,
163164
'scopeType' => 'scope',
164165
]
165166
);
@@ -176,7 +177,14 @@ public function processBlockDataProvider()
176177
'block',
177178
$this->once(),
178179
'',
179-
$this->never(),
180+
[
181+
'acl' => [
182+
'name' => 'Magento\Framework\View\Layout\AclCondition',
183+
'arguments' => [
184+
'acl' => 'test'
185+
],
186+
],
187+
],
180188
$this->once(),
181189
$this->once(),
182190
'acl',
@@ -186,7 +194,20 @@ public function processBlockDataProvider()
186194
'block',
187195
$this->once(),
188196
'config_path',
189-
$this->once(),
197+
[
198+
'acl' => [
199+
'name' => 'Magento\Framework\View\Layout\AclCondition',
200+
'arguments' => [
201+
'acl' => 'test'
202+
],
203+
],
204+
'ifconfig' => [
205+
'name' => 'Magento\Framework\View\Layout\ConfigCondition',
206+
'arguments' => [
207+
'configPath' => 'config_path'
208+
],
209+
],
210+
],
190211
$this->once(),
191212
$this->once(),
192213
'aclResource',
@@ -196,7 +217,20 @@ public function processBlockDataProvider()
196217
'page',
197218
$this->never(),
198219
'',
199-
$this->never(),
220+
[
221+
'acl' => [
222+
'name' => 'Magento\Framework\View\Layout\AclCondition',
223+
'arguments' => [
224+
'acl' => 'test'
225+
],
226+
],
227+
'ifconfig' => [
228+
'name' => 'Magento\Framework\View\Layout\ConfigCondition',
229+
'arguments' => [
230+
'configPath' => 'config_path'
231+
],
232+
],
233+
],
200234
$this->never(),
201235
$this->never(),
202236
'aclResource',
@@ -267,11 +301,13 @@ public function testProcessReference(
267301
. '</' . $literal . '>',
268302
$literal
269303
);
270-
304+
$objectManager = new ObjectManager($this);
305+
$condition = $objectManager->getObject(Condition::class);
271306
/** @var \Magento\Framework\View\Layout\Reader\Block $block */
272307
$block = $this->getBlock(
273308
[
274309
'readerPool' => $this->readerPool,
310+
'conditionReader' => $condition,
275311
'scopeType' => 'scope',
276312
]
277313
);

lib/internal/Magento/Framework/View/Test/Unit/Layout/Reader/UiComponentTest.php

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
*/
1010
namespace Magento\Framework\View\Test\Unit\Layout\Reader;
1111

12-
use \Magento\Framework\View\Layout\Reader\UiComponent;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
use Magento\Framework\View\Layout\Reader\Context;
14+
use Magento\Framework\View\Layout\Reader\UiComponent;
15+
use Magento\Framework\View\Layout\Reader\Visibility\Condition;
16+
use Magento\Framework\View\Layout\ScheduledStructure\Helper;
1317

1418
class UiComponentTest extends \PHPUnit_Framework_TestCase
1519
{
@@ -19,26 +23,28 @@ class UiComponentTest extends \PHPUnit_Framework_TestCase
1923
protected $model;
2024

2125
/**
22-
* @var \Magento\Framework\View\Layout\ScheduledStructure\Helper|\PHPUnit_Framework_MockObject_MockObject
26+
* @var Helper|\PHPUnit_Framework_MockObject_MockObject
2327
*/
2428
protected $helper;
2529

2630
/**
27-
* @var \Magento\Framework\View\Layout\Reader\Context|\PHPUnit_Framework_MockObject_MockObject
31+
* @var Context|\PHPUnit_Framework_MockObject_MockObject
2832
*/
2933
protected $context;
3034

3135
protected function setUp()
3236
{
33-
$this->helper = $this->getMockBuilder(\Magento\Framework\View\Layout\ScheduledStructure\Helper::class)
37+
$this->helper = $this->getMockBuilder(Helper::class)
3438
->setMethods(['scheduleStructure'])
3539
->disableOriginalConstructor()
3640
->getMock();
37-
$this->context = $this->getMockBuilder(\Magento\Framework\View\Layout\Reader\Context::class)
41+
$this->context = $this->getMockBuilder(Context::class)
3842
->setMethods(['getScheduledStructure', 'setElementToIfconfigList'])
3943
->disableOriginalConstructor()
4044
->getMock();
41-
$this->model = new UiComponent($this->helper, 'scope');
45+
$objectManager = new ObjectManager($this);
46+
$condition = $objectManager->getObject(Condition::class);
47+
$this->model = new UiComponent($this->helper, $condition);
4248
}
4349

4450
public function testGetSupportedNodes()
@@ -77,16 +83,24 @@ public function testInterpret($element)
7783
'attributes' => [
7884
'group' => '',
7985
'component' => 'listing',
80-
'aclResource' => 'test',
81-
'visibilityCondition' => 'test',
86+
'aclResource' => 'test_acl',
87+
'visibilityConditions' => [
88+
'ifconfig' => [
89+
'name' => 'Magento\Framework\View\Layout\ConfigCondition',
90+
'arguments' => [
91+
'configPath' => 'config_path'
92+
],
93+
],
94+
'acl' => [
95+
'name' => 'Magento\Framework\View\Layout\AclCondition',
96+
'arguments' => [
97+
'acl' => 'test_acl'
98+
],
99+
],
100+
],
82101
],
83102
]
84103
);
85-
$scheduleStructure->expects($this->once())->method('setElementToIfconfigList')->with(
86-
$element->getAttribute('name'),
87-
'config_path',
88-
'scope'
89-
);
90104
$this->model->interpret($this->context, $element);
91105
}
92106

@@ -97,10 +111,10 @@ public function interpretDataProvider()
97111
$this->getElement(
98112
'<uiComponent
99113
name="cms_block_listing"
100-
aclResource="test" visibilityCondition="test"
114+
aclResource="test_acl"
101115
component="listing"
102116
ifconfig="config_path"
103-
/>',
117+
><visibilityCondition name="test_name" className="name"></visibilityCondition></uiComponent>',
104118
'uiComponent'
105119
),
106120
]

lib/internal/Magento/Framework/View/Test/Unit/Layout/ScheduledStructureTest.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ protected function setUp()
5454
'element6' => ['data', 'of', 'element', 'to', 'remove', '6'],
5555
'element7' => ['data', 'of', 'element', 'to', 'remove', '7'],
5656
],
57-
'scheduledIfconfig' => [
58-
'element1' => ['data', 'of', 'ifconfig', 'element', '1'],
59-
'element4' => ['data', 'of', 'ifconfig', 'element', '4'],
60-
'element6' => ['data', 'of', 'ifconfig', 'element', '6'],
61-
'element8' => ['data', 'of', 'ifconfig', 'element', '8'],
62-
],
6357
'scheduledPaths' => [
6458
'path1' => 'path 1',
6559
'path2' => 'path 2',
@@ -99,12 +93,6 @@ public function testGetListToRemove()
9993
$this->assertEquals($expected, $this->model->getListToRemove());
10094
}
10195

102-
public function testGetIfconfigList()
103-
{
104-
$expected = ['element1', 'element4'];
105-
$this->assertEquals($expected, $this->model->getIfconfigList());
106-
}
107-
10896
/**
10997
* @return void
11098
*/
@@ -236,26 +224,6 @@ public function testSetElementToRemoveList()
236224
$this->assertContains('element1', $this->model->getListToRemove());
237225
}
238226

239-
/**
240-
* @return void
241-
*/
242-
public function testUnsetElementFromIfconfigList()
243-
{
244-
$this->assertContains('element4', $this->model->getIfconfigList());
245-
$this->model->unsetElementFromIfconfigList('element4');
246-
$this->assertNotContains('element4', $this->model->getIfconfigList());
247-
}
248-
249-
/**
250-
* @return void
251-
*/
252-
public function testSetElementToIfconfigList()
253-
{
254-
$this->assertNotContains('element5', $this->model->getIfconfigList());
255-
$this->model->setElementToIfconfigList('element5', 'config_path', 'scope');
256-
$this->assertContains('element5', $this->model->getIfconfigList());
257-
}
258-
259227
/**
260228
* @return void
261229
*/

0 commit comments

Comments
 (0)