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

Commit

Permalink
GraphQl-972: added support of the Global scope in the config fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy Boyko committed Sep 27, 2019
1 parent ea71192 commit 3489da5
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 8 deletions.
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,30 @@ 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
);
} else {
\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,18 +88,13 @@ private function getTestAppConfig()
private function persistConfig($path, $value, $scopeType, $scopeCode): void
{
$pathParts = explode('/', $path);
$store = '';
$store = 0;
if ($scopeType === \Magento\Store\Model\ScopeInterface::SCOPE_STORE) {
if ($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 = [
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']);
}
}

0 comments on commit 3489da5

Please sign in to comment.