|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
6 | 6 |
|
| 7 | +namespace Magento\Eav\Test\Unit\Model\Validator\Attribute; |
| 8 | + |
7 | 9 | /**
|
8 | 10 | * Test for \Magento\Eav\Model\Validator\Attribute\Data
|
9 | 11 | */
|
10 |
| -namespace Magento\Eav\Test\Unit\Model\Validator\Attribute; |
11 |
| - |
12 | 12 | class DataTest extends \PHPUnit\Framework\TestCase
|
13 | 13 | {
|
| 14 | + /** |
| 15 | + * @var \Magento\Eav\Model\AttributeDataFactory|\PHPUnit_Framework_MockObject_MockObject |
| 16 | + */ |
| 17 | + private $attrDataFactory; |
| 18 | + |
| 19 | + /** |
| 20 | + * @var \Magento\Eav\Model\Validator\Attribute\Data |
| 21 | + */ |
| 22 | + private $model; |
| 23 | + |
| 24 | + /** |
| 25 | + * @inheritdoc |
| 26 | + */ |
| 27 | + protected function setUp() |
| 28 | + { |
| 29 | + $this->attrDataFactory = $this->getMockBuilder(\Magento\Eav\Model\AttributeDataFactory::class) |
| 30 | + ->setMethods(['create']) |
| 31 | + ->setConstructorArgs( |
| 32 | + [ |
| 33 | + 'objectManager' => $this->createMock(\Magento\Framework\ObjectManagerInterface::class), |
| 34 | + 'string' => $this->createMock(\Magento\Framework\Stdlib\StringUtils::class) |
| 35 | + ] |
| 36 | + ) |
| 37 | + ->getMock(); |
| 38 | + |
| 39 | + $this->model = new \Magento\Eav\Model\Validator\Attribute\Data( |
| 40 | + $this->attrDataFactory |
| 41 | + ); |
| 42 | + } |
| 43 | + |
14 | 44 | /**
|
15 | 45 | * Testing \Magento\Eav\Model\Validator\Attribute\Data::isValid
|
16 | 46 | *
|
@@ -381,13 +411,15 @@ public function testAddErrorMessages()
|
381 | 411 | protected function _getAttributeMock($attributeData)
|
382 | 412 | {
|
383 | 413 | $attribute = $this->getMockBuilder(\Magento\Eav\Model\Attribute::class)
|
384 |
| - ->setMethods([ |
385 |
| - 'getAttributeCode', |
386 |
| - 'getDataModel', |
387 |
| - 'getFrontendInput', |
388 |
| - '__wakeup', |
389 |
| - 'getIsVisible', |
390 |
| - ]) |
| 414 | + ->setMethods( |
| 415 | + [ |
| 416 | + 'getAttributeCode', |
| 417 | + 'getDataModel', |
| 418 | + 'getFrontendInput', |
| 419 | + '__wakeup', |
| 420 | + 'getIsVisible', |
| 421 | + ] |
| 422 | + ) |
391 | 423 | ->disableOriginalConstructor()
|
392 | 424 | ->getMock();
|
393 | 425 |
|
@@ -466,4 +498,35 @@ protected function _getEntityMock()
|
466 | 498 | )->disableOriginalConstructor()->getMock();
|
467 | 499 | return $entity;
|
468 | 500 | }
|
| 501 | + |
| 502 | + /** |
| 503 | + * Test for isValid() without data for attribute. |
| 504 | + * |
| 505 | + * @return void |
| 506 | + */ |
| 507 | + public function testIsValidWithoutData() : void |
| 508 | + { |
| 509 | + $attributeData = ['attribute_code' => 'attribute', 'frontend_input' => 'text', 'is_visible' => true]; |
| 510 | + $entity = $this->_getEntityMock(); |
| 511 | + $attribute = $this->_getAttributeMock($attributeData); |
| 512 | + $this->model->setAttributes([$attribute])->setData([]); |
| 513 | + $dataModel = $this->getMockBuilder(\Magento\Eav\Model\Attribute\Data\AbstractData::class) |
| 514 | + ->disableOriginalConstructor() |
| 515 | + ->setMethods(['validateValue']) |
| 516 | + ->getMockForAbstractClass(); |
| 517 | + $dataModel->expects($this->once()) |
| 518 | + ->method('validateValue') |
| 519 | + // only empty string |
| 520 | + ->with( |
| 521 | + $this->logicalAnd( |
| 522 | + $this->isEmpty(), |
| 523 | + $this->isType('string') |
| 524 | + ) |
| 525 | + )->willReturn(true); |
| 526 | + $this->attrDataFactory->expects($this->once()) |
| 527 | + ->method('create') |
| 528 | + ->with($attribute, $entity) |
| 529 | + ->willReturn($dataModel); |
| 530 | + $this->assertEquals(true, $this->model->isValid($entity)); |
| 531 | + } |
469 | 532 | }
|
0 commit comments