/** * Get items * * @param array $transaction * @dataProvider getConfigDataProvider */ public function testGetCustomAttributes($transaction) { $this->transactionStub = Transaction::factory($transaction); $fields = TransactionMap::$simpleFieldsMap; $fieldsQty = count($fields); $this->attributeValueFactoryMock->expects($this->exactly($fieldsQty))->method('create')->willReturnCallback(function () { return new AttributeValue(); }); $map = new TransactionMap($this->attributeValueFactoryMock, $this->transactionStub); /** @var AttributeValue[] $result */ $result = $map->getCustomAttributes(); $this->assertEquals($fieldsQty, count($result)); $this->assertInstanceOf(AttributeValue::class, $result[1]); $this->assertEquals($transaction['id'], $result[0]->getValue()); $this->assertEquals($transaction['paypalDetails']->paymentId, $result[4]->getValue()); $this->assertEquals($transaction['createdAt']->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT), $result[6]->getValue()); $this->assertEquals(implode(', ', $transaction['refundIds']), $result[11]->getValue()); }
public function testSetCustomAttributesAsLiterals() { $attributeCode = 'attribute2'; $attributeValue = 'attribute_value'; $attributeMock = $this->getMockBuilder('\\Magento\\Framework\\Api\\AttributeValue')->disableOriginalConstructor()->getMock(); $attributeMock->expects($this->never())->method('setAttributeCode')->with($attributeCode)->will($this->returnSelf()); $attributeMock->expects($this->never())->method('setValue')->with($attributeValue)->will($this->returnSelf()); $this->attributeValueFactoryMock->expects($this->never())->method('create')->willReturn($attributeMock); $this->model->setData(\Magento\Framework\Api\CustomAttributesDataInterface::CUSTOM_ATTRIBUTES, [$attributeCode => $attributeValue]); }
public function testPopulateWithArrayWithCustomAttributes() { $id = 5; $customAttributeCode = 'custom_attribute_code_1'; $customAttributeValue = 'custom_attribute_value_1'; $attributeMetaDataMock = $this->getMockBuilder('\\Magento\\Customer\\Api\\Data\\AttributeMetadataInterface')->getMock(); $attributeMetaDataMock->expects($this->once())->method('getAttributeCode')->willReturn($customAttributeCode); $metadataServiceMock = $this->getMockBuilder('Magento\\Customer\\Model\\Metadata\\AddressMetadata')->disableOriginalConstructor()->getMock(); $metadataServiceMock->expects($this->once())->method('getCustomAttributesMetadata')->with('Magento\\Customer\\Model\\Data\\Address')->willReturn([$attributeMetaDataMock]); /** @var \Magento\Customer\Model\Data\Address $addressDataObject */ $addressDataObject = $this->objectManager->getObject('Magento\\Customer\\Model\\Data\\Address', ['dataObjectHelper' => $this->dataObjectHelper, 'metadataService' => $metadataServiceMock, 'attributeValueFactory' => $this->attributeValueFactoryMock]); $data = ['id' => $id, CustomAttributesDataInterface::CUSTOM_ATTRIBUTES => [[AttributeInterface::ATTRIBUTE_CODE => $customAttributeCode, AttributeInterface::VALUE => $customAttributeValue]]]; $customAttribute = $this->objectManager->getObject('Magento\\Framework\\Api\\AttributeValue'); $this->attributeValueFactoryMock->expects($this->once())->method('create')->willReturn($customAttribute); $this->dataObjectHelper->populateWithArray($addressDataObject, $data, '\\Magento\\Customer\\Api\\Data\\AddressInterface'); $this->assertEquals($id, $addressDataObject->getId()); $this->assertEquals($customAttributeValue, $addressDataObject->getCustomAttribute($customAttributeCode)->getValue()); $this->assertEquals($customAttributeCode, $addressDataObject->getCustomAttribute($customAttributeCode)->getAttributeCode()); }
/** * Create mock for attribute value factory * @return void */ private function initAttributeValueFactoryMock() { $this->attributeValueFactory = $this->getMockBuilder(AttributeValueFactory::class)->disableOriginalConstructor()->setMethods(['create'])->getMock(); $attributeValue = new AttributeValue(); $this->attributeValueFactory->expects(static::once())->method('create')->willReturn($attributeValue); }