Skip to content

Commit a5d33d6

Browse files
author
Yaroslav Onischenko
committed
MAGETWO-52042: Saving swatch option cause errors
1 parent 4565624 commit a5d33d6

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/AddAttribute.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\ConfigurableProduct\Controller\Adminhtml\Product;
88

99
use Magento\Backend\App\Action;
10+
use Magento\Framework\Controller\ResultFactory;
1011

1112
class AddAttribute extends Action
1213
{
@@ -28,16 +29,11 @@ public function __construct(
2829
}
2930

3031
/**
31-
* Add "super" attribute from popup window
32-
*
33-
* @return void
32+
* @inheritdoc
3433
*/
3534
public function execute()
3635
{
3736
$this->productBuilder->build($this->getRequest());
38-
$attributeBlock = $this->_view->getLayout()->createBlock(
39-
'Magento\ConfigurableProduct\Block\Adminhtml\Product\Attribute\NewAttribute\Product\Created'
40-
);
41-
$this->getResponse()->setBody($attributeBlock->toHtml());
37+
return $this->resultFactory->create(ResultFactory::TYPE_LAYOUT);
4238
}
4339
}

app/code/Magento/ConfigurableProduct/Test/Unit/Controller/Adminhtml/Product/AddAttributeTest.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66

77
namespace Magento\ConfigurableProduct\Test\Unit\Controller\Adminhtml\Product;
88

9+
use Magento\Framework\Controller\ResultFactory;
910
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1011

1112
class AddAttributeTest extends \PHPUnit_Framework_TestCase
1213
{
14+
/** @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject */
15+
private $resultFactory;
16+
1317
/** @var \Magento\ConfigurableProduct\Controller\Adminhtml\Product\AddAttribute */
1418
protected $controller;
1519

@@ -45,35 +49,39 @@ protected function setUp()
4549
{
4650
$this->objectManagerHelper = new ObjectManagerHelper($this);
4751

48-
$this->context = $this->getMockBuilder('\Magento\Backend\App\Action\Context')
52+
$this->context = $this->getMockBuilder(\Magento\Backend\App\Action\Context::class)
4953
->disableOriginalConstructor()
5054
->getMock();
51-
$this->request = $this->getMock('Magento\Framework\App\RequestInterface');
55+
$this->request = $this->getMock(\Magento\Framework\App\RequestInterface::class);
56+
$this->resultFactory = $this->getMock(\Magento\Framework\Controller\ResultFactory::class, [], [], '', false);
5257
$this->response = $this->getMock(
53-
'\Magento\Framework\App\ResponseInterface',
58+
\Magento\Framework\App\ResponseInterface::class,
5459
[
5560
'sendResponse',
5661
'setBody'
5762
]
5863
);
59-
$this->productBuilder = $this->getMockBuilder('\Magento\Catalog\Controller\Adminhtml\Product\Builder')
64+
$this->productBuilder = $this->getMockBuilder(\Magento\Catalog\Controller\Adminhtml\Product\Builder::class)
6065
->disableOriginalConstructor()
6166
->setMethods(['build'])
6267
->getMock();
63-
$this->view = $this->getMock('\Magento\Framework\App\ViewInterface');
68+
$this->view = $this->getMock(\Magento\Framework\App\ViewInterface::class);
6469

6570
$this->context->expects($this->any())
6671
->method('getRequest')
6772
->will($this->returnValue($this->request));
6873
$this->context->expects($this->any())
6974
->method('getResponse')
7075
->will($this->returnValue($this->response));
76+
$this->context->expects($this->any())
77+
->method('getResultFactory')
78+
->will($this->returnValue($this->resultFactory));
7179
$this->context->expects($this->any())
7280
->method('getView')
7381
->will($this->returnValue($this->view));
7482

7583
$this->controller = $this->objectManagerHelper->getObject(
76-
'\Magento\ConfigurableProduct\Controller\Adminhtml\Product\AddAttribute',
84+
\Magento\ConfigurableProduct\Controller\Adminhtml\Product\AddAttribute::class,
7785
[
7886
'context' => $this->context,
7987
'productBuilder' => $this->productBuilder
@@ -83,22 +91,16 @@ protected function setUp()
8391

8492
public function testExecute()
8593
{
86-
$product = $this->getMockBuilder('\Magento\Catalog\Model\Product')
94+
$product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
8795
->disableOriginalConstructor()
8896
->setMethods(['_wakeup', 'getId'])
8997
->getMock();
90-
$layout = $this->getMock('\Magento\Framework\View\LayoutInterface');
91-
$block = $this->getMockBuilder(
92-
'Magento\ConfigurableProduct\Block\Adminhtml\Product\Attribute\NewAttribute\Product\Created'
93-
)
94-
->disableOriginalConstructor()
95-
->setMethods(['setIndex', 'toHtml'])
96-
->getMock();
9798

9899
$this->productBuilder->expects($this->once())->method('build')->with($this->request)->willReturn($product);
99-
$this->view->expects($this->once())->method('getLayout')->willReturn($layout);
100-
$layout->expects($this->once())->method('createBlock')->willReturn($block);
100+
$resultLayout = $this->getMock(\Magento\Framework\View\Result\Layout::class, [], [], '', false);
101+
$this->resultFactory->expects($this->once())->method('create')->with(ResultFactory::TYPE_LAYOUT)
102+
->willReturn($resultLayout);
101103

102-
$this->controller->execute();
104+
$this->assertInstanceOf(\Magento\Framework\View\Result\Layout::class, $this->controller->execute());
103105
}
104106
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
9+
<container name="root">
10+
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Attribute\NewAttribute\Product\Created" template="Magento_ConfigurableProduct::catalog/product/attribute/new/created.phtml" as="product.attribute.created" />
11+
</container>
12+
</layout>

0 commit comments

Comments
 (0)