Skip to content

Commit bc0b412

Browse files
committed
Merge remote-tracking branch 'github-magento2ce/MAGETWO-98748' into EPAM-PR-56
2 parents 2d02740 + b93edb5 commit bc0b412

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

app/code/Magento/Catalog/Plugin/Block/Topmenu.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
*/
1515
class Topmenu
1616
{
17+
/**
18+
* Cache tag for menu block
19+
*/
20+
private $cacheTag = "top_menu";
21+
1722
/**
1823
* Catalog category
1924
*
@@ -119,6 +124,7 @@ public function beforeGetIdentities(\Magento\Theme\Block\Html\Topmenu $subject)
119124
$subject->addIdentity(Category::CACHE_TAG);
120125
$rootId = $this->storeManager->getStore()->getRootCategoryId();
121126
$storeId = $this->storeManager->getStore()->getId();
127+
$currentCategory = $this->getCurrentCategory();
122128
/** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $collection */
123129
$collection = $this->getCategoryTree($storeId, $rootId);
124130
$mapping = [$rootId => $subject->getMenu()]; // use nodes stack to avoid recursion
@@ -128,6 +134,9 @@ public function beforeGetIdentities(\Magento\Theme\Block\Html\Topmenu $subject)
128134
}
129135
$subject->addIdentity(Category::CACHE_TAG . '_' . $category->getId());
130136
}
137+
if ($currentCategory) {
138+
$subject->addIdentity($this->cacheTag . '_' . Category::CACHE_TAG . '_' . $currentCategory->getId());
139+
}
131140
}
132141

