Skip to content

Commit d60888d

Browse files
authored
ENGCOM-5989: GraphQl-972: added support of the Global scope in the config fixture #973
2 parents 86681a5 + b1178fa commit d60888d

File tree

3 files changed

+79
-12
lines changed

3 files changed

+79
-12
lines changed

dev/tests/api-functional/framework/Magento/TestFramework/Annotation/ApiConfigFixture.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Config\Model\Config;
1111
use Magento\Config\Model\ResourceModel\Config as ConfigResource;
1212
use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory;
13+
use Magento\Framework\App\Config\ScopeConfigInterface;
1314
use Magento\TestFramework\Helper\Bootstrap;
1415
use Magento\Store\Model\StoreManagerInterface;
1516
use PHPUnit\Framework\TestCase;
@@ -156,4 +157,31 @@ private function getStoreIdByCode(string $storeCode): int
156157
$store = $storeManager->getStore($storeCode);
157158
return (int)$store->getId();
158159
}
160+
161+
/**
162+
* @inheritDoc
163+
*/
164+
protected function _setConfigValue($configPath, $value, $storeCode = false)
165+
{
166+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
167+
if ($storeCode === false) {
168+
$objectManager->get(
169+
\Magento\TestFramework\App\ApiMutableScopeConfig::class
170+
)->setValue(
171+
$configPath,
172+
$value,
173+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
174+
);
175+
176+
return;
177+
}
178+
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
179+
\Magento\TestFramework\App\ApiMutableScopeConfig::class
180+
)->setValue(
181+
$configPath,
182+
$value,
183+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
184+
$storeCode
185+
);
186+
}
159187
}

dev/tests/api-functional/framework/Magento/TestFramework/App/MutableScopeConfig.php renamed to dev/tests/api-functional/framework/Magento/TestFramework/App/ApiMutableScopeConfig.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/**
1818
* @inheritdoc
1919
*/
20-
class MutableScopeConfig implements MutableScopeConfigInterface
20+
class ApiMutableScopeConfig implements MutableScopeConfigInterface
2121
{
2222
/**
2323
* @var Config
@@ -56,7 +56,6 @@ public function setValue(
5656
/**
5757
* Clean app config cache
5858
*
59-
* @param string|null $type
6059
* @return void
6160
*/
6261
public function clean()
@@ -89,19 +88,13 @@ private function getTestAppConfig()
8988
private function persistConfig($path, $value, $scopeType, $scopeCode): void
9089
{
9190
$pathParts = explode('/', $path);
92-
$store = '';
93-
if ($scopeType === \Magento\Store\Model\ScopeInterface::SCOPE_STORE) {
94-
if ($scopeCode !== null) {
95-
$store = ObjectManager::getInstance()
91+
$store = 0;
92+
if ($scopeType === \Magento\Store\Model\ScopeInterface::SCOPE_STORE
93+
&& $scopeCode !== null) {
94+
$store = ObjectManager::getInstance()
9695
->get(\Magento\Store\Api\StoreRepositoryInterface::class)
9796
->get($scopeCode)
9897
->getId();
99-
} else {
100-
$store = ObjectManager::getInstance()
101-
->get(\Magento\Store\Model\StoreManagerInterface::class)
102-
->getStore()
103-
->getId();
104-
}
10598
}
10699
$configData = [
107100
'section' => $pathParts[0],

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/StoreConfigTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,50 @@ public function testGetStoreConfig()
5959
$this->assertEquals('asc', $response['storeConfig']['catalog_default_sort_by']);
6060
$this->assertEquals(2, $response['storeConfig']['root_category_id']);
6161
}
62+
63+
/**
64+
* @magentoApiDataFixture Magento/Store/_files/store.php
65+
* @magentoConfigFixture catalog/seo/product_url_suffix global_test_product_suffix
66+
* @magentoConfigFixture catalog/seo/category_url_suffix global_test_category_suffix
67+
* @magentoConfigFixture catalog/seo/title_separator __
68+
* @magentoConfigFixture catalog/frontend/list_mode 3
69+
* @magentoConfigFixture catalog/frontend/grid_per_page_values 16
70+
* @magentoConfigFixture catalog/frontend/list_per_page_values 8
71+
* @magentoConfigFixture catalog/frontend/grid_per_page 16
72+
* @magentoConfigFixture catalog/frontend/list_per_page 8
73+
* @magentoConfigFixture catalog/frontend/default_sort_by asc
74+
*/
75+
public function testGetStoreConfigGlobal()
76+
{
77+
$query
78+
= <<<QUERY
79+
{
80+
storeConfig{
81+
product_url_suffix,
82+
category_url_suffix,
83+
title_separator,
84+
list_mode,
85+
grid_per_page_values,
86+
list_per_page_values,
87+
grid_per_page,
88+
list_per_page,
89+
catalog_default_sort_by,
90+
root_category_id
91+
}
92+
}
93+
QUERY;
94+
$response = $this->graphQlQuery($query);
95+
$this->assertArrayHasKey('storeConfig', $response);
96+
97+
$this->assertEquals('global_test_product_suffix', $response['storeConfig']['product_url_suffix']);
98+
$this->assertEquals('global_test_category_suffix', $response['storeConfig']['category_url_suffix']);
99+
$this->assertEquals('__', $response['storeConfig']['title_separator']);
100+
$this->assertEquals('3', $response['storeConfig']['list_mode']);
101+
$this->assertEquals('16', $response['storeConfig']['grid_per_page_values']);
102+
$this->assertEquals(16, $response['storeConfig']['grid_per_page']);
103+
$this->assertEquals('8', $response['storeConfig']['list_per_page_values']);
104+
$this->assertEquals(8, $response['storeConfig']['list_per_page']);
105+
$this->assertEquals('asc', $response['storeConfig']['catalog_default_sort_by']);
106+
$this->assertEquals(2, $response['storeConfig']['root_category_id']);
107+
}
62108
}

0 commit comments

Comments
 (0)