|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) |
| 4 | + */ |
| 5 | + |
| 6 | +namespace Magento\Catalog\Api; |
| 7 | + |
| 8 | +use Magento\Catalog\Api\Data\ProductInterface as Product; |
| 9 | +use Magento\TestFramework\Helper\Bootstrap; |
| 10 | +use Magento\TestFramework\TestCase\WebapiAbstract; |
| 11 | +use Magento\Webapi\Model\Rest\Config as RestConfig; |
| 12 | + |
| 13 | +class ProductRepositoryMultiStoreTest extends WebapiAbstract |
| 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 | + |
| 20 | + private $productData = [ |
| 21 | + [ |
| 22 | + Product::SKU => 'simple', |
| 23 | + Product::NAME => 'Simple Related Product', |
| 24 | + Product::TYPE_ID => 'simple', |
| 25 | + Product::PRICE => 10 |
| 26 | + ], |
| 27 | + [ |
| 28 | + Product::SKU => 'simple_with_cross', |
| 29 | + Product::NAME => 'Simple Product With Related Product', |
| 30 | + Product::TYPE_ID => 'simple', |
| 31 | + Product::PRICE => 10 |
| 32 | + ], |
| 33 | + ]; |
| 34 | + |
| 35 | + /** |
| 36 | + * Create another store one time for testSearch |
| 37 | + * @magentoApiDataFixture Magento/Core/_files/store.php |
| 38 | + */ |
| 39 | + public function testCreateAnotherStore() |
| 40 | + { |
| 41 | + /** @var $store \Magento\Store\Model\Store */ |
| 42 | + $store = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Store\Model\Store'); |
| 43 | + $store->load('fixturestore'); |
| 44 | + $this->assertNotNull($store->getId()); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php |
| 49 | + * @depends testCreateAnotherStore |
| 50 | + */ |
| 51 | + public function testGetMultiStore() |
| 52 | + { |
| 53 | + $productData = $this->productData[0]; |
| 54 | + $nameInFixtureStore = 'Name in fixture store'; |
| 55 | + /** @var $store \Magento\Store\Model\Group */ |
| 56 | + $store = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Store\Model\Group'); |
| 57 | + $store->load(self::STORE_CODE_FROM_FIXTURE); |
| 58 | + $this->assertNotNull($store->getId(), 'Precondition failed: fixture store was not created.'); |
| 59 | + $sku = $productData[Product::SKU]; |
| 60 | + /** @var \Magento\Catalog\Model\Product $product */ |
| 61 | + $product = Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product'); |
| 62 | + $product->load($product->getIdBySku($sku)); |
| 63 | + $product->setName($nameInFixtureStore)->setStoreId($store->getId())->save(); |
| 64 | + $serviceInfo = [ |
| 65 | + 'rest' => [ |
| 66 | + 'resourcePath' => self::RESOURCE_PATH . '/' . $sku, |
| 67 | + 'httpMethod' => RestConfig::HTTP_METHOD_GET |
| 68 | + ], |
| 69 | + 'soap' => [ |
| 70 | + 'service' => self::SERVICE_NAME, |
| 71 | + 'serviceVersion' => self::SERVICE_VERSION, |
| 72 | + 'operation' => self::SERVICE_NAME . 'get' |
| 73 | + ] |
| 74 | + ]; |
| 75 | + |
| 76 | + $requestData = ['id' => $sku, 'productSku' => $sku]; |
| 77 | + $defaultStoreResponse = $this->_webApiCall($serviceInfo, $requestData); |
| 78 | + $nameInDefaultStore = 'Simple Product'; |
| 79 | + $this->assertEquals( |
| 80 | + $nameInDefaultStore, |
| 81 | + $defaultStoreResponse[Product::NAME], |
| 82 | + 'Product name in default store is invalid.' |
| 83 | + ); |
| 84 | + $fixtureStoreResponse = $this->_webApiCall($serviceInfo, $requestData, null, self::STORE_CODE_FROM_FIXTURE); |
| 85 | + $this->assertEquals( |
| 86 | + $nameInFixtureStore, |
| 87 | + $fixtureStoreResponse[Product::NAME], |
| 88 | + 'Product name in fixture store is invalid.' |
| 89 | + ); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Remove test store |
| 94 | + */ |
| 95 | + public static function tearDownAfterClass() |
| 96 | + { |
| 97 | + parent::tearDownAfterClass(); |
| 98 | + /** @var \Magento\Framework\Registry $registry */ |
| 99 | + $registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\Registry'); |
| 100 | + |
| 101 | + $registry->unregister('isSecureArea'); |
| 102 | + $registry->register('isSecureArea', true); |
| 103 | + |
| 104 | + /** @var $store \Magento\Store\Model\Store */ |
| 105 | + $store = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Store\Model\Store'); |
| 106 | + $store->load('fixturestore'); |
| 107 | + if ($store->getId()) { |
| 108 | + $store->delete(); |
| 109 | + } |
| 110 | + |
| 111 | + $registry->unregister('isSecureArea'); |
| 112 | + $registry->register('isSecureArea', false); |
| 113 | + } |
| 114 | +} |
0 commit comments