Skip to content

Commit 550ae56

Browse files
committed
MAGETWO-71520: Product Grid filtered to Store View is broken if corresponding Store is deleted
- fix unit test
1 parent ad9b645 commit 550ae56

File tree

3 files changed

+106
-3
lines changed

3 files changed

+106
-3
lines changed

app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(
5353
/**
5454
* Action for AJAX request
5555
*
56-
* @return void
56+
* @return void|\Magento\Framework\Controller\ResultInterface
5757
*/
5858
public function execute()
5959
{

app/code/Magento/Ui/Test/Unit/Controller/Adminhtml/Index/RenderTest.php

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Ui\Test\Unit\Controller\Adminhtml\Index;
77

88
use \Magento\Ui\Controller\Adminhtml\Index\Render;
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
910

1011
/**
1112
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -17,6 +18,11 @@ class RenderTest extends \PHPUnit\Framework\TestCase
1718
*/
1819
private $render;
1920

21+
/**
22+
* @var ObjectManagerHelper
23+
*/
24+
private $objectManagerHelper;
25+
2026
/**
2127
* @var \PHPUnit_Framework_MockObject_MockObject
2228
*/
@@ -73,6 +79,21 @@ class RenderTest extends \PHPUnit\Framework\TestCase
7379
*/
7480
private $uiComponentMock;
7581

82+
/**
83+
* @var \Magento\Framework\Controller\Result\JsonFactory|\PHPUnit_Framework_MockObject_MockObject
84+
*/
85+
private $resultJsonFactoryMock;
86+
87+
/**
88+
* @var \Magento\Framework\Escaper|\PHPUnit_Framework_MockObject_MockObject
89+
*/
90+
private $escaperMock;
91+
92+
/**
93+
* @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
94+
*/
95+
private $loggerMock;
96+
7697
protected function setUp()
7798
{
7899
$this->requestMock = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
@@ -114,6 +135,20 @@ protected function setUp()
114135
['render']
115136
);
116137

138+
$this->resultJsonFactoryMock = $this->getMockBuilder(
139+
\Magento\Framework\Controller\Result\JsonFactory::class
140+
)
141+
->disableOriginalConstructor()
142+
->getMock();
143+
144+
$this->escaperMock = $this->getMockBuilder(
145+
\Magento\Framework\Escaper::class
146+
)
147+
->disableOriginalConstructor()
148+
->getMock();
149+
150+
$this->loggerMock = $this->getMockForAbstractClass(\Psr\Log\LoggerInterface::class);
151+
117152
$this->contextMock->expects($this->any())
118153
->method('getRequest')
119154
->willReturn($this->requestMock);
@@ -136,7 +171,75 @@ protected function setUp()
136171
->method('getDataProvider')
137172
->willReturn($this->dataProviderMock);
138173

139-
$this->render = new Render($this->contextMock, $this->uiFactoryMock);
174+
$this->objectManagerHelper = new ObjectManagerHelper($this);
175+
176+
$this->render = $this->objectManagerHelper->getObject(
177+
\Magento\Ui\Controller\Adminhtml\Index\Render::class,
178+
[
179+
'context' => $this->contextMock,
180+
'factory' => $this->uiFactoryMock,
181+
'resultJsonFactory' => $this->resultJsonFactoryMock,
182+
'escaper' => $this->escaperMock,
183+
'logger' => $this->loggerMock
184+
]
185+
);
186+
}
187+
188+
public function testExecuteAjaxRequestException()
189+
{
190+
$name = 'test-name';
191+
$renderedData = '<html>data</html>';
192+
193+
$this->requestMock->expects($this->any())
194+
->method('getParam')
195+
->with('namespace')
196+
->willReturn($name);
197+
$this->requestMock->expects($this->any())
198+
->method('getParams')
199+
->willReturn([]);
200+
$this->responseMock->expects($this->once())
201+
->method('appendBody')
202+
->willThrowException(new \Exception('exception'));
203+
204+
$jsonResultMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Json::class)
205+
->disableOriginalConstructor()
206+
->setMethods(['setData'])
207+
->getMock();
208+
209+
$this->resultJsonFactoryMock->expects($this->once())
210+
->method('create')
211+
->willReturn($jsonResultMock);
212+
213+
$jsonResultMock->expects($this->once())
214+
->method('setData')
215+
->willReturnSelf();
216+
217+
$this->loggerMock->expects($this->once())
218+
->method('critical')
219+
->willReturnSelf();
220+
221+
$this->escaperMock->expects($this->once())
222+
->method('escapeHtml')
223+
->willReturnSelf();
224+
225+
$this->dataProviderMock->expects($this->once())
226+
->method('getConfigData')
227+
->willReturn([]);
228+
229+
$this->uiComponentMock->expects($this->once())
230+
->method('render')
231+
->willReturn($renderedData);
232+
$this->uiComponentMock->expects($this->once())
233+
->method('getChildComponents')
234+
->willReturn([]);
235+
$this->uiComponentMock->expects($this->once())
236+
->method('getContext')
237+
->willReturn($this->uiComponentContextMock);
238+
$this->uiFactoryMock->expects($this->once())
239+
->method('create')
240+
->willReturn($this->uiComponentMock);
241+
242+
$this->render->executeAjaxRequest();
140243
}
141244

142245
public function testExecuteAjaxRequest()

dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertResetFilterMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66

0 commit comments

Comments
 (0)