Skip to content

Commit 4602b14

Browse files
committed
PWA-805: Expose localization system / store config from GraphQL
1 parent b761e87 commit 4602b14

File tree

4 files changed

+206
-2
lines changed

4 files changed

+206
-2
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Store/AvailableStoreConfigTest.php

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function testDefaultWebsiteAvailableStoreConfigs(): void
8787
secure_base_static_url,
8888
secure_base_media_url,
8989
store_name
90+
use_store_in_url
9091
}
9192
}
9293
QUERY;
@@ -126,6 +127,7 @@ public function testNonDefaultWebsiteAvailableStoreConfigs(): void
126127
secure_base_static_url,
127128
secure_base_media_url,
128129
store_name
130+
use_store_in_url
129131
}
130132
}
131133
QUERY;
@@ -167,5 +169,99 @@ private function validateStoreConfig(StoreConfigInterface $storeConfig, array $r
167169
$this->assertEquals($storeConfig->getSecureBaseStaticUrl(), $responseConfig['secure_base_static_url']);
168170
$this->assertEquals($storeConfig->getSecureBaseMediaUrl(), $responseConfig['secure_base_media_url']);
169171
$this->assertEquals($store->getName(), $responseConfig['store_name']);
172+
$this->assertEquals($store->isUseStoreInUrl(), $responseConfig['use_store_in_url']);
173+
}
174+
175+
/**
176+
* @magentoApiDataFixture Magento/Store/_files/second_website_with_four_stores_divided_in_groups.php
177+
* @magentoConfigFixture web/url/use_store 1
178+
*/
179+
public function testAllStoreConfigsWithCodeInUrlEnabled(): void
180+
{
181+
$storeConfigs = $this->storeConfigManager->getStoreConfigs(
182+
[
183+
'fixture_second_store',
184+
'fixture_third_store',
185+
'fixture_fourth_store',
186+
'fixture_fifth_store'
187+
]
188+
);
189+
190+
$query
191+
= <<<QUERY
192+
{
193+
availableStores(useCurrentGroup:false) {
194+
id,
195+
code,
196+
website_id,
197+
locale,
198+
base_currency_code,
199+
default_display_currency_code,
200+
timezone,
201+
weight_unit,
202+
base_url,
203+
base_link_url,
204+
base_static_url,
205+
base_media_url,
206+
secure_base_url,
207+
secure_base_link_url,
208+
secure_base_static_url,
209+
secure_base_media_url,
210+
store_name
211+
use_store_in_url
212+
}
213+
}
214+
QUERY;
215+
$headerMap = ['Store' => 'fixture_fifth_store'];
216+
$response = $this->graphQlQuery($query, [], '', $headerMap);
217+
218+
$this->assertArrayHasKey('availableStores', $response);
219+
$this->assertCount(4, $response['availableStores']);
220+
foreach ($response['availableStores'] as $key => $responseConfig) {
221+
$this->validateStoreConfig($storeConfigs[$key], $responseConfig);
222+
$this->assertEquals(true, $responseConfig['use_store_in_url']);
223+
}
224+
}
225+
226+
/**
227+
* @magentoApiDataFixture Magento/Store/_files/second_website_with_four_stores_divided_in_groups.php
228+
*/
229+
public function testCurrentGroupStoreConfigs(): void
230+
{
231+
$storeConfigs = $this->storeConfigManager->getStoreConfigs(['fixture_fourth_store', 'fixture_fifth_store']);
232+
233+
$query
234+
= <<<QUERY
235+
{
236+
availableStores(useCurrentGroup:true) {
237+
id,
238+
code,
239+
website_id,
240+
locale,
241+
base_currency_code,
242+
default_display_currency_code,
243+
timezone,
244+
weight_unit,
245+
base_url,
246+
base_link_url,
247+
base_static_url,
248+
base_media_url,
249+
secure_base_url,
250+
secure_base_link_url,
251+
secure_base_static_url,
252+
secure_base_media_url,
253+
store_name
254+
use_store_in_url
255+
}
256+
}
257+
QUERY;
258+
$headerMap = ['Store' => 'fixture_fifth_store'];
259+
$response = $this->graphQlQuery($query, [], '', $headerMap);
260+
261+
$this->assertArrayHasKey('availableStores', $response);
262+
$this->assertCount(2, $response['availableStores']);
263+
foreach ($response['availableStores'] as $key => $responseConfig) {
264+
$this->validateStoreConfig($storeConfigs[$key], $responseConfig);
265+
}
170266
}
171267
}

