Skip to content

Commit

Permalink
Merge remote-tracking branch 'local/ACP2E-1225' into PR_combine
Browse files Browse the repository at this point in the history
  • Loading branch information
o-dubovyk committed Nov 5, 2022
2 parents 4670034 + 2c2ab18 commit a31a7ea
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/code/Magento/Sales/Model/AdminOrder/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -1490,8 +1490,12 @@ public function setShippingAsBilling($flag)
$tmpAddress->unsAddressId()->unsAddressType();
$data = $tmpAddress->getData();
$data['save_in_address_book'] = 0;
$shippingAddressTmp = $this->getShippingAddress()->getData();
// Do not duplicate address (billing address will do saving too)
$this->getShippingAddress()->addData($data);
if (array_key_exists('weight', $shippingAddressTmp) && !empty($shippingAddressTmp['weight'])) {
$this->getShippingAddress()->setWeight($shippingAddressTmp['weight']);
}
}
$this->getShippingAddress()->setSameAsBilling($flag);
$this->setRecollect(true);
Expand Down
124 changes: 123 additions & 1 deletion app/code/Magento/Sales/Test/Unit/Model/AdminOrder/CreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
class CreateTest extends TestCase
{
const CUSTOMER_ID = 1;
public const CUSTOMER_ID = 1;

/**
* @var Create
Expand Down Expand Up @@ -461,4 +461,126 @@ public function testInitFromOrder()

$this->adminOrderCreate->initFromOrder($this->orderMock);
}

/**
* Test case for setShippingAsBilling
*
* @dataProvider setShippingAsBillingDataProvider
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testSetShippingAsBilling(bool $flag, array $billingData, array $shippingData): void
{
$billingAddress = $this->createPartialMock(Address::class, ['getData']);
$shippingAddress = $this->createPartialMock(
Address::class,
[
'addData',
'setSameAsBilling',
'getData',
]
);
$billingAddress->expects($this->any())
->method('getData')
->willReturn($billingData);
$shippingAddress->expects($this->any())
->method('getData')
->willReturn($shippingData);
$shippingAddress->expects($this->any())
->method('addData')
->willReturnSelf();
$shippingAddress->expects($this->any())
->method('setSameAsBilling')
->with($flag)
->willReturnSelf();
$quote = $this->getMockBuilder(Quote::class)
->disableOriginalConstructor()
->setMethods(
[
'getBillingAddress',
'getShippingAddress',
'setRecollect'
]
)
->getMock();

$quote->expects($this->any())
->method('getBillingAddress')
->willReturn($billingAddress);
$quote->expects($this->any())
->method('getShippingAddress')
->willReturn($shippingAddress);
$quote->expects($this->any())
->method('setRecollect')
->willReturn(true);
$this->sessionQuote
->method('getQuote')
->willReturn($quote);
$this->adminOrderCreate->setShippingAsBilling($flag);
}

/**
* Data provider for setShippingAsBilling function
*
* @return array
*/
public function setShippingAsBillingDataProvider(): array
{
return [
'testcase when sameAsBillingFlag is false' => [
false,
[
'quote_id' => 1,
'entity_id' => 1,
'same_as_billing' => 1,
'customer_address_id' => null,
'weight' => '0.0000',
'free_shipping' => '0'
],
[
'quote_id' => 1,
'entity_id' => 1,
'same_as_billing' => 1,
'customer_address_id' => null,
'weight' => '0.0000',
'free_shipping' => '0'
]
],
'testcase when sameAsBillingFlag is true and there is no `weight` property' => [
true,
[
'quote_id' => 1,
'entity_id' => 1,
'same_as_billing' => 1,
'customer_address_id' => null,
'free_shipping' => '0'
],
[
'quote_id' => 1,
'entity_id' => 1,
'same_as_billing' => 1,
'customer_address_id' => null,
'free_shipping' => '0'
]
],
'testcase when sameAsBillingFlag is true and there is `weight` property' => [
false,
[
'quote_id' => 1,
'entity_id' => 1,
'same_as_billing' => 1,
'customer_address_id' => null,
'weight' => '0.0000',
'free_shipping' => '1'
],
[
'quote_id' => 1,
'entity_id' => 1,
'same_as_billing' => 1,
'customer_address_id' => null,
'weight' => '8.0000',
'free_shipping' => '1'
]
]
];
}
}

0 comments on commit a31a7ea

Please sign in to comment.