Skip to content

Commit 370e8b3

Browse files
authored
Merge pull request #1859 from algolia/fix/MAGE-1453-category-check-block-3.18
MAGE-1453: Fixed category check in configuration block (3.18)
2 parents 938a350 + 808d7e3 commit 370e8b3

File tree

3 files changed

+178
-9
lines changed

3 files changed

+178
-9
lines changed

Block/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function isSearchPage(): bool
2727

2828
if ($this->getConfigHelper()->replaceCategories() && $request->getControllerName() === 'category') {
2929
$category = $this->getCurrentCategory();
30-
if ($category && $category->getDisplayMode() !== 'PAGE') {
30+
if ($category->getId() && $category->getDisplayMode() !== 'PAGE') {
3131
return true;
3232
}
3333
}
@@ -125,7 +125,7 @@ public function getConfiguration()
125125
&& $request->getControllerName() === 'category') {
126126
$category = $this->getCurrentCategory();
127127

128-
if ($category && $category->getDisplayMode() !== 'PAGE') {
128+
if ($category->getId() && $category->getDisplayMode() !== 'PAGE') {
129129
$category->getUrlInstance()->setStore($this->getStoreId());
130130
if (self::IS_CATEGORY_NAVIGATION_ENABLED) {
131131
$childCategories = $this->getChildCategoryUrls($category);

CHANGELOG.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@
88
- Updated unit and integration tests.
99
- `IndexOptionsBuilder::buildWithComputedIndex` now requires an index suffix
1010

11-
## 3.17.0-beta.2
12-
13-
### Bug fixes
14-
15-
- Fixed 3.17 setup:upgrade on PHP 8.4
16-
17-
## 3.17.0-beta.1
11+
## 3.17.0
1812

1913
### Features
2014
- Added an Algolia indexing cache for storing metadata to prevent extra queries. Large collections that run periodic full indexes can benefit from this cache.
@@ -32,6 +26,9 @@
3226

3327
### Bug fixes
3428
- Fixed indexing queue templates escaping.
29+
- Fixed 3.17 setup:upgrade on PHP 8.4
30+
- Fixed issue where missing pricing keys were not handled gracefully in the Autocomplete product template
31+
- Fixed issue where category was not properly checked in the configuration block - thank you @benjamin-volle
3532

3633
## 3.16.1
3734

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Test\Unit\Block;
4+
5+
use Algolia\AlgoliaSearch\Block\Configuration as ConfigurationBlock;
6+
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
7+
use Algolia\AlgoliaSearch\Helper\Configuration\AutocompleteHelper;
8+
use Algolia\AlgoliaSearch\Helper\Configuration\InstantSearchHelper;
9+
use Algolia\AlgoliaSearch\Helper\Configuration\PersonalizationHelper;
10+
use Algolia\AlgoliaSearch\Helper\Data as CoreHelper;
11+
use Algolia\AlgoliaSearch\Helper\Entity\CategoryHelper;
12+
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
13+
use Algolia\AlgoliaSearch\Helper\Entity\SuggestionHelper;
14+
use Algolia\AlgoliaSearch\Helper\LandingPageHelper;
15+
use Algolia\AlgoliaSearch\Registry\CurrentCategory;
16+
use Algolia\AlgoliaSearch\Registry\CurrentProduct;
17+
use Algolia\AlgoliaSearch\Service\AlgoliaConnector;
18+
use Algolia\AlgoliaSearch\Service\Product\SortingTransformer;
19+
use Magento\Catalog\Model\Category;
20+
use Magento\Checkout\Model\Session as CheckoutSession;
21+
use Magento\Framework\App\Http\Context as HttpContext;
22+
use Magento\Framework\App\Request\Http;
23+
use Magento\Framework\Data\Form\FormKey;
24+
use Magento\Framework\Locale\Currency;
25+
use Magento\Framework\Locale\Format;
26+
use Magento\Framework\Stdlib\DateTime\DateTime;
27+
use Magento\Framework\Url\Helper\Data as UrlHelper;
28+
use Magento\Framework\View\Element\Template\Context;
29+
use Magento\Search\Helper\Data as CatalogSearchHelper;
30+
use PHPUnit\Framework\TestCase;
31+
32+
class ConfigurationTest extends TestCase
33+
{
34+
protected ?ConfigurationBlock $configurationBlock;
35+
36+
protected ?ConfigHelper $config;
37+
protected ?AutocompleteHelper $autocompleteConfig;
38+
protected ?InstantSearchHelper $instantSearchConfig;
39+
protected ?PersonalizationHelper $personalizationHelper;
40+
protected ?CatalogSearchHelper $catalogSearchHelper;
41+
protected ?ProductHelper $productHelper;
42+
protected ?Currency $currency;
43+
protected ?Format $format;
44+
protected ?CurrentProduct $currentProduct;
45+
protected ?AlgoliaConnector $algoliaConnector;
46+
protected ?UrlHelper $urlHelper;
47+
protected ?FormKey $formKey;
48+
protected ?HttpContext $httpContext;
49+
protected ?CoreHelper $coreHelper;
50+
protected ?CategoryHelper $categoryHelper;
51+
protected ?SuggestionHelper $suggestionHelper;
52+
protected ?LandingPageHelper $landingPageHelper;
53+
protected ?CheckoutSession $checkoutSession;
54+
protected ?DateTime $date;
55+
protected ?CurrentCategory $currentCategory;
56+
protected ?SortingTransformer $sortingTransformer;
57+
protected ?Context $context;
58+
59+
protected ?Http $request;
60+
61+
protected function setUp(): void
62+
{
63+
$this->config = $this->createMock(ConfigHelper::class);
64+
$this->autocompleteConfig = $this->createMock(AutocompleteHelper::class);
65+
$this->instantSearchConfig = $this->createMock(InstantSearchHelper::class);
66+
$this->personalizationHelper = $this->createMock(PersonalizationHelper::class);
67+
$this->catalogSearchHelper = $this->createMock(CatalogSearchHelper::class);
68+
$this->productHelper = $this->createMock(ProductHelper::class);
69+
$this->currency = $this->createMock(Currency::class);
70+
$this->format = $this->createMock(Format::class);
71+
$this->currentProduct = $this->createMock(CurrentProduct::class);
72+
$this->algoliaConnector = $this->createMock(AlgoliaConnector::class);
73+
$this->urlHelper = $this->createMock(UrlHelper::class);
74+
$this->formKey = $this->createMock(FormKey::class);
75+
$this->httpContext = $this->createMock(HttpContext::class);
76+
$this->coreHelper = $this->createMock(CoreHelper::class);
77+
$this->categoryHelper = $this->createMock(CategoryHelper::class);
78+
$this->suggestionHelper = $this->createMock(SuggestionHelper::class);
79+
$this->landingPageHelper = $this->createMock(LandingPageHelper::class);
80+
$this->checkoutSession = $this->createMock(CheckoutSession::class);
81+
$this->date = $this->createMock(DateTime::class);
82+
$this->currentCategory = $this->createMock(CurrentCategory::class);
83+
$this->sortingTransformer = $this->createMock(SortingTransformer::class);
84+
$this->context = $this->createMock(Context::class);
85+
86+
$this->request = $this->createMock(Http::class);
87+
$this->context->method('getRequest')->willReturn($this->request);
88+
89+
$this->configurationBlock = new ConfigurationBlock(
90+
$this->config,
91+
$this->autocompleteConfig ,
92+
$this->instantSearchConfig ,
93+
$this->personalizationHelper ,
94+
$this->catalogSearchHelper ,
95+
$this->productHelper,
96+
$this->currency ,
97+
$this->format ,
98+
$this->currentProduct ,
99+
$this->algoliaConnector ,
100+
$this->urlHelper ,
101+
$this->formKey ,
102+
$this->httpContext ,
103+
$this->coreHelper ,
104+
$this->categoryHelper,
105+
$this->suggestionHelper ,
106+
$this->landingPageHelper ,
107+
$this->checkoutSession,
108+
$this->date ,
109+
$this->currentCategory ,
110+
$this->sortingTransformer ,
111+
$this->context,
112+
);
113+
}
114+
115+
/**
116+
* @dataProvider searchPageDataProvider
117+
*/
118+
public function testIsSearchPage($action, $categoryId, $categoryDisplayMode, $expectedResult): void
119+
{
120+
$this->config->method('isInstantEnabled')->willReturn(true);
121+
$this->request->method('getFullActionName')->willReturn($action);
122+
123+
$controller = explode('_', $action);
124+
$controller = $controller[1];
125+
126+
$this->request->method('getControllerName')->willReturn($controller);
127+
$this->config->method('replaceCategories')->willReturn(true);
128+
129+
$category = $this->createMock(Category::class);
130+
$category->method('getId')->willReturn($categoryId);
131+
$category->method('getDisplayMode')->willReturn($categoryDisplayMode);
132+
$this->currentCategory->method('get')->willReturn($category);
133+
134+
$this->assertEquals($expectedResult, $this->configurationBlock->isSearchPage());
135+
}
136+
137+
public static function searchPageDataProvider(): array
138+
{
139+
return [
140+
[ // true if category has an ID
141+
'action' => 'catalog_category_view',
142+
'categoryId' => 1,
143+
'categoryDisplayMode' => 'PRODUCT',
144+
'expectedResult' => true
145+
],
146+
[ // false if category has no ID
147+
'action' => 'catalog_category_view',
148+
'categoryId' => null,
149+
'categoryDisplayMode' => 'PRODUCT',
150+
'expectedResult' => false
151+
],
152+
[ // false if category has a PAGE as display mode
153+
'action' => 'catalog_category_view',
154+
'categoryId' => 1,
155+
'categoryDisplayMode' => 'PAGE',
156+
'expectedResult' => false
157+
],
158+
[ // true if catalogsearch
159+
'action' => 'catalogsearch_result_index',
160+
'categoryId' => null,
161+
'categoryDisplayMode' => 'FOO',
162+
'expectedResult' => true
163+
],
164+
[ // true if landing page
165+
'action' => 'algolia_landingpage_view',
166+
'categoryId' => null,
167+
'categoryDisplayMode' => 'FOO',
168+
'expectedResult' => true
169+
]
170+
];
171+
}
172+
}

0 commit comments

Comments
 (0)