diff --git a/app/code/Magento/LayeredNavigation/Block/Navigation.php b/app/code/Magento/LayeredNavigation/Block/Navigation.php index 85d3dd2a2a01d..a9bfa86728c72 100644 --- a/app/code/Magento/LayeredNavigation/Block/Navigation.php +++ b/app/code/Magento/LayeredNavigation/Block/Navigation.php @@ -1,13 +1,14 @@ getLayer()->getCurrentCategory()->getDisplayMode() !== \Magento\Catalog\Model\Category::DM_PAGE + /** @var Http $request */ + $request = $this->getRequest(); + return ( + $this->getLayer()->getCurrentCategory()->getDisplayMode() !== \Magento\Catalog\Model\Category::DM_PAGE + || $request->getRouteName() === 'catalogsearch' + ) && $this->visibilityFlag->isEnabled($this->getLayer(), $this->getFilters()); } diff --git a/app/code/Magento/LayeredNavigation/Test/Unit/Block/NavigationTest.php b/app/code/Magento/LayeredNavigation/Test/Unit/Block/NavigationTest.php index f78ef1d0089e6..84f0b5c8d41f5 100644 --- a/app/code/Magento/LayeredNavigation/Test/Unit/Block/NavigationTest.php +++ b/app/code/Magento/LayeredNavigation/Test/Unit/Block/NavigationTest.php @@ -1,7 +1,7 @@ catalogLayerMock = $this->createMock(Layer::class); $this->filterListMock = $this->createMock(FilterList::class); $this->visibilityFlagMock = $this->getMockForAbstractClass(AvailabilityFlagInterface::class); + $this->requestMock = $this->getMockBuilder(Http::class) + ->disableOriginalConstructor() + ->onlyMethods(['getRouteName']) + ->getMock(); /** @var MockObject|Resolver $layerResolver */ $layerResolver = $this->getMockBuilder(Resolver::class) @@ -70,7 +80,8 @@ protected function setUp(): void [ 'layerResolver' => $layerResolver, 'filterList' => $this->filterListMock, - 'visibilityFlag' => $this->visibilityFlagMock + 'visibilityFlag' => $this->visibilityFlagMock, + '_request' => $this->requestMock ] ); $this->layoutMock = $this->getMockForAbstractClass(LayoutInterface::class); @@ -137,7 +148,7 @@ public function testCanShowBlock(): void * @return void * @dataProvider canShowBlockDataProvider */ - public function testCanShowBlockWithDifferentDisplayModes(string $mode, bool $result): void + public function testCanShowBlockWithDifferentDisplayModes(string $mode, string $routeName, bool $result): void { $filters = ['To' => 'be', 'or' => 'not', 'to' => 'be']; @@ -154,6 +165,8 @@ public function testCanShowBlockWithDifferentDisplayModes(string $mode, bool $re $category = $this->createMock(Category::class); $this->catalogLayerMock->expects($this->atLeastOnce())->method('getCurrentCategory')->willReturn($category); + $this->requestMock->expects($this->any())->method('getRouteName')->willReturn($routeName); + $category->expects($this->once())->method('getDisplayMode')->willReturn($mode); $this->assertEquals($result, $this->model->canShowBlock()); } @@ -166,14 +179,32 @@ public static function canShowBlockDataProvider(): array return [ [ Category::DM_PRODUCT, + 'catalog', true ], [ Category::DM_PAGE, + 'catalog', false ], [ Category::DM_MIXED, + 'catalog', + true + ], + [ + Category::DM_PRODUCT, + 'catalogsearch', + true + ], + [ + Category::DM_PAGE, + 'catalogsearch', + true + ], + [ + Category::DM_MIXED, + 'catalogsearch', true ], ];