Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

GraphQl-972: added support of the Global scope in the config fixture #973

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Magento\Config\Model\Config;
use Magento\Config\Model\ResourceModel\Config as ConfigResource;
use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Store\Model\StoreManagerInterface;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -156,4 +157,31 @@ private function getStoreIdByCode(string $storeCode): int
$store = $storeManager->getStore($storeCode);
return (int)$store->getId();
}

/**
* @inheritDoc
*/
protected function _setConfigValue($configPath, $value, $storeCode = false)
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
if ($storeCode === false) {
$objectManager->get(
\Magento\TestFramework\App\ApiMutableScopeConfig::class
)->setValue(
$configPath,
$value,
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
);

return;
}
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\TestFramework\App\ApiMutableScopeConfig::class
)->setValue(
$configPath,
$value,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$storeCode
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* @inheritdoc
*/
class MutableScopeConfig implements MutableScopeConfigInterface
class ApiMutableScopeConfig implements MutableScopeConfigInterface
{
/**
* @var Config
Expand Down Expand Up @@ -56,7 +56,6 @@ public function setValue(
/**
* Clean app config cache
*
* @param string|null $type
* @return void
*/
public function clean()
Expand Down Expand Up @@ -89,19 +88,13 @@ private function getTestAppConfig()
private function persistConfig($path, $value, $scopeType, $scopeCode): void
{
$pathParts = explode('/', $path);
$store = '';
if ($scopeType === \Magento\Store\Model\ScopeInterface::SCOPE_STORE) {
if ($scopeCode !== null) {
$store = ObjectManager::getInstance()
$store = 0;
if ($scopeType === \Magento\Store\Model\ScopeInterface::SCOPE_STORE
&& $scopeCode !== null) {
$store = ObjectManager::getInstance()
->get(\Magento\Store\Api\StoreRepositoryInterface::class)
->get($scopeCode)
->getId();
} else {
$store = ObjectManager::getInstance()
->get(\Magento\Store\Model\StoreManagerInterface::class)
->getStore()
->getId();
}
}
$configData = [
'section' => $pathParts[0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,50 @@ public function testGetStoreConfig()
$this->assertEquals('asc', $response['storeConfig']['catalog_default_sort_by']);
$this->assertEquals(2, $response['storeConfig']['root_category_id']);
}

/**
* @magentoApiDataFixture Magento/Store/_files/store.php
* @magentoConfigFixture catalog/seo/product_url_suffix global_test_product_suffix
* @magentoConfigFixture catalog/seo/category_url_suffix global_test_category_suffix
* @magentoConfigFixture catalog/seo/title_separator __
* @magentoConfigFixture catalog/frontend/list_mode 3
* @magentoConfigFixture catalog/frontend/grid_per_page_values 16
* @magentoConfigFixture catalog/frontend/list_per_page_values 8
* @magentoConfigFixture catalog/frontend/grid_per_page 16
* @magentoConfigFixture catalog/frontend/list_per_page 8
* @magentoConfigFixture catalog/frontend/default_sort_by asc
*/
public function testGetStoreConfigGlobal()
{
$query
= <<<QUERY
{
storeConfig{
product_url_suffix,
category_url_suffix,
title_separator,
list_mode,
grid_per_page_values,
list_per_page_values,
grid_per_page,
list_per_page,
catalog_default_sort_by,
root_category_id
}
}
QUERY;
$response = $this->graphQlQuery($query);
$this->assertArrayHasKey('storeConfig', $response);

$this->assertEquals('global_test_product_suffix', $response['storeConfig']['product_url_suffix']);
$this->assertEquals('global_test_category_suffix', $response['storeConfig']['category_url_suffix']);
$this->assertEquals('__', $response['storeConfig']['title_separator']);
$this->assertEquals('3', $response['storeConfig']['list_mode']);
$this->assertEquals('16', $response['storeConfig']['grid_per_page_values']);
$this->assertEquals(16, $response['storeConfig']['grid_per_page']);
$this->assertEquals('8', $response['storeConfig']['list_per_page_values']);
$this->assertEquals(8, $response['storeConfig']['list_per_page']);
$this->assertEquals('asc', $response['storeConfig']['catalog_default_sort_by']);
$this->assertEquals(2, $response['storeConfig']['root_category_id']);
}
}