public function testAddMediaDataToProduct()
 {
     $attribute = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute::class)->disableOriginalConstructor()->getMock();
     $attribute->expects($this->any())->method('getAttributeCode')->will($this->returnValue('image'));
     $this->attributeRepository->expects($this->once())->method('get')->with('media_gallery')->willReturn($attribute);
     $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)->disableOriginalConstructor()->getMock();
     $product->expects($this->once())->method('setData')->with('image', ['images' => [10 => ['value_id' => 10]], 'values' => []]);
     $this->model->addMediaDataToProduct($product, [['value_id' => 10]]);
 }
Example #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\\ResourceModel\\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->attributeRepository->expects($this->once())->method('get')->with('media_gallery')->willReturn($attribute);
     $this->dataObject->setData(['attr_code' => 'attribute data']);
     $this->assertEquals(!$value, $this->model->validate($this->dataObject));
 }