|
18 | 18 | class ProductInMultipleStoresCacheTest extends GraphQlAbstract
|
19 | 19 | {
|
20 | 20 | /**
|
21 |
| - * Test a non existing or non allowed currency |
| 21 | + * @inheritdoc |
| 22 | + */ |
| 23 | + protected function setUp() |
| 24 | + { |
| 25 | + /** @var \Magento\Store\Model\Store $store */ |
| 26 | + $store = ObjectManager::getInstance()->get(\Magento\Store\Model\Store::class); |
| 27 | + $storeCodeFromFixture = 'fixture_second_store'; |
| 28 | + |
| 29 | + /** @var \Magento\Config\Model\ResourceModel\Config $configResource */ |
| 30 | + $configResource = ObjectManager::getInstance()->get(\Magento\Config\Model\ResourceModel\Config::class); |
| 31 | + /** @var \Magento\Config\App\Config\Type\System $config */ |
| 32 | + $config = ObjectManager::getInstance()->get(\Magento\Config\App\Config\Type\System::class); |
| 33 | + |
| 34 | + $configResource->saveConfig( |
| 35 | + \Magento\Directory\Model\Currency::XML_PATH_CURRENCY_DEFAULT, |
| 36 | + 'EUR', |
| 37 | + \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES, |
| 38 | + $store->load($storeCodeFromFixture)->getWebsiteId() |
| 39 | + ); |
| 40 | + |
| 41 | + // allow USD & EUR currency |
| 42 | + $configResource->saveConfig( |
| 43 | + \Magento\Directory\Model\Currency::XML_PATH_CURRENCY_ALLOW, |
| 44 | + 'EUR,USD', |
| 45 | + \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES, |
| 46 | + $store->load($storeCodeFromFixture)->getWebsiteId() |
| 47 | + ); |
| 48 | + |
| 49 | + // allow USD & EUR currency |
| 50 | + $configResource->saveConfig( |
| 51 | + \Magento\Directory\Model\Currency::XML_PATH_CURRENCY_ALLOW, |
| 52 | + 'EUR,USD' |
| 53 | + ); |
| 54 | + |
| 55 | + // configuration cache clean is required to reload currency setting |
| 56 | + $config->clean(); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * @inheritdoc |
| 61 | + */ |
| 62 | + protected function tearDown() |
| 63 | + { |
| 64 | + /** @var \Magento\Config\App\Config\Type\System $config */ |
| 65 | + $config = ObjectManager::getInstance()->get(\Magento\Config\App\Config\Type\System::class); |
| 66 | + /** @var \Magento\Config\Model\ResourceModel\Config $configResource */ |
| 67 | + $configResource = ObjectManager::getInstance()->get(\Magento\Config\Model\ResourceModel\Config::class); |
| 68 | + |
| 69 | + // restore allow USD currency |
| 70 | + $configResource->saveConfig( |
| 71 | + \Magento\Directory\Model\Currency::XML_PATH_CURRENCY_ALLOW, |
| 72 | + 'USD' |
| 73 | + ); |
| 74 | + |
| 75 | + // configuration cache clean is required to reload currency setting |
| 76 | + $config->clean(); |
| 77 | + parent::tearDown(); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Test a non existing or non existing currency |
22 | 82 | *
|
23 | 83 | * @magentoApiDataFixture Magento/Store/_files/second_website_with_second_currency.php
|
24 | 84 | * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
|
25 | 85 | * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
26 | 86 | */
|
27 |
| - public function testProductFromSpecificAndDefaultStoreWithMultiCurrencyNotAllowed() |
| 87 | + public function testProductFromSpecificAndDefaultStoreWithMultiCurrencyNonExisting() |
28 | 88 | {
|
29 | 89 | $productSku = 'simple';
|
30 | 90 |
|
@@ -56,16 +116,58 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrencyNotAllowe
|
56 | 116 | }
|
57 | 117 | QUERY;
|
58 | 118 |
|
59 |
| - $storeCodeFromFixture = 'fixture_second_store'; |
60 |
| - |
61 | 119 | //test non existing currency
|
62 | 120 | $headerMap = ['Store' => 'default', 'Content-Currency' => 'someNonExistentCurrency'];
|
63 |
| - $this->expectExceptionMessage('Currency someNonExistentCurrency not allowed for store default'); |
| 121 | + $this->expectExceptionMessage('GraphQL response contains errors: Currency not allowed for store default'); |
64 | 122 | $this->graphQlQuery($query, [], '', $headerMap);
|
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Test a non existing or non allowed currency |
| 127 | + * |
| 128 | + * @magentoApiDataFixture Magento/Store/_files/second_website_with_second_currency.php |
| 129 | + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php |
| 130 | + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
| 131 | + */ |
| 132 | + public function testProductFromSpecificAndDefaultStoreWithMultiCurrencyNotAllowed() |
| 133 | + { |
| 134 | + $productSku = 'simple'; |
| 135 | + |
| 136 | + $query = <<<QUERY |
| 137 | +{ |
| 138 | + products(filter: {sku: {eq: "{$productSku}"}}) |
| 139 | + { |
| 140 | + items { |
| 141 | + attribute_set_id |
| 142 | + created_at |
| 143 | + id |
| 144 | + name |
| 145 | + price { |
| 146 | + minimalPrice { |
| 147 | + amount { |
| 148 | + value |
| 149 | + currency |
| 150 | + } |
| 151 | + } |
| 152 | + } |
| 153 | + sku |
| 154 | + type_id |
| 155 | + updated_at |
| 156 | + ... on PhysicalProductInterface { |
| 157 | + weight |
| 158 | + } |
| 159 | + } |
| 160 | + } |
| 161 | +} |
| 162 | +QUERY; |
| 163 | + |
| 164 | + $storeCodeFromFixture = 'fixture_second_store'; |
65 | 165 |
|
66 | 166 | //test not allowed existing currency
|
67 | 167 | $headerMap = ['Store' => $storeCodeFromFixture, 'Content-Currency' => 'CAD'];
|
68 |
| - $this->expectExceptionMessage('Currency not allowed for store ' . $storeCodeFromFixture); |
| 168 | + $this->expectExceptionMessage( |
| 169 | + "GraphQL response contains errors: Currency not allowed for store {$storeCodeFromFixture}" |
| 170 | + ); |
69 | 171 | $this->graphQlQuery($query, [], '', $headerMap);
|
70 | 172 | }
|
71 | 173 |
|
@@ -113,28 +215,6 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
|
113 | 215 | $storeCodeFromFixture = 'fixture_second_store';
|
114 | 216 | $storeId = $store->load($storeCodeFromFixture)->getStoreId();
|
115 | 217 |
|
116 |
| - $configResource = ObjectManager::getInstance()->get(\Magento\Config\Model\ResourceModel\Config::class); |
117 |
| - |
118 |
| - $configResource->saveConfig( |
119 |
| - \Magento\Directory\Model\Currency::XML_PATH_CURRENCY_DEFAULT, |
120 |
| - 'EUR', |
121 |
| - \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES, |
122 |
| - $store->load($storeCodeFromFixture)->getWebsiteId() |
123 |
| - ); |
124 |
| - |
125 |
| - // allow USD & EUR currency |
126 |
| - $configResource->saveConfig( |
127 |
| - \Magento\Directory\Model\Currency::XML_PATH_CURRENCY_ALLOW, |
128 |
| - 'EUR,USD', |
129 |
| - \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES, |
130 |
| - $store->load($storeCodeFromFixture)->getWebsiteId() |
131 |
| - ); |
132 |
| - |
133 |
| - /** @var \Magento\Config\App\Config\Type\System $config */ |
134 |
| - $config = ObjectManager::getInstance()->get(\Magento\Config\App\Config\Type\System::class); |
135 |
| - // configuration cache clean is required to reload currency setting |
136 |
| - $config->clean(); |
137 |
| - |
138 | 218 | /** @var \Magento\Catalog\Model\Product $product */
|
139 | 219 | $product = ObjectManager::getInstance()->get(\Magento\Catalog\Model\Product::class);
|
140 | 220 | $product->load($product->getIdBySku($productSku));
|
@@ -234,7 +314,9 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
|
234 | 314 |
|
235 | 315 | // test cached response store + currency header with non existing currency, and no valid response, no cache
|
236 | 316 | $headerMap = ['Store' => $storeCodeFromFixture, 'Content-Currency' => 'SOMECURRENCY'];
|
237 |
| - $this->expectExceptionMessage('Currency not allowed for store ' . $storeCodeFromFixture); |
| 317 | + $this->expectExceptionMessage( |
| 318 | + "GraphQL response contains errors: Currency not allowed for store {$storeCodeFromFixture}" |
| 319 | + ); |
238 | 320 | $this->graphQlQuery($query, [], '', $headerMap);
|
239 | 321 | }
|
240 | 322 | }
|
0 commit comments