|
8 | 8 | use Magento\Catalog\Model\Product\Type;
|
9 | 9 | use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav;
|
10 | 10 | use Magento\Eav\Model\Config;
|
| 11 | +use Magento\Eav\Model\Entity\Attribute\Source\SourceInterface; |
11 | 12 | use Magento\Framework\App\RequestInterface;
|
12 | 13 | use Magento\Framework\EntityManager\EventManager;
|
13 | 14 | use Magento\Store\Model\StoreManagerInterface;
|
@@ -256,7 +257,15 @@ protected function setUp()
|
256 | 257 | $this->searchResultsMock = $this->getMockBuilder(SearchResultsInterface::class)
|
257 | 258 | ->getMockForAbstractClass();
|
258 | 259 | $this->eavAttributeMock = $this->getMockBuilder(Attribute::class)
|
259 |
| - ->setMethods(['load', 'getAttributeGroupCode', 'getApplyTo', 'getFrontendInput', 'getAttributeCode']) |
| 260 | + ->setMethods([ |
| 261 | + 'load', |
| 262 | + 'getAttributeGroupCode', |
| 263 | + 'getApplyTo', |
| 264 | + 'getFrontendInput', |
| 265 | + 'getAttributeCode', |
| 266 | + 'usesSource', |
| 267 | + 'getSource' |
| 268 | + ]) |
260 | 269 | ->disableOriginalConstructor()
|
261 | 270 | ->getMock();
|
262 | 271 | $this->productAttributeMock = $this->getMockBuilder(ProductAttributeInterface::class)
|
@@ -450,72 +459,100 @@ public function testModifyData()
|
450 | 459 | }
|
451 | 460 |
|
452 | 461 | /**
|
453 |
| - * @param int $productId |
| 462 | + * @param int|null $productId |
454 | 463 | * @param bool $productRequired
|
455 |
| - * @param string $attrValue |
| 464 | + * @param string|null $attrValue |
456 | 465 | * @param array $expected
|
457 | 466 | * @covers \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav::isProductExists
|
458 | 467 | * @covers \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav::setupAttributeMeta
|
459 | 468 | * @dataProvider setupAttributeMetaDataProvider
|
460 | 469 | */
|
461 |
| - public function testSetupAttributeMetaDefaultAttribute($productId, $productRequired, $attrValue, $expected) |
462 |
| - { |
463 |
| - $configPath = 'arguments/data/config'; |
| 470 | + public function testSetupAttributeMetaDefaultAttribute( |
| 471 | + $productId, |
| 472 | + $productRequired, |
| 473 | + $attrValue, |
| 474 | + $expected |
| 475 | + ) { |
| 476 | + $configPath = 'arguments/data/config'; |
464 | 477 | $groupCode = 'product-details';
|
465 | 478 | $sortOrder = '0';
|
| 479 | + $attributeOptions = [ |
| 480 | + ['value' => 1, 'label' => 'Int label'], |
| 481 | + ['value' => 1.5, 'label' => 'Float label'], |
| 482 | + ['value' => true, 'label' => 'Boolean label'], |
| 483 | + ['value' => 'string', 'label' => 'String label'], |
| 484 | + ['value' => ['test1', 'test2'], 'label' => 'Array label'] |
| 485 | + ]; |
| 486 | + $attributeOptionsExpected = [ |
| 487 | + ['value' => '1', 'label' => 'Int label'], |
| 488 | + ['value' => '1.5', 'label' => 'Float label'], |
| 489 | + ['value' => '1', 'label' => 'Boolean label'], |
| 490 | + ['value' => 'string', 'label' => 'String label'], |
| 491 | + ['value' => ['test1', 'test2'], 'label' => 'Array label'] |
| 492 | + ]; |
466 | 493 |
|
467 |
| - $this->productMock->expects($this->any()) |
468 |
| - ->method('getId') |
| 494 | + $this->productMock->method('getId') |
469 | 495 | ->willReturn($productId);
|
470 | 496 |
|
471 |
| - $this->productAttributeMock->expects($this->any()) |
472 |
| - ->method('getIsRequired') |
| 497 | + $this->productAttributeMock->method('getIsRequired') |
473 | 498 | ->willReturn($productRequired);
|
474 | 499 |
|
475 |
| - $this->productAttributeMock->expects($this->any()) |
476 |
| - ->method('getDefaultValue') |
| 500 | + $this->productAttributeMock->method('getDefaultValue') |
477 | 501 | ->willReturn('required_value');
|
478 | 502 |
|
479 |
| - $this->productAttributeMock->expects($this->any()) |
480 |
| - ->method('getAttributeCode') |
| 503 | + $this->productAttributeMock->method('getAttributeCode') |
481 | 504 | ->willReturn('code');
|
482 | 505 |
|
483 |
| - $this->productAttributeMock->expects($this->any()) |
484 |
| - ->method('getValue') |
| 506 | + $this->productAttributeMock->method('getValue') |
485 | 507 | ->willReturn('value');
|
486 | 508 |
|
487 | 509 | $attributeMock = $this->getMockBuilder(AttributeInterface::class)
|
488 | 510 | ->setMethods(['getValue'])
|
489 | 511 | ->disableOriginalConstructor()
|
490 | 512 | ->getMockForAbstractClass();
|
491 | 513 |
|
492 |
| - $attributeMock->expects($this->any()) |
493 |
| - ->method('getValue') |
| 514 | + $attributeMock->method('getValue') |
494 | 515 | ->willReturn($attrValue);
|
495 | 516 |
|
496 |
| - $this->productMock->expects($this->any()) |
497 |
| - ->method('getCustomAttribute') |
| 517 | + $this->productMock->method('getCustomAttribute') |
498 | 518 | ->willReturn($attributeMock);
|
| 519 | + $this->eavAttributeMock->method('usesSource') |
| 520 | + ->willReturn(true); |
| 521 | + |
| 522 | + $attributeSource = $this->getMockBuilder(SourceInterface::class) |
| 523 | + ->getMockForAbstractClass(); |
| 524 | + $attributeSource->method('getAllOptions') |
| 525 | + ->willReturn($attributeOptions); |
499 | 526 |
|
500 |
| - $this->arrayManagerMock->expects($this->any()) |
501 |
| - ->method('set') |
| 527 | + $this->eavAttributeMock->method('getSource') |
| 528 | + ->willReturn($attributeSource); |
| 529 | + |
| 530 | + $this->arrayManagerMock->method('set') |
502 | 531 | ->with(
|
503 | 532 | $configPath,
|
504 | 533 | [],
|
505 | 534 | $expected
|
506 | 535 | )
|
507 | 536 | ->willReturn($expected);
|
508 | 537 |
|
509 |
| - $this->arrayManagerMock->expects($this->any()) |
| 538 | + $this->arrayManagerMock->expects($this->once()) |
510 | 539 | ->method('merge')
|
| 540 | + ->with( |
| 541 | + $this->anything(), |
| 542 | + $this->anything(), |
| 543 | + $this->callback( |
| 544 | + function ($value) use ($attributeOptionsExpected) { |
| 545 | + return $value['options'] === $attributeOptionsExpected; |
| 546 | + } |
| 547 | + ) |
| 548 | + ) |
511 | 549 | ->willReturn($expected);
|
512 | 550 |
|
513 |
| - $this->arrayManagerMock->expects($this->any()) |
514 |
| - ->method('get') |
| 551 | + $this->arrayManagerMock->method('get') |
515 | 552 | ->willReturn([]);
|
516 | 553 |
|
517 |
| - $this->arrayManagerMock->expects($this->any()) |
518 |
| - ->method('exists'); |
| 554 | + $this->arrayManagerMock->method('exists') |
| 555 | + ->willReturn(true); |
519 | 556 |
|
520 | 557 | $this->assertEquals(
|
521 | 558 | $expected,
|
|
0 commit comments