21
21
use Magento \Eav \Model \ResourceModel \Entity \Attribute \Set \Collection ;
22
22
use Magento \Framework \DataObject ;
23
23
use Magento \Framework \Model \AbstractModel ;
24
- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
25
24
use Magento \Rule \Model \Condition \Product \AbstractProduct ;
26
25
use Magento \Store \Api \Data \StoreInterface ;
27
26
use Magento \Store \Model \StoreManagerInterface ;
@@ -68,17 +67,11 @@ class AbstractProductTest extends TestCase
68
67
*/
69
68
private $ productCategoryListProperty ;
70
69
71
- /**
72
- * @var ObjectManager
73
- */
74
- protected $ objectManager ;
75
-
76
70
/**
77
71
* @inheritdoc
78
72
*/
79
73
protected function setUp (): void
80
74
{
81
- $ this ->objectManager = new ObjectManager ($ this );
82
75
$ this ->_condition = $ this ->getMockForAbstractClass (
83
76
AbstractProduct::class,
84
77
[],
@@ -351,6 +344,8 @@ public function testGetMappedSqlField()
351
344
* @param bool $expectedAttrObjSourceAllOptionsParam
352
345
* @param array $expectedValueSelectOptions
353
346
* @param array $expectedValueOption
347
+ * @param array|null $options,
348
+ * @param array|null $optionsDefault
354
349
* @dataProvider prepareValueOptionsDataProvider
355
350
* @SuppressWarnings(PHPMD.NPathComplexity)
356
351
*/
@@ -361,40 +356,32 @@ public function testPrepareValueOptions(
361
356
$ attrSetCollectionOptionsArray ,
362
357
$ expectedAttrObjSourceAllOptionsParam ,
363
358
$ expectedValueSelectOptions ,
364
- $ expectedValueOption
359
+ $ expectedValueOption ,
360
+ $ options = null ,
361
+ $ optionsDefault = null
365
362
) {
366
363
foreach ($ setData as $ key => $ value ) {
367
364
$ this ->_condition ->setData ($ key , $ value );
368
365
}
369
366
370
- if ($ attributeObjectFrontendInput == 'select ' ) {
367
+ $ attributeObjectMock = $ this ->getMockBuilder (Attribute::class)
368
+ ->disableOriginalConstructor ()
369
+ ->getMock ();
370
+ if ($ attributeObjectFrontendInput == 'select ' || $ attributeObjectFrontendInput == 'multiselect ' ) {
371
371
$ attrObjectSourceMock = $ this ->verifySelectAllOptions (
372
372
$ attrObjectSourceAllOptionsValue ,
373
- $ expectedAttrObjSourceAllOptionsParam
373
+ $ expectedAttrObjSourceAllOptionsParam ,
374
+ $ options ,
375
+ $ optionsDefault
374
376
);
375
- } else {
376
- $ attrObjectSourceMock = $ this ->getMockBuilder (AbstractSource::class)
377
- ->onlyMethods (['getAllOptions ' ])
378
- ->disableOriginalConstructor ()
379
- ->getMock ();
380
- $ attrObjectSourceMock
381
- ->expects ((null === $ expectedAttrObjSourceAllOptionsParam ) ? $ this ->never () : $ this ->once ())
382
- ->method ('getAllOptions ' )
383
- ->with ($ expectedAttrObjSourceAllOptionsParam )
384
- ->willReturn ($ attrObjectSourceAllOptionsValue );
377
+ $ attributeObjectMock ->method ('getSource ' )->willReturn ($ attrObjectSourceMock );
385
378
}
386
379
387
- $ attributeObjectMock = $ this ->getMockBuilder (Attribute::class)
388
- ->addMethods (['getAllOptions ' ])
389
- ->onlyMethods (['usesSource ' , 'getFrontendInput ' , 'getSource ' ])
390
- ->disableOriginalConstructor ()
391
- ->getMock ();
392
380
$ attributeObjectMock ->method ('usesSource ' )->willReturn (true );
393
381
$ attributeObjectMock
394
382
->expects ((null === $ attributeObjectFrontendInput ) ? $ this ->never () : $ this ->once ())
395
383
->method ('getFrontendInput ' )
396
384
->willReturn ($ attributeObjectFrontendInput );
397
- $ attributeObjectMock ->method ('getSource ' )->willReturn ($ attrObjectSourceMock );
398
385
399
386
$ entityTypeMock = $ this ->getMockBuilder (Type::class)
400
387
->onlyMethods (['getId ' ])
@@ -456,7 +443,9 @@ public function testPrepareValueOptions(
456
443
*/
457
444
private function verifySelectAllOptions (
458
445
array $ attrObjectSourceAllOptionsValue ,
459
- bool $ expectedAttrObjSourceAllOptionsParam
446
+ bool $ expectedAttrObjSourceAllOptionsParam ,
447
+ array $ options ,
448
+ array $ optionsDefault
460
449
): Table {
461
450
$ collectionFactory = $ this ->getMockBuilder (CollectionFactory::class)
462
451
->addMethods (
@@ -485,35 +474,23 @@ private function verifySelectAllOptions(
485
474
]
486
475
)
487
476
->disableOriginalConstructor ()
488
- ->getMockForAbstractClass ();
489
-
490
- $ attrObjectSourceMock = $ this ->objectManager ->getObject (
491
- Table::class,
492
- [
493
- 'attrOptionCollectionFactory ' => $ collectionFactory ,
494
- 'attrOptionFactory ' => $ attrOptionFactory
495
- ]
496
- );
497
- $ attrObjectSourceMock ->setAttribute ($ abstractAttributeMock );
477
+ ->getMock ();
498
478
499
- $ storeManagerMock = $ this ->getMockForAbstractClass (StoreManagerInterface::class);
500
- $ storeMock = $ this ->getMockForAbstractClass (StoreInterface::class);
479
+ $ storeManagerMock = $ this ->getMockBuilder (StoreManagerInterface::class)-> getMock ( );
480
+ $ storeMock = $ this ->getMockBuilder (StoreInterface::class)-> getMock ( );
501
481
502
- $ this ->objectManager ->setBackwardCompatibleProperty (
503
- $ attrObjectSourceMock ,
504
- 'storeManager ' ,
505
- $ storeManagerMock
506
- );
482
+ $ attrObjectSourceMock = new Table ($ collectionFactory , $ attrOptionFactory , $ storeManagerMock );
483
+ $ attrObjectSourceMock ->setAttribute ($ abstractAttributeMock );
507
484
508
485
$ storeId = '1 ' ;
509
486
$ attributeId = '42 ' ;
510
487
511
- $ abstractAttributeMock ->expects ($ this ->any ())->method ('getStoreId ' )->willReturn (null );
488
+ $ abstractAttributeMock ->expects ($ this ->atLeastOnce ())->method ('getStoreId ' )->willReturn (null );
512
489
513
- $ storeManagerMock ->expects ($ this ->any ())->method ('getStore ' )->willReturn ($ storeMock );
514
- $ storeMock ->expects ($ this ->any ())->method ('getId ' )->willReturn ($ storeId );
490
+ $ storeManagerMock ->expects ($ this ->atLeastOnce ())->method ('getStore ' )->willReturn ($ storeMock );
491
+ $ storeMock ->expects ($ this ->atLeastOnce ())->method ('getId ' )->willReturn ($ storeId );
515
492
516
- $ abstractAttributeMock ->expects ($ this ->any ())->method ('getId ' )->willReturn ($ attributeId );
493
+ $ abstractAttributeMock ->expects ($ this ->atLeastOnce ())->method ('getId ' )->willReturn ($ attributeId );
517
494
518
495
$ collectionFactory ->expects ($ this ->once ())
519
496
->method ('create ' )
@@ -532,8 +509,6 @@ private function verifySelectAllOptions(
532
509
$ collectionFactory ->expects ($ this ->once ())
533
510
->method ('load ' )
534
511
->willReturn ($ attributeOptionCollectionMock );
535
- $ options = [['value ' => '16 ' , 'label ' => 'default sv black ' ], ['value ' => '17 ' , 'label ' => 'default sv white ' ]];
536
- $ optionsDefault = [['value ' => '16 ' , 'label ' => 'black ' ], ['value ' => '17 ' , 'label ' => 'white ' ]];
537
512
$ attributeOptionCollectionMock ->expects ($ this ->any ())
538
513
->method ('toOptionArray ' )
539
514
->willReturnMap (
@@ -640,6 +615,14 @@ public static function prepareValueOptionsDataProvider()
640
615
'value7 ' => 'Label for value 7 ' ,
641
616
'value8 ' => 'Label for value 8 ' ,
642
617
],
618
+ [
619
+ ['value ' => 'value7 ' , 'label ' => 'Label for default sv value 7 ' ],
620
+ ['value ' => 'value8 ' , 'label ' => 'Label for default sv value 8 ' ],
621
+ ],
622
+ [
623
+ ['value ' => 'value7 ' , 'label ' => 'Label for value 7 ' ],
624
+ ['value ' => 'value8 ' , 'label ' => 'Label for value 8 ' ],
625
+ ]
643
626
],
644
627
[
645
628
[],
@@ -657,6 +640,14 @@ public static function prepareValueOptionsDataProvider()
657
640
[
658
641
'valueA ' => 'Label for value A ' ,
659
642
],
643
+ [
644
+ ['value ' => 'valueA ' , 'label ' => 'Label for default sv value A ' ],
645
+ ['value ' => ['array value ' ], 'label ' => 'Label for default sv value B ' ]
646
+ ],
647
+ [
648
+ ['value ' => 'valueA ' , 'label ' => 'Label for value A ' ],
649
+ ['value ' => ['array value ' ], 'label ' => 'Label for value B ' ]
650
+ ],
660
651
],
661
652
[
662
653
[],
@@ -678,6 +669,14 @@ public static function prepareValueOptionsDataProvider()
678
669
'16 ' => 'black ' ,
679
670
'17 ' => 'white '
680
671
],
672
+ [
673
+ ['value ' => '16 ' , 'label ' => 'default sv black ' ],
674
+ ['value ' => '17 ' , 'label ' => 'default sv white ' ]
675
+ ],
676
+ [
677
+ ['value ' => '16 ' , 'label ' => 'black ' ],
678
+ ['value ' => '17 ' , 'label ' => 'white ' ]
679
+ ],
681
680
]
682
681
];
683
682
}
0 commit comments