This repository has been archived by the owner on Dec 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 154
120 implement store configs coverage #126
Merged
magento-engcom-team
merged 7 commits into
magento:2.3-develop
from
VitaliyBoyko:120-Implement-storeConfigs-coverage
Jul 24, 2018
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e1f53d4
graphql-ce-120: added store configs schema and resolver
5229cd6
graphql-ce-120: added api-functional test fixed resolver and dataprov…
af4b258
graphql-ce-120: added api functional test
3b64955
graphql-ce-120: added missing dependency to composer json
b5a2a98
graphql-ce-120: fixed resolver name
e85a6e5
graphql-ce-120: get single store config instead multiple
8f3c6e9
graphql-ce-120: fixed api functional test for store config
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigDataProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\StoreGraphQl\Model\Resolver\Store; | ||
|
||
use Magento\Store\Api\Data\StoreConfigInterface; | ||
use Magento\Store\Api\StoreConfigManagerInterface; | ||
use Magento\Store\Api\StoreRepositoryInterface; | ||
use Magento\Store\Api\StoreResolverInterface; | ||
|
||
/** | ||
* StoreConfig field data provider, used for GraphQL request processing. | ||
*/ | ||
class StoreConfigDataProvider | ||
{ | ||
/** | ||
* @var StoreConfigManagerInterface | ||
*/ | ||
private $storeConfigManager; | ||
|
||
/** | ||
* @var StoreResolverInterface | ||
*/ | ||
private $storeResolver; | ||
|
||
/** | ||
* @var StoreRepositoryInterface | ||
*/ | ||
private $storeRepository; | ||
|
||
/** | ||
* @param StoreConfigManagerInterface $storeConfigManager | ||
* @param StoreResolverInterface $storeResolver | ||
* @param StoreRepositoryInterface $storeRepository | ||
*/ | ||
public function __construct( | ||
StoreConfigManagerInterface $storeConfigManager, | ||
StoreResolverInterface $storeResolver, | ||
StoreRepositoryInterface $storeRepository | ||
) { | ||
$this->storeConfigManager = $storeConfigManager; | ||
$this->storeResolver = $storeResolver; | ||
$this->storeRepository = $storeRepository; | ||
} | ||
|
||
/** | ||
* Get store config for current store | ||
* | ||
* @return array | ||
*/ | ||
public function getStoreConfig() : array | ||
{ | ||
$storeId = $this->storeResolver->getCurrentStoreId(); | ||
$store = $this->storeRepository->getById($storeId); | ||
$storeConfig = current($this->storeConfigManager->getStoreConfigs([$store->getCode()])); | ||
|
||
return $this->hidrateStoreConfig($storeConfig); | ||
} | ||
|
||
/** | ||
* Transform StoreConfig object to in array format | ||
* | ||
* @param StoreConfigInterface $storeConfig | ||
* @return array | ||
*/ | ||
private function hidrateStoreConfig($storeConfig): array | ||
{ | ||
/** @var StoreConfigInterface $storeConfig */ | ||
$storeConfigData = [ | ||
'id' => $storeConfig->getId(), | ||
'code' => $storeConfig->getCode(), | ||
'website_id' => $storeConfig->getWebsiteId(), | ||
'locale' => $storeConfig->getLocale(), | ||
'base_currency_code' => $storeConfig->getBaseCurrencyCode(), | ||
'default_display_currency_code' => $storeConfig->getDefaultDisplayCurrencyCode(), | ||
'timezone' => $storeConfig->getTimezone(), | ||
'weight_unit' => $storeConfig->getWeightUnit(), | ||
'base_url' => $storeConfig->getBaseUrl(), | ||
'base_link_url' => $storeConfig->getBaseLinkUrl(), | ||
'base_static_url' => $storeConfig->getSecureBaseStaticUrl(), | ||
'base_media_url' => $storeConfig->getBaseMediaUrl(), | ||
'secure_base_url' => $storeConfig->getSecureBaseUrl(), | ||
'secure_base_link_url' => $storeConfig->getSecureBaseLinkUrl(), | ||
'secure_base_static_url' => $storeConfig->getSecureBaseStaticUrl(), | ||
'secure_base_media_url' => $storeConfig->getSecureBaseMediaUrl() | ||
]; | ||
|
||
return $storeConfigData; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\StoreGraphQl\Model\Resolver; | ||
|
||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\Resolver\Value; | ||
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider; | ||
|
||
/** | ||
* StoreConfig page field resolver, used for GraphQL request processing. | ||
*/ | ||
class StoreConfigResolver implements ResolverInterface | ||
{ | ||
/** | ||
* @var StoreConfigDataProvider | ||
*/ | ||
private $storeConfigDataProvider; | ||
|
||
/** | ||
* @var ValueFactory | ||
*/ | ||
private $valueFactory; | ||
|
||
/** | ||
* @param StoreConfigDataProvider $storeConfigsDataProvider | ||
* @param ValueFactory $valueFactory | ||
*/ | ||
public function __construct( | ||
StoreConfigDataProvider $storeConfigsDataProvider, | ||
ValueFactory $valueFactory | ||
) { | ||
$this->valueFactory = $valueFactory; | ||
$this->storeConfigDataProvider = $storeConfigsDataProvider; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) : Value { | ||
|
||
$storeConfigData = $this->storeConfigDataProvider->getStoreConfig(); | ||
|
||
$result = function () use ($storeConfigData) { | ||
return !empty($storeConfigData) ? $storeConfigData : []; | ||
}; | ||
|
||
return $this->valueFactory->create($result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigResolverTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\GraphQl\Store; | ||
|
||
use Magento\Store\Api\Data\StoreConfigInterface; | ||
use Magento\Store\Api\StoreConfigManagerInterface; | ||
use Magento\Store\Api\StoreRepositoryInterface; | ||
use Magento\Store\Api\StoreResolverInterface; | ||
use Magento\TestFramework\ObjectManager; | ||
use Magento\TestFramework\TestCase\GraphQlAbstract; | ||
|
||
/** | ||
* Test the GraphQL endpoint's StoreConfigs query | ||
*/ | ||
class StoreConfigResolverTest extends GraphQlAbstract | ||
{ | ||
|
||
/** @var ObjectManager */ | ||
private $objectManager; | ||
|
||
protected function setUp() | ||
{ | ||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Store/_files/store.php | ||
*/ | ||
public function testGetStoreConfig() | ||
{ | ||
/** @var StoreConfigManagerInterface $storeConfigsManager */ | ||
$storeConfigsManager = $this->objectManager->get(StoreConfigManagerInterface::class); | ||
/** @var StoreResolverInterface $storeResolver */ | ||
$storeResolver = $this->objectManager->get(StoreResolverInterface::class); | ||
/** @var StoreRepositoryInterface $storeRepository */ | ||
$storeRepository = $this->objectManager->get(StoreRepositoryInterface::class); | ||
$storeId = $storeResolver->getCurrentStoreId(); | ||
$store = $storeRepository->getById($storeId); | ||
/** @var StoreConfigInterface $storeConfig */ | ||
$storeConfig = current($storeConfigsManager->getStoreConfigs([$store->getCode()])); | ||
$query | ||
= <<<QUERY | ||
{ | ||
storeConfig{ | ||
items{ | ||
id, | ||
code, | ||
website_id, | ||
locale, | ||
base_currency_code, | ||
default_display_currency_code, | ||
timezone, | ||
weight_unit, | ||
base_url, | ||
base_link_url, | ||
base_static_url, | ||
base_media_url, | ||
secure_base_url, | ||
secure_base_link_url, | ||
secure_base_static_url, | ||
secure_base_media_url | ||
} | ||
} | ||
} | ||
QUERY; | ||
$response = $this->graphQlQuery($query); | ||
$this->assertArrayHasKey('storeConfig', $response); | ||
$this->assertEquals($storeConfig->getId(), $response['storeConfig']['id']); | ||
$this->assertEquals($storeConfig->getCode(), $response['storeConfig']['code']); | ||
$this->assertEquals($storeConfig->getLocale(), $response['storeConfig']['locale']); | ||
$this->assertEquals($storeConfig->getBaseCurrencyCode(), $response['storeConfig']['base_currency_code']); | ||
$this->assertEquals( | ||
$storeConfig->getDefaultDisplayCurrencyCode(), | ||
$response['storeConfig']['default_display_currency_code'] | ||
); | ||
$this->assertEquals($storeConfig->getTimezone(), $response['storeConfig']['timezone']); | ||
$this->assertEquals($storeConfig->getWeightUnit(), $response['storeConfig']['weight_unit']); | ||
$this->assertEquals($storeConfig->getBaseUrl(), $response['storeConfig']['base_url']); | ||
$this->assertEquals($storeConfig->getBaseLinkUrl(), $response['storeConfig']['base_link_url']); | ||
$this->assertEquals($storeConfig->getBaseStaticUrl(), $response['storeConfig']['base_static_url']); | ||
$this->assertEquals($storeConfig->getBaseMediaUrl(), $response['storeConfig']['base_media_url']); | ||
$this->assertEquals($storeConfig->getSecureBaseUrl(), $response['storeConfig']['secure_base_url']); | ||
$this->assertEquals($storeConfig->getSecureBaseLinkUrl(), $response['storeConfig']['secure_base_link_url']); | ||
$this->assertEquals( | ||
$storeConfig->getSecureBaseStaticUrl(), | ||
$response['storeConfig']['secure_base_static_url'] | ||
); | ||
$this->assertEquals($storeConfig->getSecureBaseMediaUrl(), $response['storeConfig']['secure_base_media_url']); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please align test. Looks like you removed "items" on your last code update. Should be also removed here.