Ejemplo n.º 1
0
 public function testValidate()
 {
     $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $this->assertTrue($this->_model->validate($product));
     $this->_model->getAttribute()->setIsRequired(true);
     try {
         $this->assertFalse($this->_model->validate($product));
         $this->_model->getAttribute()->setIsRequired(false);
     } catch (\Exception $e) {
         $this->_model->getAttribute()->setIsRequired(false);
         throw $e;
     }
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider validateDataProvider
  * @param bool $value
  */
 public function testValidate($value)
 {
     $attributeCode = 'attr_code';
     $attribute = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute', ['getAttributeCode', 'getIsRequired', 'isValueEmpty', 'getIsUnique', 'getEntityType', '__wakeup'], [], '', false);
     $attributeEntity = $this->getMock('\\Magento\\Framework\\Model\\ModelResource\\AbstractResourceAbstractEntity', ['checkAttributeUniqueValue']);
     $attribute->expects($this->any())->method('getAttributeCode')->will($this->returnValue($attributeCode));
     $attribute->expects($this->any())->method('getIsRequired')->will($this->returnValue(true));
     $attribute->expects($this->any())->method('isValueEmpty')->will($this->returnValue($value));
     $attribute->expects($this->any())->method('getIsUnique')->will($this->returnValue(true));
     $attribute->expects($this->any())->method('getEntityType')->will($this->returnValue($attributeEntity));
     $attributeEntity->expects($this->any())->method('checkAttributeUniqueValue')->will($this->returnValue(true));
     $this->model->setAttribute($attribute);
     $this->dataObject->setData(['attr_code' => 'attribute data']);
     $this->assertEquals(!$value, $this->model->validate($this->dataObject));
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function validate($object)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'validate');
     if (!$pluginInfo) {
         return parent::validate($object);
     } else {
         return $this->___callPlugins('validate', func_get_args(), $pluginInfo);
     }
 }