diff --git a/app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php b/app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php index bd12a173e0c8d..e4600b054c012 100644 --- a/app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php +++ b/app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php @@ -53,7 +53,7 @@ public function __construct( /** * Action for AJAX request * - * @return void + * @return void|\Magento\Framework\Controller\ResultInterface */ public function execute() { diff --git a/app/code/Magento/Ui/Test/Unit/Controller/Adminhtml/Index/RenderTest.php b/app/code/Magento/Ui/Test/Unit/Controller/Adminhtml/Index/RenderTest.php index 5ab08a8a64a19..d3415cf5cf2e8 100644 --- a/app/code/Magento/Ui/Test/Unit/Controller/Adminhtml/Index/RenderTest.php +++ b/app/code/Magento/Ui/Test/Unit/Controller/Adminhtml/Index/RenderTest.php @@ -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) @@ -17,6 +18,11 @@ class RenderTest extends \PHPUnit\Framework\TestCase */ private $render; + /** + * @var ObjectManagerHelper + */ + private $objectManagerHelper; + /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -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) @@ -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); @@ -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 = 'data'; + + $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() diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertResetFilterMessage.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertResetFilterMessage.php index ed056bf8a998e..5816744e7a3b2 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertResetFilterMessage.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertResetFilterMessage.php @@ -1,6 +1,6 @@