diff --git a/app/code/Magento/Catalog/Plugin/Block/Topmenu.php b/app/code/Magento/Catalog/Plugin/Block/Topmenu.php index b4aa5bd960b..3a76c554aa0 100644 --- a/app/code/Magento/Catalog/Plugin/Block/Topmenu.php +++ b/app/code/Magento/Catalog/Plugin/Block/Topmenu.php @@ -12,13 +12,12 @@ use Magento\Framework\Data\Tree\Node; /** - * Plugin for top menu block + * Plugin that enhances the top menu block by building and managing the category tree + * for menu rendering in a storefront. */ class Topmenu { /** - * Catalog category - * * @var \Magento\Catalog\Helper\Category */ protected $catalogCategory; @@ -33,29 +32,21 @@ class Topmenu */ private $storeManager; - /** - * @var \Magento\Catalog\Model\Layer\Resolver - */ - private $layerResolver; - /** * Initialize dependencies. * * @param \Magento\Catalog\Helper\Category $catalogCategory * @param \Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory $categoryCollectionFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver */ public function __construct( \Magento\Catalog\Helper\Category $catalogCategory, \Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory $categoryCollectionFactory, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Catalog\Model\Layer\Resolver $layerResolver + \Magento\Store\Model\StoreManagerInterface $storeManager ) { $this->catalogCategory = $catalogCategory; $this->collectionFactory = $categoryCollectionFactory; $this->storeManager = $storeManager; - $this->layerResolver = $layerResolver; } /** @@ -78,7 +69,6 @@ public function beforeGetHtml( $storeId = $this->storeManager->getStore()->getId(); /** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $collection */ $collection = $this->getCategoryTree($storeId, $rootId); - $currentCategory = $this->getCurrentCategory(); $mapping = [$rootId => $subject->getMenu()]; // use nodes stack to avoid recursion foreach ($collection as $category) { $categoryParentId = $category->getParentId(); @@ -97,7 +87,6 @@ public function beforeGetHtml( $categoryNode = new Node( $this->getCategoryAsArray( $category, - $currentCategory, $category->getParentId() == $categoryParentId ), 'id', @@ -132,39 +121,20 @@ public function beforeGetIdentities(\Magento\Theme\Block\Html\Topmenu $subject) } } - /** - * Get current Category from catalog layer - * - * @return \Magento\Catalog\Model\Category - */ - private function getCurrentCategory() - { - $catalogLayer = $this->layerResolver->get(); - - if (!$catalogLayer) { - return null; - } - - return $catalogLayer->getCurrentCategory(); - } - /** * Convert category to array * - * @param \Magento\Catalog\Model\Category $category - * @param \Magento\Catalog\Model\Category $currentCategory + * @param Category $category * @param bool $isParentActive * @return array */ - private function getCategoryAsArray($category, $currentCategory, $isParentActive) + private function getCategoryAsArray($category, $isParentActive): array { $categoryId = $category->getId(); return [ 'name' => $category->getName(), 'id' => 'category-node-' . $categoryId, 'url' => $this->catalogCategory->getCategoryUrl($category), - 'has_active' => in_array((string)$categoryId, explode('/', (string)$currentCategory->getPath()), true), - 'is_active' => $categoryId == $currentCategory->getId(), 'is_category' => true, 'is_parent_active' => $isParentActive ]; @@ -196,22 +166,4 @@ protected function getCategoryTree($storeId, $rootId) return $collection; } - - /** - * Add active - * - * @param \Magento\Theme\Block\Html\Topmenu $subject - * @param string[] $result - * @return string[] - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function afterGetCacheKeyInfo(\Magento\Theme\Block\Html\Topmenu $subject, array $result) - { - $activeCategory = $this->getCurrentCategory(); - if ($activeCategory) { - $result[] = Category::CACHE_TAG . '_' . $activeCategory->getId(); - } - - return $result; - } } diff --git a/app/code/Magento/Catalog/Test/Mftf/Data/SeoConfigData.xml b/app/code/Magento/Catalog/Test/Mftf/Data/SeoConfigData.xml new file mode 100644 index 00000000000..043955a6189 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/Data/SeoConfigData.xml @@ -0,0 +1,23 @@ + + + + + + catalog/seo/product_use_categories + 0 + Yes + 1 + + + catalog/seo/product_use_categories + 0 + No + 0 + + diff --git a/app/code/Magento/Catalog/Test/Mftf/Section/AdminCategorySidebarTreeSection.xml b/app/code/Magento/Catalog/Test/Mftf/Section/AdminCategorySidebarTreeSection.xml index de8b887cc26..f5fb74ab4eb 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Section/AdminCategorySidebarTreeSection.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Section/AdminCategorySidebarTreeSection.xml @@ -12,7 +12,9 @@ + + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontNoStoreCodeNoCategoryPathHtmlSuffixNavigationTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontNoStoreCodeNoCategoryPathHtmlSuffixNavigationTest.xml new file mode 100644 index 00000000000..3008e280de8 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontNoStoreCodeNoCategoryPathHtmlSuffixNavigationTest.xml @@ -0,0 +1,270 @@ + + + + + + + + + + <description value="This test verifies that the correct category is highlighted in the navigation menu when navigating through categories and products on the storefront, specifically with .html URL suffixes and the settings 'Add Store Code to Urls: No' and 'Use Categories Path for Product URLs: No'. The test focuses on the impact of these configurations on category highlighting."/> + <testCaseId value="AC-10833"/> + <severity value="MAJOR"/> + <group value="catalog"/> + <group value="theme"/> + </annotations> + <before> + <!-- Create categories --> + <createData entity="ApiCategory" stepKey="category_0"/> + <createData entity="ApiCategory" stepKey="category_1"/> + <createData entity="SubCategoryWithParent" stepKey="category_1_1"> + <requiredEntity createDataKey="category_1"/> + </createData> + <createData entity="NewSubCategoryWithParent" stepKey="category_1_2"> + <requiredEntity createDataKey="category_1"/> + </createData> + <!-- Create products --> + <createData entity="ApiSimpleProduct" stepKey="product_1_1"> + <requiredEntity createDataKey="category_1_1"/> + </createData> + <createData entity="ApiSimpleProduct" stepKey="product_1_2"> + <requiredEntity createDataKey="category_1_2"/> + </createData> + <createData entity="ApiSimpleProduct" stepKey="product_1_1_1_2"> + <requiredEntity createDataKey="category_1_1"/> + <requiredEntity createDataKey="category_1_2"/> + </createData> + <!-- Reindex indexers --> + <actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex"> + <argument name="indices" value=""/> + </actionGroup> + <!-- Set url suffixes --> + <magentoCLI command="config:set catalog/seo/category_url_suffix .html" stepKey="setCategoryUrlSuffix"/> + <magentoCLI command="config:set catalog/seo/product_url_suffix .html" stepKey="setProductUrlSuffix"/> + <!-- Set "Add Store Code to Urls": No --> + <magentoCLI command="config:set {{StorefrontDisableAddStoreCodeToUrls.path}} {{StorefrontDisableAddStoreCodeToUrls.value}}" stepKey="disableStoreCodeToUrls"/> + <!-- Set "Use Categories Path for Product URLs": No --> + <magentoCLI command="config:set {{DisableCategoriesPathForProductUrls.path}} {{DisableCategoriesPathForProductUrls.value}}" stepKey="disableCategoriesPathForProductUrls"/> + <!-- Flush needed cache --> + <actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCacheAfterChangingConfig"> + <argument name="tags" value=""/> + </actionGroup> + </before> + <after> + <!-- Delete categories and products --> + <deleteData createDataKey="category_0" stepKey="deleteCategory0" /> + <deleteData createDataKey="category_1" stepKey="deleteCategory1" /> + <deleteData createDataKey="product_1_1" stepKey="deleteProduct_1_1" /> + <deleteData createDataKey="product_1_2" stepKey="deleteProduct_1_2" /> + <deleteData createDataKey="product_1_1_1_2" stepKey="deleteProduct_1_1_1_2" /> + </after> + <!-- Open storefront homepage --> + <actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="openStorefrontPage"/> + + <!-- Open Category 1 --> + <click selector="{{AdminCategorySidebarTreeSection.categoryInFrontendTree($$category_1.name$$)}}" stepKey="clickCategory1Name"/> + <waitForPageLoad stepKey="waitForCategory1Page"/> + <!-- Check if Category 1 has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory1Class"/> + <assertStringContainsString stepKey="assertCategory1IsHighlighted"> + <actualResult type="const">$grabCategory1Class</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!--Check if Category 1 is highlighted and the others are not--> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount"/> + <assertEquals stepKey="assertCategoryIsActive"> + <actualResult type="const">$highlightedCategoryAmount</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild"> + <actualResult type="const">$highlightedParentCategoryAmount</actualResult> + <expectedResult type="int">0</expectedResult> + </assertEquals> + + <!-- Open Category 1_1 --> + <moveMouseOver selector="{{StorefrontHeaderSection.NavigationCategoryByName($$category_1.name$$)}}" stepKey="hoverOverCategory1"/> + <click selector="{{AdminCategorySidebarTreeSection.categoryInFrontendTree($$category_1_1.name$$)}}" stepKey="clickCategory_1_1_Name"/> + <waitForPageLoad stepKey="waitForCategory_1_1_Page"/> + <!-- Check if parent Category 1 has 'has-active' class and selected Category 1.1 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive"> + <actualResult type="const">$grabCategory_1_Class</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_1.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_1_Class"/> + <assertStringContainsString stepKey="assertCategory_1_1_Active"> + <actualResult type="const">$grabCategory_1_1_Class</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if current category and its parent are highlighted and the others are not --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try2"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try2"/> + <assertEquals stepKey="assertCategoryIsActive_Try2"> + <actualResult type="const">$highlightedCategoryAmount_Try2</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try2"> + <actualResult type="const">$highlightedParentCategoryAmount_Try2</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- From Category 1.1 page open product assigned to both Category 1_1 & Category 1_2 --> + <actionGroup ref="StorefrontOpenProductFromCategoryPageActionGroup" stepKey="openProductFromCategoryPage"> + <argument name="productName" value="$product_1_1_1_2.name$"/> + </actionGroup> + <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="waitForProductDisplayPageLoad"/> + <actionGroup ref="StorefrontAssertProductNameOnProductPageActionGroup" stepKey="seeCorrectName"> + <argument name="productName" value="$product_1_1_1_2.name$"/> + </actionGroup> + <actionGroup ref="StorefrontAssertProductSkuOnProductPageActionGroup" stepKey="seeCorrectSku"> + <argument name="productSku" value="$product_1_1_1_2.sku$"/> + </actionGroup> + <!-- Check if parent Category 1 has 'has-active' class and Category 1.1 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class_Try2"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive_Try2"> + <actualResult type="const">$grabCategory_1_Class_Try2</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_1.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_1_Class_Try2"/> + <assertStringContainsString stepKey="assertCategory_1_1_Active_Try2"> + <actualResult type="const">$grabCategory_1_1_Class_Try2</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if Category 1.1 and its parent Category 1 are highlighted and the others are not --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try3"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try3"/> + <assertEquals stepKey="assertCategoryIsActive_Try3"> + <actualResult type="const">$highlightedCategoryAmount_Try3</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try3"> + <actualResult type="const">$highlightedParentCategoryAmount_Try3</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- Click on home page --> + <click selector="{{StorefrontHeaderSection.logoLink}}" stepKey="clickOnLogo"/> + <waitForPageLoad stepKey="waitForHomePageLoadedAfterClickOnLogo"/> + <!-- Check that no category is highlighted --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try4"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try4"/> + <assertEquals stepKey="assertNoCategoryIsActive"> + <actualResult type="const">$highlightedCategoryAmount_Try4</actualResult> + <expectedResult type="int">0</expectedResult> + </assertEquals> + <assertEquals stepKey="assertNoParentCategoryHasActiveChild"> + <actualResult type="const">$highlightedParentCategoryAmount_Try4</actualResult> + <expectedResult type="int">0</expectedResult> + </assertEquals> + + <!-- Open Category 1_2 --> + <moveMouseOver selector="{{StorefrontHeaderSection.NavigationCategoryByName($$category_1.name$$)}}" stepKey="hoverOverCategory1_Try2"/> + <click selector="{{AdminCategorySidebarTreeSection.categoryInFrontendTree($$category_1_2.name$$)}}" stepKey="clickCategory_1_2_Name"/> + <waitForPageLoad stepKey="waitForCategory_1_2_Page"/> + <!-- Check if parent Category 1 has 'has-active' class and selected Category 1.2 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class_Try3"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive_Try3"> + <actualResult type="const">$grabCategory_1_Class_Try3</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_2.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_2_Class"/> + <assertStringContainsString stepKey="assertCategory_1_2_Active"> + <actualResult type="const">$grabCategory_1_2_Class</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if only 1 category has 'active' class & 1 category has 'has-active' class --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try5"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try5"/> + <assertEquals stepKey="assertCategoryIsActive_Try4"> + <actualResult type="const">$highlightedCategoryAmount_Try5</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try4"> + <actualResult type="const">$highlightedParentCategoryAmount_Try5</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- Open direct Category 1.2 url --> + <amOnPage url="/$$category_1.custom_attributes[url_key]$$/$$category_1_2.custom_attributes[url_key]$$.html" stepKey="openCategoryPageDirectly"/> + <waitForPageLoad stepKey="waitForCategoryStoreFrontPageToLoad"/> + <!-- Check if parent Category 1 has 'has-active' class and Category 1.2 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class_Try4"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive_Try4"> + <actualResult type="const">$grabCategory_1_Class_Try4</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_2.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_2_Class_Try2"/> + <assertStringContainsString stepKey="assertCategory_1_2_Active_Try2"> + <actualResult type="const">$grabCategory_1_2_Class_Try2</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if only 1 category has 'active' class & 1 category has 'has-active' class --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try6"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try6"/> + <assertEquals stepKey="assertCategoryIsActive_Try5"> + <actualResult type="const">$highlightedCategoryAmount_Try6</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try5"> + <actualResult type="const">$highlightedParentCategoryAmount_Try6</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- From Category 1.2 page open product assigned to both Category 1_1 & Category 1_2 --> + <actionGroup ref="StorefrontOpenProductFromCategoryPageActionGroup" stepKey="openProductFromCategoryPage_Try2"> + <argument name="productName" value="$product_1_1_1_2.name$"/> + </actionGroup> + <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="waitForProductDisplayPageLoad_Try2"/> + <actionGroup ref="StorefrontAssertProductNameOnProductPageActionGroup" stepKey="seeCorrectName_Try2"> + <argument name="productName" value="$product_1_1_1_2.name$"/> + </actionGroup> + <actionGroup ref="StorefrontAssertProductSkuOnProductPageActionGroup" stepKey="seeCorrectSku_Try2"> + <argument name="productSku" value="$product_1_1_1_2.sku$"/> + </actionGroup> + <!-- Check if parent Category 1 has 'has-active' class and Category 1.2 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class_Try5"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive_Try5"> + <actualResult type="const">$grabCategory_1_Class_Try5</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_2.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_2_Class_Try3"/> + <assertStringContainsString stepKey="assertCategory_1_2_Active_Try3"> + <actualResult type="const">$grabCategory_1_2_Class_Try3</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if only 1 category has 'active' class & 1 category has 'has-active' class --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try7"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try7"/> + <assertEquals stepKey="assertCategoryIsActive_Try6"> + <actualResult type="const">$highlightedCategoryAmount_Try7</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try6"> + <actualResult type="const">$highlightedParentCategoryAmount_Try7</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- Open product assigned to both Category 1_1 & Category 1_2 by its direct page url --> + <actionGroup ref="OpenStoreFrontProductPageActionGroup" stepKey="openProductPageDirectly"> + <argument name="productUrlKey" value="$product_1_1_1_2.custom_attributes[url_key]$"/> + </actionGroup> + <waitForPageLoad stepKey="waitForProductPageLoad"/> + <!-- Check that no category is highlighted --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try8"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try8"/> + <assertEquals stepKey="assertNoCategoryIsActive_Try2"> + <actualResult type="const">$highlightedCategoryAmount_Try8</actualResult> + <expectedResult type="int">0</expectedResult> + </assertEquals> + <assertEquals stepKey="assertNoParentCategoryHasActiveChild_Try2"> + <actualResult type="const">$highlightedParentCategoryAmount_Try8</actualResult> + <expectedResult type="int">0</expectedResult> + </assertEquals> + </test> +</tests> diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontNoStoreCodeYesCategoryPathHtmlSuffixNavigationTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontNoStoreCodeYesCategoryPathHtmlSuffixNavigationTest.xml new file mode 100644 index 00000000000..c131aee6e03 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontNoStoreCodeYesCategoryPathHtmlSuffixNavigationTest.xml @@ -0,0 +1,285 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> + <test name="StorefrontNoStoreCodeYesCategoryPathHtmlSuffixNavigationTest"> + <annotations> + <features value="Catalog"/> + <stories value="Navigation Menu Highlighting with .html Suffix, No Store Code, Yes Category Path"/> + <title value="Validation of Navigation Menu Highlighting with .html Suffix, No Store Code and Yes Category Path in URLs"/> + <description value="This test verifies that the correct category is highlighted in the navigation menu when navigating through categories and products on the storefront, specifically with .html URL suffixes and the settings 'Add Store Code to Urls: No' and 'Use Categories Path for Product URLs: Yes'. The test focuses on the impact of these configurations on category highlighting."/> + <testCaseId value="AC-10851"/> + <severity value="MAJOR"/> + <group value="catalog"/> + <group value="theme"/> + </annotations> + <before> + <!-- Create categories --> + <createData entity="ApiCategory" stepKey="category_0"/> + <createData entity="ApiCategory" stepKey="category_1"/> + <createData entity="SubCategoryWithParent" stepKey="category_1_1"> + <requiredEntity createDataKey="category_1"/> + </createData> + <createData entity="NewSubCategoryWithParent" stepKey="category_1_2"> + <requiredEntity createDataKey="category_1"/> + </createData> + <!-- Create products --> + <createData entity="ApiSimpleProduct" stepKey="product_1_1"> + <requiredEntity createDataKey="category_1_1"/> + </createData> + <createData entity="ApiSimpleProduct" stepKey="product_1_2"> + <requiredEntity createDataKey="category_1_2"/> + </createData> + <createData entity="ApiSimpleProduct" stepKey="product_1_1_1_2"> + <requiredEntity createDataKey="category_1_1"/> + <requiredEntity createDataKey="category_1_2"/> + </createData> + <!-- Reindex indexers --> + <actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex"> + <argument name="indices" value=""/> + </actionGroup> + <!-- Set custom url suffixes --> + <magentoCLI command="config:set catalog/seo/category_url_suffix .html" stepKey="setCategoryUrlSuffix"/> + <magentoCLI command="config:set catalog/seo/product_url_suffix .html" stepKey="setProductUrlSuffix"/> + <!-- Set "Add Store Code to Urls": No --> + <magentoCLI command="config:set {{StorefrontDisableAddStoreCodeToUrls.path}} {{StorefrontDisableAddStoreCodeToUrls.value}}" stepKey="disableStoreCodeToUrls"/> + <!-- Set "Use Categories Path for Product URLs": Yes --> + <magentoCLI command="config:set {{EnableCategoriesPathForProductUrls.path}} {{EnableCategoriesPathForProductUrls.value}}" stepKey="enableCategoriesPathForProductUrls"/> + <!-- Flush needed cache --> + <actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCacheAfterChangingConfig"> + <argument name="tags" value=""/> + </actionGroup> + </before> + <after> + <!-- Delete categories and products --> + <deleteData createDataKey="category_0" stepKey="deleteCategory0" /> + <deleteData createDataKey="category_1" stepKey="deleteCategory1" /> + <deleteData createDataKey="product_1_1" stepKey="deleteProduct_1_1" /> + <deleteData createDataKey="product_1_2" stepKey="deleteProduct_1_2" /> + <deleteData createDataKey="product_1_1_1_2" stepKey="deleteProduct_1_1_1_2" /> + <!-- Set "Use Categories Path for Product URLs": No --> + <magentoCLI command="config:set {{DisableCategoriesPathForProductUrls.path}} {{DisableCategoriesPathForProductUrls.value}}" stepKey="disableCategoriesPathForProductUrls"/> + <!-- Flush needed cache --> + <actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCacheAfterChangingConfig"> + <argument name="tags" value="config full_page"/> + </actionGroup> + </after> + <!-- Open storefront homepage --> + <actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="openStorefrontPage"/> + + <!-- Open Category 1 --> + <click selector="{{AdminCategorySidebarTreeSection.categoryInFrontendTree($$category_1.name$$)}}" stepKey="clickCategory1Name"/> + <waitForPageLoad stepKey="waitForCategory1Page"/> + <!-- Check if Category 1 has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory1Class"/> + <assertStringContainsString stepKey="assertCategory1IsHighlighted"> + <actualResult type="const">$grabCategory1Class</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!--Check if Category 1 is highlighted and the others are not--> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount"/> + <assertEquals stepKey="assertCategoryIsActive"> + <actualResult type="const">$highlightedCategoryAmount</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild"> + <actualResult type="const">$highlightedParentCategoryAmount</actualResult> + <expectedResult type="int">0</expectedResult> + </assertEquals> + + <!-- Open Category 1_1 --> + <moveMouseOver selector="{{StorefrontHeaderSection.NavigationCategoryByName($$category_1.name$$)}}" stepKey="hoverOverCategory1"/> + <click selector="{{AdminCategorySidebarTreeSection.categoryInFrontendTree($$category_1_1.name$$)}}" stepKey="clickCategory_1_1_Name"/> + <waitForPageLoad stepKey="waitForCategory_1_1_Page"/> + <!-- Check if parent Category 1 has 'has-active' class and selected Category 1.1 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive"> + <actualResult type="const">$grabCategory_1_Class</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_1.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_1_Class"/> + <assertStringContainsString stepKey="assertCategory_1_1_Active"> + <actualResult type="const">$grabCategory_1_1_Class</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if current category and its parent are highlighted and the others are not --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try2"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try2"/> + <assertEquals stepKey="assertCategoryIsActive_Try2"> + <actualResult type="const">$highlightedCategoryAmount_Try2</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try2"> + <actualResult type="const">$highlightedParentCategoryAmount_Try2</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- From Category 1.1 page open product assigned to both Category 1_1 & Category 1_2 --> + <actionGroup ref="StorefrontOpenProductFromCategoryPageActionGroup" stepKey="openProductFromCategoryPage"> + <argument name="productName" value="$product_1_1_1_2.name$"/> + </actionGroup> + <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="waitForProductDisplayPageLoad"/> + <actionGroup ref="StorefrontAssertProductNameOnProductPageActionGroup" stepKey="seeCorrectName"> + <argument name="productName" value="$product_1_1_1_2.name$"/> + </actionGroup> + <actionGroup ref="StorefrontAssertProductSkuOnProductPageActionGroup" stepKey="seeCorrectSku"> + <argument name="productSku" value="$product_1_1_1_2.sku$"/> + </actionGroup> + <!-- Check if parent Category 1 has 'has-active' class and Category 1.1 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class_Try2"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive_Try2"> + <actualResult type="const">$grabCategory_1_Class_Try2</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_1.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_1_Class_Try2"/> + <assertStringContainsString stepKey="assertCategory_1_1_Active_Try2"> + <actualResult type="const">$grabCategory_1_1_Class_Try2</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if Category 1.1 and its parent Category 1 are highlighted and the others are not --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try3"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try3"/> + <assertEquals stepKey="assertCategoryIsActive_Try3"> + <actualResult type="const">$highlightedCategoryAmount_Try3</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try3"> + <actualResult type="const">$highlightedParentCategoryAmount_Try3</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- Click on home page --> + <click selector="{{StorefrontHeaderSection.logoLink}}" stepKey="clickOnLogo"/> + <waitForPageLoad stepKey="waitForHomePageLoadedAfterClickOnLogo"/> + <!-- Check that no category is highlighted --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try4"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try4"/> + <assertEquals stepKey="assertNoCategoryIsActive"> + <actualResult type="const">$highlightedCategoryAmount_Try4</actualResult> + <expectedResult type="int">0</expectedResult> + </assertEquals> + <assertEquals stepKey="assertNoParentCategoryHasActiveChild"> + <actualResult type="const">$highlightedParentCategoryAmount_Try4</actualResult> + <expectedResult type="int">0</expectedResult> + </assertEquals> + + <!-- Open Category 1_2 --> + <moveMouseOver selector="{{StorefrontHeaderSection.NavigationCategoryByName($$category_1.name$$)}}" stepKey="hoverOverCategory1_Try2"/> + <click selector="{{AdminCategorySidebarTreeSection.categoryInFrontendTree($$category_1_2.name$$)}}" stepKey="clickCategory_1_2_Name"/> + <waitForPageLoad stepKey="waitForCategory_1_2_Page"/> + <!-- Check if parent Category 1 has 'has-active' class and selected Category 1.2 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class_Try3"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive_Try3"> + <actualResult type="const">$grabCategory_1_Class_Try3</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_2.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_2_Class"/> + <assertStringContainsString stepKey="assertCategory_1_2_Active"> + <actualResult type="const">$grabCategory_1_2_Class</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if only 1 category has 'active' class & 1 category has 'has-active' class --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try5"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try5"/> + <assertEquals stepKey="assertCategoryIsActive_Try4"> + <actualResult type="const">$highlightedCategoryAmount_Try5</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try4"> + <actualResult type="const">$highlightedParentCategoryAmount_Try5</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- Open direct Category 1.2 url --> + <amOnPage url="/$$category_1.custom_attributes[url_key]$$/$$category_1_2.custom_attributes[url_key]$$.html" stepKey="openCategoryPageDirectly"/> + <waitForPageLoad stepKey="waitForCategoryStoreFrontPageToLoad"/> + <!-- Check if parent Category 1 has 'has-active' class and Category 1.2 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class_Try4"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive_Try4"> + <actualResult type="const">$grabCategory_1_Class_Try4</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_2.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_2_Class_Try2"/> + <assertStringContainsString stepKey="assertCategory_1_2_Active_Try2"> + <actualResult type="const">$grabCategory_1_2_Class_Try2</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if only 1 category has 'active' class & 1 category has 'has-active' class --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try6"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try6"/> + <assertEquals stepKey="assertCategoryIsActive_Try5"> + <actualResult type="const">$highlightedCategoryAmount_Try6</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try5"> + <actualResult type="const">$highlightedParentCategoryAmount_Try6</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- From Category 1.2 page open product assigned to both Category 1_1 & Category 1_2 --> + <actionGroup ref="StorefrontOpenProductFromCategoryPageActionGroup" stepKey="openProductFromCategoryPage_Try2"> + <argument name="productName" value="$product_1_1_1_2.name$"/> + </actionGroup> + <comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="waitForProductDisplayPageLoad_Try2"/> + <actionGroup ref="StorefrontAssertProductNameOnProductPageActionGroup" stepKey="seeCorrectName_Try2"> + <argument name="productName" value="$product_1_1_1_2.name$"/> + </actionGroup> + <actionGroup ref="StorefrontAssertProductSkuOnProductPageActionGroup" stepKey="seeCorrectSku_Try2"> + <argument name="productSku" value="$product_1_1_1_2.sku$"/> + </actionGroup> + <!-- Check if parent Category 1 has 'has-active' class and Category 1.2 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class_Try5"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive_Try5"> + <actualResult type="const">$grabCategory_1_Class_Try5</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_2.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_2_Class_Try3"/> + <assertStringContainsString stepKey="assertCategory_1_2_Active_Try3"> + <actualResult type="const">$grabCategory_1_2_Class_Try3</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if only 1 category has 'active' class & 1 category has 'has-active' class --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try7"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try7"/> + <assertEquals stepKey="assertCategoryIsActive_Try6"> + <actualResult type="const">$highlightedCategoryAmount_Try7</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try6"> + <actualResult type="const">$highlightedParentCategoryAmount_Try7</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- Open product assigned to both Category 1_1 & Category 1_2 by its direct page url with category in it --> + <amOnPage url="/$$category_1.custom_attributes[url_key]$$/$$category_1_2.custom_attributes[url_key]$$/$$product_1_1_1_2.custom_attributes[url_key]$$.html" stepKey="openProductPageDirectly" /> + <waitForPageLoad stepKey="waitForProductPageLoad"/> + <!-- Check if parent Category 1 has 'has-active' class and Category 1.2 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class_Try6"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive_Try6"> + <actualResult type="const">$grabCategory_1_Class_Try6</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_2.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_2_Class_Try4"/> + <assertStringContainsString stepKey="assertCategory_1_2_Active_Try4"> + <actualResult type="const">$grabCategory_1_2_Class_Try4</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if only 1 category has 'active' class & 1 category has 'has-active' class --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try8"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try8"/> + <assertEquals stepKey="assertCategoryIsActive_Try7"> + <actualResult type="const">$highlightedCategoryAmount_Try8</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try7"> + <actualResult type="const">$highlightedParentCategoryAmount_Try8</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + </test> +</tests> diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontYesStoreCodeNoCategoryPathNoSuffixNavigationTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontYesStoreCodeNoCategoryPathNoSuffixNavigationTest.xml new file mode 100644 index 00000000000..d97bb47215f --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontYesStoreCodeNoCategoryPathNoSuffixNavigationTest.xml @@ -0,0 +1,275 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> + <test name="StorefrontYesStoreCodeNoCategoryPathNoSuffixNavigationTest"> + <annotations> + <features value="Catalog"/> + <stories value="Navigation Menu Highlighting with No Suffix, Yes Store Code, No Category Path"/> + <title value="Validation of Navigation Menu Highlighting with No Suffix, Yes Store Code and No Category Path in URLs"/> + <description value="This test verifies that the correct category is highlighted in the navigation menu when navigating through categories and products on the storefront, specifically with no URL suffixes and the settings 'Add Store Code to Urls: Yes' and 'Use Categories Path for Product URLs: No'. The test focuses on the impact of these configurations on category highlighting."/> + <testCaseId value="AC-10854"/> + <severity value="MAJOR"/> + <group value="catalog"/> + <group value="theme"/> + </annotations> + <before> + <!-- Create categories --> + <createData entity="ApiCategory" stepKey="category_0"/> + <createData entity="ApiCategory" stepKey="category_1"/> + <createData entity="SubCategoryWithParent" stepKey="category_1_1"> + <requiredEntity createDataKey="category_1"/> + </createData> + <createData entity="NewSubCategoryWithParent" stepKey="category_1_2"> + <requiredEntity createDataKey="category_1"/> + </createData> + <!-- Create products --> + <createData entity="ApiSimpleProduct" stepKey="product_1_1"> + <requiredEntity createDataKey="category_1_1"/> + </createData> + <createData entity="ApiSimpleProduct" stepKey="product_1_2"> + <requiredEntity createDataKey="category_1_2"/> + </createData> + <createData entity="ApiSimpleProduct" stepKey="product_1_1_1_2"> + <requiredEntity createDataKey="category_1_1"/> + <requiredEntity createDataKey="category_1_2"/> + </createData> + <!-- Reindex indexers --> + <actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex"> + <argument name="indices" value=""/> + </actionGroup> + <!-- Set no url suffixes --> + <magentoCLI command="config:set catalog/seo/category_url_suffix ''" stepKey="setNoCategoryUrlSuffix"/> + <magentoCLI command="config:set catalog/seo/product_url_suffix ''" stepKey="setNoProductUrlSuffix"/> + <!-- Set "Add Store Code to Urls": Yes --> + <magentoCLI command="config:set {{StorefrontEnableAddStoreCodeToUrls.path}} {{StorefrontEnableAddStoreCodeToUrls.value}}" stepKey="enableStoreCodeToUrls"/> + <!-- Set "Use Categories Path for Product URLs": No --> + <magentoCLI command="config:set {{DisableCategoriesPathForProductUrls.path}} {{DisableCategoriesPathForProductUrls.value}}" stepKey="disableCategoriesPathForProductUrls"/> + <!-- Flush needed cache --> + <actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCacheAfterChangingConfig"> + <argument name="tags" value=""/> + </actionGroup> + </before> + <after> + <!-- Delete categories and products --> + <deleteData createDataKey="category_0" stepKey="deleteCategory0" /> + <deleteData createDataKey="category_1" stepKey="deleteCategory1" /> + <deleteData createDataKey="product_1_1" stepKey="deleteProduct_1_1" /> + <deleteData createDataKey="product_1_2" stepKey="deleteProduct_1_2" /> + <deleteData createDataKey="product_1_1_1_2" stepKey="deleteProduct_1_1_1_2" /> + <!-- Set url suffixes to its default values --> + <magentoCLI command="config:set catalog/seo/category_url_suffix .html" stepKey="setCategoryUrlSuffix"/> + <magentoCLI command="config:set catalog/seo/product_url_suffix .html" stepKey="setProductUrlSuffix"/> + <!-- Set "Add Store Code to Urls": No --> + <magentoCLI command="config:set {{StorefrontDisableAddStoreCodeToUrls.path}} {{StorefrontDisableAddStoreCodeToUrls.value}}" stepKey="disableStoreCodeToUrls"/> + <!-- Flush needed cache --> + <actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCacheAfterChangingConfig"> + <argument name="tags" value=""/> + </actionGroup> + </after> + <!-- Open storefront homepage --> + <actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="openStorefrontPage"/> + + <!-- Open Category 1 --> + <click selector="{{AdminCategorySidebarTreeSection.categoryInFrontendTree($$category_1.name$$)}}" stepKey="clickCategory1Name"/> + <waitForPageLoad stepKey="waitForCategory1Page"/> + <!-- Check if Category 1 has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory1Class"/> + <assertStringContainsString stepKey="assertCategory1IsHighlighted"> + <actualResult type="const">$grabCategory1Class</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!--Check if Category 1 is highlighted and the others are not--> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount"/> + <assertEquals stepKey="assertCategoryIsActive"> + <actualResult type="const">$highlightedCategoryAmount</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild"> + <actualResult type="const">$highlightedParentCategoryAmount</actualResult> + <expectedResult type="int">0</expectedResult> + </assertEquals> + + <!-- Open Category 1_1 --> + <moveMouseOver selector="{{StorefrontHeaderSection.NavigationCategoryByName($$category_1.name$$)}}" stepKey="hoverOverCategory1"/> + <click selector="{{AdminCategorySidebarTreeSection.categoryInFrontendTree($$category_1_1.name$$)}}" stepKey="clickCategory_1_1_Name"/> + <waitForPageLoad stepKey="waitForCategory_1_1_Page"/> + <!-- Check if parent Category 1 has 'has-active' class and selected Category 1.1 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive"> + <actualResult type="const">$grabCategory_1_Class</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_1.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_1_Class"/> + <assertStringContainsString stepKey="assertCategory_1_1_Active"> + <actualResult type="const">$grabCategory_1_1_Class</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if current category and its parent are highlighted and the others are not --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try2"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try2"/> + <assertEquals stepKey="assertCategoryIsActive_Try2"> + <actualResult type="const">$highlightedCategoryAmount_Try2</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try2"> + <actualResult type="const">$highlightedParentCategoryAmount_Try2</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- From Category 1.1 page open product assigned to both Category 1_1 & Category 1_2 --> + <actionGroup ref="StorefrontOpenProductFromCategoryPageActionGroup" stepKey="openProductFromCategoryPage"> + <argument name="productName" value="$product_1_1_1_2.name$"/> + </actionGroup> + <actionGroup ref="StorefrontAssertProductNameOnProductPageActionGroup" stepKey="seeCorrectName"> + <argument name="productName" value="$product_1_1_1_2.name$"/> + </actionGroup> + <actionGroup ref="StorefrontAssertProductSkuOnProductPageActionGroup" stepKey="seeCorrectSku"> + <argument name="productSku" value="$product_1_1_1_2.sku$"/> + </actionGroup> + <!-- Check if parent Category 1 has 'has-active' class and Category 1.1 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class_Try2"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive_Try2"> + <actualResult type="const">$grabCategory_1_Class_Try2</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_1.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_1_Class_Try2"/> + <assertStringContainsString stepKey="assertCategory_1_1_Active_Try2"> + <actualResult type="const">$grabCategory_1_1_Class_Try2</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if Category 1.1 and its parent Category 1 are highlighted and the others are not --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try3"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try3"/> + <assertEquals stepKey="assertCategoryIsActive_Try3"> + <actualResult type="const">$highlightedCategoryAmount_Try3</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try3"> + <actualResult type="const">$highlightedParentCategoryAmount_Try3</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- Click on home page --> + <click selector="{{StorefrontHeaderSection.logoLink}}" stepKey="clickOnLogo"/> + <waitForPageLoad stepKey="waitForHomePageLoadedAfterClickOnLogo"/> + <!-- Check that no category is highlighted --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try4"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try4"/> + <assertEquals stepKey="assertNoCategoryIsActive"> + <actualResult type="const">$highlightedCategoryAmount_Try4</actualResult> + <expectedResult type="int">0</expectedResult> + </assertEquals> + <assertEquals stepKey="assertNoParentCategoryHasActiveChild"> + <actualResult type="const">$highlightedParentCategoryAmount_Try4</actualResult> + <expectedResult type="int">0</expectedResult> + </assertEquals> + + <!-- Open Category 1_2 --> + <moveMouseOver selector="{{StorefrontHeaderSection.NavigationCategoryByName($$category_1.name$$)}}" stepKey="hoverOverCategory1_Try2"/> + <click selector="{{AdminCategorySidebarTreeSection.categoryInFrontendTree($$category_1_2.name$$)}}" stepKey="clickCategory_1_2_Name"/> + <waitForPageLoad stepKey="waitForCategory_1_2_Page"/> + <!-- Check if parent Category 1 has 'has-active' class and selected Category 1.2 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class_Try3"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive_Try3"> + <actualResult type="const">$grabCategory_1_Class_Try3</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_2.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_2_Class"/> + <assertStringContainsString stepKey="assertCategory_1_2_Active"> + <actualResult type="const">$grabCategory_1_2_Class</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if only 1 category has 'active' class & 1 category has 'has-active' class --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try5"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try5"/> + <assertEquals stepKey="assertCategoryIsActive_Try4"> + <actualResult type="const">$highlightedCategoryAmount_Try5</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try4"> + <actualResult type="const">$highlightedParentCategoryAmount_Try5</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- Open direct Category 1.2 url --> + <amOnPage url="/default/$$category_1.custom_attributes[url_key]$$/$$category_1_2.custom_attributes[url_key]$$" stepKey="openCategoryPageDirectly"/> + <waitForPageLoad stepKey="waitForCategoryStoreFrontPageToLoad"/> + <!-- Check if parent Category 1 has 'has-active' class and Category 1.2 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class_Try4"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive_Try4"> + <actualResult type="const">$grabCategory_1_Class_Try4</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_2.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_2_Class_Try2"/> + <assertStringContainsString stepKey="assertCategory_1_2_Active_Try2"> + <actualResult type="const">$grabCategory_1_2_Class_Try2</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if only 1 category has 'active' class & 1 category has 'has-active' class --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try6"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try6"/> + <assertEquals stepKey="assertCategoryIsActive_Try5"> + <actualResult type="const">$highlightedCategoryAmount_Try6</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try5"> + <actualResult type="const">$highlightedParentCategoryAmount_Try6</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- From Category 1.2 page open product assigned to both Category 1_1 & Category 1_2 --> + <actionGroup ref="StorefrontOpenProductFromCategoryPageActionGroup" stepKey="openProductFromCategoryPage_Try2"> + <argument name="productName" value="$product_1_1_1_2.name$"/> + </actionGroup> + <actionGroup ref="StorefrontAssertProductNameOnProductPageActionGroup" stepKey="seeCorrectName_Try2"> + <argument name="productName" value="$product_1_1_1_2.name$"/> + </actionGroup> + <actionGroup ref="StorefrontAssertProductSkuOnProductPageActionGroup" stepKey="seeCorrectSku_Try2"> + <argument name="productSku" value="$product_1_1_1_2.sku$"/> + </actionGroup> + <!-- Check if parent Category 1 has 'has-active' class and Category 1.2 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class_Try5"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive_Try5"> + <actualResult type="const">$grabCategory_1_Class_Try5</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_2.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_2_Class_Try3"/> + <assertStringContainsString stepKey="assertCategory_1_2_Active_Try3"> + <actualResult type="const">$grabCategory_1_2_Class_Try3</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if only 1 category has 'active' class & 1 category has 'has-active' class --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try7"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try7"/> + <assertEquals stepKey="assertCategoryIsActive_Try6"> + <actualResult type="const">$highlightedCategoryAmount_Try7</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try6"> + <actualResult type="const">$highlightedParentCategoryAmount_Try7</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- Open product assigned to both Category 1_1 & Category 1_2 by its direct page url with store in it --> + <amOnPage url="/default/$$product_1_1_1_2.custom_attributes[url_key]$$" stepKey="openProductPageDirectly" /> + <waitForPageLoad stepKey="waitForProductPageLoad"/> + <!-- Check that no category is highlighted --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try8"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try8"/> + <assertEquals stepKey="assertNoCategoryIsActive_Try2"> + <actualResult type="const">$highlightedCategoryAmount_Try8</actualResult> + <expectedResult type="int">0</expectedResult> + </assertEquals> + <assertEquals stepKey="assertNoParentCategoryHasActiveChild_Try2"> + <actualResult type="const">$highlightedParentCategoryAmount_Try8</actualResult> + <expectedResult type="int">0</expectedResult> + </assertEquals> + </test> +</tests> diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontYesStoreCodeYesCategoryPathNoSuffixNavigationTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontYesStoreCodeYesCategoryPathNoSuffixNavigationTest.xml new file mode 100644 index 00000000000..0069684b813 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontYesStoreCodeYesCategoryPathNoSuffixNavigationTest.xml @@ -0,0 +1,288 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> + <test name="StorefrontYesStoreCodeYesCategoryPathNoSuffixNavigationTest"> + <annotations> + <features value="Catalog"/> + <stories value="Navigation Menu Highlighting with No Suffix, Yes Store Code, Yes Category Path"/> + <title value="Validation of Navigation Menu Highlighting with No Suffix, Yes Store Code and Yes Category Path in URLs"/> + <description value="This test verifies that the correct category is highlighted in the navigation menu when navigating through categories and products on the storefront, specifically with no URL suffixes and the settings 'Add Store Code to Urls: Yes' and 'Use Categories Path for Product URLs: Yes'. The test focuses on the impact of these configurations on category highlighting."/> + <testCaseId value="AC-10852"/> + <severity value="MAJOR"/> + <group value="catalog"/> + <group value="theme"/> + </annotations> + <before> + <!-- Create categories --> + <createData entity="ApiCategory" stepKey="category_0"/> + <createData entity="ApiCategory" stepKey="category_1"/> + <createData entity="SubCategoryWithParent" stepKey="category_1_1"> + <requiredEntity createDataKey="category_1"/> + </createData> + <createData entity="NewSubCategoryWithParent" stepKey="category_1_2"> + <requiredEntity createDataKey="category_1"/> + </createData> + <!-- Create products --> + <createData entity="ApiSimpleProduct" stepKey="product_1_1"> + <requiredEntity createDataKey="category_1_1"/> + </createData> + <createData entity="ApiSimpleProduct" stepKey="product_1_2"> + <requiredEntity createDataKey="category_1_2"/> + </createData> + <createData entity="ApiSimpleProduct" stepKey="product_1_1_1_2"> + <requiredEntity createDataKey="category_1_1"/> + <requiredEntity createDataKey="category_1_2"/> + </createData> + <!-- Reindex indexers --> + <actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex"> + <argument name="indices" value=""/> + </actionGroup> + <!-- Set no url suffixes --> + <magentoCLI command="config:set catalog/seo/category_url_suffix ''" stepKey="setNoCategoryUrlSuffix"/> + <magentoCLI command="config:set catalog/seo/product_url_suffix ''" stepKey="setNoProductUrlSuffix"/> + <!-- Set "Add Store Code to Urls": Yes --> + <magentoCLI command="config:set {{StorefrontEnableAddStoreCodeToUrls.path}} {{StorefrontEnableAddStoreCodeToUrls.value}}" stepKey="enableStoreCodeToUrls"/> + <!-- Set "Use Categories Path for Product URLs": Yes --> + <magentoCLI command="config:set {{EnableCategoriesPathForProductUrls.path}} {{EnableCategoriesPathForProductUrls.value}}" stepKey="enableCategoriesPathForProductUrls"/> + <!-- Flush needed cache --> + <actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCacheAfterChangingConfig"> + <argument name="tags" value=""/> + </actionGroup> + </before> + <after> + <!-- Delete categories and products --> + <deleteData createDataKey="category_0" stepKey="deleteCategory0" /> + <deleteData createDataKey="category_1" stepKey="deleteCategory1" /> + <deleteData createDataKey="product_1_1" stepKey="deleteProduct_1_1" /> + <deleteData createDataKey="product_1_2" stepKey="deleteProduct_1_2" /> + <deleteData createDataKey="product_1_1_1_2" stepKey="deleteProduct_1_1_1_2" /> + <!-- Set url suffixes to its default values --> + <magentoCLI command="config:set catalog/seo/category_url_suffix .html" stepKey="setCategoryUrlSuffix"/> + <magentoCLI command="config:set catalog/seo/product_url_suffix .html" stepKey="setProductUrlSuffix"/> + <!-- Set "Add Store Code to Urls": No --> + <magentoCLI command="config:set {{StorefrontDisableAddStoreCodeToUrls.path}} {{StorefrontDisableAddStoreCodeToUrls.value}}" stepKey="disableStoreCodeToUrls"/> + <!-- Set "Use Categories Path for Product URLs": No --> + <magentoCLI command="config:set {{DisableCategoriesPathForProductUrls.path}} {{DisableCategoriesPathForProductUrls.value}}" stepKey="disableCategoriesPathForProductUrls"/> + <!-- Flush needed cache --> + <actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCacheAfterChangingConfig"> + <argument name="tags" value=""/> + </actionGroup> + </after> + <!-- Open storefront homepage --> + <actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="openStorefrontPage"/> + + <!-- Open Category 1 --> + <click selector="{{AdminCategorySidebarTreeSection.categoryInFrontendTree($$category_1.name$$)}}" stepKey="clickCategory1Name"/> + <waitForPageLoad stepKey="waitForCategory1Page"/> + <!-- Check if Category 1 has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory1Class"/> + <assertStringContainsString stepKey="assertCategory1IsHighlighted"> + <actualResult type="const">$grabCategory1Class</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!--Check if Category 1 is highlighted and the others are not--> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount"/> + <assertEquals stepKey="assertCategoryIsActive"> + <actualResult type="const">$highlightedCategoryAmount</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild"> + <actualResult type="const">$highlightedParentCategoryAmount</actualResult> + <expectedResult type="int">0</expectedResult> + </assertEquals> + + <!-- Open Category 1_1 --> + <moveMouseOver selector="{{StorefrontHeaderSection.NavigationCategoryByName($$category_1.name$$)}}" stepKey="hoverOverCategory1"/> + <click selector="{{AdminCategorySidebarTreeSection.categoryInFrontendTree($$category_1_1.name$$)}}" stepKey="clickCategory_1_1_Name"/> + <waitForPageLoad stepKey="waitForCategory_1_1_Page"/> + <!-- Check if parent Category 1 has 'has-active' class and selected Category 1.1 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive"> + <actualResult type="const">$grabCategory_1_Class</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_1.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_1_Class"/> + <assertStringContainsString stepKey="assertCategory_1_1_Active"> + <actualResult type="const">$grabCategory_1_1_Class</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if current category and its parent are highlighted and the others are not --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try2"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try2"/> + <assertEquals stepKey="assertCategoryIsActive_Try2"> + <actualResult type="const">$highlightedCategoryAmount_Try2</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try2"> + <actualResult type="const">$highlightedParentCategoryAmount_Try2</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- From Category 1.1 page open product assigned to both Category 1_1 & Category 1_2 --> + <actionGroup ref="StorefrontOpenProductFromCategoryPageActionGroup" stepKey="openProductFromCategoryPage"> + <argument name="productName" value="$product_1_1_1_2.name$"/> + </actionGroup> + <actionGroup ref="StorefrontAssertProductNameOnProductPageActionGroup" stepKey="seeCorrectName"> + <argument name="productName" value="$product_1_1_1_2.name$"/> + </actionGroup> + <actionGroup ref="StorefrontAssertProductSkuOnProductPageActionGroup" stepKey="seeCorrectSku"> + <argument name="productSku" value="$product_1_1_1_2.sku$"/> + </actionGroup> + <!-- Check if parent Category 1 has 'has-active' class and Category 1.1 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class_Try2"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive_Try2"> + <actualResult type="const">$grabCategory_1_Class_Try2</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_1.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_1_Class_Try2"/> + <assertStringContainsString stepKey="assertCategory_1_1_Active_Try2"> + <actualResult type="const">$grabCategory_1_1_Class_Try2</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if Category 1.1 and its parent Category 1 are highlighted and the others are not --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try3"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try3"/> + <assertEquals stepKey="assertCategoryIsActive_Try3"> + <actualResult type="const">$highlightedCategoryAmount_Try3</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try3"> + <actualResult type="const">$highlightedParentCategoryAmount_Try3</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- Click on home page --> + <click selector="{{StorefrontHeaderSection.logoLink}}" stepKey="clickOnLogo"/> + <waitForPageLoad stepKey="waitForHomePageLoadedAfterClickOnLogo"/> + <!-- Check that no category is highlighted --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try4"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try4"/> + <assertEquals stepKey="assertNoCategoryIsActive"> + <actualResult type="const">$highlightedCategoryAmount_Try4</actualResult> + <expectedResult type="int">0</expectedResult> + </assertEquals> + <assertEquals stepKey="assertNoParentCategoryHasActiveChild"> + <actualResult type="const">$highlightedParentCategoryAmount_Try4</actualResult> + <expectedResult type="int">0</expectedResult> + </assertEquals> + + <!-- Open Category 1_2 --> + <moveMouseOver selector="{{StorefrontHeaderSection.NavigationCategoryByName($$category_1.name$$)}}" stepKey="hoverOverCategory1_Try2"/> + <click selector="{{AdminCategorySidebarTreeSection.categoryInFrontendTree($$category_1_2.name$$)}}" stepKey="clickCategory_1_2_Name"/> + <waitForPageLoad stepKey="waitForCategory_1_2_Page"/> + <!-- Check if parent Category 1 has 'has-active' class and selected Category 1.2 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class_Try3"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive_Try3"> + <actualResult type="const">$grabCategory_1_Class_Try3</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_2.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_2_Class"/> + <assertStringContainsString stepKey="assertCategory_1_2_Active"> + <actualResult type="const">$grabCategory_1_2_Class</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if only 1 category has 'active' class & 1 category has 'has-active' class --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try5"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try5"/> + <assertEquals stepKey="assertCategoryIsActive_Try4"> + <actualResult type="const">$highlightedCategoryAmount_Try5</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try4"> + <actualResult type="const">$highlightedParentCategoryAmount_Try5</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- Open direct Category 1.2 url --> + <amOnPage url="/default/$$category_1.custom_attributes[url_key]$$/$$category_1_2.custom_attributes[url_key]$$" stepKey="openCategoryPageDirectly"/> + <waitForPageLoad stepKey="waitForCategoryStoreFrontPageToLoad"/> + <!-- Check if parent Category 1 has 'has-active' class and Category 1.2 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class_Try4"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive_Try4"> + <actualResult type="const">$grabCategory_1_Class_Try4</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_2.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_2_Class_Try2"/> + <assertStringContainsString stepKey="assertCategory_1_2_Active_Try2"> + <actualResult type="const">$grabCategory_1_2_Class_Try2</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if only 1 category has 'active' class & 1 category has 'has-active' class --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try6"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try6"/> + <assertEquals stepKey="assertCategoryIsActive_Try5"> + <actualResult type="const">$highlightedCategoryAmount_Try6</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try5"> + <actualResult type="const">$highlightedParentCategoryAmount_Try6</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- From Category 1.2 page open product assigned to both Category 1_1 & Category 1_2 --> + <actionGroup ref="StorefrontOpenProductFromCategoryPageActionGroup" stepKey="openProductFromCategoryPage_Try2"> + <argument name="productName" value="$product_1_1_1_2.name$"/> + </actionGroup> + <actionGroup ref="StorefrontAssertProductNameOnProductPageActionGroup" stepKey="seeCorrectName_Try2"> + <argument name="productName" value="$product_1_1_1_2.name$"/> + </actionGroup> + <actionGroup ref="StorefrontAssertProductSkuOnProductPageActionGroup" stepKey="seeCorrectSku_Try2"> + <argument name="productSku" value="$product_1_1_1_2.sku$"/> + </actionGroup> + <!-- Check if parent Category 1 has 'has-active' class and Category 1.2 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class_Try5"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive_Try5"> + <actualResult type="const">$grabCategory_1_Class_Try5</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_2.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_2_Class_Try3"/> + <assertStringContainsString stepKey="assertCategory_1_2_Active_Try3"> + <actualResult type="const">$grabCategory_1_2_Class_Try3</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if only 1 category has 'active' class & 1 category has 'has-active' class --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try7"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try7"/> + <assertEquals stepKey="assertCategoryIsActive_Try6"> + <actualResult type="const">$highlightedCategoryAmount_Try7</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try6"> + <actualResult type="const">$highlightedParentCategoryAmount_Try7</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + + <!-- Open product assigned to both Category 1_1 & Category 1_2 by its direct page url with category & store in it --> + <amOnPage url="/default/$$category_1.custom_attributes[url_key]$$/$$category_1_2.custom_attributes[url_key]$$/$$product_1_1_1_2.custom_attributes[url_key]$$" stepKey="openProductPageDirectly" /> + <waitForPageLoad stepKey="waitForProductPageLoad"/> + <!-- Check if parent Category 1 has 'has-active' class and Category 1.2 child category has 'active' class --> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category_1.name$$)}}" userInput="class" stepKey="grabCategory_1_Class_Try6"/> + <assertStringContainsString stepKey="assertCategory_1_HasActive_Try6"> + <actualResult type="const">$grabCategory_1_Class_Try6</actualResult> + <expectedResult type="string">has-active</expectedResult> + </assertStringContainsString> + <grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.dynamicActiveClassSelector($$category_1_2.name$$, 'active', 'has-active')}}" userInput="class" stepKey="grabCategory_1_2_Class_Try4"/> + <assertStringContainsString stepKey="assertCategory_1_2_Active_Try4"> + <actualResult type="const">$grabCategory_1_2_Class_Try4</actualResult> + <expectedResult type="string">active</expectedResult> + </assertStringContainsString> + <!-- Check if only 1 category has 'active' class & 1 category has 'has-active' class --> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedCategoryAmount_Try8"/> + <executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.parentCategoryNotHighlighted}}').length" stepKey="highlightedParentCategoryAmount_Try8"/> + <assertEquals stepKey="assertCategoryIsActive_Try7"> + <actualResult type="const">$highlightedCategoryAmount_Try8</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + <assertEquals stepKey="assertParentCategoryHasActiveChild_Try7"> + <actualResult type="const">$highlightedParentCategoryAmount_Try8</actualResult> + <expectedResult type="int">1</expectedResult> + </assertEquals> + </test> +</tests> diff --git a/app/code/Magento/Catalog/Test/Unit/Plugin/Block/TopmenuTest.php b/app/code/Magento/Catalog/Test/Unit/Plugin/Block/TopmenuTest.php index 7e2517e4a03..b50a4395209 100644 --- a/app/code/Magento/Catalog/Test/Unit/Plugin/Block/TopmenuTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Plugin/Block/TopmenuTest.php @@ -8,8 +8,6 @@ namespace Magento\Catalog\Test\Unit\Plugin\Block; use Magento\Catalog\Helper\Category; -use Magento\Catalog\Model\Layer; -use Magento\Catalog\Model\Layer\Resolver; use Magento\Catalog\Model\ResourceModel\Category\Collection; use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory; use Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory; @@ -42,16 +40,6 @@ class TopmenuTest extends TestCase */ protected $storeMock; - /** - * @var MockObject|Resolver - */ - protected $layerResolverMock; - - /** - * @var MockObject|Layer - */ - protected $catalogLayerMock; - /** * @var MockObject|CollectionFactory */ @@ -90,9 +78,7 @@ protected function setUp(): void $this->childrenCategoryMock = $this->_getCleanMock(\Magento\Catalog\Model\Category::class); $this->categoryHelperMock = $this->_getCleanMock(Category::class); - $this->catalogLayerMock = $this->_getCleanMock(Layer::class); $this->categoryMock = $this->_getCleanMock(\Magento\Catalog\Model\Category::class); - $this->layerResolverMock = $this->_getCleanMock(Resolver::class); $this->storeMock = $this->_getCleanMock(Store::class); $this->storeManagerMock = $this->_getCleanMock(StoreManagerInterface::class); $this->categoryCollectionMock = $this->_getCleanMock( @@ -103,9 +89,6 @@ protected function setUp(): void ['create'] ); - $this->catalogLayerMock->expects($this->once())->method('getCurrentCategory') - ->willReturn($this->childrenCategoryMock); - $this->storeManagerMock->expects($this->atLeastOnce())->method('getStore') ->willReturn($this->storeMock); @@ -114,9 +97,6 @@ protected function setUp(): void $this->categoryMock->expects($this->once())->method('getParentIds') ->willReturn($categoryParentIds); - $this->layerResolverMock->expects($this->once())->method('get') - ->willReturn($this->catalogLayerMock); - $this->storeMock->expects($this->once())->method('getRootCategoryId') ->willReturn($rootCategoryId); @@ -131,8 +111,7 @@ protected function setUp(): void [ 'catalogCategory' => $this->categoryHelperMock, 'categoryCollectionFactory' => $this->categoryCollectionFactoryMock, - 'storeManager' => $this->storeManagerMock, - 'layerResolver' => $this->layerResolverMock, + 'storeManager' => $this->storeManagerMock ] ); } diff --git a/app/code/Magento/Theme/Block/Html/Topmenu.php b/app/code/Magento/Theme/Block/Html/Topmenu.php index f8460b43ba2..37a2149d298 100644 --- a/app/code/Magento/Theme/Block/Html/Topmenu.php +++ b/app/code/Magento/Theme/Block/Html/Topmenu.php @@ -312,12 +312,6 @@ protected function _getMenuItemClasses(Node $item) $classes[] = 'first'; } - if ($item->getIsActive()) { - $classes[] = 'active'; - } elseif ($item->getHasActive()) { - $classes[] = 'has-active'; - } - if ($item->getIsLast()) { $classes[] = 'last'; } diff --git a/app/code/Magento/Theme/Test/Unit/Block/Html/TopmenuTest.php b/app/code/Magento/Theme/Test/Unit/Block/Html/TopmenuTest.php index 59b3ca6f4f7..b5fe6ac1c30 100644 --- a/app/code/Magento/Theme/Test/Unit/Block/Html/TopmenuTest.php +++ b/app/code/Magento/Theme/Test/Unit/Block/Html/TopmenuTest.php @@ -77,17 +77,10 @@ class TopmenuTest extends TestCase private $requestMock; // @codingStandardsIgnoreStart - /** @var string */ - protected $htmlWithoutCategory = <<<HTML + private $navigationMenuHtml = <<<HTML <li class="level0 nav-1 first"><a href="http://magento2/category-0.html" ><span></span></a></li><li class="level0 nav-2"><a href="http://magento2/category-1.html" ><span></span></a></li><li class="level0 nav-3"><a href="http://magento2/category-2.html" ><span></span></a></li><li class="level0 nav-4"><a href="http://magento2/category-3.html" ><span></span></a></li><li class="level0 nav-5"><a href="http://magento2/category-4.html" ><span></span></a></li><li class="level0 nav-6"><a href="http://magento2/category-5.html" ><span></span></a></li><li class="level0 nav-7"><a href="http://magento2/category-6.html" ><span></span></a></li><li class="level0 nav-8"><a href="http://magento2/category-7.html" ><span></span></a></li><li class="level0 nav-9"><a href="http://magento2/category-8.html" ><span></span></a></li><li class="level0 nav-10 last"><a href="http://magento2/category-9.html" ><span></span></a></li> HTML; - - /** @var string */ - protected $htmlWithCategory = <<<HTML -<li class="level0 nav-1 first active"><a href="http://magento2/category-0.html" ><span></span></a></li><li class="level0 nav-2"><a href="http://magento2/category-1.html" ><span></span></a></li><li class="level0 nav-3"><a href="http://magento2/category-2.html" ><span></span></a></li><li class="level0 nav-4"><a href="http://magento2/category-3.html" ><span></span></a></li><li class="level0 nav-5"><a href="http://magento2/category-4.html" ><span></span></a></li><li class="level0 nav-6"><a href="http://magento2/category-5.html" ><span></span></a></li><li class="level0 nav-7"><a href="http://magento2/category-6.html" ><span></span></a></li><li class="level0 nav-8"><a href="http://magento2/category-7.html" ><span></span></a></li><li class="level0 nav-9"><a href="http://magento2/category-8.html" ><span></span></a></li><li class="level0 nav-10 last"><a href="http://magento2/category-9.html" ><span></span></a></li> -HTML; - // @codingStandardsIgnoreEnd /** @@ -143,7 +136,7 @@ public function testGetHtmlWithoutSelectedCategory(): void $treeNode = $this->buildTree(false); - $transportObject = new DataObject(['html' => $this->htmlWithoutCategory]); + $transportObject = new DataObject(['html' => $this->navigationMenuHtml]); $this->eventManagerMock->expects($this->exactly(2)) ->method('dispatch') @@ -167,7 +160,7 @@ public function testGetHtmlWithoutSelectedCategory(): void ], ]); - $this->assertEquals($this->htmlWithoutCategory, $topmenuBlock->getHtml()); + $this->assertEquals($this->navigationMenuHtml, $topmenuBlock->getHtml()); } /** @@ -179,7 +172,7 @@ public function testGetHtmlWithSelectedCategory(): void $treeNode = $this->buildTree(true); - $transportObject = new DataObject(['html' => $this->htmlWithCategory]); + $transportObject = new DataObject(['html' => $this->navigationMenuHtml]); $this->eventManagerMock->expects($this->exactly(2)) ->method('dispatch') @@ -203,7 +196,7 @@ public function testGetHtmlWithSelectedCategory(): void ], ]); - $this->assertEquals($this->htmlWithCategory, $topmenuBlock->getHtml()); + $this->assertEquals($this->navigationMenuHtml, $topmenuBlock->getHtml()); } /** @@ -236,7 +229,7 @@ public function testGetCacheKeyInfo(): void * @param bool $isCurrentItem * @return MockObject */ - private function buildTree($isCurrentItem): MockObject + private function buildTree(bool $isCurrentItem): MockObject { $treeMock = $this->getMockBuilder(Tree::class) ->disableOriginalConstructor() diff --git a/lib/web/mage/menu.js b/lib/web/mage/menu.js index ed958adf336..ea44a9450a5 100644 --- a/lib/web/mage/menu.js +++ b/lib/web/mage/menu.js @@ -16,6 +16,7 @@ define([ */ $.widget('mage.menu', $.ui.menu, { options: { + categoryLayoutClass: 'catalog-product-view', responsive: false, expanded: false, showDelay: 42, @@ -182,33 +183,77 @@ define([ }, /** - * Tries to retrieve category URL from current URL and mark this category as active - * @see _setActiveMenuForCategory(url) + * Extracts the URL extension from the given URL. + * It identifies the last segment of the URL after the last slash ('/') and returns the substring after the last dot ('.') + * If there's no dot in the last segment, it returns an empty string. * - * @example - * currentUrl - http://magento.com/category1/category12/product.html, - * category URLs has extensions .phtml - http://magento.com/category1.phtml - * method sets active category which has URL http://magento.com/category1/category12.phtml + * @param {String} url - The URL from which to extract the extension. + * @return {String} The extracted URL extension or an empty string if no extension is found. + * @private + */ + _getUrlExtension: function (url) { + var lastSegment = url.slice(url.lastIndexOf('/') + 1); + return lastSegment.includes('.') ? lastSegment.slice(lastSegment.lastIndexOf('.')) : ''; + }, + + /** + * Determines if the current page is a product page. + * It checks the catalog product view related class in the body tag of the document. + * + * @return {Boolean} True if the current page is a product page, false otherwise. + * @private + */ + _isProductPage: function () { + return document.body.classList.contains(this.options.categoryLayoutClass); + }, + + /** + * Sets the active state in the menu for a product page. Determines the category URL from either + * the referrer URL or the current URL, using the URL extension to identify the category. + * Sets the corresponding category as active in the menu if a valid category URL is found. + * Clears the active state if no valid category URL is found or if it's not a product page. * - * @param {String} currentUrl - current page URL without parameters + * @param {String} currentUrl - The current page URL without parameters. * @return void * @private */ _setActiveMenuForProduct: function (currentUrl) { - var categoryUrlExtension, - lastUrlSection, - possibleCategoryUrl, - //retrieve first category URL to know what extension is used for category URLs - firstCategoryUrl = this.element.find('> li a').attr('href'); - - if (firstCategoryUrl) { - lastUrlSection = firstCategoryUrl.substr(firstCategoryUrl.lastIndexOf('/')); - categoryUrlExtension = lastUrlSection.lastIndexOf('.') !== -1 ? - lastUrlSection.substr(lastUrlSection.lastIndexOf('.')) : ''; - - possibleCategoryUrl = currentUrl.substr(0, currentUrl.lastIndexOf('/')) + categoryUrlExtension; - this._setActiveMenuForCategory(possibleCategoryUrl); + var firstCategoryUrl = this.element.find('> li a').attr('href'); + + if (!firstCategoryUrl) { + this._clearActiveState(); + return; } + + var categoryUrlExtension = this._getUrlExtension(firstCategoryUrl); + var categoryUrl; + var isProductPage = this._isProductPage(); + + if (isProductPage) { + var currentHostname = window.location.hostname; + + if (document.referrer.includes(currentHostname) && document.referrer.endsWith(categoryUrlExtension)) { + categoryUrl = document.referrer.split('?')[0]; + } else { + categoryUrl = currentUrl.substring(0, currentUrl.lastIndexOf('/')) + categoryUrlExtension; + } + + this._setActiveMenuForCategory(categoryUrl); + } else { + this._clearActiveState(); + } + }, + + /** + * Clears the active state from all menu items within the navigation element. + * It removes 'active' and 'has-active' classes from all list items (li elements), + * which are used to indicate the currently selected or parent of a selected item. + * + * @return void + * @private + */ + _clearActiveState: function () { + this.element.find('li').removeClass('active has-active'); }, /**