Skip to content

Commit e3e80a0

Browse files
author
Yuri Kovsher
committed
Merge remote-tracking branch 'tango-ce/MAGETWO-17690' into Tango_Pull_Request_Bug_Fixing
2 parents 4381aef + 2b07c12 commit e3e80a0

File tree

2 files changed

+131
-3
lines changed
  • app/code/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab
  • dev/tests/unit/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab

2 files changed

+131
-3
lines changed

app/code/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Properties.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
class Properties extends \Magento\Widget\Block\Adminhtml\Widget\Options implements
1414
\Magento\Backend\Block\Widget\Tab\TabInterface
1515
{
16+
/**
17+
* Widget config parameters
18+
*
19+
* @var array
20+
*/
21+
protected $hiddenParameters = [
22+
'template'
23+
];
24+
1625
/**
1726
* Prepare label for tab
1827
*
@@ -46,11 +55,21 @@ public function canShowTab()
4655
/**
4756
* Returns status flag about this tab hidden or not
4857
*
49-
* @return true
58+
* @return bool
5059
*/
5160
public function isHidden()
5261
{
53-
return false;
62+
$widgetConfig = $this->getWidgetInstance()->getWidgetConfigAsArray();
63+
64+
if (isset($widgetConfig['parameters'])) {
65+
foreach ($widgetConfig['parameters'] as $key => $parameter) {
66+
if ($parameter['visible'] == 1 && !in_array($key, $this->hiddenParameters)) {
67+
return false;
68+
}
69+
}
70+
}
71+
72+
return true;
5473
}
5574

5675
/**
@@ -87,7 +106,7 @@ protected function _preparelayout()
87106
*/
88107
protected function _addField($parameter)
89108
{
90-
if ($parameter->getKey() != 'template') {
109+
if (!in_array($parameter->getKey(), $this->hiddenParameters)) {
91110
return parent::_addField($parameter);
92111
}
93112
return false;
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
4+
*/
5+
namespace Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Tab;
6+
7+
class PropertiesTest extends \PHPUnit_Framework_TestCase
8+
{
9+
/**
10+
* @var \PHPUnit_Framework_MockObject_MockObject
11+
*/
12+
protected $widget;
13+
14+
/**
15+
* @var \PHPUnit_Framework_MockObject_MockObject
16+
*/
17+
protected $registry;
18+
19+
/**
20+
* @var \Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Tab\Properties
21+
*/
22+
protected $propertiesBlock;
23+
24+
protected function setUp()
25+
{
26+
$this->widget = $this->getMock('Magento\Widget\Model\Widget\Instance', [], [], '', false);
27+
$this->registry = $this->getMock('Magento\Framework\Registry', [], [], '', false);
28+
29+
$objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
30+
$this->propertiesBlock = $objectManager->getObject(
31+
'Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Tab\Properties',
32+
[
33+
'registry' => $this->registry
34+
]
35+
);
36+
}
37+
38+
/**
39+
* @param array $widgetConfig
40+
* @param boolean $isHidden
41+
*
42+
* @dataProvider isHiddenDataProvider
43+
*/
44+
public function testIsHidden($widgetConfig, $isHidden)
45+
{
46+
$this->widget->expects($this->atLeastOnce())->method('getWidgetConfigAsArray')->willReturn($widgetConfig);
47+
48+
$this->registry->expects($this->atLeastOnce())
49+
->method('registry')
50+
->with('current_widget_instance')
51+
->willReturn($this->widget);
52+
53+
$this->assertEquals($isHidden, $this->propertiesBlock->isHidden());
54+
}
55+
56+
/**
57+
* @return array
58+
*/
59+
public function isHiddenDataProvider()
60+
{
61+
return [
62+
[
63+
'widgetConfig' => [
64+
'parameters' => [
65+
'title' => [
66+
'type' => 'text',
67+
'visible' => '0',
68+
],
69+
'template' => [
70+
'type' => 'select',
71+
'visible' => '1',
72+
],
73+
]
74+
],
75+
'isHidden' => true
76+
],
77+
[
78+
'widgetConfig' => [
79+
'parameters' => [
80+
'types' => [
81+
'type' => 'multiselect',
82+
'visible' => '1',
83+
],
84+
'template' => [
85+
'type' => 'select',
86+
'visible' => '1',
87+
],
88+
]
89+
],
90+
'isHidden' => false
91+
],
92+
[
93+
'widgetConfig' => [],
94+
'isHidden' => true
95+
],
96+
[
97+
'widgetConfig' => [
98+
'parameters' => [
99+
'template' => [
100+
'type' => 'select',
101+
'visible' => '0',
102+
],
103+
]
104+
],
105+
'isHidden' => true
106+
]
107+
];
108+
}
109+
}

0 commit comments

Comments
 (0)