11
11
use Magento \Catalog \Model \ResourceModel \Eav \Attribute ;
12
12
use Magento \CatalogSearch \Model \Indexer \Fulltext \Action \DataProvider ;
13
13
use Magento \Eav \Api \Data \AttributeOptionInterface ;
14
+ use Magento \Eav \Model \Entity \Attribute \Source \SourceInterface ;
14
15
use Magento \Elasticsearch \Model \Adapter \BatchDataMapper \ProductDataMapper ;
15
16
use Magento \Elasticsearch \Model \Adapter \Document \Builder ;
16
17
use Magento \Elasticsearch \Model \Adapter \FieldMapperInterface ;
@@ -199,11 +200,17 @@ public function testGetMapWithOptions()
199
200
*/
200
201
private function getAttribute (array $ attributeData ): MockObject
201
202
{
202
- $ attributeMock = $ this ->createMock (Attribute::class);
203
- $ attributeMock ->method ('getAttributeCode ' )->willReturn ($ attributeData ['code ' ]);
204
- $ attributeMock ->method ('getBackendType ' )->willReturn ($ attributeData ['backendType ' ]);
205
- $ attributeMock ->method ('getFrontendInput ' )->willReturn ($ attributeData ['frontendInput ' ]);
206
- $ attributeMock ->method ('getIsSearchable ' )->willReturn ($ attributeData ['is_searchable ' ]);
203
+ $ attributeMock = $ this ->createPartialMock (
204
+ Attribute::class,
205
+ [
206
+ 'getSource ' ,
207
+ 'getOptions ' ,
208
+ ]
209
+ );
210
+
211
+ $ sourceMock = $ this ->createMock (SourceInterface::class);
212
+ $ attributeMock ->method ('getSource ' )->willReturn ($ sourceMock );
213
+ $ sourceMock ->method ('getAllOptions ' )->willReturn ($ attributeData ['options ' ] ?? []);
207
214
$ options = [];
208
215
foreach ($ attributeData ['options ' ] as $ option ) {
209
216
$ optionMock = $ this ->getMockForAbstractClass (AttributeOptionInterface::class);
@@ -212,6 +219,8 @@ private function getAttribute(array $attributeData): MockObject
212
219
$ options [] = $ optionMock ;
213
220
}
214
221
$ attributeMock ->method ('getOptions ' )->willReturn ($ options );
222
+ unset($ attributeData ['options ' ]);
223
+ $ attributeMock ->setData ($ attributeData );
215
224
216
225
return $ attributeMock ;
217
226
}
@@ -226,9 +235,9 @@ public static function mapProvider(): array
226
235
'text ' => [
227
236
10 ,
228
237
[
229
- 'code ' => 'description ' ,
230
- 'backendType ' => 'text ' ,
231
- 'frontendInput ' => 'text ' ,
238
+ 'attribute_code ' => 'description ' ,
239
+ 'backend_type ' => 'text ' ,
240
+ 'frontend_input ' => 'text ' ,
232
241
'is_searchable ' => false ,
233
242
'options ' => [],
234
243
],
@@ -238,9 +247,9 @@ public static function mapProvider(): array
238
247
'datetime ' => [
239
248
10 ,
240
249
[
241
- 'code ' => 'created_at ' ,
242
- 'backendType ' => 'datetime ' ,
243
- 'frontendInput ' => 'date ' ,
250
+ 'attribute_code ' => 'created_at ' ,
251
+ 'backend_type ' => 'datetime ' ,
252
+ 'frontend_input ' => 'date ' ,
244
253
'is_searchable ' => false ,
245
254
'options ' => [],
246
255
],
@@ -251,9 +260,9 @@ public static function mapProvider(): array
251
260
'array single value ' => [
252
261
10 ,
253
262
[
254
- 'code ' => 'attribute_array ' ,
255
- 'backendType ' => 'text ' ,
256
- 'frontendInput ' => 'text ' ,
263
+ 'attribute_code ' => 'attribute_array ' ,
264
+ 'backend_type ' => 'text ' ,
265
+ 'frontend_input ' => 'text ' ,
257
266
'is_searchable ' => false ,
258
267
'options ' => [],
259
268
],
@@ -263,9 +272,9 @@ public static function mapProvider(): array
263
272
'array multiple value ' => [
264
273
10 ,
265
274
[
266
- 'code ' => 'attribute_array ' ,
267
- 'backendType ' => 'text ' ,
268
- 'frontendInput ' => 'text ' ,
275
+ 'attribute_code ' => 'attribute_array ' ,
276
+ 'backend_type ' => 'text ' ,
277
+ 'frontend_input ' => 'text ' ,
269
278
'is_searchable ' => false ,
270
279
'options ' => [],
271
280
],
@@ -275,9 +284,9 @@ public static function mapProvider(): array
275
284
'array multiple decimal value ' => [
276
285
10 ,
277
286
[
278
- 'code ' => 'decimal_array ' ,
279
- 'backendType ' => 'decimal ' ,
280
- 'frontendInput ' => 'text ' ,
287
+ 'attribute_code ' => 'decimal_array ' ,
288
+ 'backend_type ' => 'decimal ' ,
289
+ 'frontend_input ' => 'text ' ,
281
290
'is_searchable ' => false ,
282
291
'options ' => [],
283
292
],
@@ -287,9 +296,9 @@ public static function mapProvider(): array
287
296
'array excluded from merge ' => [
288
297
10 ,
289
298
[
290
- 'code ' => 'status ' ,
291
- 'backendType ' => 'int ' ,
292
- 'frontendInput ' => 'select ' ,
299
+ 'attribute_code ' => 'status ' ,
300
+ 'backend_type ' => 'int ' ,
301
+ 'frontend_input ' => 'select ' ,
293
302
'is_searchable ' => false ,
294
303
'options ' => [
295
304
['value ' => '1 ' , 'label ' => 'Enabled ' ],
@@ -302,9 +311,9 @@ public static function mapProvider(): array
302
311
'select without options ' => [
303
312
10 ,
304
313
[
305
- 'code ' => 'color ' ,
306
- 'backendType ' => 'text ' ,
307
- 'frontendInput ' => 'select ' ,
314
+ 'attribute_code ' => 'color ' ,
315
+ 'backend_type ' => 'text ' ,
316
+ 'frontend_input ' => 'select ' ,
308
317
'is_searchable ' => false ,
309
318
'options ' => [],
310
319
],
@@ -314,9 +323,9 @@ public static function mapProvider(): array
314
323
'unsearchable select with options ' => [
315
324
10 ,
316
325
[
317
- 'code ' => 'color ' ,
318
- 'backendType ' => 'text ' ,
319
- 'frontendInput ' => 'select ' ,
326
+ 'attribute_code ' => 'color ' ,
327
+ 'backend_type ' => 'text ' ,
328
+ 'frontend_input ' => 'select ' ,
320
329
'is_searchable ' => false ,
321
330
'options ' => [
322
331
['value ' => '44 ' , 'label ' => 'red ' ],
@@ -329,9 +338,9 @@ public static function mapProvider(): array
329
338
'searchable select with options ' => [
330
339
10 ,
331
340
[
332
- 'code ' => 'color ' ,
333
- 'backendType ' => 'text ' ,
334
- 'frontendInput ' => 'select ' ,
341
+ 'attribute_code ' => 'color ' ,
342
+ 'backend_type ' => 'text ' ,
343
+ 'frontend_input ' => 'select ' ,
335
344
'is_searchable ' => true ,
336
345
'options ' => [
337
346
['value ' => '44 ' , 'label ' => 'red ' ],
@@ -344,9 +353,9 @@ public static function mapProvider(): array
344
353
'composite select with options ' => [
345
354
10 ,
346
355
[
347
- 'code ' => 'color ' ,
348
- 'backendType ' => 'text ' ,
349
- 'frontendInput ' => 'select ' ,
356
+ 'attribute_code ' => 'color ' ,
357
+ 'backend_type ' => 'text ' ,
358
+ 'frontend_input ' => 'select ' ,
350
359
'is_searchable ' => true ,
351
360
'options ' => [
352
361
['value ' => '44 ' , 'label ' => 'red ' ],
@@ -359,9 +368,9 @@ public static function mapProvider(): array
359
368
'multiselect without options ' => [
360
369
10 ,
361
370
[
362
- 'code ' => 'multicolor ' ,
363
- 'backendType ' => 'text ' ,
364
- 'frontendInput ' => 'multiselect ' ,
371
+ 'attribute_code ' => 'multicolor ' ,
372
+ 'backend_type ' => 'text ' ,
373
+ 'frontend_input ' => 'multiselect ' ,
365
374
'is_searchable ' => false ,
366
375
'options ' => [],
367
376
],
@@ -371,9 +380,9 @@ public static function mapProvider(): array
371
380
'unsearchable multiselect with options ' => [
372
381
10 ,
373
382
[
374
- 'code ' => 'multicolor ' ,
375
- 'backendType ' => 'text ' ,
376
- 'frontendInput ' => 'multiselect ' ,
383
+ 'attribute_code ' => 'multicolor ' ,
384
+ 'backend_type ' => 'text ' ,
385
+ 'frontend_input ' => 'multiselect ' ,
377
386
'is_searchable ' => false ,
378
387
'options ' => [
379
388
['value ' => '44 ' , 'label ' => 'red ' ],
@@ -386,9 +395,9 @@ public static function mapProvider(): array
386
395
'searchable multiselect with options ' => [
387
396
10 ,
388
397
[
389
- 'code ' => 'multicolor ' ,
390
- 'backendType ' => 'text ' ,
391
- 'frontendInput ' => 'multiselect ' ,
398
+ 'attribute_code ' => 'multicolor ' ,
399
+ 'backend_type ' => 'text ' ,
400
+ 'frontend_input ' => 'multiselect ' ,
392
401
'is_searchable ' => true ,
393
402
'options ' => [
394
403
['value ' => '44 ' , 'label ' => 'red ' ],
@@ -401,9 +410,9 @@ public static function mapProvider(): array
401
410
'composite multiselect with options ' => [
402
411
10 ,
403
412
[
404
- 'code ' => 'multicolor ' ,
405
- 'backendType ' => 'text ' ,
406
- 'frontendInput ' => 'multiselect ' ,
413
+ 'attribute_code ' => 'multicolor ' ,
414
+ 'backend_type ' => 'text ' ,
415
+ 'frontend_input ' => 'multiselect ' ,
407
416
'is_searchable ' => true ,
408
417
'options ' => [
409
418
['value ' => '44 ' , 'label ' => 'red ' ],
@@ -417,9 +426,9 @@ public static function mapProvider(): array
417
426
'excluded attribute ' => [
418
427
10 ,
419
428
[
420
- 'code ' => 'price ' ,
421
- 'backendType ' => 'int ' ,
422
- 'frontendInput ' => 'int ' ,
429
+ 'attribute_code ' => 'price ' ,
430
+ 'backend_type ' => 'int ' ,
431
+ 'frontend_input ' => 'int ' ,
423
432
'is_searchable ' => false ,
424
433
'options ' => []
425
434
],
0 commit comments