CreateTest.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\InventoryApi\Test\Api\SourceRepository;
  8. use Magento\Framework\App\ResourceConnection;
  9. use Magento\Framework\Webapi\Rest\Request;
  10. use Magento\InventoryApi\Api\Data\SourceInterface;
  11. use Magento\TestFramework\Assert\AssertArrayContains;
  12. use Magento\TestFramework\Helper\Bootstrap;
  13. use Magento\TestFramework\TestCase\WebapiAbstract;
  14. class CreateTest extends WebapiAbstract
  15. {
  16. /**#@+
  17. * Service constants
  18. */
  19. const RESOURCE_PATH = '/V1/inventory/sources';
  20. const SERVICE_NAME = 'inventoryApiSourceRepositoryV1';
  21. /**#@-*/
  22. public function testCreate()
  23. {
  24. $sourceCode = 'source-code-1';
  25. $expectedData = [
  26. SourceInterface::SOURCE_CODE => 'source-code-1',
  27. SourceInterface::NAME => 'source-name-1',
  28. SourceInterface::CONTACT_NAME => 'source-contact-name',
  29. SourceInterface::EMAIL => 'source-email',
  30. SourceInterface::ENABLED => true,
  31. SourceInterface::DESCRIPTION => 'source-description',
  32. SourceInterface::LATITUDE => 11.123456,
  33. SourceInterface::LONGITUDE => 12.123456,
  34. SourceInterface::COUNTRY_ID => 'US',
  35. SourceInterface::REGION_ID => 10,
  36. SourceInterface::CITY => 'source-city',
  37. SourceInterface::STREET => 'source-street',
  38. SourceInterface::POSTCODE => 'source-postcode',
  39. SourceInterface::PHONE => 'source-phone',
  40. SourceInterface::FAX => 'source-fax',
  41. SourceInterface::USE_DEFAULT_CARRIER_CONFIG => 1,
  42. SourceInterface::CARRIER_LINKS => [],
  43. ];
  44. $serviceInfo = [
  45. 'rest' => [
  46. 'resourcePath' => self::RESOURCE_PATH,
  47. 'httpMethod' => Request::HTTP_METHOD_POST,
  48. ],
  49. 'soap' => [
  50. 'service' => self::SERVICE_NAME,
  51. 'operation' => self::SERVICE_NAME . 'Save',
  52. ],
  53. ];
  54. $this->_webApiCall($serviceInfo, ['source' => $expectedData]);
  55. AssertArrayContains::assert($expectedData, $this->getSourceDataByCode($sourceCode));
  56. }
  57. protected function tearDown()
  58. {
  59. /** @var ResourceConnection $connection */
  60. $connection = Bootstrap::getObjectManager()->get(ResourceConnection::class);
  61. $connection->getConnection()->delete($connection->getTableName('inventory_source'), [
  62. SourceInterface::NAME . ' IN (?)' => ['source-name-1'],
  63. ]);
  64. parent::tearDown();
  65. }
  66. /**
  67. * @param string $sourceCode
  68. * @return array
  69. */
  70. private function getSourceDataByCode(string $sourceCode): array
  71. {
  72. $serviceInfo = [
  73. 'rest' => [
  74. 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceCode,
  75. 'httpMethod' => Request::HTTP_METHOD_GET,
  76. ],
  77. 'soap' => [
  78. 'service' => self::SERVICE_NAME,
  79. 'operation' => self::SERVICE_NAME . 'Get',
  80. ],
  81. ];
  82. $response = (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST)
  83. ? $this->_webApiCall($serviceInfo)
  84. : $this->_webApiCall($serviceInfo, ['sourceCode' => $sourceCode]);
  85. self::assertArrayHasKey(SourceInterface::SOURCE_CODE, $response);
  86. return $response;
  87. }
  88. }