@@ -37,47 +37,6 @@ protected function setUp(): void
37
37
);
38
38
}
39
39
40
- protected function mockFacets (): void
41
- {
42
- $ this ->configHelper
43
- ->method ('getFacets ' )
44
- ->willReturn ([
45
- [FacetBuilder::FACET_KEY_ATTRIBUTE_NAME => 'brand ' , FacetBuilder::FACET_KEY_SEARCHABLE => FacetBuilder::FACET_SEARCHABLE_NOT_SEARCHABLE ],
46
- [FacetBuilder::FACET_KEY_ATTRIBUTE_NAME => 'color ' , FacetBuilder::FACET_KEY_SEARCHABLE => FacetBuilder::FACET_SEARCHABLE_SEARCHABLE ],
47
- [FacetBuilder::FACET_KEY_ATTRIBUTE_NAME => FacetBuilder::FACET_ATTRIBUTE_PRICE ]
48
- ]);
49
- }
50
-
51
- protected function mockStoreConfig ($ storeId , $ websiteId ): void
52
- {
53
- $ this ->configHelper
54
- ->method ('getAllowedCurrencies ' )
55
- ->willReturn (['EUR ' , 'USD ' ]);
56
-
57
- $ storeMock = $ this ->createMock (\Magento \Store \Api \Data \StoreInterface::class);
58
- $ storeMock ->method ('getWebsiteId ' )->willReturn ($ websiteId );
59
- $ this ->storeManager ->method ('getStore ' )->with ($ storeId )->willReturn ($ storeMock );
60
- }
61
-
62
- protected function mockCategoryConfig ($ storeId ): void
63
- {
64
- $ this ->configHelper
65
- ->method ('replaceCategories ' )
66
- ->with ($ storeId )
67
- ->willReturn (true );
68
- }
69
-
70
- protected function mockGroups (): void
71
- {
72
- $ groupMock1 = $ this ->createMock (\Magento \Customer \Model \Group::class);
73
- $ groupMock1 ->method ('getData ' )->with ('customer_group_id ' )->willReturn (1 );
74
-
75
- $ groupMock2 = $ this ->createMock (\Magento \Customer \Model \Group::class);
76
- $ groupMock2 ->method ('getData ' )->with ('customer_group_id ' )->willReturn (2 );
77
-
78
- $ this ->groupCollection ->method ('getIterator ' )->willReturn (new \ArrayIterator ([$ groupMock1 , $ groupMock2 ]));
79
- }
80
-
81
40
/**
82
41
* @throws NoSuchEntityException
83
42
* @throws LocalizedException
@@ -159,6 +118,61 @@ public function testGetAttributesForFacetingExcludesWebsites(): void
159
118
$ this ->assertNotContains ('price.USD.group_2 ' , $ result );
160
119
}
161
120
121
+
122
+ /**
123
+ * attributesForFaceting must include level0 to be selectable via renderingContent/merch rule UI
124
+ * @return void
125
+ * @throws LocalizedException
126
+ * @throws NoSuchEntityException
127
+ */
128
+ public function testGetAttributesForFacetingIncludesCategoryLevel0 (): void
129
+ {
130
+ $ storeId = 1 ;
131
+ $ this ->mockFacets ();
132
+ $ this ->mockCategoryConfig ($ storeId );
133
+ $ result = $ this ->facetBuilder ->getAttributesForFaceting ($ storeId );
134
+ $ this ->assertContains ('categories.level0 ' , $ result );
135
+ }
136
+
137
+ /**
138
+ * If category PLPs are supported then attributesForFaceting must contain category merch meta data
139
+ * @return void
140
+ * @throws LocalizedException
141
+ * @throws NoSuchEntityException
142
+ */
143
+ public function testGetAttributesForFacetingIncludesMerchMetaData (): void
144
+ {
145
+ $ storeId = 1 ;
146
+ $ this ->mockFacets ();
147
+ $ this ->mockCategoryConfig ($ storeId );
148
+
149
+ $ result = $ this ->facetBuilder ->getAttributesForFaceting ($ storeId );
150
+
151
+ $ this ->assertContains ('categories ' , $ result );
152
+ $ this ->assertContains ('categoryIds ' , $ result );
153
+ $ this ->assertNotContains ('categoryPageId ' , $ result );
154
+ }
155
+
156
+ /*
157
+ * When visual merchandising is enabled through Merchandising Studio then a searchable
158
+ * category page ID (default categoryPageId) must be added to attributesForFaceting
159
+ *
160
+ * @return void
161
+ * @throws LocalizedException
162
+ * @throws NoSuchEntityException
163
+ */
164
+ public function testGetAttributesForFacetingIncludesVisualMerchData (): void
165
+ {
166
+ $ storeId = 1 ;
167
+ $ this ->mockFacets ();
168
+ $ this ->mockCategoryConfig ($ storeId );
169
+ $ this ->mockVisualMerchEnablement ($ storeId );
170
+
171
+ $ result = $ this ->facetBuilder ->getAttributesForFaceting ($ storeId );
172
+
173
+ $ this ->assertContains ('searchable(categoryPageId) ' , $ result );
174
+ }
175
+
162
176
/**
163
177
* @throws NoSuchEntityException
164
178
* @throws LocalizedException
@@ -226,72 +240,19 @@ public function testGetRenderingContentFormatsCategoriesAttribute(): void
226
240
$ this ->assertArrayNotHasKey ('categories ' , $ values );
227
241
}
228
242
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
243
244
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
- }
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
- *
245
+ * Category merch meta data should not be included with renderingContent
267
246
* @return void
268
247
* @throws LocalizedException
269
248
* @throws NoSuchEntityException
270
249
*/
271
- public function testGetAttributesForFacetingIncludesVisualMerchData (): void
272
- {
273
- $ storeId = 1 ;
274
- $ this ->mockFacets ();
275
- $ this ->mockCategoryConfig ($ storeId );
276
- $ this ->configHelper
277
- ->method ('isVisualMerchEnabled ' )
278
- ->with ($ storeId )
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
250
public function testGetRenderingContentDoesNotIncludeMetaData (): void
291
251
{
292
252
$ storeId = 1 ;
293
253
$ this ->mockFacets ();
294
254
$ this ->mockCategoryConfig ($ storeId );
255
+ $ this ->mockVisualMerchEnablement ($ storeId );
295
256
296
257
$ result = $ this ->facetBuilder ->getRenderingContent ($ storeId );
297
258
@@ -301,7 +262,6 @@ public function testGetRenderingContentDoesNotIncludeMetaData(): void
301
262
$ this ->assertNotContains ('categoryPageId ' , $ facets );
302
263
}
303
264
304
-
305
265
/**
306
266
* @throws NoSuchEntityException
307
267
* @throws LocalizedException
@@ -361,4 +321,57 @@ public function testDecorateAttributeForFacetingHandlesFilterOnlyCorrectly(): vo
361
321
$ result = $ this ->facetBuilder ->decorateAttributeForFaceting ($ facet );
362
322
$ this ->assertEquals ('filterOnly(size) ' , $ result );
363
323
}
324
+
325
+ protected function mockFacets (): void
326
+ {
327
+ $ this ->configHelper
328
+ ->method ('getFacets ' )
329
+ ->willReturn ([
330
+ [FacetBuilder::FACET_KEY_ATTRIBUTE_NAME => 'brand ' , FacetBuilder::FACET_KEY_SEARCHABLE => FacetBuilder::FACET_SEARCHABLE_NOT_SEARCHABLE ],
331
+ [FacetBuilder::FACET_KEY_ATTRIBUTE_NAME => 'color ' , FacetBuilder::FACET_KEY_SEARCHABLE => FacetBuilder::FACET_SEARCHABLE_SEARCHABLE ],
332
+ [FacetBuilder::FACET_KEY_ATTRIBUTE_NAME => FacetBuilder::FACET_ATTRIBUTE_PRICE ]
333
+ ]);
334
+ }
335
+
336
+ protected function mockStoreConfig (int $ storeId , int $ websiteId ): void
337
+ {
338
+ $ this ->configHelper
339
+ ->method ('getAllowedCurrencies ' )
340
+ ->willReturn (['EUR ' , 'USD ' ]);
341
+
342
+ $ storeMock = $ this ->createMock (\Magento \Store \Api \Data \StoreInterface::class);
343
+ $ storeMock ->method ('getWebsiteId ' )->willReturn ($ websiteId );
344
+ $ this ->storeManager ->method ('getStore ' )->with ($ storeId )->willReturn ($ storeMock );
345
+ }
346
+
347
+ protected function mockCategoryConfig (int $ storeId ): void
348
+ {
349
+ $ this ->configHelper
350
+ ->method ('replaceCategories ' )
351
+ ->with ($ storeId )
352
+ ->willReturn (true );
353
+ }
354
+
355
+ protected function mockGroups (): void
356
+ {
357
+ $ groupMock1 = $ this ->createMock (\Magento \Customer \Model \Group::class);
358
+ $ groupMock1 ->method ('getData ' )->with ('customer_group_id ' )->willReturn (1 );
359
+
360
+ $ groupMock2 = $ this ->createMock (\Magento \Customer \Model \Group::class);
361
+ $ groupMock2 ->method ('getData ' )->with ('customer_group_id ' )->willReturn (2 );
362
+
363
+ $ this ->groupCollection ->method ('getIterator ' )->willReturn (new \ArrayIterator ([$ groupMock1 , $ groupMock2 ]));
364
+ }
365
+
366
+ protected function mockVisualMerchEnablement (int $ storeId ): void
367
+ {
368
+ $ this ->configHelper
369
+ ->method ('isVisualMerchEnabled ' )
370
+ ->with ($ storeId )
371
+ ->willReturn (true );
372
+ $ this ->configHelper
373
+ ->method ('getCategoryPageIdAttributeName ' )
374
+ ->with ($ storeId )
375
+ ->willReturn ('categoryPageId ' );
376
+ }
364
377
}
0 commit comments