/** * @param $addressId * @param $isDefaultBilling * @param $isDefaultShipping * * @dataProvider getSaveDataProvider */ public function testSave($addressId, $isDefaultBilling, $isDefaultShipping) { /** @var $customer \Magento\Customer\Model\Address|\PHPUnit_Framework_MockObject_MockObject */ $customer = $this->getMock('Magento\\Customer\\Model\\Customer', ['__wakeup', 'setDefaultBilling', 'setDefaultShipping', 'save', 'load'], [], '', false); $customer->expects($this->any())->method('load')->willReturnSelf(); $this->customerFactory->expects($this->any())->method('create')->willReturn($customer); /** @var $address \Magento\Customer\Model\Address|\PHPUnit_Framework_MockObject_MockObject */ $address = $this->getMock('Magento\\Customer\\Model\\Address', ['__wakeup', 'getId', 'getEntityTypeId', 'getIsDefaultBilling', 'getIsDefaultShipping', 'hasDataChanges', 'validateBeforeSave', 'beforeSave', 'afterSave', 'isSaveAllowed'], [], '', false); $address->expects($this->once())->method('hasDataChanges')->willReturn(true); $address->expects($this->once())->method('isSaveAllowed')->willReturn(true); $address->expects($this->once())->method('validateBeforeSave'); $address->expects($this->once())->method('beforeSave'); $address->expects($this->once())->method('afterSave'); $address->expects($this->any())->method('getEntityTypeId')->willReturn('3'); $address->expects($this->any())->method('getId')->willReturn($addressId); $address->expects($this->any())->method('getIsDefaultShipping')->willReturn($isDefaultShipping); $address->expects($this->any())->method('getIsDefaultBilling')->willReturn($isDefaultBilling); if ($addressId && ($isDefaultBilling || $isDefaultShipping)) { if ($isDefaultBilling) { $customer->expects($this->once())->method('setDefaultBilling')->with($addressId); } if ($isDefaultShipping) { $customer->expects($this->once())->method('setDefaultShipping')->with($addressId); } $customer->expects($this->once())->method('save'); } else { $customer->expects($this->never())->method('setDefaultBilling'); $customer->expects($this->never())->method('setDefaultShipping'); $customer->expects($this->never())->method('save'); } $this->addressResource->setType('customer_address'); $this->addressResource->save($address); }
/** * @param $addressId * @param $isDefaultBilling * @param $isDefaultShipping * * @dataProvider getSaveDataProvider */ public function testSave($addressId, $isDefaultBilling, $isDefaultShipping) { /** @var $address \Magento\Customer\Model\Address|\PHPUnit_Framework_MockObject_MockObject */ $address = $this->getMock('Magento\\Customer\\Model\\Address', ['__wakeup', 'getId', 'getEntityTypeId', 'getIsDefaultBilling', 'getIsDefaultShipping', 'hasDataChanges', 'validateBeforeSave', 'beforeSave', 'afterSave', 'isSaveAllowed'], [], '', false); $this->entitySnapshotMock->expects($this->once())->method('isModified')->willReturn(true); $this->entityRelationCompositeMock->expects($this->once())->method('processRelations'); $address->expects($this->once())->method('isSaveAllowed')->willReturn(true); $address->expects($this->once())->method('validateBeforeSave'); $address->expects($this->once())->method('beforeSave'); $address->expects($this->once())->method('afterSave'); $address->expects($this->any())->method('getEntityTypeId')->willReturn('3'); $address->expects($this->any())->method('getId')->willReturn($addressId); $address->expects($this->any())->method('getIsDefaultShipping')->willReturn($isDefaultShipping); $address->expects($this->any())->method('getIsDefaultBilling')->willReturn($isDefaultBilling); $this->addressResource->setType('customer_address'); $this->addressResource->save($address); }