dev/tests/integration/framework/Magento/TestFramework/Annotation/ConfigFixture.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ protected function _assignConfigData(TestCase $test)
158158
self::ANNOTATION
159159
);
160160
foreach ($testAnnotations as $configPathAndValue) {
161-
if (preg_match('/^.+?(?=_store\s)/', $configPathAndValue, $matches)) {
161+
if (preg_match('/^[^\/]+?(?=_store\s)/', $configPathAndValue, $matches)) {
162162
$this->setStoreConfigValue($matches ?? [], $configPathAndValue);
163-
} elseif (preg_match('/^.+?(?=_website\s)/', $configPathAndValue, $matches)) {
163+
} elseif (preg_match('/^[^\/]+?(?=_website\s)/', $configPathAndValue, $matches)) {
164164
$this->setWebsiteConfigValue($matches ?? [], $configPathAndValue);
165165
} else {
166166
$this->setGlobalConfigValue($configPathAndValue);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Helper\DefaultCategory;
9+
use Magento\CatalogSearch\Model\Indexer\Fulltext;
10+
use Magento\Framework\Indexer\IndexerRegistry;
11+
use Magento\Store\Api\Data\GroupInterface;
12+
use Magento\Store\Api\Data\GroupInterfaceFactory;
13+
use Magento\Store\Model\ResourceModel\Group as GroupResource;
14+
use Magento\Store\Model\Store;
15+
use Magento\Store\Model\StoreManagerInterface;
16+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
17+
18+
Resolver::getInstance()->requireDataFixture('Magento/Store/_files/second_website_with_two_stores.php');
19+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
20+
21+
/** @var $website \Magento\Store\Model\Website */
22+
$website = $objectManager->create(\Magento\Store\Model\Website::class);
23+
$website->load('test', 'code')->getId();
24+
$websiteId = $website->getId();
25+
26+
/** @var StoreManagerInterface $storeManager */
27+
$storeManager = $objectManager->get(StoreManagerInterface::class);
28+
/** @var DefaultCategory $defaultCategory */
29+
$defaultCategory = $objectManager->get(DefaultCategory::class);
30+
/** @var GroupInterface $storeGroup */
31+
$storeGroup = $objectManager->get(GroupInterfaceFactory::class)->create();
32+
$storeGroup->setCode('second_group')
33+
->setRootCategoryId($defaultCategory->getId())
34+
->setName('second store group')
35+
->setWebsite($website);
36+
$objectManager->get(GroupResource::class)->save($storeGroup);
37+
/* Refresh stores memory cache */
38+
$storeManager->reinitStores();
39+
40+
$store = $objectManager->create(Store::class);
41+
if (!$store->load('fixture_fourth_store', 'code')->getId()) {
42+
$store->setCode(
43+
'fixture_fourth_store'
44+
)->setWebsiteId(
45+
$websiteId
46+
)->setGroupId(
47+
$storeGroup->getId()
48+
)->setName(
49+
'Fixture Fourth Store'
50+
)->setSortOrder(
51+
6
52+
)->setIsActive(
53+
1
54+
);
55+
$store->save();
56+
}
57+
58+
$store = $objectManager->create(Store::class);
59+
if (!$store->load('fixture_fifth_store', 'code')->getId()) {
60+
$store->setCode(
61+
'fixture_fifth_store'
62+
)->setWebsiteId(
63+
$websiteId
64+
)->setGroupId(
65+
$storeGroup->getId()
66+
)->setName(
67+
'Fixture Fifth Store'
68+
)->setSortOrder(
69+
5
70+
)->setIsActive(
71+
1
72+
);
73+
$store->save();
74+
}
75+
76+
/* Refresh CatalogSearch index */
77+
/** @var IndexerRegistry $indexerRegistry */
78+
$indexerRegistry = $objectManager->get(IndexerRegistry::class);
79+
$indexerRegistry->get(Fulltext::INDEXER_ID)->reindexAll();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
9+
10+
/** @var \Magento\Framework\Registry $registry */
11+
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
12+
13+
$registry->unregister('isSecureArea');
14+
$registry->register('isSecureArea', true);
15+
16+
$store = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Store\Model\Store::class);
17+
if ($store->load('fixture_fourth_store', 'code')->getId()) {
18+
$store->delete();
19+
}
20+
21+
$store = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Store\Model\Store::class);
22+
if ($store->load('fixture_fifth_store', 'code')->getId()) {
23+
$store->delete();
24+
}
25+
26+
$registry->unregister('isSecureArea');
27+
$registry->register('isSecureArea', false);
28+
29+
Resolver::getInstance()->requireDataFixture('Magento/Store/_files/second_website_with_two_stores_rollback.php');

0 commit comments

Comments
 (0)