|
5 | 5 | */
|
6 | 6 | namespace Magento\Sales\Model\AdminOrder;
|
7 | 7 |
|
| 8 | +use Magento\Sales\Api\OrderManagementInterface; |
8 | 9 | use Magento\TestFramework\Helper\Bootstrap;
|
9 | 10 | use Magento\Sales\Model\Order;
|
10 | 11 | use Magento\Framework\Registry;
|
@@ -423,6 +424,55 @@ public function testCreateOrderNewCustomer()
|
423 | 424 | $this->_verifyCreatedOrder($order, $shippingMethod);
|
424 | 425 | }
|
425 | 426 |
|
| 427 | + /** |
| 428 | + * Tests order creation with new customer after failed first place order action. |
| 429 | + * |
| 430 | + * @magentoDataFixture Magento/Catalog/_files/product_simple.php |
| 431 | + * @magentoDbIsolation enabled |
| 432 | + * @magentoAppIsolation enabled |
| 433 | + */ |
| 434 | + public function testCreateOrderNewCustomerWithFailedFirstPlaceOrderAction() |
| 435 | + { |
| 436 | + $productIdFromFixture = 1; |
| 437 | + $shippingMethod = 'freeshipping_freeshipping'; |
| 438 | + $paymentMethod = 'checkmo'; |
| 439 | + $shippingAddressAsBilling = 1; |
| 440 | + $customerEmail = '[email protected]'; |
| 441 | + $orderData = [ |
| 442 | + 'currency' => 'USD', |
| 443 | + 'account' => ['group_id' => '1', 'email' => $customerEmail], |
| 444 | + 'billing_address' => array_merge($this->_getValidAddressData(), ['save_in_address_book' => '1']), |
| 445 | + 'shipping_method' => $shippingMethod, |
| 446 | + 'comment' => ['customer_note' => ''], |
| 447 | + 'send_confirmation' => false, |
| 448 | + ]; |
| 449 | + $paymentData = ['method' => $paymentMethod]; |
| 450 | + |
| 451 | + $this->_preparePreconditionsForCreateOrder( |
| 452 | + $productIdFromFixture, |
| 453 | + $customerEmail, |
| 454 | + $shippingMethod, |
| 455 | + $shippingAddressAsBilling, |
| 456 | + $paymentData, |
| 457 | + $orderData, |
| 458 | + $paymentMethod |
| 459 | + ); |
| 460 | + |
| 461 | + // Emulates failing place order action |
| 462 | + $orderManagement = $this->getMockForAbstractClass(OrderManagementInterface::class); |
| 463 | + $orderManagement->method('place') |
| 464 | + ->willThrowException(new \Exception('Can\'t place order')); |
| 465 | + Bootstrap::getObjectManager()->addSharedInstance($orderManagement, OrderManagementInterface::class); |
| 466 | + try { |
| 467 | + $this->_model->createOrder(); |
| 468 | + } catch (\Exception $e) { |
| 469 | + Bootstrap::getObjectManager()->removeSharedInstance(OrderManagementInterface::class); |
| 470 | + } |
| 471 | + |
| 472 | + $order = $this->_model->createOrder(); |
| 473 | + $this->_verifyCreatedOrder($order, $shippingMethod); |
| 474 | + } |
| 475 | + |
426 | 476 | /**
|
427 | 477 | * @magentoDataFixture Magento/Catalog/_files/product_simple.php
|
428 | 478 | * @magentoDataFixture Magento/Customer/_files/customer.php
|
|
0 commit comments