Skip to content

Commit 2f268e6

Browse files
committed
MAGE-1258 Add unit tests for adjusted faceting expectations
1 parent ae7c4d0 commit 2f268e6

File tree

1 file changed

+90
-4
lines changed

1 file changed

+90
-4
lines changed

Test/Unit/Service/Product/FacetBuilderTest.php

Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ protected function mockStoreConfig($storeId, $websiteId): void
5959
$this->storeManager->method('getStore')->with($storeId)->willReturn($storeMock);
6060
}
6161

62+
protected function mockCategoryConfig($storeId): void
63+
{
64+
$this->configHelper
65+
->method('replaceCategories')
66+
->with($storeId)
67+
->willReturn(true);
68+
}
69+
6270
protected function mockGroups(): void
6371
{
6472
$groupMock1 = $this->createMock(\Magento\Customer\Model\Group::class);
@@ -188,10 +196,13 @@ public function testGetRenderingContentReturnsExpectedFormat(): void
188196
}
189197

190198
/**
199+
* Categories must be added to renderingContent as level0
200+
* `categories` Object attribute should not be added as it is not compatible for facet render
201+
*
191202
* @throws NoSuchEntityException
192203
* @throws LocalizedException
193204
*/
194-
public function testRenderingContentsFormatsCategoriesAttribute(): void
205+
public function testGetRenderingContentFormatsCategoriesAttribute(): void
195206
{
196207
$storeId = 1;
197208
$websiteId = 2;
@@ -204,18 +215,93 @@ public function testRenderingContentsFormatsCategoriesAttribute(): void
204215

205216
$this->mockGroups();
206217
$this->mockStoreConfig($storeId, $websiteId);
218+
$this->mockCategoryConfig($storeId);
219+
220+
$result = $this->facetBuilder->getRenderingContent($storeId);
221+
222+
$this->assertContains('categories.level0', $result['facetOrdering']['facets']['order']);
223+
224+
$values = $result['facetOrdering']['values'];
225+
$this->assertArrayHasKey('categories.level0', $values);
226+
$this->assertArrayNotHasKey('categories', $values);
227+
}
228+
229+
/**
230+
* attributesForFaceting must include level0 to be selectable via renderingContent/merch rule UI
231+
* @return void
232+
* @throws LocalizedException
233+
* @throws NoSuchEntityException
234+
*/
235+
public function testGetAttributesForFacetingIncludesCategoryLevel0(): void
236+
{
237+
$storeId = 1;
238+
$this->mockFacets();
239+
$this->mockCategoryConfig($storeId);
240+
$result = $this->facetBuilder->getAttributesForFaceting($storeId);
241+
$this->assertContains('categories.level0', $result);
242+
}
243+
244+
/**
245+
* If category PLPs are supported then attributesForFaceting must contain category merch meta data
246+
* @return void
247+
* @throws LocalizedException
248+
* @throws NoSuchEntityException
249+
*/
250+
public function testGetAttributesForFacetingIncludesMerchMetaData(): void
251+
{
252+
$storeId = 1;
253+
$this->mockFacets();
254+
$this->mockCategoryConfig($storeId);
255+
256+
$result = $this->facetBuilder->getAttributesForFaceting($storeId);
257+
258+
$this->assertContains('categories', $result);
259+
$this->assertContains('categoryIds', $result);
260+
$this->assertNotContains('categoryPageId', $result);
261+
}
207262

263+
/*
264+
* When visual merchandising is enabled through Merchandising Studio then a searchable
265+
* category page ID (default categoryPageId) must be added to attributesForFaceting
266+
*
267+
* @return void
268+
* @throws LocalizedException
269+
* @throws NoSuchEntityException
270+
*/
271+
public function testGetAttributesForFacetingIncludesVisualMerchData(): void
272+
{
273+
$storeId = 1;
274+
$this->mockFacets();
275+
$this->mockCategoryConfig($storeId);
208276
$this->configHelper
209-
->method('replaceCategories')
277+
->method('isVisualMerchEnabled')
210278
->with($storeId)
211279
->willReturn(true);
280+
$this->configHelper
281+
->method('getCategoryPageIdAttributeName')
282+
->with($storeId)
283+
->willReturn('categoryPageId');
284+
285+
$result = $this->facetBuilder->getAttributesForFaceting($storeId);
286+
287+
$this->assertContains('searchable(categoryPageId)', $result);
288+
}
289+
290+
public function testGetRenderingContentDoesNotIncludeMetaData(): void
291+
{
292+
$storeId = 1;
293+
$this->mockFacets();
294+
$this->mockCategoryConfig($storeId);
212295

213296
$result = $this->facetBuilder->getRenderingContent($storeId);
214297

215-
$this->assertContains('categories.level0', $result['facetOrdering']['facets']['order']);
216-
$this->assertArrayHasKey('categories.level0', $result['facetOrdering']['values']);
298+
$facets = $result['facetOrdering']['facets']['order'];
299+
$this->assertNotContains('categories', $facets);
300+
$this->assertNotContains('categoryIds', $facets);
301+
$this->assertNotContains('categoryPageId', $facets);
217302
}
218303

304+
219305
/**
220306
* @throws NoSuchEntityException
221307
* @throws LocalizedException

0 commit comments

Comments
 (0)