8
8
use Magento \Catalog \Api \Data \ProductAttributeInterface ;
9
9
use Magento \Catalog \Api \ProductAttributeGroupRepositoryInterface ;
10
10
use Magento \Catalog \Api \ProductAttributeRepositoryInterface ;
11
+ use Magento \Eav \Model \Entity \Attribute \Source \SourceInterface ;
11
12
use Magento \Catalog \Model \ResourceModel \Eav \Attribute ;
12
13
use Magento \Catalog \Model \ResourceModel \Eav \Attribute as EavAttribute ;
13
14
use Magento \Catalog \Model \ResourceModel \Eav \AttributeFactory as EavAttributeFactory ;
@@ -254,7 +255,15 @@ protected function setUp()
254
255
$ this ->searchResultsMock = $ this ->getMockBuilder (SearchResultsInterface::class)
255
256
->getMockForAbstractClass ();
256
257
$ this ->eavAttributeMock = $ this ->getMockBuilder (Attribute::class)
257
- ->setMethods (['load ' , 'getAttributeGroupCode ' , 'getApplyTo ' , 'getFrontendInput ' , 'getAttributeCode ' ])
258
+ ->setMethods ([
259
+ 'load ' ,
260
+ 'getAttributeGroupCode ' ,
261
+ 'getApplyTo ' ,
262
+ 'getFrontendInput ' ,
263
+ 'getAttributeCode ' ,
264
+ 'usesSource ' ,
265
+ 'getSource ' ,
266
+ ])
258
267
->disableOriginalConstructor ()
259
268
->getMock ();
260
269
$ this ->productAttributeMock = $ this ->getMockBuilder (ProductAttributeInterface::class)
@@ -460,6 +469,20 @@ public function testSetupAttributeMetaDefaultAttribute($productId, array $attrib
460
469
$ configPath = 'arguments/data/config ' ;
461
470
$ groupCode = 'product-details ' ;
462
471
$ sortOrder = '0 ' ;
472
+ $ attributeOptions = [
473
+ ['value ' => 1 , 'label ' => 'Int label ' ],
474
+ ['value ' => 1.5 , 'label ' => 'Float label ' ],
475
+ ['value ' => true , 'label ' => 'Boolean label ' ],
476
+ ['value ' => 'string ' , 'label ' => 'String label ' ],
477
+ ['value ' => ['test1 ' , 'test2 ' ], 'label ' => 'Array label ' ],
478
+ ];
479
+ $ attributeOptionsExpected = [
480
+ ['value ' => '1 ' , 'label ' => 'Int label ' , '__disableTmpl ' => true ],
481
+ ['value ' => '1.5 ' , 'label ' => 'Float label ' , '__disableTmpl ' => true ],
482
+ ['value ' => '1 ' , 'label ' => 'Boolean label ' , '__disableTmpl ' => true ],
483
+ ['value ' => 'string ' , 'label ' => 'String label ' , '__disableTmpl ' => true ],
484
+ ['value ' => ['test1 ' , 'test2 ' ], 'label ' => 'Array label ' , '__disableTmpl ' => true ],
485
+ ];
463
486
464
487
$ this ->productMock ->expects ($ this ->any ())
465
488
->method ('getId ' )
@@ -491,6 +514,11 @@ public function testSetupAttributeMetaDefaultAttribute($productId, array $attrib
491
514
->method ('getCustomAttribute ' )
492
515
->willReturn ($ attributeMock );
493
516
517
+ $ this ->eavAttributeMock ->method ('usesSource ' )->willReturn (true );
518
+ $ attributeSource = $ this ->getMockBuilder (SourceInterface::class)->getMockForAbstractClass ();
519
+ $ attributeSource ->method ('getAllOptions ' )->willReturn ($ attributeOptions );
520
+ $ this ->eavAttributeMock ->method ('getSource ' )->willReturn ($ attributeSource );
521
+
494
522
$ this ->arrayManagerMock ->expects ($ this ->any ())
495
523
->method ('set ' )
496
524
->with (
@@ -502,6 +530,15 @@ public function testSetupAttributeMetaDefaultAttribute($productId, array $attrib
502
530
503
531
$ this ->arrayManagerMock ->expects ($ this ->any ())
504
532
->method ('merge ' )
533
+ ->with (
534
+ $ this ->anything (),
535
+ $ this ->anything (),
536
+ $ this ->callback (
537
+ function ($ value ) use ($ attributeOptionsExpected ) {
538
+ return isset ($ value ['options ' ]) ? $ value ['options ' ] === $ attributeOptionsExpected : true ;
539
+ }
540
+ )
541
+ )
505
542
->willReturn ($ expected );
506
543
507
544
$ this ->arrayManagerMock ->expects ($ this ->any ())
0 commit comments