GetStockSourceLinksTest.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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\StockSourceLink;
  8. use Magento\Framework\Api\SearchCriteria;
  9. use Magento\Framework\Api\SortOrder;
  10. use Magento\Framework\Webapi\Rest\Request;
  11. use Magento\InventoryApi\Api\Data\StockSourceLinkInterface;
  12. use Magento\TestFramework\Assert\AssertArrayContains;
  13. use Magento\TestFramework\TestCase\WebapiAbstract;
  14. class GetStockSourceLinksTest extends WebapiAbstract
  15. {
  16. /**#@+
  17. * Service constants
  18. */
  19. const RESOURCE_PATH = '/V1/inventory/stock-source-links';
  20. const SERVICE_NAME = 'inventoryApiGetStockSourceLinksV1';
  21. /**#@-*/
  22. /**
  23. * @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
  24. * @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php
  25. * @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php
  26. */
  27. public function testGetList()
  28. {
  29. $requestData = [
  30. 'searchCriteria' => [
  31. SearchCriteria::FILTER_GROUPS => [
  32. [
  33. 'filters' => [
  34. [
  35. 'field' => StockSourceLinkInterface::STOCK_ID,
  36. 'value' => 10,
  37. 'condition_type' => 'eq',
  38. ],
  39. ],
  40. ],
  41. ],
  42. SearchCriteria::SORT_ORDERS => [
  43. [
  44. 'field' => StockSourceLinkInterface::SOURCE_CODE,
  45. 'direction' => SortOrder::SORT_DESC,
  46. ],
  47. ],
  48. SearchCriteria::CURRENT_PAGE => 2,
  49. SearchCriteria::PAGE_SIZE => 2,
  50. ],
  51. ];
  52. $expectedTotalCount = 4;
  53. $expectedItemsData = [
  54. [
  55. StockSourceLinkInterface::SOURCE_CODE => 'eu-2',
  56. StockSourceLinkInterface::STOCK_ID => 10,
  57. StockSourceLinkInterface::PRIORITY => 2,
  58. ],
  59. [
  60. StockSourceLinkInterface::SOURCE_CODE => 'eu-1',
  61. StockSourceLinkInterface::STOCK_ID => 10,
  62. StockSourceLinkInterface::PRIORITY => 1,
  63. ],
  64. ];
  65. $serviceInfo = [
  66. 'rest' => [
  67. 'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($requestData),
  68. 'httpMethod' => Request::HTTP_METHOD_GET,
  69. ],
  70. 'soap' => [
  71. 'service' => self::SERVICE_NAME,
  72. 'operation' => self::SERVICE_NAME . 'Execute',
  73. ],
  74. ];
  75. $response = (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST)
  76. ? $this->_webApiCall($serviceInfo)
  77. : $this->_webApiCall($serviceInfo, $requestData);
  78. AssertArrayContains::assert($requestData['searchCriteria'], $response['search_criteria']);
  79. self::assertEquals($expectedTotalCount, $response['total_count']);
  80. AssertArrayContains::assert($expectedItemsData, $response['items']);
  81. }
  82. }