diff --git a/app/code/Magento/LayeredNavigation/Block/Navigation.php b/app/code/Magento/LayeredNavigation/Block/Navigation.php index 4173469da8e42..d4709ac05426f 100644 --- a/app/code/Magento/LayeredNavigation/Block/Navigation.php +++ b/app/code/Magento/LayeredNavigation/Block/Navigation.php @@ -107,7 +107,8 @@ public function getFilters() */ public function canShowBlock() { - return $this->visibilityFlag->isEnabled($this->getLayer(), $this->getFilters()); + return $this->getLayer()->getCurrentCategory()->getDisplayMode() !== \Magento\Catalog\Model\Category::DM_PAGE + && $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 e37e58b14f027..52a711fad2b60 100644 --- a/app/code/Magento/LayeredNavigation/Test/Unit/Block/NavigationTest.php +++ b/app/code/Magento/LayeredNavigation/Test/Unit/Block/NavigationTest.php @@ -6,6 +6,8 @@ namespace Magento\LayeredNavigation\Test\Unit\Block; +use Magento\Catalog\Model\Category; + class NavigationTest extends \PHPUnit\Framework\TestCase { /** @@ -98,9 +100,62 @@ public function testCanShowBlock() ->method('isEnabled') ->with($this->catalogLayerMock, $filters) ->will($this->returnValue($enabled)); + + $category = $this->createMock(Category::class); + $this->catalogLayerMock->expects($this->atLeastOnce())->method('getCurrentCategory')->willReturn($category); + $category->expects($this->once())->method('getDisplayMode')->willReturn(Category::DM_PRODUCT); + $this->assertEquals($enabled, $this->model->canShowBlock()); } + /** + * Test canShowBlock() with different category display types. + * + * @param string $mode + * @param bool $result + * + * @dataProvider canShowBlockDataProvider + */ + public function testCanShowBlockWithDifferentDisplayModes(string $mode, bool $result) + { + $filters = ['To' => 'be', 'or' => 'not', 'to' => 'be']; + + $this->filterListMock->expects($this->atLeastOnce())->method('getFilters') + ->with($this->catalogLayerMock) + ->will($this->returnValue($filters)); + $this->assertEquals($filters, $this->model->getFilters()); + + $this->visibilityFlagMock + ->expects($this->any()) + ->method('isEnabled') + ->with($this->catalogLayerMock, $filters) + ->will($this->returnValue(true)); + + $category = $this->createMock(Category::class); + $this->catalogLayerMock->expects($this->atLeastOnce())->method('getCurrentCategory')->willReturn($category); + $category->expects($this->once())->method('getDisplayMode')->willReturn($mode); + + $this->assertEquals($result, $this->model->canShowBlock()); + } + + public function canShowBlockDataProvider() + { + return [ + [ + Category::DM_PRODUCT, + true, + ], + [ + Category::DM_PAGE, + false, + ], + [ + Category::DM_MIXED, + true, + ], + ]; + } + public function testGetClearUrl() { $this->filterListMock->expects($this->any())->method('getFilters')->will($this->returnValue([]));