Skip to content

Commit 3a88885

Browse files
author
Andrii Kasian
committed
Merge branch 'MAGETWO-37213' into S67
2 parents 09bb50b + b863051 commit 3a88885

File tree

2 files changed

+85
-4
lines changed
  • app/code/Magento/Bundle
    • Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes
    • Test/Unit/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes

2 files changed

+85
-4
lines changed

app/code/Magento/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes/Extend.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,12 @@ public function getOptions()
110110
*/
111111
public function isDisabledField()
112112
{
113-
return $this->getProduct()->getId() &&
114-
$this->getAttribute()->getAttributeCode() === 'price' ||
115-
$this->getElement()->getReadonly();
113+
return $this->_getData('is_disabled_field')
114+
|| ($this->getProduct()->getId()
115+
&& $this->getAttribute()->getAttributeCode() === 'price'
116+
)
117+
|| $this->getElement()->getReadonly();
118+
116119
}
117120

118121
/**
@@ -142,7 +145,9 @@ public function getExtendedElement($switchAttributeCode)
142145
'values' => $this->getOptions(),
143146
'value' => $switchAttributeCode,
144147
'class' => 'required-entry next-toinput',
145-
'disabled' => $this->isDisabledField()
148+
'no_span' => true,
149+
'disabled' => $this->isDisabledField(),
150+
'value' => $this->getProduct()->getData($switchAttributeCode),
146151
]
147152
);
148153
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Bundle\Test\Unit\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes;
7+
8+
use Magento\Catalog\Model\Product;
9+
10+
class ExtendTest extends \PHPUnit_Framework_TestCase
11+
{
12+
/** @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject */
13+
protected $registry;
14+
15+
/** @var \Magento\Framework\Data\FormFactory|\PHPUnit_Framework_MockObject_MockObject */
16+
protected $formFactory;
17+
18+
/** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */
19+
protected $objectManagerHelper;
20+
21+
/** @var \Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes\Extend */
22+
protected $object;
23+
24+
public function setUp()
25+
{
26+
$this->registry = $this->getMockBuilder('Magento\\Framework\\Registry')->disableOriginalConstructor()->getMock(
27+
);
28+
$this->formFactory = $this->getMockBuilder('Magento\\Framework\\Data\\FormFactory')->disableOriginalConstructor(
29+
)->getMock();
30+
$this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
31+
$this->object = $this->objectManagerHelper->getObject(
32+
'Magento\\Bundle\\Block\\Adminhtml\\Catalog\\Product\\Edit\\Tab\\Attributes\\Extend',
33+
['registry' => $this->registry, 'formFactory' => $this->formFactory]
34+
);
35+
}
36+
37+
/**
38+
* @return \PHPUnit_Framework_MockObject_MockObject
39+
*/
40+
public function getProduct()
41+
{
42+
$product = $this->getMockBuilder(Product::class)->disableOriginalConstructor()->getMock();
43+
$this->registry->expects($this->once())
44+
->method('registry')
45+
->with('product')
46+
->will(
47+
$this->returnValue($product)
48+
);
49+
return $product;
50+
}
51+
52+
public function testGetExtendedElement()
53+
{
54+
$switchAttributeCode = 'test_code';
55+
$form = $this->getMockBuilder(\Magento\Framework\Data\Form::class)->disableOriginalConstructor()->getMock();
56+
$and = new \PHPUnit_Framework_Constraint_And();
57+
$and->setConstraints(
58+
[
59+
new \PHPUnit_Framework_Constraint_ArrayHasKey('value')
60+
]
61+
);
62+
$form->expects($this->once())->method('addField')->with(
63+
$switchAttributeCode,
64+
'select',
65+
$and
66+
);
67+
68+
$this->formFactory->expects($this->once())->method('create')->with()->will($this->returnValue($form));
69+
$product = $this->getProduct();
70+
$product->expects($this->once())->method('getData')->with($switchAttributeCode)->will(
71+
$this->returnValue(123)
72+
);
73+
$this->object->setIsDisabledField(true);
74+
$this->object->getExtendedElement($switchAttributeCode);
75+
}
76+
}

0 commit comments

Comments
 (0)