-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#28569: Multi-store: Missing store codes in relation to a group and w…
…ebsite - Created separate test for available stores Added website specific store output
- Loading branch information
Showing
4 changed files
with
208 additions
and
55 deletions.
There are no files selected for viewing
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
171 changes: 171 additions & 0 deletions
171
dev/tests/api-functional/testsuite/Magento/GraphQl/Store/AvailableStoreConfigTest.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,171 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\GraphQl\Store; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\ObjectManagerInterface; | ||
use Magento\Store\Api\Data\StoreConfigInterface; | ||
use Magento\Store\Api\StoreConfigManagerInterface; | ||
use Magento\Store\Model\ScopeInterface; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\TestCase\GraphQlAbstract; | ||
|
||
/** | ||
* Test the GraphQL endpoint's StoreConfigs and AvailableStores queries | ||
*/ | ||
class AvailableStoreConfigTest extends GraphQlAbstract | ||
{ | ||
|
||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->objectManager = Bootstrap::getObjectManager(); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Store/_files/store.php | ||
* @magentoApiDataFixture Magento/Store/_files/inactive_store.php | ||
* @magentoConfigFixture default_store store/information/name Default Store | ||
* @magentoConfigFixture test_store store/information/name Test Store | ||
*/ | ||
public function testDefaultWebsiteAvailableStoreConfigs(): void | ||
{ | ||
/** @var StoreConfigManagerInterface $storeConfigManager */ | ||
$storeConfigManager = $this->objectManager->get(StoreConfigManagerInterface::class); | ||
$storeConfigs = $storeConfigManager->getStoreConfigs(); | ||
|
||
$expectedAvailableStores = []; | ||
$expectedAvailableStoreCodes = [ | ||
'default', | ||
'test' | ||
]; | ||
|
||
foreach ($storeConfigs as $storeConfig) { | ||
if (in_array($storeConfig->getCode(), $expectedAvailableStoreCodes)) { | ||
$expectedAvailableStores[] = $storeConfig; | ||
} | ||
} | ||
|
||
$query | ||
= <<<QUERY | ||
{ | ||
availableStores { | ||
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, | ||
store_name | ||
} | ||
} | ||
QUERY; | ||
$response = $this->graphQlQuery($query); | ||
|
||
$this->assertArrayHasKey('availableStores', $response); | ||
foreach ($expectedAvailableStores as $key => $storeConfig) { | ||
$this->validateStoreConfig($storeConfig, $response['availableStores'][$key]); | ||
} | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Store/_files/second_website_with_two_stores.php | ||
* @magentoConfigFixture fixture_second_store_store store/information/name Fixture Second Store | ||
* @magentoConfigFixture fixture_third_store_store store/information/name Fixture Third Store | ||
*/ | ||
public function testNonDefaultWebsiteAvailableStoreConfigs(): void | ||
{ | ||
/** @var StoreConfigManagerInterface $storeConfigManager */ | ||
$storeConfigManager = $this->objectManager->get(StoreConfigManagerInterface::class); | ||
$storeConfigs = $storeConfigManager->getStoreConfigs(['fixture_second_store', 'fixture_third_store']); | ||
|
||
$query | ||
= <<<QUERY | ||
{ | ||
availableStores { | ||
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, | ||
store_name | ||
} | ||
} | ||
QUERY; | ||
$headerMap = ['Store' => 'fixture_second_store']; | ||
$response = $this->graphQlQuery($query, [], '', $headerMap); | ||
|
||
$this->assertArrayHasKey('availableStores', $response); | ||
foreach ($storeConfigs as $key => $storeConfig) { | ||
$this->validateStoreConfig($storeConfig, $response['availableStores'][$key]); | ||
} | ||
} | ||
|
||
/** | ||
* Validate Store Config Data | ||
* | ||
* @param StoreConfigInterface $storeConfig | ||
* @param array $responseConfig | ||
*/ | ||
private function validateStoreConfig($storeConfig, $responseConfig): void | ||
{ | ||
/* @var $scopeConfig ScopeConfigInterface */ | ||
$scopeConfig = $this->objectManager->get(ScopeConfigInterface::class); | ||
$this->assertEquals($storeConfig->getId(), $responseConfig['id']); | ||
$this->assertEquals($storeConfig->getCode(), $responseConfig['code']); | ||
$this->assertEquals($storeConfig->getLocale(), $responseConfig['locale']); | ||
$this->assertEquals($storeConfig->getBaseCurrencyCode(), $responseConfig['base_currency_code']); | ||
$this->assertEquals( | ||
$storeConfig->getDefaultDisplayCurrencyCode(), | ||
$responseConfig['default_display_currency_code'] | ||
); | ||
$this->assertEquals($storeConfig->getTimezone(), $responseConfig['timezone']); | ||
$this->assertEquals($storeConfig->getWeightUnit(), $responseConfig['weight_unit']); | ||
$this->assertEquals($storeConfig->getBaseUrl(), $responseConfig['base_url']); | ||
$this->assertEquals($storeConfig->getBaseLinkUrl(), $responseConfig['base_link_url']); | ||
$this->assertEquals($storeConfig->getBaseStaticUrl(), $responseConfig['base_static_url']); | ||
$this->assertEquals($storeConfig->getBaseMediaUrl(), $responseConfig['base_media_url']); | ||
$this->assertEquals($storeConfig->getSecureBaseUrl(), $responseConfig['secure_base_url']); | ||
$this->assertEquals($storeConfig->getSecureBaseLinkUrl(), $responseConfig['secure_base_link_url']); | ||
$this->assertEquals($storeConfig->getSecureBaseStaticUrl(), $responseConfig['secure_base_static_url']); | ||
$this->assertEquals($storeConfig->getSecureBaseMediaUrl(), $responseConfig['secure_base_media_url']); | ||
$this->assertEquals($scopeConfig->getValue( | ||
'store/information/name', | ||
ScopeInterface::SCOPE_STORE, | ||
$storeConfig->getId() | ||
), $responseConfig['store_name']); | ||
} | ||
} |
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