Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Block/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 4 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@
- Updated unit and integration tests.
- `IndexOptionsBuilder::buildWithComputedIndex` now requires an index suffix

## 3.17.0-beta.2

### Bug fixes

- Fixed 3.17 setup:upgrade on PHP 8.4

## 3.17.0-beta.1
## 3.17.0

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

### Bug fixes
- Fixed indexing queue templates escaping.
- Fixed 3.17 setup:upgrade on PHP 8.4
- 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

Expand Down
172 changes: 172 additions & 0 deletions Test/Unit/Block/ConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<?php

namespace Algolia\AlgoliaSearch\Test\Unit\Block;

use Algolia\AlgoliaSearch\Block\Configuration as ConfigurationBlock;
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
use Algolia\AlgoliaSearch\Helper\Configuration\AutocompleteHelper;
use Algolia\AlgoliaSearch\Helper\Configuration\InstantSearchHelper;
use Algolia\AlgoliaSearch\Helper\Configuration\PersonalizationHelper;
use Algolia\AlgoliaSearch\Helper\Data as CoreHelper;
use Algolia\AlgoliaSearch\Helper\Entity\CategoryHelper;
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
use Algolia\AlgoliaSearch\Helper\Entity\SuggestionHelper;
use Algolia\AlgoliaSearch\Helper\LandingPageHelper;
use Algolia\AlgoliaSearch\Registry\CurrentCategory;
use Algolia\AlgoliaSearch\Registry\CurrentProduct;
use Algolia\AlgoliaSearch\Service\AlgoliaConnector;
use Algolia\AlgoliaSearch\Service\Product\SortingTransformer;
use Magento\Catalog\Model\Category;
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Framework\App\Http\Context as HttpContext;
use Magento\Framework\App\Request\Http;
use Magento\Framework\Data\Form\FormKey;
use Magento\Framework\Locale\Currency;
use Magento\Framework\Locale\Format;
use Magento\Framework\Stdlib\DateTime\DateTime;
use Magento\Framework\Url\Helper\Data as UrlHelper;
use Magento\Framework\View\Element\Template\Context;
use Magento\Search\Helper\Data as CatalogSearchHelper;
use PHPUnit\Framework\TestCase;

class ConfigurationTest extends TestCase
{
protected ?ConfigurationBlock $configurationBlock;

protected ?ConfigHelper $config;
protected ?AutocompleteHelper $autocompleteConfig;
protected ?InstantSearchHelper $instantSearchConfig;
protected ?PersonalizationHelper $personalizationHelper;
protected ?CatalogSearchHelper $catalogSearchHelper;
protected ?ProductHelper $productHelper;
protected ?Currency $currency;
protected ?Format $format;
protected ?CurrentProduct $currentProduct;
protected ?AlgoliaConnector $algoliaConnector;
protected ?UrlHelper $urlHelper;
protected ?FormKey $formKey;
protected ?HttpContext $httpContext;
protected ?CoreHelper $coreHelper;
protected ?CategoryHelper $categoryHelper;
protected ?SuggestionHelper $suggestionHelper;
protected ?LandingPageHelper $landingPageHelper;
protected ?CheckoutSession $checkoutSession;
protected ?DateTime $date;
protected ?CurrentCategory $currentCategory;
protected ?SortingTransformer $sortingTransformer;
protected ?Context $context;

protected ?Http $request;

protected function setUp(): void
{
$this->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
]
];
}
}