/** * @param bool $isPermissionAllowed * @param array $expectedValue * @dataProvider buildOutputDataArrayWithPermissionProvider */ public function testBuildOutputDataArrayWithPermission($isPermissionAllowed, $expectedValue) { $dataObject = new \Magento\Framework\Reflection\Test\Unit\ExtensionAttributesObject(); $dataObjectType = 'Magento\\Framework\\Reflection\\Test\\Unit\\ExtensionAttributesObject'; $methodName = 'getAttrName'; $attributeName = 'attr_name'; $attributeValue = 'attrName'; $this->methodsMapProcessorMock->expects($this->once())->method('getMethodsMap')->with($dataObjectType)->will($this->returnValue([$methodName => []])); $this->methodsMapProcessorMock->expects($this->once())->method('isMethodValidForDataField')->with($dataObjectType, $methodName)->will($this->returnValue(true)); $this->fieldNamerMock->expects($this->once())->method('getFieldNameForMethodName')->with($methodName)->will($this->returnValue($attributeName)); $permissionName = 'Magento_Permission'; $this->configReaderMock->expects($this->once())->method('read')->will($this->returnValue([$dataObjectType => [$attributeName => [Converter::RESOURCE_PERMISSIONS => [$permissionName]]]])); $this->authorizationMock->expects($this->once())->method('isAllowed')->with($permissionName)->will($this->returnValue($isPermissionAllowed)); if ($isPermissionAllowed) { $this->methodsMapProcessorMock->expects($this->once())->method('getMethodReturnType')->with($dataObjectType, $methodName)->will($this->returnValue('string')); $this->typeCasterMock->expects($this->once())->method('castValueToType')->with($attributeValue, 'string')->will($this->returnValue($attributeValue)); } $value = $this->model->buildOutputDataArray($dataObject, $dataObjectType); $this->assertEquals($value, $expectedValue); }
/** * @param array $data1 * @param array $data2 * @dataProvider dataProviderForTestMergeDataObjects */ public function testMergeDataObjects($data1, $data2) { /** @var \Magento\Customer\Model\Data\Address $addressDataObject */ $firstAddressDataObject = $this->objectManager->getObject('Magento\\Customer\\Model\\Data\\Address', ['dataObjectHelper' => $this->dataObjectHelper]); /** @var \Magento\Customer\Model\Data\Region $regionDataObject */ $firstRegionDataObject = $this->objectManager->getObject('Magento\\Customer\\Model\\Data\\Region', ['dataObjectHelper' => $this->dataObjectHelper]); $firstRegionDataObject->setRegionId($data1['region']['region_id']); $firstRegionDataObject->setRegion($data1['region']['region']); if (isset($data1['id'])) { $firstAddressDataObject->setId($data1['id']); } if (isset($data1['country_id'])) { $firstAddressDataObject->setCountryId($data1['country_id']); } $firstAddressDataObject->setStreet($data1['street']); $firstAddressDataObject->setIsDefaultShipping($data1['default_shipping']); $firstAddressDataObject->setRegion($firstRegionDataObject); $secondAddressDataObject = $this->objectManager->getObject('Magento\\Customer\\Model\\Data\\Address', ['dataObjectHelper' => $this->dataObjectHelper]); /** @var \Magento\Customer\Model\Data\Region $regionDataObject */ $secondRegionDataObject = $this->objectManager->getObject('Magento\\Customer\\Model\\Data\\Region', ['dataObjectHelper' => $this->dataObjectHelper]); $secondRegionDataObject->setRegionId($data2['region']['region_id']); $secondRegionDataObject->setRegion($data2['region']['region']); if (isset($data2['id'])) { $secondAddressDataObject->setId($data2['id']); } if (isset($data2['country_id'])) { $secondAddressDataObject->setCountryId($data2['country_id']); } $secondAddressDataObject->setStreet($data2['street']); $secondAddressDataObject->setIsDefaultShipping($data2['default_shipping']); $secondAddressDataObject->setRegion($secondRegionDataObject); $this->objectProcessorMock->expects($this->once())->method('buildOutputDataArray')->with($secondAddressDataObject, get_class($firstAddressDataObject))->willReturn($data2); $this->methodsMapProcessor->expects($this->at(0))->method('getMethodReturnType')->with('Magento\\Customer\\Model\\Data\\Address', 'getStreet')->willReturn('string[]'); $this->methodsMapProcessor->expects($this->at(1))->method('getMethodReturnType')->with('Magento\\Customer\\Model\\Data\\Address', 'getRegion')->willReturn('\\Magento\\Customer\\Api\\Data\\RegionInterface'); $this->objectFactoryMock->expects($this->once())->method('create')->with('\\Magento\\Customer\\Api\\Data\\RegionInterface', [])->willReturn($secondRegionDataObject); $this->dataObjectHelper->mergeDataObjects(get_class($firstAddressDataObject), $firstAddressDataObject, $secondAddressDataObject); $this->assertSame($firstAddressDataObject->getId(), $secondAddressDataObject->getId()); $this->assertSame($firstAddressDataObject->getCountryId(), $secondAddressDataObject->getCountryId()); $this->assertSame($firstAddressDataObject->getStreet(), $secondAddressDataObject->getStreet()); $this->assertSame($firstAddressDataObject->isDefaultShipping(), $secondAddressDataObject->isDefaultShipping()); $this->assertSame($firstAddressDataObject->getRegion(), $secondAddressDataObject->getRegion()); }