Skip to content
2 changes: 1 addition & 1 deletion app/code/Magento/Quote/Model/QuoteManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ private function placeOrderRun($cartId, PaymentInterface $paymentMethod = null)
) {
$quote->setCustomerFirstname($billingAddress->getFirstname());
$quote->setCustomerLastname($billingAddress->getLastname());
if ($billingAddress->getMiddlename() === null) {
if ($billingAddress->getMiddlename() !== null) {
$quote->setCustomerMiddlename($billingAddress->getMiddlename());
}
}
Expand Down
62 changes: 57 additions & 5 deletions app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Magento\Framework\Lock\LockManagerInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Model\CartMutexInterface;
use Magento\Quote\Model\CustomerManagement;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\Quote\Address;
Expand Down Expand Up @@ -203,8 +204,12 @@ class QuoteManagementTest extends TestCase
private $lockManagerMock;

/**
* @inheritDoc
*
* @var CartMutexInterface
*/
private $cartMutexMock;

/**
* @inheriDoc
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function setUp(): void
Expand Down Expand Up @@ -255,6 +260,12 @@ protected function setUp(): void
'setCustomerId',
'setRemoteIp',
'setXForwardedFor',
'getCustomerFirstname',
'getCustomerLastname',
'getCustomerMiddlename',
'setCustomerFirstname',
'setCustomerLastname',
'setCustomerMiddlename'
]
)
->onlyMethods(
Expand Down Expand Up @@ -301,6 +312,9 @@ protected function setUp(): void
$this->lockManagerMock = $this->getMockBuilder(LockManagerInterface::class)
->getMockForAbstractClass();

$this->cartMutexMock = $this->getMockBuilder(CartMutexInterface::class)
->getMockForAbstractClass();

$this->model = $objectManager->getObject(
QuoteManagement::class,
[
Expand Down Expand Up @@ -838,6 +852,7 @@ public function testSubmit(): void
/**
* @dataProvider guestPlaceOrderDataProvider
* @return void
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testPlaceOrderIfCustomerIsGuest(?string $settledEmail, int $countSetAddress): void
{
Expand All @@ -846,6 +861,9 @@ public function testPlaceOrderIfCustomerIsGuest(?string $settledEmail, int $coun
$orderIncrementId = 100003332;
$orderStatus = 'status1';
$email = '[email protected]';
$firstName = 'TestFirst';
$middleName = 'TestMiddle';
$lastName = 'TestLast';

$this->quoteRepositoryMock->expects($this->once())
->method('getActive')
Expand All @@ -870,12 +888,44 @@ public function testPlaceOrderIfCustomerIsGuest(?string $settledEmail, int $coun
->with($email)
->willReturnSelf();

$addressMock = $this->createPartialMock(Address::class, ['getEmail']);
$addressMock = $this->createPartialMock(
Address::class,
[
'getEmail',
'getFirstname',
'getLastname',
'getMiddlename'
]
);
$addressMock->expects($this->exactly($countSetAddress))->method('getEmail')->willReturn($email);
$this->quoteMock->expects($this->any())->method('getBillingAddress')->with()->willReturn($addressMock);

$this->quoteMock->expects($this->once())->method('setCustomerIsGuest')->with(true)->willReturnSelf();
$this->quoteMock->expects($this->once())->method('getCustomerId')->willReturn(null);
$this->quoteMock->expects($this->once())
->method('getCustomerFirstname')
->willReturn(null);
$this->quoteMock->expects($this->once())
->method('getCustomerLastname')
->willReturn(null);
$addressMock->expects($this->once())
->method('getFirstname')
->willReturn($firstName);
$addressMock->expects($this->once())
->method('getLastname')
->willReturn($lastName);
$this->quoteMock->expects($this->once())
->method('setCustomerFirstname')
->willReturn($firstName);
$this->quoteMock->expects($this->once())
->method('setCustomerLastname')
->willReturn($lastName);
$addressMock->expects($this->exactly(2))
->method('getMiddlename')
->willReturn($middleName);
$this->quoteMock->expects($this->once())
->method('setCustomerLastname')
->willReturn($middleName);
$this->quoteMock->expects($this->once())
->method('setCustomerGroupId')
->with(GroupInterface::NOT_LOGGED_IN_ID);
Expand Down Expand Up @@ -908,7 +958,8 @@ public function testPlaceOrderIfCustomerIsGuest(?string $settledEmail, int $coun
'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock,
'addressRepository' => $this->addressRepositoryMock,
'request' => $this->requestMock,
'remoteAddress' => $this->remoteAddressMock
'remoteAddress' => $this->remoteAddressMock,
'cartMutex' => $this->cartMutexMock
]
)
->getMock();
Expand Down Expand Up @@ -990,7 +1041,8 @@ public function testPlaceOrder(): void
'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock,
'addressRepository' => $this->addressRepositoryMock,
'request' => $this->requestMock,
'remoteAddress' => $this->remoteAddressMock
'remoteAddress' => $this->remoteAddressMock,
'cartMutex' => $this->cartMutexMock
]
)
->getMock();
Expand Down