Esempio n. 1
0
 public function testisValidSuccess()
 {
     $attributeMock = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute', [], [], '', false);
     $resourceMock = $this->getMock('\\Magento\\Eav\\Model\\Entity\\AbstractEntity', [], [], '', false);
     $this->entityMock->expects($this->once())->method('getResource')->willReturn($resourceMock);
     $resourceMock->expects($this->once())->method('loadAllAttributes')->with($this->entityMock)->willReturnSelf();
     $resourceMock->expects($this->once())->method('getAttributesByCode')->willReturn([$attributeMock]);
     $backendMock = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend');
     $backendMock->expects($this->once())->method('validate')->with($this->entityMock)->willReturn(true);
     $attributeMock->expects($this->once())->method('getBackend')->willReturn($backendMock);
     $this->assertTrue($this->model->isValid($this->entityMock));
 }
 /**
  * Test method for \Magento\Eav\Model\Validator\Attribute\Backend::isValid
  *
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testIsValid()
 {
     /** @var $entity \Magento\Customer\Model\Customer */
     $entity = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\Customer')->load(1);
     $this->assertTrue($this->_model->isValid($entity));
     $this->assertEmpty($this->_model->getMessages());
     $entity->setData('email', null);
     $this->assertFalse($this->_model->isValid($entity));
     $this->assertArrayHasKey('email', $this->_model->getMessages());
     $entity->setData('firstname', null);
     $this->assertFalse($this->_model->isValid($entity));
     $this->assertArrayHasKey('email', $this->_model->getMessages());
     $this->assertArrayHasKey('firstname', $this->_model->getMessages());
 }