1
1
<?php
2
2
/**
3
- * Copyright 2011 Adobe
4
- * All Rights Reserved .
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details .
5
5
*/
6
6
declare (strict_types=1 );
7
7
11
11
use Magento \Catalog \Model \ResourceModel \Eav \Attribute ;
12
12
use Magento \Catalog \Model \ResourceModel \Product ;
13
13
use Magento \Eav \Model \Config ;
14
- use Magento \Eav \Model \Entity \Attribute \AbstractAttribute ;
15
- use Magento \Eav \Model \Entity \Attribute \Source \Table ;
14
+ use Magento \Eav \Model \Entity \Attribute \Source \AbstractSource ;
16
15
use Magento \Eav \Model \Entity \Type ;
17
- use Magento \Eav \Model \ResourceModel \Entity \Attribute \Option \Collection as AttributeOptionCollection ;
18
- use Magento \Eav \Model \ResourceModel \Entity \Attribute \Option \CollectionFactory ;
19
- use Magento \Eav \Model \ResourceModel \Entity \Attribute \OptionFactory ;
20
16
use Magento \Eav \Model \ResourceModel \Entity \Attribute \Set \Collection ;
21
17
use Magento \Framework \DataObject ;
22
18
use Magento \Framework \Model \AbstractModel ;
23
19
use Magento \Rule \Model \Condition \Product \AbstractProduct ;
24
- use Magento \Store \Api \Data \StoreInterface ;
25
- use Magento \Store \Model \StoreManagerInterface ;
26
20
use PHPUnit \Framework \MockObject \MockObject ;
27
21
use PHPUnit \Framework \TestCase ;
28
22
@@ -343,8 +337,6 @@ public function testGetMappedSqlField()
343
337
* @param bool $expectedAttrObjSourceAllOptionsParam
344
338
* @param array $expectedValueSelectOptions
345
339
* @param array $expectedValueOption
346
- * @param array|null $options,
347
- * @param array|null $optionsDefault
348
340
* @dataProvider prepareValueOptionsDataProvider
349
341
* @SuppressWarnings(PHPMD.NPathComplexity)
350
342
*/
@@ -355,32 +347,33 @@ public function testPrepareValueOptions(
355
347
$ attrSetCollectionOptionsArray ,
356
348
$ expectedAttrObjSourceAllOptionsParam ,
357
349
$ expectedValueSelectOptions ,
358
- $ expectedValueOption ,
359
- $ options = null ,
360
- $ optionsDefault = null
350
+ $ expectedValueOption
361
351
) {
362
352
foreach ($ setData as $ key => $ value ) {
363
353
$ this ->_condition ->setData ($ key , $ value );
364
354
}
365
355
366
- $ attributeObjectMock = $ this ->getMockBuilder (Attribute::class)
356
+ $ attrObjectSourceMock = $ this ->getMockBuilder (AbstractSource::class)
357
+ ->onlyMethods (['getAllOptions ' ])
367
358
->disableOriginalConstructor ()
368
359
->getMock ();
369
- if ($ attributeObjectFrontendInput == 'select ' || $ attributeObjectFrontendInput == 'multiselect ' ) {
370
- $ attrObjectSourceMock = $ this ->verifySelectAllOptions (
371
- $ attrObjectSourceAllOptionsValue ,
372
- $ expectedAttrObjSourceAllOptionsParam ,
373
- $ options ,
374
- $ optionsDefault
375
- );
376
- $ attributeObjectMock ->method ('getSource ' )->willReturn ($ attrObjectSourceMock );
377
- }
360
+ $ attrObjectSourceMock
361
+ ->expects ((null === $ expectedAttrObjSourceAllOptionsParam ) ? $ this ->never () : $ this ->once ())
362
+ ->method ('getAllOptions ' )
363
+ ->with ($ expectedAttrObjSourceAllOptionsParam , true )
364
+ ->willReturn ($ attrObjectSourceAllOptionsValue );
378
365
366
+ $ attributeObjectMock = $ this ->getMockBuilder (Attribute::class)
367
+ ->addMethods (['getAllOptions ' ])
368
+ ->onlyMethods (['usesSource ' , 'getFrontendInput ' , 'getSource ' ])
369
+ ->disableOriginalConstructor ()
370
+ ->getMock ();
379
371
$ attributeObjectMock ->method ('usesSource ' )->willReturn (true );
380
372
$ attributeObjectMock
381
373
->expects ((null === $ attributeObjectFrontendInput ) ? $ this ->never () : $ this ->once ())
382
374
->method ('getFrontendInput ' )
383
375
->willReturn ($ attributeObjectFrontendInput );
376
+ $ attributeObjectMock ->method ('getSource ' )->willReturn ($ attrObjectSourceMock );
384
377
385
378
$ entityTypeMock = $ this ->getMockBuilder (Type::class)
386
379
->onlyMethods (['getId ' ])
@@ -433,86 +426,6 @@ public function testPrepareValueOptions(
433
426
$ this ->assertEquals ($ expectedValueOption , $ this ->_condition ->getData ('value_option ' ));
434
427
}
435
428
436
- /**
437
- * Test to verify all select value options
438
- *
439
- * @param array $attrObjectSourceAllOptionsValue
440
- * @param bool $expectedAttrObjSourceAllOptionsParam
441
- * @return Table
442
- */
443
- private function verifySelectAllOptions (
444
- array $ attrObjectSourceAllOptionsValue ,
445
- bool $ expectedAttrObjSourceAllOptionsParam ,
446
- array $ options ,
447
- array $ optionsDefault
448
- ): Table {
449
- $ collectionFactory = $ this ->getMockBuilder (CollectionFactory::class)
450
- ->onlyMethods (['create ' ])
451
- ->disableOriginalConstructor ()
452
- ->getMock ();
453
-
454
- $ attributeOptionCollectionMock = $ this ->getMockBuilder (AttributeOptionCollection::class)
455
- ->onlyMethods ([
456
- 'setPositionOrder ' , 'setAttributeFilter ' , 'addFieldToFilter ' ,
457
- 'setStoreFilter ' , 'load ' , 'toOptionArray '
458
- ])
459
- ->disableOriginalConstructor ()
460
- ->getMock ();
461
-
462
- $ storeId = '1 ' ;
463
- $ storeManagerMock = $ this ->getMockBuilder (StoreManagerInterface::class)->getMock ();
464
- $ storeMock = $ this ->getMockBuilder (StoreInterface::class)->getMock ();
465
- $ storeMock ->expects ($ this ->atLeastOnce ())->method ('getId ' )->willReturn ($ storeId );
466
- $ storeManagerMock ->expects ($ this ->atLeastOnce ())->method ('getStore ' )->willReturn ($ storeMock );
467
- $ attrOptionFactory = $ this ->createPartialMock (OptionFactory::class, ['create ' ]);
468
-
469
- $ attributeId = '42 ' ;
470
- $ abstractAttributeMock = $ this ->getMockBuilder (AbstractAttribute::class)
471
- ->addMethods (['getStoreId ' ])
472
- ->onlyMethods (
473
- [
474
- 'getFrontend ' , 'getAttributeCode ' , '__wakeup ' ,
475
- 'getId ' , 'getIsRequired ' , 'getEntity ' , 'getBackend '
476
- ]
477
- )
478
- ->disableOriginalConstructor ()
479
- ->getMock ();
480
- $ abstractAttributeMock ->expects ($ this ->atLeastOnce ())->method ('getStoreId ' )->willReturn (null );
481
- $ abstractAttributeMock ->expects ($ this ->atLeastOnce ())->method ('getId ' )->willReturn ($ attributeId );
482
-
483
- $ collectionFactory ->expects ($ this ->once ())
484
- ->method ('create ' )
485
- ->willReturn ($ attributeOptionCollectionMock );
486
- $ attributeOptionCollectionMock ->expects ($ this ->once ())
487
- ->method ('setPositionOrder ' )
488
- ->willReturnSelf ();
489
- $ attributeOptionCollectionMock ->expects ($ this ->once ())
490
- ->method ('setAttributeFilter ' )
491
- ->with ($ attributeId )
492
- ->willReturnSelf ();
493
- $ attributeOptionCollectionMock ->expects ($ this ->once ())
494
- ->method ('setStoreFilter ' )
495
- ->with ($ storeId )
496
- ->willReturnSelf ();
497
- $ attributeOptionCollectionMock ->expects ($ this ->once ())
498
- ->method ('load ' )
499
- ->willReturnSelf ();
500
- $ attributeOptionCollectionMock ->expects ($ this ->any ())
501
- ->method ('toOptionArray ' )
502
- ->willReturnMap (
503
- [
504
- ['value ' , $ options ],
505
- ['default_value ' , $ optionsDefault ]
506
- ]
507
- );
508
-
509
- $ attrObjectSourceMock = new Table ($ collectionFactory , $ attrOptionFactory , $ storeManagerMock );
510
- $ attrObjectSourceMock ->setAttribute ($ abstractAttributeMock );
511
- $ allOptionsValue = $ attrObjectSourceMock ->getAllOptions ($ expectedAttrObjSourceAllOptionsParam , true );
512
- $ this ->assertEquals ($ attrObjectSourceAllOptionsValue , $ allOptionsValue );
513
- return $ attrObjectSourceMock ;
514
- }
515
-
516
429
/**
517
430
* Data provider for prepare value options
518
431
*
@@ -605,14 +518,6 @@ public static function prepareValueOptionsDataProvider()
605
518
'value7 ' => 'Label for value 7 ' ,
606
519
'value8 ' => 'Label for value 8 ' ,
607
520
],
608
- [
609
- ['value ' => 'value7 ' , 'label ' => 'Label for default sv value 7 ' ],
610
- ['value ' => 'value8 ' , 'label ' => 'Label for default sv value 8 ' ],
611
- ],
612
- [
613
- ['value ' => 'value7 ' , 'label ' => 'Label for value 7 ' ],
614
- ['value ' => 'value8 ' , 'label ' => 'Label for value 8 ' ],
615
- ]
616
521
],
617
522
[
618
523
[],
@@ -630,43 +535,27 @@ public static function prepareValueOptionsDataProvider()
630
535
[
631
536
'valueA ' => 'Label for value A ' ,
632
537
],
633
- [
634
- ['value ' => 'valueA ' , 'label ' => 'Label for default sv value A ' ],
635
- ['value ' => ['array value ' ], 'label ' => 'Label for default sv value B ' ]
636
- ],
637
- [
638
- ['value ' => 'valueA ' , 'label ' => 'Label for value A ' ],
639
- ['value ' => ['array value ' ], 'label ' => 'Label for value B ' ]
640
- ],
641
538
],
642
539
[
643
540
[],
644
541
'select ' ,
645
542
[
646
- ['value ' => '' , 'label ' => ' ' ],
647
543
['value ' => 'value7 ' , 'label ' => 'Label for value 7 ' ],
648
544
['value ' => 'value8 ' , 'label ' => 'Label for value 8 ' ],
545
+ ['value ' => 'default ' , 'label ' => 'Default Option ' ]
649
546
],
650
547
null ,
651
548
true ,
652
549
[
653
- ['value ' => '' , 'label ' => ' ' ],
654
550
['value ' => 'value7 ' , 'label ' => 'Label for value 7 ' ],
655
551
['value ' => 'value8 ' , 'label ' => 'Label for value 8 ' ],
552
+ ['value ' => 'default ' , 'label ' => 'Default Option ' ]
656
553
],
657
554
[
658
- '' => ' ' ,
659
555
'value7 ' => 'Label for value 7 ' ,
660
556
'value8 ' => 'Label for value 8 ' ,
557
+ 'default ' => 'Default Option '
661
558
],
662
- [
663
- ['value ' => 'value7 ' , 'label ' => 'Label for default sv value 7 ' ],
664
- ['value ' => 'value8 ' , 'label ' => 'Label for default sv value 8 ' ],
665
- ],
666
- [
667
- ['value ' => 'value7 ' , 'label ' => 'Label for value 7 ' ],
668
- ['value ' => 'value8 ' , 'label ' => 'Label for value 8 ' ],
669
- ]
670
559
]
671
560
];
672
561
}
0 commit comments