diff --git a/Block/Configuration.php b/Block/Configuration.php index f788e5473..8d8be8b1d 100755 --- a/Block/Configuration.php +++ b/Block/Configuration.php @@ -27,7 +27,7 @@ public function isSearchPage(): bool if ($this->getConfigHelper()->replaceCategories() && $request->getControllerName() === 'category') { $category = $this->getCurrentCategory(); - if ($category && $category->getDisplayMode() !== 'PAGE') { + if ($category->getId() && $category->getDisplayMode() !== 'PAGE') { return true; } } @@ -125,7 +125,7 @@ public function getConfiguration() && $request->getControllerName() === 'category') { $category = $this->getCurrentCategory(); - if ($category && $category->getDisplayMode() !== 'PAGE') { + if ($category->getId() && $category->getDisplayMode() !== 'PAGE') { $category->getUrlInstance()->setStore($this->getStoreId()); if (self::IS_CATEGORY_NAVIGATION_ENABLED) { $childCategories = $this->getChildCategoryUrls($category); diff --git a/CHANGELOG.md b/CHANGELOG.md index a03b69bdb..5991e1d11 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Bug fixes - Fixed issue where missing pricing keys were not handled gracefully in the Autocomplete product template +- Fixed issue where category was not properly checked in the configuration block - thank you @benjamin-volle ## 3.16.1 diff --git a/Test/Unit/Block/ConfigurationTest.php b/Test/Unit/Block/ConfigurationTest.php new file mode 100644 index 000000000..7d6a057e5 --- /dev/null +++ b/Test/Unit/Block/ConfigurationTest.php @@ -0,0 +1,172 @@ +config = $this->createMock(ConfigHelper::class); + $this->autocompleteConfig = $this->createMock(AutocompleteHelper::class); + $this->instantSearchConfig = $this->createMock(InstantSearchHelper::class); + $this->personalizationHelper = $this->createMock(PersonalizationHelper::class); + $this->catalogSearchHelper = $this->createMock(CatalogSearchHelper::class); + $this->productHelper = $this->createMock(ProductHelper::class); + $this->currency = $this->createMock(Currency::class); + $this->format = $this->createMock(Format::class); + $this->currentProduct = $this->createMock(CurrentProduct::class); + $this->algoliaConnector = $this->createMock(AlgoliaConnector::class); + $this->urlHelper = $this->createMock(UrlHelper::class); + $this->formKey = $this->createMock(FormKey::class); + $this->httpContext = $this->createMock(HttpContext::class); + $this->coreHelper = $this->createMock(CoreHelper::class); + $this->categoryHelper = $this->createMock(CategoryHelper::class); + $this->suggestionHelper = $this->createMock(SuggestionHelper::class); + $this->landingPageHelper = $this->createMock(LandingPageHelper::class); + $this->checkoutSession = $this->createMock(CheckoutSession::class); + $this->date = $this->createMock(DateTime::class); + $this->currentCategory = $this->createMock(CurrentCategory::class); + $this->sortingTransformer = $this->createMock(SortingTransformer::class); + $this->context = $this->createMock(Context::class); + + $this->request = $this->createMock(Http::class); + $this->context->method('getRequest')->willReturn($this->request); + + $this->configurationBlock = new ConfigurationBlock( + $this->config, + $this->autocompleteConfig , + $this->instantSearchConfig , + $this->personalizationHelper , + $this->catalogSearchHelper , + $this->productHelper, + $this->currency , + $this->format , + $this->currentProduct , + $this->algoliaConnector , + $this->urlHelper , + $this->formKey , + $this->httpContext , + $this->coreHelper , + $this->categoryHelper, + $this->suggestionHelper , + $this->landingPageHelper , + $this->checkoutSession, + $this->date , + $this->currentCategory , + $this->sortingTransformer , + $this->context, + ); + } + + /** + * @dataProvider searchPageDataProvider + */ + public function testIsSearchPage($action, $categoryId, $categoryDisplayMode, $expectedResult): void + { + $this->config->method('isInstantEnabled')->willReturn(true); + $this->request->method('getFullActionName')->willReturn($action); + + $controller = explode('_', $action); + $controller = $controller[1]; + + $this->request->method('getControllerName')->willReturn($controller); + $this->config->method('replaceCategories')->willReturn(true); + + $category = $this->createMock(Category::class); + $category->method('getId')->willReturn($categoryId); + $category->method('getDisplayMode')->willReturn($categoryDisplayMode); + $this->currentCategory->method('get')->willReturn($category); + + $this->assertEquals($expectedResult, $this->configurationBlock->isSearchPage()); + } + + public static function searchPageDataProvider(): array + { + return [ + [ // true if category has an ID + 'action' => 'catalog_category_view', + 'categoryId' => 1, + 'categoryDisplayMode' => 'PRODUCT', + 'expectedResult' => true + ], + [ // false if category has no ID + 'action' => 'catalog_category_view', + 'categoryId' => null, + 'categoryDisplayMode' => 'PRODUCT', + 'expectedResult' => false + ], + [ // false if category has a PAGE as display mode + 'action' => 'catalog_category_view', + 'categoryId' => 1, + 'categoryDisplayMode' => 'PAGE', + 'expectedResult' => false + ], + [ // true if catalogsearch + 'action' => 'catalogsearch_result_index', + 'categoryId' => null, + 'categoryDisplayMode' => 'FOO', + 'expectedResult' => true + ], + [ // true if landing page + 'action' => 'algolia_landingpage_view', + 'categoryId' => null, + 'categoryDisplayMode' => 'FOO', + 'expectedResult' => true + ] + ]; + } +}