Skip to content

Commit aa76e7a

Browse files
committed
Merge branch 'ACP2E-1512' of https://github.com/magento-l3/magento2ce into ACP2E-1512
2 parents 6c1e693 + 64cab6f commit aa76e7a

File tree

6 files changed

+186
-10
lines changed

6 files changed

+186
-10
lines changed

app/code/Magento/Config/Model/Config/Reader/Source/Deployed/SettingChecker.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,12 @@ public function getPlaceholderValue($path, $scope, $scopeCode = null)
102102
public function getEnvValue($placeholder)
103103
{
104104
// phpcs:disable Magento2.Security.Superglobal
105-
if ($this->placeholder->isApplicable($placeholder) && isset($_ENV[$placeholder])) {
106-
return $_ENV[$placeholder];
105+
$environment = [];
106+
foreach ($_ENV as $key => $value) {
107+
$environment[strtolower($key)] = $value;
108+
}
109+
if ($this->placeholder->isApplicable($placeholder) && isset($environment[strtolower($placeholder)])) {
110+
return $environment[strtolower($placeholder)];
107111
}
108112
// phpcs:enable
109113

app/code/Magento/Config/Test/Unit/Model/Config/Reader/Source/Deployed/SettingCheckerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ protected function setUp(): void
6969
$this->checker = new SettingChecker($this->configMock, $placeholderFactoryMock, $this->scopeCodeResolverMock);
7070
}
7171

72+
public function testGetEnvValue(): void
73+
{
74+
$_ENV = array_merge($this->env, ['SOME_PLACEHOLDER' => 0, 'another_placeholder' => 1, 'some_placeholder' => 1]);
75+
$this->placeholderMock->expects($this->any())
76+
->method('isApplicable')
77+
->willReturn(true);
78+
$this->assertSame($this->checker->getEnvValue('SOME_PLACEHOLDER'), 1);
79+
$this->assertSame($this->checker->getEnvValue('another_placeholder'), 1);
80+
}
81+
7282
/**
7383
* @param string $path
7484
* @param string $scope

app/code/Magento/Store/Model/Config/Processor/Fallback.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
use Magento\Framework\DB\Adapter\TableNotFoundException;
1212
use Magento\Store\App\Config\Type\Scopes;
1313
use Magento\Store\Model\ResourceModel\Store;
14-
use Magento\Store\Model\ResourceModel\Store\AllStoresCollectionFactory;
1514
use Magento\Store\Model\ResourceModel\Website;
16-
use Magento\Store\Model\ResourceModel\Website\AllWebsitesCollection;
17-
use Magento\Store\Model\ResourceModel\Website\AllWebsitesCollectionFactory;
1815

1916
/**
2017
* Fallback through different scopes and merge them
@@ -191,5 +188,18 @@ private function loadScopes(): void
191188
$this->storeData = [];
192189
$this->websiteData = [];
193190
}
191+
$this->normalizeStoreData();
192+
}
193+
194+
/**
195+
* Sets stores code to lower case
196+
*
197+
* @return void
198+
*/
199+
private function normalizeStoreData(): void
200+
{
201+
foreach ($this->storeData as $key => $store) {
202+
$this->storeData[$key]['code'] = strtolower($store['code']);
203+
}
194204
}
195205
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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\Test\Unit\Model\Config\Processor;
9+
10+
use Magento\Framework\App\DeploymentConfig;
11+
use Magento\Framework\App\ResourceConnection;
12+
use Magento\Store\App\Config\Type\Scopes;
13+
use Magento\Store\Model\Config\Processor\Fallback;
14+
use Magento\Store\Model\ResourceModel\Store;
15+
use Magento\Store\Model\ResourceModel\Website;
16+
use PHPUnit\Framework\MockObject\MockObject;
17+
use PHPUnit\Framework\TestCase;
18+
19+
class FallbackTest extends TestCase
20+
{
21+
/**
22+
* @var Scopes|Scopes&MockObject|MockObject
23+
*/
24+
private Scopes $scopes;
25+
/**
26+
* @var ResourceConnection|ResourceConnection&MockObject|MockObject
27+
*/
28+
private ResourceConnection $resourceConnection;
29+
/**
30+
* @var Store|Store&MockObject|MockObject
31+
*/
32+
private Store $storeResource;
33+
/**
34+
* @var Website|Website&MockObject|MockObject
35+
*/
36+
private Website $websiteResource;
37+
/**
38+
* @var DeploymentConfig|DeploymentConfig&MockObject|MockObject
39+
*/
40+
private DeploymentConfig $deploymentConfig;
41+
/**
42+
* @var Fallback
43+
*/
44+
private Fallback $fallback;
45+
46+
/**
47+
* @return void
48+
*/
49+
protected function setUp(): void
50+
{
51+
parent::setUp();
52+
53+
$this->scopes = $this->createMock(Scopes::class);
54+
$this->resourceConnection = $this->createMock(ResourceConnection::class);
55+
$this->storeResource = $this->createMock(Store::class);
56+
$this->websiteResource = $this->createMock(Website::class);
57+
$this->deploymentConfig = $this->createMock(DeploymentConfig::class);
58+
$this->fallback = new Fallback(
59+
$this->scopes,
60+
$this->resourceConnection,
61+
$this->storeResource,
62+
$this->websiteResource,
63+
$this->deploymentConfig
64+
);
65+
}
66+
67+
/**
68+
* @return void
69+
*/
70+
public function testProcessWithStoreCodeCapitalLetters()
71+
{
72+
$storesData = $this->getStoresData();
73+
$websiteData = $this->getWebsitesData();
74+
$this->deploymentConfig->expects($this->once())->method('isDbAvailable')->willReturn(true);
75+
$this->storeResource->expects($this->once())->method('readAllStores')->willReturn($storesData);
76+
$this->websiteResource->expects($this->once())->method('readAllWebsites')->willReturn($websiteData);
77+
78+
$result = $this->fallback->process(
79+
[
80+
'stores' => [
81+
'two' => [
82+
'checkout' => [
83+
'options' => ['guest_checkout' => 0]
84+
]
85+
]
86+
],
87+
'websites' => [
88+
['admin' => ['web' => ['routers' => ['frontend' => ['disabled' => true]]]]]
89+
]
90+
]
91+
);
92+
$this->assertTrue(in_array('two', array_keys($result['stores'])));
93+
}
94+
95+
/**
96+
* Sample stores data
97+
*
98+
* @return array[]
99+
*/
100+
private function getStoresData(): array
101+
{
102+
return [
103+
[
104+
'store_id' => 0,
105+
'code' => 'admin',
106+
'website_id' => 0,
107+
'group_id' => 0,
108+
'name' => 'Admin',
109+
'sort_order' => 0,
110+
'is_active' => 1
111+
],
112+
[
113+
'store_id' => 1,
114+
'code' => 'default',
115+
'website_id' => 1,
116+
'group_id' => 1,
117+
'name' => 'Default Store View',
118+
'sort_order' => 0,
119+
'is_active' => 1
120+
],
121+
[
122+
'store_id' => 2,
123+
'code' => 'TWO',
124+
'website_id' => 1,
125+
'group_id' => 1,
126+
'name' => 'TWO',
127+
'sort_order' => 0,
128+
'is_active' => 1
129+
]
130+
];
131+
}
132+
133+
private function getWebsitesData(): array
134+
{
135+
return [
136+
[
137+
'website_id' => 0,
138+
'code' => 'admin',
139+
'name' => 'Admin',
140+
'sort_order' => 0,
141+
'default_group_id' => 0,
142+
'is_default' => 0
143+
],
144+
[
145+
'website_id' => 1,
146+
'code' => 'base',
147+
'name' => 'Main Website',
148+
'sort_order' => 0,
149+
'default_group_id' => 1,
150+
'is_default' => 1
151+
]
152+
];
153+
}
154+
}

lib/internal/Magento/Framework/App/Config.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22
/**
3-
* Application configuration object. Used to access configuration when application is initialized and installed.
4-
*
53
* Copyright © Magento, Inc. All rights reserved.
64
* See COPYING.txt for license details.
75
*/
@@ -12,14 +10,14 @@
1210
use Magento\Framework\App\Config\ScopeConfigInterface;
1311

1412
/**
15-
* Class Config
13+
* Application configuration object. Used to access configuration when application is initialized and installed.
1614
*/
1715
class Config implements ScopeConfigInterface
1816
{
1917
/**
2018
* Config cache tag
2119
*/
22-
const CACHE_TAG = 'CONFIG';
20+
public const CACHE_TAG = 'CONFIG';
2321

2422
/**
2523
* @var ScopeCodeResolver

lib/internal/Magento/Framework/App/Test/Unit/ConfigTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function getValueDataProvider()
8484
{
8585
return [
8686
['store', 1],
87-
['website'],
87+
['website']
8888
];
8989
}
9090
}

0 commit comments

Comments
 (0)