Example #1
0
 /**
  * @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);
 }
 public function testDeleteById()
 {
     $addressId = 12;
     $customerId = 43;
     $this->address->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $addressCollection = $this->getMock('Magento\\Customer\\Model\\Resource\\Address\\Collection', [], [], '', false);
     $this->addressRegistry->expects($this->once())->method('retrieve')->with($addressId)->willReturn($this->address);
     $this->customerRegistry->expects($this->once())->method('retrieve')->with($customerId)->willReturn($this->customer);
     $this->customer->expects($this->once())->method('getAddressesCollection')->willReturn($addressCollection);
     $addressCollection->expects($this->once())->method('clear');
     $this->addressResourceModel->expects($this->once())->method('delete')->with($this->address);
     $this->addressRegistry->expects($this->once())->method('remove')->with($addressId);
     $this->assertTrue($this->repository->deleteById($addressId));
 }
Example #3
0
 public function testGetType()
 {
     $this->assertSame($this->eavConfigType, $this->addressResource->getEntityType());
 }