21 $this->customerFactoryMock = $this->createPartialMock(
25 $this->relation = (
new ObjectManagerHelper($this))->getObject(
36 public function testDeleteRelation($addressId, $isDefaultBilling, $isDefaultShipping)
39 $addressModel = $this->getMockBuilder(\
Magento\Framework\Model\AbstractModel::class)
40 ->disableOriginalConstructor()
41 ->setMethods([
'getIsCustomerSaveTransaction',
'getId',
'getResource'])
44 $customerModel = $this->getMockBuilder(\
Magento\
Customer\Model\Customer::class)
45 ->disableOriginalConstructor()
46 ->setMethods([
'getDefaultBilling',
'getDefaultShipping',
'getId'])
49 $addressResource = $this->getMockForAbstractClass(
56 [
'getConnection',
'getTable']
58 $connectionMock = $this->getMockForAbstractClass(
59 \
Magento\Framework\DB\Adapter\AdapterInterface::class,
65 [
'update',
'quoteInto']
67 $addressModel->expects($this->any())->method(
'getResource')->willReturn($addressResource);
68 $addressModel->expects($this->any())->method(
'getId')->willReturn($addressId);
69 $addressModel->expects($this->any())->method(
'getIsCustomerSaveTransaction')->willReturn(
false);
71 $customerModel->expects($this->any())->method(
"getDefaultBilling")->willReturn($isDefaultBilling);
72 $customerModel->expects($this->any())->method(
"getDefaultShipping")->willReturn($isDefaultShipping);
74 if ($addressId && ($isDefaultBilling || $isDefaultShipping)) {
76 $addressResource->expects($this->exactly(2))->method(
'getConnection')->willReturn($connectionMock);
77 $customerModel->expects($this->any())->method(
'getId')->willReturn(1);
78 $conditionSql =
"entity_id = $customerId";
79 $connectionMock->expects($this->once())->method(
'quoteInto')
81 ->willReturn($conditionSql);
82 $addressResource->expects($this->once())->method(
'getTable')
83 ->with(
'customer_entity')
84 ->willReturn(
'customer_entity');
86 if ($isDefaultBilling) {
87 $toUpdate[
'default_billing'] =
null;
89 if ($isDefaultShipping) {
90 $toUpdate[
'default_shipping'] =
null;
92 $connectionMock->expects($this->once())->method(
'update')->with(
98 $result = $this->relation->deleteRelation($addressModel, $customerModel);
getRelationDataProvider()