ProductLinkManagementTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\GroupedProduct\Api;
  8. /**
  9. * @magentoAppIsolation enabled
  10. */
  11. class ProductLinkManagementTest extends \Magento\TestFramework\TestCase\WebapiAbstract
  12. {
  13. const SERVICE_NAME = 'catalogProductLinkManagementV1';
  14. const SERVICE_VERSION = 'V1';
  15. const RESOURCE_PATH = '/V1/products/';
  16. /**
  17. * @magentoApiDataFixture Magento/GroupedProduct/_files/product_grouped.php
  18. */
  19. public function testGetLinkedItemsByType()
  20. {
  21. $productSku = 'grouped-product';
  22. $linkType = 'associated';
  23. $serviceInfo = [
  24. 'rest' => [
  25. 'resourcePath' => self::RESOURCE_PATH . $productSku . '/links/' . $linkType,
  26. 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
  27. ],
  28. 'soap' => [
  29. 'service' => self::SERVICE_NAME,
  30. 'serviceVersion' => self::SERVICE_VERSION,
  31. 'operation' => self::SERVICE_NAME . 'GetLinkedItemsByType',
  32. ],
  33. ];
  34. $actual = $this->_webApiCall($serviceInfo, ['sku' => $productSku, 'type' => $linkType]);
  35. $expected = [
  36. [
  37. 'sku' => 'grouped-product',
  38. 'link_type' => 'associated',
  39. 'linked_product_sku' => 'simple',
  40. 'linked_product_type' => 'simple',
  41. 'position' => 1,
  42. 'extension_attributes' => ['qty' => 1]
  43. ],
  44. [
  45. 'sku' => 'grouped-product',
  46. 'link_type' => 'associated',
  47. 'linked_product_sku' => 'virtual-product',
  48. 'linked_product_type' => 'virtual',
  49. 'position' => 2,
  50. 'extension_attributes' => ['qty' => 2]
  51. ],
  52. ];
  53. $this->assertEquals($expected, $actual);
  54. }
  55. }