Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductLinkRepositoryInterfaceTest.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Catalog\Api;
8 
11 
13 {
14  const SERVICE_NAME = 'catalogProductLinkRepositoryV1';
15  const SERVICE_VERSION = 'V1';
16  const RESOURCE_PATH = '/V1/products/';
17 
21  protected $objectManager;
22 
23  protected function setUp()
24  {
25  $this->objectManager = Bootstrap::getObjectManager();
26  }
27 
32  public function testDelete()
33  {
34  $productSku = 'simple_with_cross';
35  $linkedSku = 'simple';
36  $linkType = 'related';
37  $this->_webApiCall(
38  [
39  'rest' => [
40  'resourcePath' => self::RESOURCE_PATH . $productSku . '/links/' . $linkType . '/' . $linkedSku,
41  'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE,
42  ],
43  'soap' => [
44  'service' => self::SERVICE_NAME,
45  'serviceVersion' => self::SERVICE_VERSION,
46  'operation' => self::SERVICE_NAME . 'DeleteById',
47  ],
48  ],
49  [
50  'sku' => $productSku,
51  'type' => $linkType,
52  'linkedProductSku' => $linkedSku
53  ]
54  );
56  $linkManagement = $this->objectManager->create(\Magento\Catalog\Api\ProductLinkManagementInterface::class);
57  $linkedProducts = $linkManagement->getLinkedItemsByType($productSku, $linkType);
58  $this->assertCount(1, $linkedProducts);
60  $product = current($linkedProducts);
61  $this->assertEquals($product->getLinkedProductSku(), 'simple_with_cross_two');
62  }
63 
67  public function testSave()
68  {
69  $productSku = 'simple_with_cross';
70  $linkType = 'related';
71 
72  $serviceInfo = [
73  'rest' => [
74  'resourcePath' => self::RESOURCE_PATH . $productSku . '/links',
76  ],
77  'soap' => [
78  'service' => self::SERVICE_NAME,
79  'serviceVersion' => self::SERVICE_VERSION,
80  'operation' => self::SERVICE_NAME . 'Save',
81  ],
82  ];
83 
84  $this->_webApiCall(
85  $serviceInfo,
86  [
87  'entity' => [
88  'sku' => 'simple_with_cross',
89  'link_type' => 'related',
90  'linked_product_sku' => 'simple',
91  'linked_product_type' => 'simple',
92  'position' => 1000,
93  ]
94  ]
95  );
96 
98  $linkManagement = $this->objectManager->get(\Magento\Catalog\Api\ProductLinkManagementInterface::class);
99  $actual = $linkManagement->getLinkedItemsByType($productSku, $linkType);
100  $this->assertCount(1, $actual, 'Invalid actual linked products count');
101  $this->assertEquals(1000, $actual[0]->getPosition(), 'Product position is not updated');
102  }
103 }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)