Skip to content

Commit

Permalink
MAGETWO-71520: Product Grid filtered to Store View is broken if corre…
Browse files Browse the repository at this point in the history
…sponding Store is deleted

- fix unit test
  • Loading branch information
cpartica committed Oct 4, 2017
1 parent ad9b645 commit 550ae56
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(
/**
* Action for AJAX request
*
* @return void
* @return void|\Magento\Framework\Controller\ResultInterface
*/
public function execute()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Ui\Test\Unit\Controller\Adminhtml\Index;

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

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand All @@ -17,6 +18,11 @@ class RenderTest extends \PHPUnit\Framework\TestCase
*/
private $render;

/**
* @var ObjectManagerHelper
*/
private $objectManagerHelper;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
Expand Down Expand Up @@ -73,6 +79,21 @@ class RenderTest extends \PHPUnit\Framework\TestCase
*/
private $uiComponentMock;

/**
* @var \Magento\Framework\Controller\Result\JsonFactory|\PHPUnit_Framework_MockObject_MockObject
*/
private $resultJsonFactoryMock;

/**
* @var \Magento\Framework\Escaper|\PHPUnit_Framework_MockObject_MockObject
*/
private $escaperMock;

/**
* @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $loggerMock;

protected function setUp()
{
$this->requestMock = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
Expand Down Expand Up @@ -114,6 +135,20 @@ protected function setUp()
['render']
);

$this->resultJsonFactoryMock = $this->getMockBuilder(
\Magento\Framework\Controller\Result\JsonFactory::class
)
->disableOriginalConstructor()
->getMock();

$this->escaperMock = $this->getMockBuilder(
\Magento\Framework\Escaper::class
)
->disableOriginalConstructor()
->getMock();

$this->loggerMock = $this->getMockForAbstractClass(\Psr\Log\LoggerInterface::class);

$this->contextMock->expects($this->any())
->method('getRequest')
->willReturn($this->requestMock);
Expand All @@ -136,7 +171,75 @@ protected function setUp()
->method('getDataProvider')
->willReturn($this->dataProviderMock);

$this->render = new Render($this->contextMock, $this->uiFactoryMock);
$this->objectManagerHelper = new ObjectManagerHelper($this);

$this->render = $this->objectManagerHelper->getObject(
\Magento\Ui\Controller\Adminhtml\Index\Render::class,
[
'context' => $this->contextMock,
'factory' => $this->uiFactoryMock,
'resultJsonFactory' => $this->resultJsonFactoryMock,
'escaper' => $this->escaperMock,
'logger' => $this->loggerMock
]
);
}

public function testExecuteAjaxRequestException()
{
$name = 'test-name';
$renderedData = '<html>data</html>';

$this->requestMock->expects($this->any())
->method('getParam')
->with('namespace')
->willReturn($name);
$this->requestMock->expects($this->any())
->method('getParams')
->willReturn([]);
$this->responseMock->expects($this->once())
->method('appendBody')
->willThrowException(new \Exception('exception'));

$jsonResultMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Json::class)
->disableOriginalConstructor()
->setMethods(['setData'])
->getMock();

$this->resultJsonFactoryMock->expects($this->once())
->method('create')
->willReturn($jsonResultMock);

$jsonResultMock->expects($this->once())
->method('setData')
->willReturnSelf();

$this->loggerMock->expects($this->once())
->method('critical')
->willReturnSelf();

$this->escaperMock->expects($this->once())
->method('escapeHtml')
->willReturnSelf();

$this->dataProviderMock->expects($this->once())
->method('getConfigData')
->willReturn([]);

$this->uiComponentMock->expects($this->once())
->method('render')
->willReturn($renderedData);
$this->uiComponentMock->expects($this->once())
->method('getChildComponents')
->willReturn([]);
$this->uiComponentMock->expects($this->once())
->method('getContext')
->willReturn($this->uiComponentContextMock);
$this->uiFactoryMock->expects($this->once())
->method('create')
->willReturn($this->uiComponentMock);

$this->render->executeAjaxRequest();
}

public function testExecuteAjaxRequest()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

Expand Down

0 comments on commit 550ae56

Please sign in to comment.