Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductLinkRepositoryTest.php
Go to the documentation of this file.
1 <?php
8 
10 
12 {
13  const SERVICE_NAME = 'catalogProductLinkRepositoryV1';
14  const SERVICE_VERSION = 'V1';
15  const RESOURCE_PATH = '/V1/products/';
16 
20  protected $objectManager;
21 
22  protected function setUp()
23  {
24  $this->objectManager = Bootstrap::getObjectManager();
25  }
26 
31  public function testSave()
32  {
33  $productSku = 'grouped-product';
34  $linkType = 'associated';
35  $productData = [
36  'sku' => $productSku,
37  'link_type' => $linkType,
38  'linked_product_type' => 'simple',
39  'linked_product_sku' => 'simple-1',
40  'position' => 3,
41  'extension_attributes' => [
42  'qty' => (float) 300.0000,
43  ],
44  ];
45 
46  $serviceInfo = [
47  'rest' => [
48  'resourcePath' => self::RESOURCE_PATH . $productSku . '/links',
50  ],
51  'soap' => [
52  'service' => self::SERVICE_NAME,
53  'serviceVersion' => self::SERVICE_VERSION,
54  'operation' => self::SERVICE_NAME . 'Save',
55  ],
56  ];
57  $this->_webApiCall($serviceInfo, ['entity' => $productData]);
58 
60  $linkManagement = $this->objectManager->get(\Magento\Catalog\Api\ProductLinkManagementInterface::class);
61  $actual = $linkManagement->getLinkedItemsByType($productSku, $linkType);
62  array_walk($actual, function (&$item) {
63  $item = $item->__toArray();
64  });
65  $this->assertEquals($productData, $actual[2]);
66  }
67 }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
$productData