Skip to content

Commit 8c004a7

Browse files
committed
MAGETWO-91934: Unlock Locales Editing when SCD on Demand Mode is Enabled
- fix static tests
1 parent 44e3fab commit 8c004a7

File tree

6 files changed

+102
-122
lines changed

6 files changed

+102
-122
lines changed

app/code/Magento/Config/Model/Config/Structure/ElementVisibility/ConcealInProduction.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Config\Model\Config\Structure\ElementVisibility;
79

810
use Magento\Config\Model\Config\Structure\ElementVisibilityInterface;
@@ -80,21 +82,23 @@ public function __construct(State $state, array $configs = [], array $exemptions
8082
*/
8183
public function isHidden($path)
8284
{
83-
$result = false;
8485
$path = $this->normalizePath($path);
8586
if ($this->state->getMode() === State::MODE_PRODUCTION
8687
&& preg_match('/(?<group>(?<section>.*?)\/.*?)\/.*?/', $path, $match)) {
8788
$group = $match['group'];
8889
$section = $match['section'];
8990
$exemptions = array_keys($this->exemptions);
90-
foreach ($this->configs as $configPath => $value) {
91-
if ($value === static::HIDDEN && strpos($path, $configPath) !==false) {
92-
$result = empty(array_intersect([$section, $group, $path], $exemptions));
91+
$checkedItems = [];
92+
foreach ([$path, $group, $section] as $itemPath) {
93+
$checkedItems[] = $itemPath;
94+
if (!empty($this->configs[$itemPath])) {
95+
return $this->configs[$itemPath] === static::HIDDEN
96+
&& empty(array_intersect($checkedItems, $exemptions));
9397
}
9498
}
9599
}
96100

97-
return $result;
101+
return false;
98102
}
99103

100104
/**

app/code/Magento/Config/Model/Config/Structure/ElementVisibility/ConcealScdField.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Config\Model\Config\Structure\ElementVisibility;
79

810
use Magento\Config\Model\Config\Structure\ElementVisibilityInterface;
@@ -90,7 +92,7 @@ public function __construct(
9092
/**
9193
* @inheritdoc
9294
*/
93-
public function isHidden($path)
95+
public function isHidden($path): bool
9496
{
9597
$path = $this->normalizePath($path);
9698
if ($this->state->getMode() === State::MODE_PRODUCTION
@@ -115,7 +117,7 @@ public function isHidden($path)
115117
/**
116118
* @inheritdoc
117119
*/
118-
public function isDisabled($path)
120+
public function isDisabled($path): bool
119121
{
120122
$path = $this->normalizePath($path);
121123
if ($this->state->getMode() === State::MODE_PRODUCTION

app/code/Magento/Config/Test/Unit/Model/Config/Structure/ElementVisibility/ConcealInProductionTest.php

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Config\Test\Unit\Model\Config\Structure\ElementVisibility;
79

810
use Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction;
@@ -28,16 +30,20 @@ protected function setUp()
2830
->getMock();
2931

3032
$configs = [
31-
'first/path' => ElementVisibilityInterface::DISABLED,
32-
'second/path' => ElementVisibilityInterface::HIDDEN,
33-
'third' => ElementVisibilityInterface::DISABLED,
34-
'third/path' => 'no',
35-
'third/path/field' => ElementVisibilityInterface::DISABLED,
36-
'first/path/field' => 'no',
37-
'fourth' => ElementVisibilityInterface::HIDDEN,
33+
'section1/group1/field1' => ElementVisibilityInterface::DISABLED,
34+
'section1/group1' => ElementVisibilityInterface::HIDDEN,
35+
'section1' => ElementVisibilityInterface::DISABLED,
36+
'section1/group2' => 'no',
37+
'section2/group1' => ElementVisibilityInterface::DISABLED,
38+
'section2/group2' => ElementVisibilityInterface::HIDDEN,
39+
'section3' => ElementVisibilityInterface::HIDDEN,
40+
'section3/group1/field1' => 'no',
3841
];
3942
$exemptions = [
40-
'fourth/path/value' => '',
43+
'section1/group1/field3' => '',
44+
'section1/group2/field1' => '',
45+
'section2/group2/field1' => '',
46+
'section3/group2' => '',
4147
];
4248

4349
$this->model = new ConcealInProduction($this->stateMock, $configs, $exemptions);
@@ -46,65 +52,55 @@ protected function setUp()
4652
/**
4753
* @param string $path
4854
* @param string $mageMode
49-
* @param bool $expectedResult
55+
* @param bool $isDisabled
56+
* @param bool $isHidden
5057
* @dataProvider disabledDataProvider
5158
*/
52-
public function testIsDisabled($path, $mageMode, $expectedResult)
59+
public function testCheckVisibility(string $path, string $mageMode, bool $isHidden, bool $isDisabled): void
5360
{
54-
$this->stateMock->expects($this->once())
61+
$this->stateMock->expects($this->any())
5562
->method('getMode')
5663
->willReturn($mageMode);
57-
$this->assertSame($expectedResult, $this->model->isDisabled($path));
58-
}
59-
60-
/**
61-
* @return array
62-
*/
63-
public function disabledDataProvider()
64-
{
65-
return [
66-
['first/path', State::MODE_PRODUCTION, true],
67-
['first/path/field', State::MODE_PRODUCTION, false],
68-
['first/path/field2', State::MODE_PRODUCTION, true],
69-
['first/path', State::MODE_DEFAULT, false],
70-
['some/path', State::MODE_PRODUCTION, false],
71-
['second/path', State::MODE_PRODUCTION, false],
72-
['third', State::MODE_PRODUCTION, true],
73-
['third/path2', State::MODE_PRODUCTION, true],
74-
['third/path2/field', State::MODE_PRODUCTION, true],
75-
['third/path', State::MODE_PRODUCTION, false],
76-
['third/path/field', State::MODE_PRODUCTION, true],
77-
['third/path/field2', State::MODE_PRODUCTION, false],
78-
];
79-
}
8064

81-
/**
82-
* @param string $path
83-
* @param string $mageMode
84-
* @param bool $expectedResult
85-
* @dataProvider hiddenDataProvider
86-
*/
87-
public function testIsHidden($path, $mageMode, $expectedResult)
88-
{
89-
$this->stateMock->expects($this->once())
90-
->method('getMode')
91-
->willReturn($mageMode);
92-
$this->assertSame($expectedResult, $this->model->isHidden($path));
65+
$this->assertSame($isHidden, $this->model->isHidden($path));
66+
$this->assertSame($isDisabled, $this->model->isDisabled($path));
9367
}
9468

9569
/**
9670
* @return array
9771
*/
98-
public function hiddenDataProvider()
72+
public function disabledDataProvider(): array
9973
{
10074
return [
101-
['first/path', State::MODE_PRODUCTION, false],
102-
['first/path', State::MODE_DEFAULT, false],
103-
['some/path', State::MODE_PRODUCTION, false],
104-
['second/path/field', State::MODE_PRODUCTION, true],
105-
['second/path', State::MODE_DEVELOPER, false],
106-
['fourth/path/value', State::MODE_PRODUCTION, false],
107-
['fourth/path/test', State::MODE_PRODUCTION, true],
75+
//visibility of field 'section1/group1/field1' should be applied
76+
['section1/group1/field1', State::MODE_PRODUCTION, false, true],
77+
['section1/group1/field1', State::MODE_DEFAULT, false, false],
78+
['section1/group1/field1', State::MODE_DEVELOPER, false, false],
79+
//visibility of group 'section1/group1' should be applied
80+
['section1/group1/field2', State::MODE_PRODUCTION, true, false],
81+
['section1/group1/field2', State::MODE_DEFAULT, false, false],
82+
['section1/group1/field2', State::MODE_DEVELOPER, false, false],
83+
//exemption should be applied for section1/group2/field1
84+
['section1/group2/field1', State::MODE_PRODUCTION, false, false],
85+
['section1/group2/field1', State::MODE_DEFAULT, false, false],
86+
['section1/group2/field1', State::MODE_DEVELOPER, false, false],
87+
//as 'section1/group2' has neither Disable nor Hidden rule, this field should be visible
88+
['section1/group2/field2', State::MODE_PRODUCTION, false, false],
89+
//exemption should be applied for section1/group1/field3
90+
['section1/group1/field3', State::MODE_PRODUCTION, false, false],
91+
//visibility of group 'section2/group1' should be applied
92+
['section2/group1/field1', State::MODE_PRODUCTION, false, true],
93+
//exemption should be applied for section2/group2/field1
94+
['section2/group2/field1', State::MODE_PRODUCTION, false, false],
95+
//any rule should not be applied
96+
['section2/group3/field1', State::MODE_PRODUCTION, false, false],
97+
//any rule should not be applied
98+
['section3/group1/field1', State::MODE_PRODUCTION, false, false],
99+
//visibility of section 'section3' should be applied
100+
['section3/group1/field2', State::MODE_PRODUCTION, true, false],
101+
//exception from 'section3/group2' should be applied
102+
['section3/group2/field1', State::MODE_PRODUCTION, false, false],
103+
108104
];
109105
}
110106
}

app/code/Magento/Config/Test/Unit/Model/Config/Structure/ElementVisibility/ConcealScdFieldTest.php

Lines changed: 29 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Config\Test\Unit\Model\Config\Structure\ElementVisibility;
79

810
use Magento\Framework\App\DeploymentConfig;
@@ -43,7 +45,6 @@ protected function setUp()
4345
'section2/group2' => ElementVisibilityInterface::HIDDEN,
4446
'section3' => ElementVisibilityInterface::HIDDEN,
4547
'section3/group1/field1' => 'no',
46-
'section5' => 'no',
4748
];
4849
$exemptions = [
4950
'section1/group1/field3' => '',
@@ -63,7 +64,8 @@ protected function setUp()
6364
* @param bool $isHidden
6465
* @dataProvider disabledDataProvider
6566
*/
66-
public function testCheckVisibility($path, $mageMode, $scdOnDemand, $isHidden, $isDisabled)
67+
public function testCheckVisibility(string $path, string $mageMode,
68+
int $scdOnDemand, bool $isHidden, bool $isDisabled): void
6769
{
6870
$this->stateMock->expects($this->any())
6971
->method('getMode')
@@ -80,7 +82,7 @@ public function testCheckVisibility($path, $mageMode, $scdOnDemand, $isHidden, $
8082
/**
8183
* @return array
8284
*/
83-
public function disabledDataProvider()
85+
public function disabledDataProvider(): array
8486
{
8587
return [
8688
//visibility of field 'section1/group1/field1' should be applied
@@ -104,60 +106,31 @@ public function disabledDataProvider()
104106
['section1/group2/field1', State::MODE_DEFAULT, 1, false, false],
105107
['section1/group2/field1', State::MODE_DEVELOPER, 0, false, false],
106108
['section1/group2/field1', State::MODE_DEVELOPER, 1, false, false],
107-
//visibility of section 'section1' should be applied
108-
// ['section1/group2/field2', State::MODE_PRODUCTION, 1, false, false],
109-
// ['section1/group2/field2', State::MODE_PRODUCTION, 0, false, true],
110-
// ['section1/group2/field2', State::MODE_DEFAULT, 0, false, false],
111-
// ['section1/group2/field2', State::MODE_DEFAULT, 1, false, false],
112-
// ['section1/group2/field2', State::MODE_DEVELOPER, 0, false, false],
113-
// ['section1/group2/field2', State::MODE_DEVELOPER, 1, false, false],
114-
// //exemption should be applied for section1/group1/field3
115-
// ['section1/group1/field3', State::MODE_PRODUCTION, 1, false, false],
116-
// ['section1/group1/field3', State::MODE_PRODUCTION, 0, false, false],
117-
// ['section1/group1/field3', State::MODE_DEFAULT, 0, false, false],
118-
// ['section1/group1/field3', State::MODE_DEFAULT, 1, false, false],
119-
// ['section1/group1/field3', State::MODE_DEVELOPER, 0, false, false],
120-
// ['section1/group1/field3', State::MODE_DEVELOPER, 1, false, false],
121-
// //visibility of group 'section2/group1' should be applied
122-
// ['section2/group1/field1', State::MODE_PRODUCTION, 1, false, false],
123-
// ['section2/group1/field1', State::MODE_PRODUCTION, 0, false, true],
124-
// //exemption should be applied for section2/group2/field1
125-
// ['section2/group2/field1', State::MODE_PRODUCTION, 1, false, false],
126-
// ['section2/group2/field1', State::MODE_PRODUCTION, 0, false, false],
127-
// //any rule should not be applied
128-
// ['section2/group3/field1', State::MODE_PRODUCTION, 1, false, false],
129-
// ['section2/group3/field1', State::MODE_PRODUCTION, 0, false, false],
109+
//as 'section1/group2' has neither Disable nor Hidden rule, this field should be visible
110+
['section1/group2/field2', State::MODE_PRODUCTION, 1, false, false],
111+
['section1/group2/field2', State::MODE_PRODUCTION, 0, false, false],
112+
//exemption should be applied for section1/group1/field3
113+
['section1/group1/field3', State::MODE_PRODUCTION, 1, false, false],
114+
['section1/group1/field3', State::MODE_PRODUCTION, 0, false, false],
115+
//visibility of group 'section2/group1' should be applied
116+
['section2/group1/field1', State::MODE_PRODUCTION, 1, false, false],
117+
['section2/group1/field1', State::MODE_PRODUCTION, 0, false, true],
118+
//exemption should be applied for section2/group2/field1
119+
['section2/group2/field1', State::MODE_PRODUCTION, 1, false, false],
120+
['section2/group2/field1', State::MODE_PRODUCTION, 0, false, false],
121+
//any rule should not be applied
122+
['section2/group3/field1', State::MODE_PRODUCTION, 1, false, false],
123+
['section2/group3/field1', State::MODE_PRODUCTION, 0, false, false],
124+
//any rule should not be applied
125+
['section3/group1/field1', State::MODE_PRODUCTION, 1, false, false],
126+
['section3/group1/field1', State::MODE_PRODUCTION, 0, false, false],
127+
//visibility of section 'section3' should be applied
128+
['section3/group1/field2', State::MODE_PRODUCTION, 1, false, false],
129+
['section3/group1/field2', State::MODE_PRODUCTION, 0, true, false],
130+
//exception from 'section3/group2' should be applied
131+
['section3/group2/field1', State::MODE_PRODUCTION, 1, false, false],
132+
['section3/group2/field1', State::MODE_PRODUCTION, 0, false, false],
130133

131134
];
132135
}
133-
134-
// /**
135-
// * @param string $path
136-
// * @param string $mageMode
137-
// * @param bool $expectedResult
138-
// * @dataProvider hiddenDataProvider
139-
// */
140-
// public function testIsHidden($path, $mageMode, $expectedResult)
141-
// {
142-
// $this->stateMock->expects($this->once())
143-
// ->method('getMode')
144-
// ->willReturn($mageMode);
145-
// $this->assertSame($expectedResult, $this->model->isHidden($path));
146-
// }
147-
//
148-
// /**
149-
// * @return array
150-
// */
151-
// public function hiddenDataProvider()
152-
// {
153-
// return [
154-
// ['first/path', State::MODE_PRODUCTION, false],
155-
// ['first/path', State::MODE_DEFAULT, false],
156-
// ['some/path', State::MODE_PRODUCTION, false],
157-
// ['second/path/field', State::MODE_PRODUCTION, true],
158-
// ['second/path', State::MODE_DEVELOPER, false],
159-
// ['fourth/path/value', State::MODE_PRODUCTION, false],
160-
// ['fourth/path/test', State::MODE_PRODUCTION, true],
161-
// ];
162-
// }
163136
}

lib/internal/Magento/Framework/Locale/Deployed/Options.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Framework\Locale\Deployed;
79

810
use Magento\Framework\App\DeploymentConfig;
@@ -77,23 +79,23 @@ public function __construct(
7779
/**
7880
* {@inheritdoc}
7981
*/
80-
public function getOptionLocales()
82+
public function getOptionLocales(): array
8183
{
8284
return $this->filterLocales($this->localeLists->getOptionLocales());
8385
}
8486

8587
/**
8688
* {@inheritdoc}
8789
*/
88-
public function getTranslatedOptionLocales()
90+
public function getTranslatedOptionLocales(): array
8991
{
9092
return $this->filterLocales($this->localeLists->getTranslatedOptionLocales());
9193
}
9294

9395
/**
9496
* Filter list of locales by available locales for current theme and depends on running application mode.
9597
*
96-
* Applies filters only in production mode.
98+
* Applies filters only in production mode when flag 'static_content_on_demand_in_production' is not enabled.
9799
* For example, if the current design theme has only one generated locale en_GB then for given array of locales:
98100
* ```php
99101
* $locales = [
@@ -124,7 +126,7 @@ public function getTranslatedOptionLocales()
124126
* @param array $locales list of locales for filtering
125127
* @return array of filtered locales
126128
*/
127-
private function filterLocales(array $locales)
129+
private function filterLocales(array $locales): array
128130
{
129131
if ($this->state->getMode() != State::MODE_PRODUCTION
130132
|| $this->deploymentConfig->getConfigData(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION)) {

lib/internal/Magento/Framework/Locale/Test/Unit/Deployed/OptionsTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Framework\Locale\Test\Unit\Deployed;
79

810
use Magento\Framework\App\DeploymentConfig;
@@ -138,7 +140,8 @@ public function testGetOptionLocalesLimited($mode, $scdOnDemand, $locales, $expe
138140
* @param array $deployedCodes
139141
* @dataProvider getLimitedLocalesDataProvider
140142
*/
141-
public function testGetTranslatedOptionLocalesLimited($mode, $scdOnDemand, $locales, $expectedLocales, $deployedCodes)
143+
public function testGetTranslatedOptionLocalesLimited($mode, $scdOnDemand, $locales,
144+
$expectedLocales, $deployedCodes)
142145
{
143146
$this->localeListsMock->expects($this->once())
144147
->method('getTranslatedOptionLocales')

0 commit comments

Comments
 (0)