Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductRepositoryMultiStoreTest.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Catalog\Api;
8 
12 
14 {
15  const SERVICE_NAME = 'catalogProductRepositoryV1';
16  const SERVICE_VERSION = 'V1';
17  const RESOURCE_PATH = '/V1/products';
18  const STORE_CODE_FROM_FIXTURE = 'fixturestore';
19  const STORE_NAME_FROM_FIXTURE = 'Fixture Store';
20 
21  private $productData = [
22  [
23  Product::SKU => 'simple',
24  Product::NAME => 'Simple Related Product',
25  Product::TYPE_ID => 'simple',
26  Product::PRICE => 10
27  ],
28  [
29  Product::SKU => 'simple_with_cross',
30  Product::NAME => 'Simple Product With Related Product',
31  Product::TYPE_ID => 'simple',
32  Product::PRICE => 10
33  ],
34  ];
35 
41  public function testGetMultiStore()
42  {
43  $productData = $this->productData[0];
44  $nameInFixtureStore = 'Name in fixture store';
47  $store->load(self::STORE_CODE_FROM_FIXTURE);
48  $this->assertEquals(
49  self::STORE_NAME_FROM_FIXTURE,
50  $store->getName(),
51  'Precondition failed: fixture store was not created.'
52  );
53  $sku = $productData[Product::SKU];
55  $product = Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
56  $product->load($product->getIdBySku($sku));
57  $product->setName($nameInFixtureStore)->setStoreId($store->getId())->save();
58  $serviceInfo = [
59  'rest' => [
60  'resourcePath' => self::RESOURCE_PATH . '/' . $sku,
62  ],
63  'soap' => [
64  'service' => self::SERVICE_NAME,
65  'serviceVersion' => self::SERVICE_VERSION,
66  'operation' => self::SERVICE_NAME . 'get'
67  ]
68  ];
69 
70  $requestData = ['id' => $sku, 'sku' => $sku];
71  $defaultStoreResponse = $this->_webApiCall($serviceInfo, $requestData);
72  $nameInDefaultStore = 'Simple Product';
73  $this->assertEquals(
74  $nameInDefaultStore,
75  $defaultStoreResponse[Product::NAME],
76  'Product name in default store is invalid.'
77  );
78  $fixtureStoreResponse = $this->_webApiCall($serviceInfo, $requestData, null, self::STORE_CODE_FROM_FIXTURE);
79  $this->assertEquals(
80  $nameInFixtureStore,
81  $fixtureStoreResponse[Product::NAME],
82  'Product name in fixture store is invalid.'
83  );
84  }
85 
89  public static function tearDownAfterClass()
90  {
91  parent::tearDownAfterClass();
94  ->get(\Magento\Framework\Registry::class);
95 
96  $registry->unregister('isSecureArea');
97  $registry->register('isSecureArea', true);
98 
101  $store->load('fixturestore');
102  if ($store->getId()) {
103  $store->delete();
104  }
105 
106  $registry->unregister('isSecureArea');
107  $registry->register('isSecureArea', false);
108  }
109 }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)