From 92b29c6f9eb05dbf45cebdc601a4a9aeb95b713d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Szubert?= Date: Tue, 28 Apr 2020 13:24:24 +0200 Subject: [PATCH 1/4] Fix #28011 - remove page number from query on layered navigation swatch filter --- .../Block/LayeredNavigation/RenderLayered.php | 66 ++++--- .../LayeredNavigation/RenderLayeredTest.php | 168 +++++++++++------- 2 files changed, 150 insertions(+), 84 deletions(-) diff --git a/app/code/Magento/Swatches/Block/LayeredNavigation/RenderLayered.php b/app/code/Magento/Swatches/Block/LayeredNavigation/RenderLayered.php index fc13372520945..4fb60ceeef6bb 100644 --- a/app/code/Magento/Swatches/Block/LayeredNavigation/RenderLayered.php +++ b/app/code/Magento/Swatches/Block/LayeredNavigation/RenderLayered.php @@ -5,11 +5,17 @@ */ namespace Magento\Swatches\Block\LayeredNavigation; -use Magento\Eav\Model\Entity\Attribute; +use Magento\Catalog\Model\Layer\Filter\AbstractFilter; +use Magento\Catalog\Model\Layer\Filter\Item as FilterItem; use Magento\Catalog\Model\ResourceModel\Layer\Filter\AttributeFactory; -use Magento\Framework\View\Element\Template; +use Magento\Eav\Model\Entity\Attribute; use Magento\Eav\Model\Entity\Attribute\Option; -use Magento\Catalog\Model\Layer\Filter\Item as FilterItem; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\View\Element\Template; +use Magento\Framework\View\Element\Template\Context; +use Magento\Swatches\Helper\Data; +use Magento\Swatches\Helper\Media; +use Magento\Theme\Block\Html\Pager; /** * Class RenderLayered Render Swatches at Layered Navigation @@ -37,7 +43,7 @@ class RenderLayered extends Template protected $eavAttribute; /** - * @var \Magento\Catalog\Model\Layer\Filter\AbstractFilter + * @var AbstractFilter */ protected $filter; @@ -47,35 +53,43 @@ class RenderLayered extends Template protected $layerAttribute; /** - * @var \Magento\Swatches\Helper\Data + * @var Data */ protected $swatchHelper; /** - * @var \Magento\Swatches\Helper\Media + * @var Media */ protected $mediaHelper; /** - * @param Template\Context $context + * @var Pager + */ + private $htmlPagerBlock; + + /** + * @param Context $context * @param Attribute $eavAttribute * @param AttributeFactory $layerAttribute - * @param \Magento\Swatches\Helper\Data $swatchHelper - * @param \Magento\Swatches\Helper\Media $mediaHelper + * @param Data $swatchHelper + * @param Media $mediaHelper * @param array $data + * @param Pager|null $htmlPagerBlock */ public function __construct( - \Magento\Framework\View\Element\Template\Context $context, + Context $context, Attribute $eavAttribute, AttributeFactory $layerAttribute, - \Magento\Swatches\Helper\Data $swatchHelper, - \Magento\Swatches\Helper\Media $mediaHelper, - array $data = [] + Data $swatchHelper, + Media $mediaHelper, + array $data = [], + ?Pager $htmlPagerBlock = null ) { $this->eavAttribute = $eavAttribute; $this->layerAttribute = $layerAttribute; $this->swatchHelper = $swatchHelper; $this->mediaHelper = $mediaHelper; + $this->htmlPagerBlock = $htmlPagerBlock ?? ObjectManager::getInstance()->get(Pager::class); parent::__construct($context, $data); } @@ -114,15 +128,13 @@ public function getSwatchData() $attributeOptionIds = array_keys($attributeOptions); $swatches = $this->swatchHelper->getSwatchesByOptionsId($attributeOptionIds); - $data = [ + return [ 'attribute_id' => $this->eavAttribute->getId(), 'attribute_code' => $this->eavAttribute->getAttributeCode(), 'attribute_label' => $this->eavAttribute->getStoreLabel(), 'options' => $attributeOptions, 'swatches' => $swatches, ]; - - return $data; } /** @@ -132,8 +144,20 @@ public function getSwatchData() */ public function buildUrl($attributeCode, $optionId) { - $query = [$attributeCode => $optionId]; - return $this->_urlBuilder->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true, '_query' => $query]); + $query = [ + $attributeCode => $optionId, + // exclude current page from urls + $this->htmlPagerBlock->getPageVarName() => null + ]; + + return $this->_urlBuilder->getUrl( + '*/*/*', + [ + '_current' => true, + '_use_rewrite' => true, + '_query' => $query + ] + ); } /** @@ -192,7 +216,7 @@ protected function getOptionViewData(FilterItem $filterItem, Option $swatchOptio */ protected function isOptionVisible(FilterItem $filterItem) { - return $this->isOptionDisabled($filterItem) && $this->isShowEmptyResults() ? false : true; + return !($this->isOptionDisabled($filterItem) && $this->isShowEmptyResults()); } /** @@ -234,8 +258,6 @@ protected function getFilterItemById(array $filterItems, $id) */ public function getSwatchPath($type, $filename) { - $imagePath = $this->mediaHelper->getSwatchAttributeImage($type, $filename); - - return $imagePath; + return $this->mediaHelper->getSwatchAttributeImage($type, $filename); } } diff --git a/app/code/Magento/Swatches/Test/Unit/Block/LayeredNavigation/RenderLayeredTest.php b/app/code/Magento/Swatches/Test/Unit/Block/LayeredNavigation/RenderLayeredTest.php index 27ae0ef6fc7f2..c385086b65996 100644 --- a/app/code/Magento/Swatches/Test/Unit/Block/LayeredNavigation/RenderLayeredTest.php +++ b/app/code/Magento/Swatches/Test/Unit/Block/LayeredNavigation/RenderLayeredTest.php @@ -3,69 +3,112 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Swatches\Test\Unit\Block\LayeredNavigation; +use Magento\Catalog\Model\Layer\Filter\AbstractFilter; +use Magento\Catalog\Model\Layer\Filter\Item; +use Magento\Catalog\Model\ResourceModel\Layer\Filter\AttributeFactory; +use Magento\Eav\Model\Entity\Attribute; +use Magento\Eav\Model\Entity\Attribute\Option; +use Magento\Framework\App\RequestInterface; +use Magento\Framework\Url; +use Magento\Framework\View\Element\Template\Context; +use Magento\Swatches\Block\LayeredNavigation\RenderLayered; +use Magento\Swatches\Helper\Data; +use Magento\Swatches\Helper\Media; +use Magento\Theme\Block\Html\Pager; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; + /** * Class RenderLayered Render Swatches at Layered Navigation * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class RenderLayeredTest extends \PHPUnit\Framework\TestCase +class RenderLayeredTest extends TestCase { - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $contextMock; - - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $requestMock; - - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $urlBuilder; - - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $eavAttributeMock; - - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $layerAttributeFactoryMock; - - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $layerAttributeMock; - - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $swatchHelperMock; - - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $mediaHelperMock; - - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $filterMock; - - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $block; - - protected function setUp() + /** + * @var RenderLayered|MockObject + */ + private $block; + + /** + * @var Context|MockObject + */ + private $contextMock; + + /** + * @var RequestInterface|MockObject + */ + private $requestMock; + + /** + * @var Url|MockObject + */ + private $urlBuilder; + + /** + * @var Attribute|MockObject + */ + private $eavAttributeMock; + + /** + * @var AttributeFactory|MockObject + */ + private $layerAttributeFactoryMock; + + /** + * @var \Magento\Catalog\Model\ResourceModel\Layer\Filter\Attribute|MockObject + */ + private $layerAttributeMock; + + /** + * @var Data|MockObject + */ + private $swatchHelperMock; + + /** + * @var Media|MockObject + */ + private $mediaHelperMock; + + /** + * @var AbstractFilter|MockObject + */ + private $filterMock; + + /** + * @var Pager|MockObject + */ + private $htmlBlockPagerMock; + + protected function setUp(): void { - $this->contextMock = $this->createMock(\Magento\Framework\View\Element\Template\Context::class); - $this->requestMock = $this->createMock(\Magento\Framework\App\RequestInterface::class); + $this->contextMock = $this->createMock(Context::class); + $this->requestMock = $this->createMock(RequestInterface::class); $this->urlBuilder = $this->createPartialMock( - \Magento\Framework\Url::class, + Url::class, ['getCurrentUrl', 'getRedirectUrl', 'getUrl'] ); - $this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock); - $this->contextMock->expects($this->any())->method('getUrlBuilder')->willReturn($this->urlBuilder); - $this->eavAttributeMock = $this->createMock(\Magento\Eav\Model\Entity\Attribute::class); + $this->contextMock->method('getRequest')->willReturn($this->requestMock); + $this->contextMock->method('getUrlBuilder')->willReturn($this->urlBuilder); + $this->eavAttributeMock = $this->createMock(Attribute::class); $this->layerAttributeFactoryMock = $this->createPartialMock( - \Magento\Catalog\Model\ResourceModel\Layer\Filter\AttributeFactory::class, + AttributeFactory::class, ['create'] ); $this->layerAttributeMock = $this->createPartialMock( \Magento\Catalog\Model\ResourceModel\Layer\Filter\Attribute::class, ['getCount'] ); - $this->swatchHelperMock = $this->createMock(\Magento\Swatches\Helper\Data::class); - $this->mediaHelperMock = $this->createMock(\Magento\Swatches\Helper\Media::class); - $this->filterMock = $this->createMock(\Magento\Catalog\Model\Layer\Filter\AbstractFilter::class); + $this->swatchHelperMock = $this->createMock(Data::class); + $this->mediaHelperMock = $this->createMock(Media::class); + $this->filterMock = $this->createMock(AbstractFilter::class); + $this->htmlBlockPagerMock = $this->createMock(Pager::class); - $this->block = $this->getMockBuilder(\Magento\Swatches\Block\LayeredNavigation\RenderLayered::class) + $this->block = $this->getMockBuilder(RenderLayered::class) ->setMethods(['filter', 'eavAttribute']) ->setConstructorArgs( [ @@ -75,6 +118,7 @@ protected function setUp() $this->swatchHelperMock, $this->mediaHelperMock, [], + $this->htmlBlockPagerMock ] ) ->getMock(); @@ -92,13 +136,13 @@ public function testSetSwatchFilter() public function testGetSwatchData() { - /** @var \PHPUnit_Framework_MockObject_MockObject $item */ - $item1 = $this->createMock(\Magento\Catalog\Model\Layer\Filter\Item::class); - $item2 = $this->createMock(\Magento\Catalog\Model\Layer\Filter\Item::class); - $item3 = $this->createMock(\Magento\Catalog\Model\Layer\Filter\Item::class); - $item4 = $this->createMock(\Magento\Catalog\Model\Layer\Filter\Item::class); + /** @var MockObject $item */ + $item1 = $this->createMock(Item::class); + $item2 = $this->createMock(Item::class); + $item3 = $this->createMock(Item::class); + $item4 = $this->createMock(Item::class); - $item1->expects($this->any())->method('__call')->withConsecutive( + $item1->method('__call')->withConsecutive( ['getValue'], ['getCount'], ['getValue'], @@ -112,9 +156,9 @@ public function testGetSwatchData() 'Yellow' ); - $item2->expects($this->any())->method('__call')->with('getValue')->willReturn('blue'); + $item2->method('__call')->with('getValue')->willReturn('blue'); - $item3->expects($this->any())->method('__call')->withConsecutive( + $item3->method('__call')->withConsecutive( ['getValue'], ['getCount'] )->willReturnOnConsecutiveCalls( @@ -122,7 +166,7 @@ public function testGetSwatchData() 0 ); - $item4->expects($this->any())->method('__call')->withConsecutive( + $item4->method('__call')->withConsecutive( ['getValue'], ['getCount'], ['getValue'], @@ -145,23 +189,23 @@ public function testGetSwatchData() $this->block->method('filter')->willReturn($this->filterMock); - $option1 = $this->createMock(\Magento\Eav\Model\Entity\Attribute\Option::class); - $option1->expects($this->any())->method('getValue')->willReturn('yellow'); + $option1 = $this->createMock(Option::class); + $option1->method('getValue')->willReturn('yellow'); - $option2 = $this->createMock(\Magento\Eav\Model\Entity\Attribute\Option::class); - $option2->expects($this->any())->method('getValue')->willReturn(null); + $option2 = $this->createMock(Option::class); + $option2->method('getValue')->willReturn(null); - $option3 = $this->createMock(\Magento\Eav\Model\Entity\Attribute\Option::class); - $option3->expects($this->any())->method('getValue')->willReturn('red'); + $option3 = $this->createMock(Option::class); + $option3->method('getValue')->willReturn('red'); - $option4 = $this->createMock(\Magento\Eav\Model\Entity\Attribute\Option::class); - $option4->expects($this->any())->method('getValue')->willReturn('green'); + $option4 = $this->createMock(Option::class); + $option4->method('getValue')->willReturn('green'); $eavAttribute = $this->createMock(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class); $eavAttribute->expects($this->once()) ->method('getOptions') ->willReturn([$option1, $option2, $option3, $option4]); - $eavAttribute->expects($this->any())->method('getIsFilterable')->willReturn(0); + $eavAttribute->method('getIsFilterable')->willReturn(0); $this->filterMock->expects($this->once())->method('getAttributeModel')->willReturn($eavAttribute); $this->block->method('eavAttribute')->willReturn($eavAttribute); @@ -184,7 +228,7 @@ public function testGetSwatchDataException() { $this->block->method('filter')->willReturn($this->filterMock); $this->block->setSwatchFilter($this->filterMock); - $this->expectException('\RuntimeException'); + $this->expectException(\RuntimeException::class); $this->block->getSwatchData(); } From 475be33cdc0e4bc058176669d05243462bafc8a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Szubert?= Date: Thu, 30 Apr 2020 00:51:43 +0200 Subject: [PATCH 2/4] Add functional test --- ...tCategoryCurrentPageIsFirstActionGroup.xml | 17 +++ ...StorefrontCategoryBottomToolbarSection.xml | 2 +- .../AddTextSwatchToProductActionGroup.xml | 2 + ...rectToFirstPageOnFilteringBySwatchTest.xml | 103 ++++++++++++++++++ 4 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertStorefrontCategoryCurrentPageIsFirstActionGroup.xml create mode 100644 app/code/Magento/Swatches/Test/Mftf/Test/StorefrontRedirectToFirstPageOnFilteringBySwatchTest.xml diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertStorefrontCategoryCurrentPageIsFirstActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertStorefrontCategoryCurrentPageIsFirstActionGroup.xml new file mode 100644 index 0000000000000..34488318e16fb --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertStorefrontCategoryCurrentPageIsFirstActionGroup.xml @@ -0,0 +1,17 @@ + + + + + + + 1 + currentPageText + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/Section/StorefrontCategoryBottomToolbarSection.xml b/app/code/Magento/Catalog/Test/Mftf/Section/StorefrontCategoryBottomToolbarSection.xml index 09eb4ad954274..c27a6107e5e35 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Section/StorefrontCategoryBottomToolbarSection.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Section/StorefrontCategoryBottomToolbarSection.xml @@ -12,6 +12,6 @@ - + diff --git a/app/code/Magento/Swatches/Test/Mftf/ActionGroup/AddTextSwatchToProductActionGroup.xml b/app/code/Magento/Swatches/Test/Mftf/ActionGroup/AddTextSwatchToProductActionGroup.xml index 97a391137d8e3..5f3ec07bd4983 100644 --- a/app/code/Magento/Swatches/Test/Mftf/ActionGroup/AddTextSwatchToProductActionGroup.xml +++ b/app/code/Magento/Swatches/Test/Mftf/ActionGroup/AddTextSwatchToProductActionGroup.xml @@ -19,6 +19,7 @@ + @@ -41,6 +42,7 @@ + diff --git a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontRedirectToFirstPageOnFilteringBySwatchTest.xml b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontRedirectToFirstPageOnFilteringBySwatchTest.xml new file mode 100644 index 0000000000000..27382dab0eacc --- /dev/null +++ b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontRedirectToFirstPageOnFilteringBySwatchTest.xml @@ -0,0 +1,103 @@ + + + + + + + + + + <description value="Customers are redirected to first plp page after filtering by swatch"/> + <severity value="MINOR"/> + <group value="Swatches"/> + </annotations> + + <before> + <createData entity="SimpleSubCategory" stepKey="createCategory"/> + <createData entity="SimpleProduct" stepKey="createSimpleProduct1"> + <requiredEntity createDataKey="createCategory"/> + </createData> + <createData entity="SimpleProduct" stepKey="createSimpleProduct2"> + <requiredEntity createDataKey="createCategory"/> + </createData> + <createData entity="SimpleProduct" stepKey="createSimpleProduct3"> + <requiredEntity createDataKey="createCategory"/> + </createData> + + <magentoCLI command="config:set catalog/frontend/grid_per_page 1" stepKey="setOneProductPerPage"/> + <magentoCLI command="config:set catalog/frontend/grid_per_page_values 1" stepKey="setGridPerPage"/> + <magentoCLI command="cache:clean config full_page" stepKey="cleanInvalidatedCaches"/> + + <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> + <actionGroup ref="AddTextSwatchToProductActionGroup" stepKey="addSwatchAttribute"> + <argument name="usedInLayeredNavigation" value="1"/> + </actionGroup> + </before> + + <after> + <actionGroup ref="DeleteProductAttributeActionGroup" stepKey="deleteSwatchAttribute"> + <argument name="ProductAttribute" value="textSwatchAttribute"/> + </actionGroup> + <actionGroup ref="AdminLogoutActionGroup" stepKey="adminLogout"/> + + <magentoCLI command="config:set catalog/frontend/grid_per_page 12" stepKey="setDefaultProductsPerPage"/> + <magentoCLI command="config:set catalog/frontend/grid_per_page_values 12,24,36" stepKey="setDefaultGridPerPage"/> + <magentoCLI command="cache:clean config full_page" stepKey="cleanInvalidatedCaches"/> + + <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> + <deleteData createDataKey="createSimpleProduct1" stepKey="deleteSimpleProduct1"/> + <deleteData createDataKey="createSimpleProduct2" stepKey="deleteSimpleProduct2"/> + <deleteData createDataKey="createSimpleProduct3" stepKey="deleteSimpleProduct3"/> + </after> + + <amOnPage url="{{AdminProductAttributeSetEditPage.url}}/{{AddToDefaultSet.attributeSetId}}/" stepKey="onAttributeSetEdit"/> + <actionGroup ref="AssignAttributeToGroupActionGroup" stepKey="assignAttributeToGroup"> + <argument name="group" value="Product Details"/> + <argument name="attribute" value="{{textSwatchAttribute.attribute_code}}"/> + </actionGroup> + <actionGroup ref="SaveAttributeSetActionGroup" stepKey="SaveAttributeSet"/> + + <actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="goToProductsGridPage"/> + + <actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="goToProduct1EditPage"> + <argument name="product" value="$$createSimpleProduct1$$"/> + </actionGroup> + <selectOption selector="{{AdminProductAttributesSection.attributeDropdownByCode(textSwatchAttribute.attribute_code)}}" userInput="textSwatchOption1" stepKey="selectProduct1AttributeOption"/> + <actionGroup ref="SaveProductFormActionGroup" stepKey="saveProduct1"/> + + <actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="goToProductsGridPage2"/> + <actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="goToProduct2EditPage"> + <argument name="product" value="$$createSimpleProduct2$$"/> + </actionGroup> + <selectOption selector="{{AdminProductAttributesSection.attributeDropdownByCode(textSwatchAttribute.attribute_code)}}" userInput="textSwatchOption1" stepKey="selectProduct2AttributeOption"/> + <actionGroup ref="SaveProductFormActionGroup" stepKey="saveProduct2"/> + + <actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="goToProductsGridPage3"/> + <actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="goToProduct3EditPage"> + <argument name="product" value="$$createSimpleProduct3$$"/> + </actionGroup> + <selectOption selector="{{AdminProductAttributesSection.attributeDropdownByCode(textSwatchAttribute.attribute_code)}}" userInput="textSwatchOption2" stepKey="selectProduct3AttributeOption"/> + <actionGroup ref="SaveProductFormActionGroup" stepKey="saveProduct3"/> + + <magentoCLI command="cron:run --group=index" stepKey="runCronIndexer"/> + + <amOnPage url="$$createCategory.name$$.html" stepKey="amOnCategoryPage"/> + <waitForPageLoad stepKey="waitForPageToLoad"/> + + <scrollTo selector="{{StorefrontCategoryBottomToolbarSection.nextPage}}" stepKey="scrollToNextButton"/> + <click selector="{{StorefrontCategoryBottomToolbarSection.nextPage}}" stepKey="clickOnNextPage"/> + <waitForPageLoad stepKey="waitForPageToLoad2"/> + + <click selector="{{StorefrontCategorySidebarSection.filterOptionTitle(textSwatchAttribute.default_label)}}" stepKey="expandAttribute"/> + <click selector="{{StorefrontCategorySidebarSection.attributeNthOption(textSwatchAttribute.attribute_code, '1')}}" stepKey="filterBySwatch1"/> + <waitForPageLoad stepKey="waitForPageToLoad3"/> + + <actionGroup ref="AssertStorefrontCategoryCurrentPageIsFirstActionGroup" stepKey="assertCurrentPageIsFirst"/> + </test> +</tests> From 7630cb00855d13005e46d0b6cfcb228f986a0278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Szubert?= <bartlomiejszubert@gmail.com> Date: Thu, 30 Apr 2020 08:37:35 +0200 Subject: [PATCH 3/4] Static and functional tests fix, apply changes after review, extract navigation to next category page to action group --- ...ontNavigateCategoryNextPageActionGroup.xml | 15 +++++++++ .../Block/LayeredNavigation/RenderLayered.php | 31 +++++++++++++++++++ ...rectToFirstPageOnFilteringBySwatchTest.xml | 21 ++++++------- 3 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontNavigateCategoryNextPageActionGroup.xml diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontNavigateCategoryNextPageActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontNavigateCategoryNextPageActionGroup.xml new file mode 100644 index 0000000000000..5fe97debb1593 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontNavigateCategoryNextPageActionGroup.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. +--> + +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <!-- Navigates storefront category next page from toolbar --> + <actionGroup name="StorefrontNavigateCategoryNextPageActionGroup"> + <scrollTo selector="{{StorefrontCategoryBottomToolbarSection.nextPage}}" stepKey="scrollToNextButton"/> + <click selector="{{StorefrontCategoryBottomToolbarSection.nextPage}}" stepKey="clickOnNextPage"/> + <waitForPageLoad stepKey="waitForNextCategoryPageLoad"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Swatches/Block/LayeredNavigation/RenderLayered.php b/app/code/Magento/Swatches/Block/LayeredNavigation/RenderLayered.php index 4fb60ceeef6bb..9ba1083adab74 100644 --- a/app/code/Magento/Swatches/Block/LayeredNavigation/RenderLayered.php +++ b/app/code/Magento/Swatches/Block/LayeredNavigation/RenderLayered.php @@ -95,7 +95,10 @@ public function __construct( } /** + * Set filter and attribute objects + * * @param \Magento\Catalog\Model\Layer\Filter\AbstractFilter $filter + * * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ @@ -108,6 +111,8 @@ public function setSwatchFilter(\Magento\Catalog\Model\Layer\Filter\AbstractFilt } /** + * Get attribute swatch data + * * @return array */ public function getSwatchData() @@ -138,8 +143,11 @@ public function getSwatchData() } /** + * Build filter option url + * * @param string $attributeCode * @param int $optionId + * * @return string */ public function buildUrl($attributeCode, $optionId) @@ -161,7 +169,10 @@ public function buildUrl($attributeCode, $optionId) } /** + * Get view data for option with no results + * * @param Option $swatchOption + * * @return array */ protected function getUnusedOption(Option $swatchOption) @@ -174,8 +185,11 @@ protected function getUnusedOption(Option $swatchOption) } /** + * Get option data if visible + * * @param FilterItem[] $filterItems * @param Option $swatchOption + * * @return array */ protected function getFilterOption(array $filterItems, Option $swatchOption) @@ -190,8 +204,11 @@ protected function getFilterOption(array $filterItems, Option $swatchOption) } /** + * Get view data for option + * * @param FilterItem $filterItem * @param Option $swatchOption + * * @return array */ protected function getOptionViewData(FilterItem $filterItem, Option $swatchOption) @@ -211,7 +228,10 @@ protected function getOptionViewData(FilterItem $filterItem, Option $swatchOptio } /** + * Check if option should be visible + * * @param FilterItem $filterItem + * * @return bool */ protected function isOptionVisible(FilterItem $filterItem) @@ -220,6 +240,8 @@ protected function isOptionVisible(FilterItem $filterItem) } /** + * Check if attribute values should be visible with no results + * * @return bool */ protected function isShowEmptyResults() @@ -228,7 +250,10 @@ protected function isShowEmptyResults() } /** + * Check if option should be disabled + * * @param FilterItem $filterItem + * * @return bool */ protected function isOptionDisabled(FilterItem $filterItem) @@ -237,8 +262,11 @@ protected function isOptionDisabled(FilterItem $filterItem) } /** + * Retrieve filter item by id + * * @param FilterItem[] $filterItems * @param integer $id + * * @return bool|FilterItem */ protected function getFilterItemById(array $filterItems, $id) @@ -252,8 +280,11 @@ protected function getFilterItemById(array $filterItems, $id) } /** + * Get swatch image path + * * @param string $type * @param string $filename + * * @return string */ public function getSwatchPath($type, $filename) diff --git a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontRedirectToFirstPageOnFilteringBySwatchTest.xml b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontRedirectToFirstPageOnFilteringBySwatchTest.xml index 27382dab0eacc..49eccc18b1347 100644 --- a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontRedirectToFirstPageOnFilteringBySwatchTest.xml +++ b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontRedirectToFirstPageOnFilteringBySwatchTest.xml @@ -32,12 +32,12 @@ <magentoCLI command="config:set catalog/frontend/grid_per_page 1" stepKey="setOneProductPerPage"/> <magentoCLI command="config:set catalog/frontend/grid_per_page_values 1" stepKey="setGridPerPage"/> - <magentoCLI command="cache:clean config full_page" stepKey="cleanInvalidatedCaches"/> <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> <actionGroup ref="AddTextSwatchToProductActionGroup" stepKey="addSwatchAttribute"> <argument name="usedInLayeredNavigation" value="1"/> </actionGroup> + <magentoCLI command="cache:clean block_html collections config full_page" stepKey="cleanInvalidatedCaches"/> </before> <after> @@ -48,7 +48,7 @@ <magentoCLI command="config:set catalog/frontend/grid_per_page 12" stepKey="setDefaultProductsPerPage"/> <magentoCLI command="config:set catalog/frontend/grid_per_page_values 12,24,36" stepKey="setDefaultGridPerPage"/> - <magentoCLI command="cache:clean config full_page" stepKey="cleanInvalidatedCaches"/> + <magentoCLI command="cache:clean block_html collections config full_page" stepKey="cleanInvalidatedCaches"/> <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> <deleteData createDataKey="createSimpleProduct1" stepKey="deleteSimpleProduct1"/> @@ -63,7 +63,8 @@ </actionGroup> <actionGroup ref="SaveAttributeSetActionGroup" stepKey="SaveAttributeSet"/> - <actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="goToProductsGridPage"/> + <actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="goToProductIndexPage"/> + <actionGroup ref="ClearFiltersAdminProductGridActionGroup" stepKey="clearFiltersOnProductIndexPage"/> <actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="goToProduct1EditPage"> <argument name="product" value="$$createSimpleProduct1$$"/> @@ -85,18 +86,16 @@ <selectOption selector="{{AdminProductAttributesSection.attributeDropdownByCode(textSwatchAttribute.attribute_code)}}" userInput="textSwatchOption2" stepKey="selectProduct3AttributeOption"/> <actionGroup ref="SaveProductFormActionGroup" stepKey="saveProduct3"/> - <magentoCLI command="cron:run --group=index" stepKey="runCronIndexer"/> + <magentoCron groups="index" stepKey="runCronIndexer"/> - <amOnPage url="$$createCategory.name$$.html" stepKey="amOnCategoryPage"/> - <waitForPageLoad stepKey="waitForPageToLoad"/> - - <scrollTo selector="{{StorefrontCategoryBottomToolbarSection.nextPage}}" stepKey="scrollToNextButton"/> - <click selector="{{StorefrontCategoryBottomToolbarSection.nextPage}}" stepKey="clickOnNextPage"/> - <waitForPageLoad stepKey="waitForPageToLoad2"/> + <actionGroup ref="StorefrontNavigateCategoryPageActionGroup" stepKey="navigateToCategoryPage"> + <argument name="category" value="$$createCategory$$"/> + </actionGroup> + <actionGroup ref="StorefrontNavigateCategoryNextPageActionGroup" stepKey="navigateToCategoryNextPage"/> <click selector="{{StorefrontCategorySidebarSection.filterOptionTitle(textSwatchAttribute.default_label)}}" stepKey="expandAttribute"/> <click selector="{{StorefrontCategorySidebarSection.attributeNthOption(textSwatchAttribute.attribute_code, '1')}}" stepKey="filterBySwatch1"/> - <waitForPageLoad stepKey="waitForPageToLoad3"/> + <waitForPageLoad stepKey="waitForPageToLoad2"/> <actionGroup ref="AssertStorefrontCategoryCurrentPageIsFirstActionGroup" stepKey="assertCurrentPageIsFirst"/> </test> From 0de77c8037c45c4f5a196dc1ca7a8b4635e2d736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Szubert?= <bartlomiejszubert@gmail.com> Date: Thu, 30 Apr 2020 14:54:01 +0200 Subject: [PATCH 4/4] Apply review notes --- ...tStorefrontCategoryCurrentPageIsNthActionGroup.xml} | 10 +++++++--- .../StorefrontNavigateCategoryNextPageActionGroup.xml | 4 +++- ...frontRedirectToFirstPageOnFilteringBySwatchTest.xml | 7 ++++--- 3 files changed, 14 insertions(+), 7 deletions(-) rename app/code/Magento/Catalog/Test/Mftf/ActionGroup/{AssertStorefrontCategoryCurrentPageIsFirstActionGroup.xml => AssertStorefrontCategoryCurrentPageIsNthActionGroup.xml} (65%) diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertStorefrontCategoryCurrentPageIsFirstActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertStorefrontCategoryCurrentPageIsNthActionGroup.xml similarity index 65% rename from app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertStorefrontCategoryCurrentPageIsFirstActionGroup.xml rename to app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertStorefrontCategoryCurrentPageIsNthActionGroup.xml index 34488318e16fb..84e14269d24c2 100644 --- a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertStorefrontCategoryCurrentPageIsFirstActionGroup.xml +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertStorefrontCategoryCurrentPageIsNthActionGroup.xml @@ -7,10 +7,14 @@ --> <actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> - <actionGroup name="AssertStorefrontCategoryCurrentPageIsFirstActionGroup"> + <actionGroup name="AssertStorefrontCategoryCurrentPageIsNthActionGroup"> + <arguments> + <argument name="expectedPage" type="string"/> + </arguments> + <grabTextFrom selector="{{StorefrontCategoryBottomToolbarSection.currentPage}}" stepKey="currentPageText"/> - <assertEquals stepKey="assertIsPageFirst"> - <expectedResult type="string">1</expectedResult> + <assertEquals stepKey="assertIsPageNth"> + <expectedResult type="string">{{expectedPage}}</expectedResult> <actualResult type="variable">currentPageText</actualResult> </assertEquals> </actionGroup> diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontNavigateCategoryNextPageActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontNavigateCategoryNextPageActionGroup.xml index 5fe97debb1593..4776c9d32a34d 100644 --- a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontNavigateCategoryNextPageActionGroup.xml +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontNavigateCategoryNextPageActionGroup.xml @@ -6,8 +6,10 @@ --> <actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> - <!-- Navigates storefront category next page from toolbar --> <actionGroup name="StorefrontNavigateCategoryNextPageActionGroup"> + <annotations> + <description>Navigates storefront category next page from toolbar</description> + </annotations> <scrollTo selector="{{StorefrontCategoryBottomToolbarSection.nextPage}}" stepKey="scrollToNextButton"/> <click selector="{{StorefrontCategoryBottomToolbarSection.nextPage}}" stepKey="clickOnNextPage"/> <waitForPageLoad stepKey="waitForNextCategoryPageLoad"/> diff --git a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontRedirectToFirstPageOnFilteringBySwatchTest.xml b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontRedirectToFirstPageOnFilteringBySwatchTest.xml index 49eccc18b1347..c6266e034bffc 100644 --- a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontRedirectToFirstPageOnFilteringBySwatchTest.xml +++ b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontRedirectToFirstPageOnFilteringBySwatchTest.xml @@ -37,7 +37,6 @@ <actionGroup ref="AddTextSwatchToProductActionGroup" stepKey="addSwatchAttribute"> <argument name="usedInLayeredNavigation" value="1"/> </actionGroup> - <magentoCLI command="cache:clean block_html collections config full_page" stepKey="cleanInvalidatedCaches"/> </before> <after> @@ -48,7 +47,7 @@ <magentoCLI command="config:set catalog/frontend/grid_per_page 12" stepKey="setDefaultProductsPerPage"/> <magentoCLI command="config:set catalog/frontend/grid_per_page_values 12,24,36" stepKey="setDefaultGridPerPage"/> - <magentoCLI command="cache:clean block_html collections config full_page" stepKey="cleanInvalidatedCaches"/> + <magentoCLI command="cache:clean config full_page" stepKey="cleanInvalidatedCaches"/> <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> <deleteData createDataKey="createSimpleProduct1" stepKey="deleteSimpleProduct1"/> @@ -97,6 +96,8 @@ <click selector="{{StorefrontCategorySidebarSection.attributeNthOption(textSwatchAttribute.attribute_code, '1')}}" stepKey="filterBySwatch1"/> <waitForPageLoad stepKey="waitForPageToLoad2"/> - <actionGroup ref="AssertStorefrontCategoryCurrentPageIsFirstActionGroup" stepKey="assertCurrentPageIsFirst"/> + <actionGroup ref="AssertStorefrontCategoryCurrentPageIsNthActionGroup" stepKey="assertCurrentPageIsFirst"> + <argument name="expectedPage" value="1"/> + </actionGroup> </test> </tests>