예제 #1
0
 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]]);
 }
예제 #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));
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function getCustomAttributesMetadata($dataObjectClassName = null)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getCustomAttributesMetadata');
     if (!$pluginInfo) {
         return parent::getCustomAttributesMetadata($dataObjectClassName);
     } else {
         return $this->___callPlugins('getCustomAttributesMetadata', func_get_args(), $pluginInfo);
     }
 }
예제 #4
0
 /**
  * @expectedException \Magento\Framework\Exception\InputException
  * @expectedExceptionMessage Invalid value of "" provided for the frontend_label field.
  */
 public function testSaveInputExceptionInvalidFieldValue()
 {
     $attributeMock = $this->getMock('Magento\\Catalog\\Model\\Resource\\Eav\\Attribute', ['getFrontendLabels', 'getDefaultFrontendLabel', 'getAttributeId', '__wakeup', 'setAttributeId'], [], '', false);
     $attributeMock->expects($this->once())->method('getAttributeId')->willReturn(null);
     $attributeMock->expects($this->once())->method('setAttributeId')->with(null)->willReturnSelf();
     $labelMock = $this->getMock('Magento\\Eav\\Api\\Data\\AttributeFrontendLabelInterface', [], [], '', false);
     $attributeMock->expects($this->exactly(4))->method('getFrontendLabels')->willReturn([$labelMock]);
     $attributeMock->expects($this->exactly(2))->method('getDefaultFrontendLabel')->willReturn('test');
     $labelMock->expects($this->once())->method('getStoreId')->willReturn(0);
     $labelMock->expects($this->once())->method('getLabel')->willReturn(null);
     $this->model->save($attributeMock);
 }