|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
6 | 6 |
|
| 7 | +declare(strict_types=1); |
| 8 | + |
7 | 9 | namespace Magento\Sales\Service\V1;
|
8 | 10 |
|
| 11 | +use Magento\Framework\ObjectManagerInterface; |
| 12 | +use Magento\Framework\Webapi\Rest\Request; |
| 13 | +use Magento\Sales\Api\Data\OrderInterface; |
| 14 | +use Magento\Sales\Api\OrderRepositoryInterface; |
| 15 | +use Magento\Sales\Model\Order; |
| 16 | +use Magento\TestFramework\Helper\Bootstrap; |
9 | 17 | use Magento\TestFramework\TestCase\WebapiAbstract;
|
10 | 18 |
|
| 19 | +/** |
| 20 | + * Test for hold order. |
| 21 | + */ |
11 | 22 | class OrderHoldTest extends WebapiAbstract
|
12 | 23 | {
|
13 |
| - const SERVICE_VERSION = 'V1'; |
| 24 | + private const SERVICE_VERSION = 'V1'; |
14 | 25 |
|
15 |
| - const SERVICE_NAME = 'salesOrderManagementV1'; |
| 26 | + private const SERVICE_NAME = 'salesOrderManagementV1'; |
| 27 | + |
| 28 | + /** |
| 29 | + * @var ObjectManagerInterface |
| 30 | + */ |
| 31 | + private $objectManager; |
| 32 | + |
| 33 | + /** |
| 34 | + * @var OrderRepositoryInterface |
| 35 | + */ |
| 36 | + private $orderRepository; |
| 37 | + |
| 38 | + /** |
| 39 | + * @inheritDoc |
| 40 | + */ |
| 41 | + protected function setUp(): void |
| 42 | + { |
| 43 | + $this->objectManager = Bootstrap::getObjectManager(); |
| 44 | + $this->orderRepository = $this->objectManager->get(OrderRepositoryInterface::class); |
| 45 | + } |
16 | 46 |
|
17 | 47 | /**
|
18 |
| - * @magentoApiDataFixture Magento/Sales/_files/order.php |
| 48 | + * Test hold order and check order items product options after. |
| 49 | + * |
| 50 | + * @magentoApiDataFixture Magento/Sales/_files/order_with_two_configurable_variations.php |
| 51 | + * |
| 52 | + * @return void |
19 | 53 | */
|
20 |
| - public function testOrderHold() |
| 54 | + public function testOrderHold(): void |
21 | 55 | {
|
22 |
| - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); |
23 |
| - $order = $objectManager->get(\Magento\Sales\Model\Order::class)->loadByIncrementId('100000001'); |
| 56 | + $order = $this->objectManager->get(Order::class) |
| 57 | + ->loadByIncrementId('100000001'); |
| 58 | + $orderId = $order->getId(); |
| 59 | + $orderItemsProductOptions = $this->getOrderItemsProductOptions($order); |
| 60 | + |
24 | 61 | $serviceInfo = [
|
25 | 62 | 'rest' => [
|
26 |
| - 'resourcePath' => '/V1/orders/' . $order->getId() . '/hold', |
27 |
| - 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, |
| 63 | + 'resourcePath' => '/V1/orders/' . $orderId . '/hold', |
| 64 | + 'httpMethod' => Request::HTTP_METHOD_POST, |
28 | 65 | ],
|
29 | 66 | 'soap' => [
|
30 | 67 | 'service' => self::SERVICE_NAME,
|
31 | 68 | 'serviceVersion' => self::SERVICE_VERSION,
|
32 | 69 | 'operation' => self::SERVICE_NAME . 'hold',
|
33 | 70 | ],
|
34 | 71 | ];
|
35 |
| - $requestData = ['id' => $order->getId()]; |
| 72 | + $requestData = ['id' => $orderId]; |
36 | 73 | $result = $this->_webApiCall($serviceInfo, $requestData);
|
37 | 74 | $this->assertTrue($result);
|
| 75 | + |
| 76 | + $this->assertEquals( |
| 77 | + $orderItemsProductOptions, |
| 78 | + $this->getOrderItemsProductOptions($this->orderRepository->get($orderId)) |
| 79 | + ); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Return order items product options |
| 84 | + * |
| 85 | + * @param OrderInterface $order |
| 86 | + * @return array |
| 87 | + */ |
| 88 | + private function getOrderItemsProductOptions(OrderInterface $order): array |
| 89 | + { |
| 90 | + $result = []; |
| 91 | + foreach ($order->getItems() as $orderItem) { |
| 92 | + $result[] = $orderItem->getProductOptions(); |
| 93 | + } |
| 94 | + |
| 95 | + return $result; |
38 | 96 | }
|
39 | 97 | }
|
0 commit comments