Skip to content

Commit a929270

Browse files
committed
Merge branch 'ACP2E-1512' of https://github.com/magento-l3/magento2ce into PR-2023-02-24
2 parents 95479e6 + 7aa1568 commit a929270

File tree

11 files changed

+272
-20
lines changed

11 files changed

+272
-20
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/App/Config/Source/RuntimeConfigSource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private function getEntities($table, $keyField)
102102
);
103103

104104
foreach ($entities as $entity) {
105-
$data[$entity[$keyField]] = $entity;
105+
$data[strtolower($entity[$keyField])] = $entity;
106106
}
107107

108108
return $data;

app/code/Magento/Store/App/Config/Type/Scopes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function get($path = '')
7272
$path = $this->convertIdPathToCodePath($patchChunks);
7373
}
7474

75-
return $this->data->getData($path);
75+
return $this->data->getData(strtolower($path));
7676
}
7777

7878
/**

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

Lines changed: 26 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
@@ -114,6 +111,13 @@ private function prepareWebsitesConfig(
114111
array $websitesConfig
115112
) {
116113
$result = [];
114+
115+
foreach ($websitesConfig as $websiteCode => $webConfiguration) {
116+
if (!isset($websitesConfig[strtolower($websiteCode)])) {
117+
$websitesConfig[strtolower($websiteCode)] = $webConfiguration;
118+
unset($websitesConfig[$websiteCode]);
119+
}
120+
}
117121
foreach ((array)$this->websiteData as $website) {
118122
$code = $website['code'];
119123
$id = $website['website_id'];
@@ -139,6 +143,12 @@ private function prepareStoresConfig(
139143
) {
140144
$result = [];
141145

146+
foreach ($storesConfig as $storeCode => $storeConfiguration) {
147+
if (!isset($storesConfig[strtolower($storeCode)])) {
148+
$storesConfig[strtolower($storeCode)] = $storeConfiguration;
149+
unset($storesConfig[$storeCode]);
150+
}
151+
}
142152
foreach ((array)$this->storeData as $store) {
143153
$code = $store['code'];
144154
$id = $store['store_id'];
@@ -191,5 +201,18 @@ private function loadScopes(): void
191201
$this->storeData = [];
192202
$this->websiteData = [];
193203
}
204+
$this->normalizeStoreData();
205+
}
206+
207+
/**
208+
* Sets stores code to lower case
209+
*
210+
* @return void
211+
*/
212+
private function normalizeStoreData(): void
213+
{
214+
foreach ($this->storeData as $key => $store) {
215+
$this->storeData[$key]['code'] = strtolower($store['code']);
216+
}
194217
}
195218
}

app/code/Magento/Store/Test/Unit/App/Config/Source/RuntimeConfigSourceTest.php

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,73 @@ public function testGet()
6868
->getMock();
6969
$selectMock->expects($this->any())->method('from')->willReturnSelf();
7070
$this->connection->expects($this->any())->method('select')->willReturn($selectMock);
71-
$this->connection->expects($this->any())->method('fetchAll')->willReturn([]);
71+
$this->connection->expects($this->exactly(3))->method('fetchAll')
72+
->willReturnOnConsecutiveCalls(
73+
[
74+
'WebsiteCode' => [
75+
'website_id' => '3',
76+
'code' => 'WebsiteCode',
77+
'name' => 'website',
78+
'sort_order' => '0',
79+
'default_group_id' => '4',
80+
'is_default' => '0'
81+
]
82+
],
83+
[
84+
0 => [
85+
'group_id' => '4',
86+
'website_id' => '3',
87+
'name' => 'store',
88+
'root_category_id' => '2',
89+
'default_store_id' => '11',
90+
'code' => 'second_website'
91+
]
92+
],
93+
[
94+
'SecondWebsite' => [
95+
'store_id' => '11',
96+
'code' => 'SECOND_WEBSITE',
97+
'website_id' => '3',
98+
'group_id' => '4',
99+
'name' => 'second',
100+
'sort_order' => '0',
101+
'is_active' => '1'
102+
]
103+
]
104+
);
72105
$this->assertEquals(
73106
[
74-
'websites' => [],
75-
'groups' => [],
76-
'stores' => [],
107+
'websites' => [
108+
'websitecode' => [
109+
'website_id' => '3',
110+
'code' => 'WebsiteCode',
111+
'name' => 'website',
112+
'sort_order' => '0',
113+
'default_group_id' => '4',
114+
'is_default' => '0'
115+
]
116+
],
117+
'groups' => [
118+
4 => [
119+
'group_id' => '4',
120+
'website_id' => '3',
121+
'name' => 'store',
122+
'root_category_id' => '2',
123+
'default_store_id' => '11',
124+
'code' => 'second_website'
125+
]
126+
],
127+
'stores' => [
128+
'second_website' => [
129+
'store_id' => '11',
130+
'code' => 'SECOND_WEBSITE',
131+
'website_id' => '3',
132+
'group_id' => '4',
133+
'name' => 'second',
134+
'sort_order' => '0',
135+
'is_active' => '1'
136+
]
137+
],
77138
],
78139
$this->configSource->get()
79140
);
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: 3 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
@@ -127,6 +125,7 @@ public function clean()
127125
*/
128126
public function get($configType, $path = '', $default = null)
129127
{
128+
$path = strtolower($path);
130129
$result = null;
131130
if (isset($this->types[$configType])) {
132131
$result = $this->types[$configType]->get($path);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ public function resolve($scopeType, $scopeCode)
5959
$scopeCode = $resolverScopeCode;
6060
}
6161

62-
$this->resolvedScopeCodes[$scopeType][$scopeCode] = $resolverScopeCode;
62+
$this->resolvedScopeCodes[$scopeType][$scopeCode] =
63+
is_null($resolverScopeCode) ? null : strtolower($resolverScopeCode);
6364

64-
return $resolverScopeCode;
65+
return $this->resolvedScopeCodes[$scopeType][$scopeCode];
6566
}
6667

6768
/**

lib/internal/Magento/Framework/App/Test/Unit/Config/ScopeCodeResolverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ public function testResolve()
6767
$this->scope->expects($this->once())
6868
->method('getCode')
6969
->willReturn($scopeCode);
70-
$this->assertEquals($scopeCode, $this->scopeCodeResolver->resolve($scopeType, $scopeId));
70+
$this->assertEquals(strtolower($scopeCode), $this->scopeCodeResolver->resolve($scopeType, $scopeId));
7171
}
7272
}

0 commit comments

Comments
 (0)