@@ -59,6 +59,14 @@ protected function mockStoreConfig($storeId, $websiteId): void
59
59
$ this ->storeManager ->method ('getStore ' )->with ($ storeId )->willReturn ($ storeMock );
60
60
}
61
61
62
+ protected function mockCategoryConfig ($ storeId ): void
63
+ {
64
+ $ this ->configHelper
65
+ ->method ('replaceCategories ' )
66
+ ->with ($ storeId )
67
+ ->willReturn (true );
68
+ }
69
+
62
70
protected function mockGroups (): void
63
71
{
64
72
$ groupMock1 = $ this ->createMock (\Magento \Customer \Model \Group::class);
@@ -188,10 +196,13 @@ public function testGetRenderingContentReturnsExpectedFormat(): void
188
196
}
189
197
190
198
/**
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
+ *
191
202
* @throws NoSuchEntityException
192
203
* @throws LocalizedException
193
204
*/
194
- public function testRenderingContentsFormatsCategoriesAttribute (): void
205
+ public function testGetRenderingContentFormatsCategoriesAttribute (): void
195
206
{
196
207
$ storeId = 1 ;
197
208
$ websiteId = 2 ;
@@ -204,18 +215,93 @@ public function testRenderingContentsFormatsCategoriesAttribute(): void
204
215
205
216
$ this ->mockGroups ();
206
217
$ 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
+ }
207
262
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 );
208
276
$ this ->configHelper
209
- ->method ('replaceCategories ' )
277
+ ->method ('isVisualMerchEnabled ' )
210
278
->with ($ storeId )
211
279
->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 );
212
295
213
296
$ result = $ this ->facetBuilder ->getRenderingContent ($ storeId );
214
297
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 );
217
302
}
218
303
304
+
219
305
/**
220
306
* @throws NoSuchEntityException
221
307
* @throws LocalizedException
0 commit comments