ShipmentCreateTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Service\V1;
  7. use Magento\TestFramework\TestCase\WebapiAbstract;
  8. /**
  9. * Class ShipmentCreateTest
  10. */
  11. class ShipmentCreateTest extends WebapiAbstract
  12. {
  13. const RESOURCE_PATH = '/V1/shipment';
  14. const SERVICE_READ_NAME = 'salesShipmentRepositoryV1';
  15. const SERVICE_VERSION = 'V1';
  16. /**
  17. * @var \Magento\Framework\ObjectManagerInterface
  18. */
  19. protected $objectManager;
  20. protected function setUp()
  21. {
  22. $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  23. }
  24. /**
  25. * @magentoApiDataFixture Magento/Sales/_files/order.php
  26. */
  27. public function testInvoke()
  28. {
  29. /** @var \Magento\Sales\Model\Order $order */
  30. $order = $this->objectManager->create(\Magento\Sales\Model\Order::class)->loadByIncrementId('100000001');
  31. $orderItem = current($order->getAllItems());
  32. $items = [
  33. [
  34. 'order_item_id' => $orderItem->getId(),
  35. 'qty' => $orderItem->getQtyOrdered(),
  36. 'additional_data' => null,
  37. 'description' => null,
  38. 'entity_id' => 1,
  39. 'name' => null,
  40. 'parent_id' => null,
  41. 'price' => null,
  42. 'product_id' => null,
  43. 'row_total' => null,
  44. 'sku' => 'simple',
  45. 'weight' => null,
  46. ],
  47. ];
  48. $serviceInfo = [
  49. 'rest' => [
  50. 'resourcePath' => self::RESOURCE_PATH,
  51. 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
  52. ],
  53. 'soap' => [
  54. 'service' => self::SERVICE_READ_NAME,
  55. 'serviceVersion' => self::SERVICE_VERSION,
  56. 'operation' => self::SERVICE_READ_NAME . 'save',
  57. ],
  58. ];
  59. $data = [
  60. 'order_id' => $order->getId(),
  61. 'entity_id' => null,
  62. 'store_id' => null,
  63. 'total_weight' => null,
  64. 'total_qty' => null,
  65. 'email_sent' => null,
  66. 'customer_id' => null,
  67. 'shipping_address_id' => null,
  68. 'billing_address_id' => null,
  69. 'shipment_status' => null,
  70. 'increment_id' => null,
  71. 'created_at' => null,
  72. 'updated_at' => null,
  73. 'shipping_label' => null,
  74. 'tracks' => [
  75. [
  76. 'carrier_code' => 'UPS',
  77. 'order_id' => $order->getId(),
  78. 'title' => 'ground',
  79. 'description' => null,
  80. 'track_number' => '12345678',
  81. 'parent_id' => null,
  82. 'created_at' => null,
  83. 'updated_at' => null,
  84. 'qty' => null,
  85. 'weight' => null
  86. ]
  87. ],
  88. 'items' => $items,
  89. 'comments' => [
  90. [
  91. 'comment' => 'Shipment-related comment.',
  92. 'is_customer_notified' => null,
  93. 'is_visible_on_front' => null,
  94. 'parent_id' => null
  95. ]
  96. ],
  97. ];
  98. $result = $this->_webApiCall($serviceInfo, ['entity' => $data]);
  99. $this->assertNotEmpty($result);
  100. }
  101. }