Skip to content

Commit 711713b

Browse files
MC-32405: [Magento Cloud] - Cannot install a clean instance with pre-defined stores configuration in config.php | Forward port - MDVA-19809
1 parent 1a77b70 commit 711713b

File tree

3 files changed

+242
-1
lines changed

3 files changed

+242
-1
lines changed

app/code/Magento/Store/App/Config/Source/InitialConfigSource.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function __construct(
5252

5353
/**
5454
* Return whole config data from config file for specified config type.
55+
*
5556
* Ignore $path argument due to config source must return all config data
5657
*
5758
* @param string $path
@@ -65,7 +66,7 @@ public function get($path = '')
6566
*
6667
* @see \Magento\Store\Model\Config\Importer To import store configs
6768
*/
68-
if ($this->deploymentConfig->isAvailable()) {
69+
if ($this->deploymentConfig->isAvailable() || $this->deploymentConfig->isDbAvailable()) {
6970
return [];
7071
}
7172

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Store\App\Config\Source;
9+
10+
use Magento\Framework\App\DeploymentConfig\FileReader;
11+
use Magento\Framework\App\DeploymentConfig\Writer;
12+
use Magento\Framework\App\Filesystem\DirectoryList;
13+
use Magento\Framework\Config\File\ConfigFilePool;
14+
use Magento\Framework\Filesystem;
15+
use Magento\Store\Model\StoreManagerInterface;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
use PHPUnit\Framework\TestCase;
18+
19+
/**
20+
* Test that initial scopes config are loaded if database is available
21+
*/
22+
class InitialConfigSourceTest extends TestCase
23+
{
24+
/**
25+
* @var Filesystem
26+
*/
27+
private $filesystem;
28+
29+
/**
30+
* @var ConfigFilePool
31+
*/
32+
private $configFilePool;
33+
34+
/**
35+
* @var FileReader
36+
*/
37+
private $reader;
38+
39+
/**
40+
* @var Writer
41+
*/
42+
private $writer;
43+
44+
/**
45+
* @var array
46+
*/
47+
private $config;
48+
49+
/**
50+
* @var array
51+
*/
52+
private $envConfig;
53+
54+
/**
55+
* @var StoreManagerInterface
56+
*/
57+
private $storeManager;
58+
59+
/**
60+
* @inheritdoc
61+
*/
62+
protected function setUp()
63+
{
64+
$objectManager = Bootstrap::getObjectManager();
65+
$this->reader = $objectManager->get(FileReader::class);
66+
$this->writer = $objectManager->get(Writer::class);
67+
$this->filesystem = $objectManager->get(Filesystem::class);
68+
$this->configFilePool = $objectManager->get(ConfigFilePool::class);
69+
$this->storeManager = $objectManager->get(StoreManagerInterface::class);
70+
$this->config = $this->loadConfig();
71+
$this->envConfig = $this->loadEnvConfig();
72+
$this->loadDumpConfig();
73+
$this->storeManager->reinitStores();
74+
}
75+
76+
/**
77+
* @inheritdoc
78+
*/
79+
public function tearDown()
80+
{
81+
$this->clearConfig(ConfigFilePool::APP_CONFIG);
82+
$this->clearConfig(ConfigFilePool::APP_ENV);
83+
$this->writer->saveConfig([ConfigFilePool::APP_CONFIG => $this->config]);
84+
$this->writer->saveConfig([ConfigFilePool::APP_ENV => $this->envConfig]);
85+
$this->storeManager->reinitStores();
86+
}
87+
88+
/**
89+
* Test that initial scopes config are loaded if database is available
90+
*
91+
* @param array $websites
92+
* @param string $defaultWebsite
93+
* @param bool $offline
94+
* @throws \Magento\Framework\Exception\LocalizedException
95+
* @dataProvider getDefaultDataProvider
96+
*/
97+
public function testGetWebsites(array $websites, string $defaultWebsite, bool $offline = false): void
98+
{
99+
if ($offline) {
100+
// remove application environment config for emulate work without db
101+
$this->clearConfig(ConfigFilePool::APP_ENV);
102+
}
103+
$this->assertEquals($defaultWebsite, $this->storeManager->getWebsite()->getCode());
104+
$this->assertEquals($websites, array_keys($this->storeManager->getWebsites(true, true)), '', 0.0, 10, true);
105+
}
106+
107+
/**
108+
* @return array
109+
*/
110+
public function getDefaultDataProvider(): array
111+
{
112+
return [
113+
[
114+
[
115+
'admin',
116+
'base',
117+
],
118+
'base',
119+
false
120+
],
121+
[
122+
[
123+
'admin',
124+
'main',
125+
],
126+
'main',
127+
true
128+
]
129+
];
130+
}
131+
132+
private function clearConfig(string $type): void
133+
{
134+
$this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile(
135+
$this->configFilePool->getPath($type),
136+
"<?php\n return [];\n"
137+
);
138+
}
139+
140+
/**
141+
* @return void
142+
*/
143+
private function loadDumpConfig(): void
144+
{
145+
$data = array_replace_recursive(
146+
$this->config,
147+
$this->getDumpConfig()
148+
);
149+
$this->writer->saveConfig([ConfigFilePool::APP_CONFIG => $data], true);
150+
}
151+
152+
/**
153+
* @return array
154+
*/
155+
private function getDumpConfig(): array
156+
{
157+
return require __DIR__ . '/../../../_files/dump_config.php';
158+
}
159+
160+
/**
161+
* @return array
162+
*/
163+
private function loadConfig(): array
164+
{
165+
return $this->reader->load(ConfigFilePool::APP_CONFIG);
166+
}
167+
168+
/**
169+
* @return array
170+
*/
171+
private function loadEnvConfig(): array
172+
{
173+
return $this->reader->load(ConfigFilePool::APP_ENV);
174+
}
175+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
return [
7+
'scopes' => [
8+
'websites' => [
9+
'admin' => [
10+
'website_id' => '0',
11+
'code' => 'admin',
12+
'name' => 'Admin',
13+
'sort_order' => '0',
14+
'default_group_id' => '0',
15+
'is_default' => '0',
16+
],
17+
'main' => [ // base website code was changed to main
18+
'website_id' => '1',
19+
'code' => 'main',
20+
'name' => 'Main Website',
21+
'sort_order' => '0',
22+
'default_group_id' => '1',
23+
'is_default' => '1',
24+
],
25+
],
26+
'groups' => [
27+
0 => [
28+
'group_id' => '0',
29+
'website_id' => '0',
30+
'code' => 'default',
31+
'name' => 'Default',
32+
'root_category_id' => '0',
33+
'default_store_id' => '0',
34+
],
35+
1 => [
36+
'group_id' => '1',
37+
'website_id' => '1',
38+
'code' => 'main_website_store',
39+
'name' => 'Main Website Store',
40+
'root_category_id' => '2',
41+
'default_store_id' => '1',
42+
],
43+
],
44+
'stores' => [
45+
'admin' => [
46+
'store_id' => '0',
47+
'code' => 'admin',
48+
'website_id' => '0',
49+
'group_id' => '0',
50+
'name' => 'Admin',
51+
'sort_order' => '0',
52+
'is_active' => '1',
53+
],
54+
'default' => [
55+
'store_id' => '1',
56+
'code' => 'default',
57+
'website_id' => '1',
58+
'group_id' => '1',
59+
'name' => 'Default Store View',
60+
'sort_order' => '0',
61+
'is_active' => '1',
62+
],
63+
],
64+
]
65+
];

0 commit comments

Comments
 (0)