Skip to content

Commit f6f33e3

Browse files
committed
Remove active category in the cache key
- Update tests to reflect changes with removal of active related attributes from ViewModel layer;
1 parent f6e8697 commit f6f33e3

File tree

3 files changed

+8
-46
lines changed

3 files changed

+8
-46
lines changed

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
class Topmenu
1919
{
2020
/**
21-
* Catalog category
22-
*
2321
* @var \Magento\Catalog\Helper\Category
2422
*/
2523
protected $catalogCategory;
@@ -34,29 +32,21 @@ class Topmenu
3432
*/
3533
private $storeManager;
3634

37-
/**
38-
* @var \Magento\Catalog\Model\Layer\Resolver
39-
*/
40-
private $layerResolver;
41-
4235
/**
4336
* Initialize dependencies.
4437
*
4538
* @param \Magento\Catalog\Helper\Category $catalogCategory
4639
* @param \Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory $categoryCollectionFactory
4740
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
48-
* @param \Magento\Catalog\Model\Layer\Resolver $layerResolver
4941
*/
5042
public function __construct(
5143
\Magento\Catalog\Helper\Category $catalogCategory,
5244
\Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory $categoryCollectionFactory,
53-
\Magento\Store\Model\StoreManagerInterface $storeManager,
54-
\Magento\Catalog\Model\Layer\Resolver $layerResolver
45+
\Magento\Store\Model\StoreManagerInterface $storeManager
5546
) {
5647
$this->catalogCategory = $catalogCategory;
5748
$this->collectionFactory = $categoryCollectionFactory;
5849
$this->storeManager = $storeManager;
59-
$this->layerResolver = $layerResolver;
6050
}
6151

6252
/**

app/code/Magento/Catalog/Test/Unit/Plugin/Block/TopmenuTest.php

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
namespace Magento\Catalog\Test\Unit\Plugin\Block;
99

1010
use Magento\Catalog\Helper\Category;
11-
use Magento\Catalog\Model\Layer;
12-
use Magento\Catalog\Model\Layer\Resolver;
1311
use Magento\Catalog\Model\ResourceModel\Category\Collection;
1412
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
1513
use Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory;
@@ -42,16 +40,6 @@ class TopmenuTest extends TestCase
4240
*/
4341
protected $storeMock;
4442

45-
/**
46-
* @var MockObject|Resolver
47-
*/
48-
protected $layerResolverMock;
49-
50-
/**
51-
* @var MockObject|Layer
52-
*/
53-
protected $catalogLayerMock;
54-
5543
/**
5644
* @var MockObject|CollectionFactory
5745
*/
@@ -90,9 +78,7 @@ protected function setUp(): void
9078

9179
$this->childrenCategoryMock = $this->_getCleanMock(\Magento\Catalog\Model\Category::class);
9280
$this->categoryHelperMock = $this->_getCleanMock(Category::class);
93-
$this->catalogLayerMock = $this->_getCleanMock(Layer::class);
9481
$this->categoryMock = $this->_getCleanMock(\Magento\Catalog\Model\Category::class);
95-
$this->layerResolverMock = $this->_getCleanMock(Resolver::class);
9682
$this->storeMock = $this->_getCleanMock(Store::class);
9783
$this->storeManagerMock = $this->_getCleanMock(StoreManagerInterface::class);
9884
$this->categoryCollectionMock = $this->_getCleanMock(
@@ -103,9 +89,6 @@ protected function setUp(): void
10389
['create']
10490
);
10591

106-
$this->catalogLayerMock->expects($this->once())->method('getCurrentCategory')
107-
->willReturn($this->childrenCategoryMock);
108-
10992
$this->storeManagerMock->expects($this->atLeastOnce())->method('getStore')
11093
->willReturn($this->storeMock);
11194

@@ -114,9 +97,6 @@ protected function setUp(): void
11497
$this->categoryMock->expects($this->once())->method('getParentIds')
11598
->willReturn($categoryParentIds);
11699

117-
$this->layerResolverMock->expects($this->once())->method('get')
118-
->willReturn($this->catalogLayerMock);
119-
120100
$this->storeMock->expects($this->once())->method('getRootCategoryId')
121101
->willReturn($rootCategoryId);
122102

@@ -131,8 +111,7 @@ protected function setUp(): void
131111
[
132112
'catalogCategory' => $this->categoryHelperMock,
133113
'categoryCollectionFactory' => $this->categoryCollectionFactoryMock,
134-
'storeManager' => $this->storeManagerMock,
135-
'layerResolver' => $this->layerResolverMock,
114+
'storeManager' => $this->storeManagerMock
136115
]
137116
);
138117
}

app/code/Magento/Theme/Test/Unit/Block/Html/TopmenuTest.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,10 @@ class TopmenuTest extends TestCase
7777
private $requestMock;
7878

7979
// @codingStandardsIgnoreStart
80-
8180
/** @var string */
82-
protected $htmlWithoutCategory = <<<HTML
81+
private $navigationMenuHtml = <<<HTML
8382
<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>
8483
HTML;
85-
86-
/** @var string */
87-
protected $htmlWithCategory = <<<HTML
88-
<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>
89-
HTML;
90-
9184
// @codingStandardsIgnoreEnd
9285

9386
/**
@@ -143,7 +136,7 @@ public function testGetHtmlWithoutSelectedCategory(): void
143136

144137
$treeNode = $this->buildTree(false);
145138

146-
$transportObject = new DataObject(['html' => $this->htmlWithoutCategory]);
139+
$transportObject = new DataObject(['html' => $this->navigationMenuHtml]);
147140

148141
$this->eventManagerMock->expects($this->exactly(2))
149142
->method('dispatch')
@@ -167,7 +160,7 @@ public function testGetHtmlWithoutSelectedCategory(): void
167160
],
168161
]);
169162

170-
$this->assertEquals($this->htmlWithoutCategory, $topmenuBlock->getHtml());
163+
$this->assertEquals($this->navigationMenuHtml, $topmenuBlock->getHtml());
171164
}
172165

173166
/**
@@ -179,7 +172,7 @@ public function testGetHtmlWithSelectedCategory(): void
179172

180173
$treeNode = $this->buildTree(true);
181174

182-
$transportObject = new DataObject(['html' => $this->htmlWithCategory]);
175+
$transportObject = new DataObject(['html' => $this->navigationMenuHtml]);
183176

184177
$this->eventManagerMock->expects($this->exactly(2))
185178
->method('dispatch')
@@ -203,7 +196,7 @@ public function testGetHtmlWithSelectedCategory(): void
203196
],
204197
]);
205198

206-
$this->assertEquals($this->htmlWithCategory, $topmenuBlock->getHtml());
199+
$this->assertEquals($this->navigationMenuHtml, $topmenuBlock->getHtml());
207200
}
208201

209202
/**
@@ -236,7 +229,7 @@ public function testGetCacheKeyInfo(): void
236229
* @param bool $isCurrentItem
237230
* @return MockObject
238231
*/
239-
private function buildTree($isCurrentItem): MockObject
232+
private function buildTree(bool $isCurrentItem): MockObject
240233
{
241234
$treeMock = $this->getMockBuilder(Tree::class)
242235
->disableOriginalConstructor()

0 commit comments

Comments
 (0)