From 29333257017adfcb894ec8b852d413c1f67b5af7 Mon Sep 17 00:00:00 2001 From: Cristian Partica Date: Tue, 3 Oct 2017 15:56:09 -0500 Subject: [PATCH 1/4] MAGETWO-71520: Product Grid filtered to Store View is broken if corresponding Store is deleted - fixing grid to render and reset filters if filters will throw an exception - covering with functional tests --- .../Ui/Controller/Adminhtml/Index/Render.php | 78 +++++++++- .../view/base/web/js/grid/filters/filters.js | 51 ++++++- .../Ui/view/base/web/js/grid/provider.js | 8 +- .../Test/Block/System/Store/StoreGrid.php | 12 ++ .../Test/Block/Adminhtml/Product/Grid.php | 4 + .../AssertProductGridIsRendered.php | 39 +++++ .../Constraint/AssertResetFilterMessage.php | 38 +++++ .../GridFilteringDeletedEntityTest.xml | 30 ++++ .../TestStep/DeleteWebsitesEntityStep.php | 122 ++++++++++++++++ .../GridFilteringDeletedEntityTest.php | 136 ++++++++++++++++++ 10 files changed, 510 insertions(+), 8 deletions(-) create mode 100644 dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductGridIsRendered.php create mode 100644 dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertResetFilterMessage.php create mode 100644 dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/GridFilteringDeletedEntityTest.xml create mode 100644 dev/tests/functional/tests/app/Magento/Store/Test/TestStep/DeleteWebsitesEntityStep.php create mode 100644 dev/tests/functional/tests/app/Magento/Ui/Test/TestCase/GridFilteringDeletedEntityTest.php diff --git a/app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php b/app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php index 7a1bbf986de61..bd12a173e0c8d 100644 --- a/app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php +++ b/app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php @@ -7,9 +7,49 @@ use Magento\Ui\Controller\Adminhtml\AbstractAction; use Magento\Framework\View\Element\UiComponentInterface; +use Magento\Backend\App\Action\Context; +use Magento\Framework\View\Element\UiComponentFactory; class Render extends AbstractAction { + /** + * @var \Magento\Framework\Controller\Result\JsonFactory + */ + private $resultJsonFactory; + + /** + * @var \Magento\Framework\Escaper + */ + private $escaper; + + /** + * @var \Psr\Log\LoggerInterface + */ + private $logger; + + /** + * @param Context $context + * @param UiComponentFactory $factory + * @param \Magento\Framework\Controller\Result\JsonFactory|null $resultJsonFactory + * @param \Magento\Framework\Escaper|null $escaper + * @param \Psr\Log\LoggerInterface|null $logger + */ + public function __construct( + Context $context, + UiComponentFactory $factory, + \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory = null, + \Magento\Framework\Escaper $escaper = null, + \Psr\Log\LoggerInterface $logger = null + ) { + parent::__construct($context, $factory); + $this->resultJsonFactory = $resultJsonFactory ?: $this->_objectManager + ->get(\Magento\Framework\Controller\Result\JsonFactory::class); + $this->escaper = $escaper ?: $this->_objectManager + ->get(\Magento\Framework\Escaper::class); + $this->logger = $logger ?: $this->_objectManager + ->get(\Psr\Log\LoggerInterface::class); + } + /** * Action for AJAX request * @@ -22,10 +62,40 @@ public function execute() return; } - $component = $this->factory->create($this->_request->getParam('namespace')); - if ($this->validateAclResource($component->getContext()->getDataProvider()->getConfigData())) { - $this->prepareComponent($component); - $this->_response->appendBody((string) $component->render()); + try { + $component = $this->factory->create($this->_request->getParam('namespace')); + if ($this->validateAclResource($component->getContext()->getDataProvider()->getConfigData())) { + $this->prepareComponent($component); + $this->_response->appendBody((string) $component->render()); + } + } catch (\Magento\Framework\Exception\LocalizedException $e) { + $this->logger->critical($e); + $result = [ + 'error' => $this->escaper->escapeHtml($e->getMessage()), + 'errorcode' => $this->escaper->escapeHtml($e->getCode()) + ]; + /** @var \Magento\Framework\Controller\Result\Json $resultJson */ + $resultJson = $this->resultJsonFactory->create(); + $resultJson->setStatusHeader( + \Zend\Http\Response::STATUS_CODE_400, + \Zend\Http\AbstractMessage::VERSION_11, + 'Bad Request' + ); + return $resultJson->setData($result); + } catch (\Exception $e) { + $this->logger->critical($e); + $result = [ + 'error' => _('UI component could not be rendered because of system exception'), + 'errorcode' => $this->escaper->escapeHtml($e->getCode()) + ]; + /** @var \Magento\Framework\Controller\Result\Json $resultJson */ + $resultJson = $this->resultJsonFactory->create(); + $resultJson->setStatusHeader( + \Zend\Http\Response::STATUS_CODE_400, + \Zend\Http\AbstractMessage::VERSION_11, + 'Bad Request' + ); + return $resultJson->setData($result); } } diff --git a/app/code/Magento/Ui/view/base/web/js/grid/filters/filters.js b/app/code/Magento/Ui/view/base/web/js/grid/filters/filters.js index 22ba19657168d..7748aa94eeec4 100644 --- a/app/code/Magento/Ui/view/base/web/js/grid/filters/filters.js +++ b/app/code/Magento/Ui/view/base/web/js/grid/filters/filters.js @@ -10,8 +10,10 @@ define([ 'underscore', 'mageUtils', 'uiLayout', - 'uiCollection' -], function (_, utils, layout, Collection) { + 'uiCollection', + 'mage/translate', + 'jquery' +], function (_, utils, layout, Collection, $t, $) { 'use strict'; /** @@ -48,6 +50,7 @@ define([ stickyTmpl: 'ui/grid/sticky/filters', _processed: [], columnsProvider: 'ns = ${ $.ns }, componentType = columns', + bookmarksProvider: 'ns = ${ $.ns }, componentType = bookmark', applied: { placeholder: true }, @@ -102,7 +105,9 @@ define([ applied: '${ $.provider }:params.filters' }, imports: { - 'onColumnsUpdate': '${ $.columnsProvider }:elems' + onColumnsUpdate: '${ $.columnsProvider }:elems', + onBackendError: '${ $.provider }:lastError', + bookmarksActiveIndex: '${ $.bookmarksProvider }:activeIndex' }, modules: { columns: '${ $.columnsProvider }', @@ -350,6 +355,15 @@ define([ return this.active.length; }, + /** + * Assigns filters index change. + * + * @param {integer} index - Selected index of the filter. + */ + onActiveIndexChange: function (index) { + this.activeIndex = index; + }, + /** * Extract previews of a specified filters. * @@ -371,6 +385,37 @@ define([ */ onColumnsUpdate: function (columns) { columns.forEach(this.addFilter, this); + }, + + /** + * Provider ajax error listener. + * + * @param {bool} isError - Selected index of the filter. + */ + onBackendError: function (isError) { + var defaultMessage = 'Something went wrong with processing the default view and we have restored the' + + ' filter to its original state.', + customMessage = 'Something went wrong with processing current custom view and filters have been' + + ' reset to its original state. Please edit filters then click apply.'; + + if (isError) { + this.clear(); + + $('body').notification('clear') + .notification('add', { + error: true, + message: $.mage.__(this.bookmarksActiveIndex !== 'default' ? customMessage : defaultMessage), + + /** + * @param {String} message + */ + insertMethod: function (message) { + var $wrapper = $('
').html(message); + + $('.page-main-actions').after($wrapper); + } + }); + } } }); }); diff --git a/app/code/Magento/Ui/view/base/web/js/grid/provider.js b/app/code/Magento/Ui/view/base/web/js/grid/provider.js index 14a64216ef597..cc73dc7b07307 100644 --- a/app/code/Magento/Ui/view/base/web/js/grid/provider.js +++ b/app/code/Magento/Ui/view/base/web/js/grid/provider.js @@ -120,7 +120,7 @@ define([ request .done(this.onReload) - .fail(this.onError); + .fail(this.onError.bind(this)); return request; }, @@ -144,6 +144,10 @@ define([ return; } + this.set('lastError', true); + + this.firstLoad = false; + alert({ content: $t('Something went wrong.') }); @@ -157,6 +161,8 @@ define([ onReload: function (data) { this.firstLoad = false; + this.set('lastError', false); + this.setData(data) .trigger('reloaded'); }, diff --git a/dev/tests/functional/tests/app/Magento/Backend/Test/Block/System/Store/StoreGrid.php b/dev/tests/functional/tests/app/Magento/Backend/Test/Block/System/Store/StoreGrid.php index ae3857d8e4f6d..87a3ed048dbb9 100644 --- a/dev/tests/functional/tests/app/Magento/Backend/Test/Block/System/Store/StoreGrid.php +++ b/dev/tests/functional/tests/app/Magento/Backend/Test/Block/System/Store/StoreGrid.php @@ -99,6 +99,18 @@ public function searchAndOpenWebsite(Website $website) $this->_rootElement->find(sprintf($this->storeName, $websiteName), Locator::SELECTOR_XPATH)->click(); } + /** + * Search and open appropriate Website by name. + * + * @param string $websiteName + * @return void + */ + public function searchAndOpenWebsiteByName($websiteName) + { + $this->search(['website_title' => $websiteName]); + $this->_rootElement->find(sprintf($this->storeName, $websiteName), Locator::SELECTOR_XPATH)->click(); + } + /** * Search and open appropriate Store View. * diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Grid.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Grid.php index 67ef167e3fcdd..29efb2b4fa037 100755 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Grid.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Grid.php @@ -60,6 +60,10 @@ class Grid extends DataGrid 'selector' => '[name="attribute_set_id"]', 'input' => 'select', ], + 'store_id' => [ + 'selector' => '[name="store_id"]', + 'input' => 'select', + ], ]; /** diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductGridIsRendered.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductGridIsRendered.php new file mode 100644 index 0000000000000..1d5c1e33c94d6 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductGridIsRendered.php @@ -0,0 +1,39 @@ +open()->getProductGrid()->getFirstItemId(); + \PHPUnit_Framework_Assert::assertNotNull( + $productId, + 'Product grid is not rendered correctly.' + ); + } + + /** + * Returns a string representation of the object. + * + * @return string + */ + public function toString() + { + return 'Product grid is rendered correctly.'; + } +} 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 new file mode 100644 index 0000000000000..ed056bf8a998e --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertResetFilterMessage.php @@ -0,0 +1,38 @@ +getMessagesBlock()->getErrorMessage() + ); + } + + /** + * Returns a string representation of the object. + * + * @return string + */ + public function toString() + { + return 'Filters have been reset successfully.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/GridFilteringDeletedEntityTest.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/GridFilteringDeletedEntityTest.xml new file mode 100644 index 0000000000000..4f7f7fc9f6b96 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/GridFilteringDeletedEntityTest.xml @@ -0,0 +1,30 @@ + + + + + + severity:S2 + + + Magento\Store\Test\TestStep\DeleteWebsitesEntityStep + + + catalogProductSimple + product_with_additional_website + + + :name + + + Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex + getProductGrid + + + + + diff --git a/dev/tests/functional/tests/app/Magento/Store/Test/TestStep/DeleteWebsitesEntityStep.php b/dev/tests/functional/tests/app/Magento/Store/Test/TestStep/DeleteWebsitesEntityStep.php new file mode 100644 index 0000000000000..c18f5629d2e02 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Store/Test/TestStep/DeleteWebsitesEntityStep.php @@ -0,0 +1,122 @@ +storeIndex = $storeIndex; + $this->editWebsite = $editWebsite; + $this->backupIndex = $backupIndex; + $this->deleteWebsite = $deleteWebsite; + $this->item = $item; + $this->createBackup = $createBackup; + $this->fixtureFactory = $fixtureFactory; + } + + /** + * Delete specific Store View. + * + * @return void + */ + public function run() + { + $this->backupIndex->open()->getBackupGrid()->massaction([], 'Delete', true, 'Select All'); + $this->storeIndex->open(); + $websiteNames = $this->item->getWebsiteIds(); + if (is_array($websiteNames) && count($websiteNames) > 0) { + $websiteName = end($websiteNames); + $this->storeIndex->getStoreGrid()->searchAndOpenWebsiteByName($websiteName); + $this->editWebsite->getFormPageActions()->delete(); + $this->deleteWebsite->getDeleteWebsiteForm()->fillForm(['create_backup' => $this->createBackup]); + $this->deleteWebsite->getFormPageActions()->delete(); + } + } +} diff --git a/dev/tests/functional/tests/app/Magento/Ui/Test/TestCase/GridFilteringDeletedEntityTest.php b/dev/tests/functional/tests/app/Magento/Ui/Test/TestCase/GridFilteringDeletedEntityTest.php new file mode 100644 index 0000000000000..6c5d91fda0d9c --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Ui/Test/TestCase/GridFilteringDeletedEntityTest.php @@ -0,0 +1,136 @@ +pageFactory = $pageFactory; + $this->fixtureFactory = $fixtureFactory; + } + + /** + * @param string $pageClass + * @param string $gridRetriever + * @param string[] $filters + * @param string $fixtureName + * @param string[] $steps + * @param array $fixtureDataSet + * @return void + */ + public function test( + $pageClass, + $gridRetriever, + array $filters, + $fixtureName, + array $steps = [], + $fixtureDataSet = null + ) { + $item = $this->createItems($fixtureName, $fixtureDataSet); + $page = $this->pageFactory->create($pageClass); + + $page->open(); + /** @var DataGrid $gridBlock */ + $gridBlock = $page->$gridRetriever(); + $gridBlock->resetFilter(); + + foreach ($filters as $itemFilters) { + $filterArray = []; + foreach ($itemFilters as $itemFiltersName => $itemFilterValue) { + if (substr($itemFilterValue, 0, 1) === ':') { + $value = $item->getData(substr($itemFilterValue, 1)); + } else { + $value = $itemFilterValue; + } + $filterArray[$itemFiltersName] = $value; + } + + $storesArray = $item->getDataFieldConfig('website_ids')['source']->getStores(); + $store = end($storesArray); + $filterArray['store_id'] = $store->getName(); + $gridBlock->search($filterArray); + } + + if (!empty($steps)) { + foreach ($steps as $step) { + $this->processSteps($item, $step); + } + } + } + + /** + * @param string $fixtureName + * @param string $fixtureDataSet + * @return FixtureInterface + */ + private function createItems($fixtureName, $fixtureDataSet) + { + $item = $this->fixtureFactory->createByCode($fixtureName, ['dataset' => $fixtureDataSet]); + $item->persist(); + return $item; + } + + /** + * @param FixtureInterface $item + * @param array $steps + * @return void + */ + private function processSteps(FixtureInterface $item, $steps) + { + foreach ($steps as $step) { + $processStep = $this->objectManager->create($step, ['item' => $item]); + $processStep->run(); + } + } +} From 550ae5620a7ce15574503bc9ccd2c61e5363c60c Mon Sep 17 00:00:00 2001 From: Cristian Partica Date: Wed, 4 Oct 2017 11:32:21 -0500 Subject: [PATCH 2/4] MAGETWO-71520: Product Grid filtered to Store View is broken if corresponding Store is deleted - fix unit test --- .../Ui/Controller/Adminhtml/Index/Render.php | 2 +- .../Controller/Adminhtml/Index/RenderTest.php | 105 +++++++++++++++++- .../Constraint/AssertResetFilterMessage.php | 2 +- 3 files changed, 106 insertions(+), 3 deletions(-) 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 @@ Date: Wed, 4 Oct 2017 11:48:16 -0500 Subject: [PATCH 3/4] MAGETWO-71520: Product Grid filtered to Store View is broken if corresponding Store is deleted - fix unit test --- .../Controller/Adminhtml/Index/RenderTest.php | 16 ---------------- 1 file changed, 16 deletions(-) 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 d3415cf5cf2e8..dea3e95049bbe 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 @@ -84,11 +84,6 @@ class RenderTest extends \PHPUnit\Framework\TestCase */ private $resultJsonFactoryMock; - /** - * @var \Magento\Framework\Escaper|\PHPUnit_Framework_MockObject_MockObject - */ - private $escaperMock; - /** * @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject */ @@ -141,12 +136,6 @@ protected function setUp() ->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()) @@ -179,7 +168,6 @@ protected function setUp() 'context' => $this->contextMock, 'factory' => $this->uiFactoryMock, 'resultJsonFactory' => $this->resultJsonFactoryMock, - 'escaper' => $this->escaperMock, 'logger' => $this->loggerMock ] ); @@ -218,10 +206,6 @@ public function testExecuteAjaxRequestException() ->method('critical') ->willReturnSelf(); - $this->escaperMock->expects($this->once()) - ->method('escapeHtml') - ->willReturnSelf(); - $this->dataProviderMock->expects($this->once()) ->method('getConfigData') ->willReturn([]); From a6a230174b220eab2f4bf4044651d42b545af326 Mon Sep 17 00:00:00 2001 From: Cristian Partica Date: Thu, 5 Oct 2017 13:21:15 -0500 Subject: [PATCH 4/4] MAGETWO-71520: Product Grid filtered to Store View is broken if corresponding Store is deleted - fix CR --- .../Ui/Controller/Adminhtml/Index/Render.php | 27 ++++++++++--------- .../Controller/Adminhtml/Index/RenderTest.php | 2 +- .../view/base/web/js/grid/filters/filters.js | 17 +++--------- .../Ui/view/base/web/js/grid/provider.js | 1 + .../GridFilteringDeletedEntityTest.xml | 2 +- 5 files changed, 22 insertions(+), 27 deletions(-) diff --git a/app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php b/app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php index e4600b054c012..a0c687bde1b47 100644 --- a/app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php +++ b/app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php @@ -9,44 +9,47 @@ use Magento\Framework\View\Element\UiComponentInterface; use Magento\Backend\App\Action\Context; use Magento\Framework\View\Element\UiComponentFactory; +use Psr\Log\LoggerInterface; +use Magento\Framework\Escaper; +use Magento\Framework\Controller\Result\JsonFactory; class Render extends AbstractAction { /** - * @var \Magento\Framework\Controller\Result\JsonFactory + * @var JsonFactory */ private $resultJsonFactory; /** - * @var \Magento\Framework\Escaper + * @var Escaper */ private $escaper; /** - * @var \Psr\Log\LoggerInterface + * @var LoggerInterface */ private $logger; /** * @param Context $context * @param UiComponentFactory $factory - * @param \Magento\Framework\Controller\Result\JsonFactory|null $resultJsonFactory - * @param \Magento\Framework\Escaper|null $escaper - * @param \Psr\Log\LoggerInterface|null $logger + * @param JsonFactory|null $resultJsonFactory + * @param Escaper|null $escaper + * @param LoggerInterface|null $logger */ public function __construct( Context $context, UiComponentFactory $factory, - \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory = null, - \Magento\Framework\Escaper $escaper = null, - \Psr\Log\LoggerInterface $logger = null + JsonFactory $resultJsonFactory = null, + Escaper $escaper = null, + LoggerInterface $logger = null ) { parent::__construct($context, $factory); - $this->resultJsonFactory = $resultJsonFactory ?: $this->_objectManager + $this->resultJsonFactory = $resultJsonFactory ?: \Magento\Framework\App\ObjectManager::getInstance() ->get(\Magento\Framework\Controller\Result\JsonFactory::class); - $this->escaper = $escaper ?: $this->_objectManager + $this->escaper = $escaper ?: \Magento\Framework\App\ObjectManager::getInstance() ->get(\Magento\Framework\Escaper::class); - $this->logger = $logger ?: $this->_objectManager + $this->logger = $logger ?: \Magento\Framework\App\ObjectManager::getInstance() ->get(\Psr\Log\LoggerInterface::class); } 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 dea3e95049bbe..7d5de26be6d2e 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 @@ -5,7 +5,7 @@ */ namespace Magento\Ui\Test\Unit\Controller\Adminhtml\Index; -use \Magento\Ui\Controller\Adminhtml\Index\Render; +use Magento\Ui\Controller\Adminhtml\Index\Render; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; /** diff --git a/app/code/Magento/Ui/view/base/web/js/grid/filters/filters.js b/app/code/Magento/Ui/view/base/web/js/grid/filters/filters.js index 7748aa94eeec4..47897cd99cab6 100644 --- a/app/code/Magento/Ui/view/base/web/js/grid/filters/filters.js +++ b/app/code/Magento/Ui/view/base/web/js/grid/filters/filters.js @@ -355,15 +355,6 @@ define([ return this.active.length; }, - /** - * Assigns filters index change. - * - * @param {integer} index - Selected index of the filter. - */ - onActiveIndexChange: function (index) { - this.activeIndex = index; - }, - /** * Extract previews of a specified filters. * @@ -393,10 +384,10 @@ define([ * @param {bool} isError - Selected index of the filter. */ onBackendError: function (isError) { - var defaultMessage = 'Something went wrong with processing the default view and we have restored the' + - ' filter to its original state.', - customMessage = 'Something went wrong with processing current custom view and filters have been' + - ' reset to its original state. Please edit filters then click apply.'; + var defaultMessage = 'Something went wrong with processing the default view and we have restored the filter' + + ' to its original state.', + customMessage = 'Something went wrong with processing current custom view and filters have been reset' + + ' to its original state. Please edit filters then click apply.'; if (isError) { this.clear(); diff --git a/app/code/Magento/Ui/view/base/web/js/grid/provider.js b/app/code/Magento/Ui/view/base/web/js/grid/provider.js index cc73dc7b07307..25bf25e6f65c0 100644 --- a/app/code/Magento/Ui/view/base/web/js/grid/provider.js +++ b/app/code/Magento/Ui/view/base/web/js/grid/provider.js @@ -21,6 +21,7 @@ define([ return Element.extend({ defaults: { firstLoad: true, + lastError: false, storageConfig: { component: 'Magento_Ui/js/grid/data-storage', provider: '${ $.storageConfig.name }', diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/GridFilteringDeletedEntityTest.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/GridFilteringDeletedEntityTest.xml index 4f7f7fc9f6b96..e49d4e3a9ccd4 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/GridFilteringDeletedEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/GridFilteringDeletedEntityTest.xml @@ -23,7 +23,7 @@ Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex getProductGrid - +