133142
/**

app/code/Magento/Catalog/Test/Mftf/Section/AdminCategorySidebarTreeSection.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
<element name="expandAll" type="button" selector=".tree-actions a:last-child"/>
1414
<element name="categoryTreeRoot" type="text" selector="div.x-tree-root-node>li.x-tree-node:first-of-type>div.x-tree-node-el:first-of-type" timeout="30"/>
1515
<element name="categoryInTree" type="text" selector="//a/span[contains(text(), '{{name}}')]" parameterized="true" timeout="30"/>
16+
<element name="categoryHighlighted" type="text" selector="//ul[@id='ui-id-2']//li//a/span[contains(text(),'{{name}}')]/../.." parameterized="true" timeout="30"/>
17+
<element name="categoryNotHighlighted" type="text" selector="ul[id=\'ui-id-2\'] li[class~=\'active\']" timeout="30"/>
1618
<element name="categoryInTreeUnderRoot" type="text" selector="//li/ul/li[@class='x-tree-node']/div/a/span[contains(text(), '{{name}}')]" parameterized="true"/>
1719
<element name="lastCreatedCategory" type="block" selector=".x-tree-root-ct li li:last-child" />
1820
<element name="treeContainer" type="block" selector=".tree-holder" />
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="CheckCurrentCategoryIsHighlightedAndProductsDisplayed">
12+
<annotations>
13+
<features value="Catalog"/>
14+
<title value="Сheck that current category is highlighted and all products displayed for it"/>
15+
<description value="Сheck that current category is highlighted and all products displayed for it"/>
16+
<severity value="MAJOR"/>
17+
<testCaseId value="MAGETWO-99028"/>
18+
<useCaseId value="MAGETWO-98748"/>
19+
<group value="Catalog"/>
20+
</annotations>
21+
<before>
22+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
23+
<createData entity="SimpleSubCategory" stepKey="category1"/>
24+
<createData entity="SimpleSubCategory" stepKey="category2"/>
25+
<createData entity="SimpleSubCategory" stepKey="category3"/>
26+
<createData entity="SimpleSubCategory" stepKey="category4"/>
27+
<createData entity="SimpleProduct" stepKey="product1">
28+
<requiredEntity createDataKey="category1"/>
29+
</createData>
30+
<createData entity="SimpleProduct" stepKey="product2">
31+
<requiredEntity createDataKey="category1"/>
32+
</createData>
33+
</before>
34+
<after>
35+
<deleteData createDataKey="product1" stepKey="deleteProduct1"/>
36+
<deleteData createDataKey="product2" stepKey="deleteProduct2"/>
37+
<deleteData createDataKey="category1" stepKey="deleteCategory1"/>
38+
<deleteData createDataKey="category2" stepKey="deleteCategory2"/>
39+
<deleteData createDataKey="category3" stepKey="deleteCategory3"/>
40+
<deleteData createDataKey="category4" stepKey="deleteCategory4"/>
41+
<actionGroup ref="logout" stepKey="logout"/>
42+
</after>
43+
<!--Open Storefront home page-->
44+
<comment userInput="Open Storefront home page" stepKey="openStorefrontHomePage"/>
45+
<amOnPage url="{{StorefrontHomePage.url}}" stepKey="goToStorefrontHomePage"/>
46+
<waitForPageLoad stepKey="waitForSimpleProductPage"/>
47+
<!--Click on first category-->
48+
<comment userInput="Click on first category" stepKey="openFirstCategoryPage"/>
49+
<click selector="{{AdminCategorySidebarTreeSection.categoryInTree($$category1.name$$)}}" stepKey="clickCategory1Name"/>
50+
<waitForPageLoad stepKey="waitForCategory1Page"/>
51+
<!--Check if current category is highlighted and the others are not-->
52+
<comment userInput="Check if current category is highlighted and the others are not" stepKey="checkCateg1NameIsHighlighted"/>
53+
<grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category1.name$$)}}" userInput="class" stepKey="grabCategory1Class"/>
54+
<assertContains expectedType="string" expected="active" actual="$grabCategory1Class" stepKey="assertCategory1IsHighlighted"/>
55+
<executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedAmount"/>
56+
<assertEquals expectedType="int" expected="1" actual="$highlightedAmount" stepKey="assertRestCategories1IsNotHighlighted"/>
57+
<!--See products in the category page-->
58+
<comment userInput="See products in the category page" stepKey="seeProductsInCategoryPage"/>
59+
<seeElement selector="{{StorefrontCategoryMainSection.specifiedProductItemInfo($product1.name$)}}" stepKey="seeProduct1InCategoryPage"/>
60+
<seeElement selector="{{StorefrontCategoryMainSection.specifiedProductItemInfo($product2.name$)}}" stepKey="seeProduct2InCategoryPage"/>
61+
<!--Click on second category-->
62+
<comment userInput="Click on second category" stepKey="openSecondCategoryPage"/>
63+
<click selector="{{AdminCategorySidebarTreeSection.categoryInTree($$category2.name$$)}}" stepKey="clickCategory2Name"/>
64+
<waitForPageLoad stepKey="waitForCategory2Page"/>
65+
<!--Check if current category is highlighted and the others are not-->
66+
<comment userInput="Check if current category is highlighted and the others are not" stepKey="checkCateg2NameIsHighlighted"/>
67+
<grabAttributeFrom selector="{{AdminCategorySidebarTreeSection.categoryHighlighted($$category2.name$$)}}" userInput="class" stepKey="grabCategory2Class"/>
68+
<assertContains expectedType="string" expected="active" actual="$grabCategory2Class" stepKey="assertCategory2IsHighlighted"/>
69+
<executeJS function="return document.querySelectorAll('{{AdminCategorySidebarTreeSection.categoryNotHighlighted}}').length" stepKey="highlightedAmount2"/>
70+
<assertEquals expectedType="int" expected="1" actual="$highlightedAmount2" stepKey="assertRestCategories1IsNotHighlighted2"/>
71+
</test>
72+
</tests>

app/code/Magento/Theme/Block/Html/Topmenu.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ protected function getCacheLifetime()
7474
return parent::getCacheLifetime() ?: 3600;
7575
}
7676

77+
/**
78+
* Get cache key informative items
79+
*
80+
* @return array
81+
*/
82+
public function getCacheKeyInfo()
83+
{
84+
return array_merge(parent::getCacheKeyInfo(), $this->getIdentities());
85+
}
86+
7787
/**
7888
* Get top menu html
7989
*

0 commit comments

Comments
 (0)