diff --git a/app/code/Magento/Backend/etc/adminhtml/di.xml b/app/code/Magento/Backend/etc/adminhtml/di.xml index 1ec23a0dd5582..d6c3273a9a67f 100644 --- a/app/code/Magento/Backend/etc/adminhtml/di.xml +++ b/app/code/Magento/Backend/etc/adminhtml/di.xml @@ -139,10 +139,16 @@ - + Magento\Config\Model\Config\Structure\ElementVisibilityInterface::HIDDEN + + + + + + Magento\Config\Model\Config\Structure\ElementVisibilityInterface::DISABLED diff --git a/app/code/Magento/Config/Model/Config/Structure/ConcealInProductionConfigList.php b/app/code/Magento/Config/Model/Config/Structure/ConcealInProductionConfigList.php index 115a372e6150a..c60d634210339 100644 --- a/app/code/Magento/Config/Model/Config/Structure/ConcealInProductionConfigList.php +++ b/app/code/Magento/Config/Model/Config/Structure/ConcealInProductionConfigList.php @@ -11,7 +11,8 @@ * Defines status of visibility of form elements on Stores > Settings > Configuration page * in Admin Panel in Production mode. * @api - * @since 100.2.0 + * @deprecated class location was changed + * @see \Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction */ class ConcealInProductionConfigList implements ElementVisibilityInterface { @@ -54,7 +55,7 @@ public function __construct(State $state, array $configs = []) /** * @inheritdoc - * @since 100.2.0 + * @deprecated */ public function isHidden($path) { @@ -66,7 +67,7 @@ public function isHidden($path) /** * @inheritdoc - * @since 100.2.0 + * @deprecated */ public function isDisabled($path) { diff --git a/app/code/Magento/Config/Model/Config/Structure/ElementVisibility/ConcealInProduction.php b/app/code/Magento/Config/Model/Config/Structure/ElementVisibility/ConcealInProduction.php new file mode 100755 index 0000000000000..d5ded9292864a --- /dev/null +++ b/app/code/Magento/Config/Model/Config/Structure/ElementVisibility/ConcealInProduction.php @@ -0,0 +1,138 @@ + Settings > Configuration page + * in Admin Panel in Production mode. + * @api + */ +class ConcealInProduction implements ElementVisibilityInterface +{ + /** + * The list of form element paths with concrete visibility status. + * + * E.g. + * + * ```php + * [ + * 'general/locale/code' => ElementVisibilityInterface::DISABLED, + * 'general/country' => ElementVisibilityInterface::HIDDEN, + * ]; + * ``` + * + * It means that: + * - field Locale (in group Locale Options in section General) will be disabled + * - group Country Options (in section General) will be hidden + * + * @var array + */ + private $configs = []; + + /** + * The object that has information about the state of the system. + * + * @var State + */ + private $state; + + /** + * + * The list of form element paths which ignore visibility status. + * + * E.g. + * + * ```php + * [ + * 'general/country/default' => '', + * ]; + * ``` + * + * It means that: + * - field 'default' in group Country Options (in section General) will be showed, even if all group(section) + * will be hidden. + * + * @var array + */ + private $exemptions = []; + + /** + * @param State $state The object that has information about the state of the system + * @param array $configs The list of form element paths with concrete visibility status. + * @param array $exemptions The list of form element paths which ignore visibility status. + */ + public function __construct(State $state, array $configs = [], array $exemptions = []) + { + $this->state = $state; + $this->configs = $configs; + $this->exemptions = $exemptions; + } + + /** + * @inheritdoc + * @since 100.2.0 + */ + public function isHidden($path) + { + $path = $this->normalizePath($path); + if ($this->state->getMode() === State::MODE_PRODUCTION + && preg_match('/(?(?
.*?)\/.*?)\/.*?/', $path, $match)) { + $group = $match['group']; + $section = $match['section']; + $exemptions = array_keys($this->exemptions); + $checkedItems = []; + foreach ([$path, $group, $section] as $itemPath) { + $checkedItems[] = $itemPath; + if (!empty($this->configs[$itemPath])) { + return $this->configs[$itemPath] === static::HIDDEN + && empty(array_intersect($checkedItems, $exemptions)); + } + } + } + + return false; + } + + /** + * @inheritdoc + * @since 100.2.0 + */ + public function isDisabled($path) + { + $path = $this->normalizePath($path); + if ($this->state->getMode() === State::MODE_PRODUCTION) { + while (true) { + if (!empty($this->configs[$path])) { + return $this->configs[$path] === static::DISABLED; + } + + $position = strripos($path, '/'); + if ($position === false) { + break; + } + $path = substr($path, 0, $position); + } + } + + return false; + } + + /** + * Returns normalized path. + * + * @param string $path The path to be normalized + * @return string The normalized path + */ + private function normalizePath($path) + { + return trim($path, '/'); + } +} diff --git a/app/code/Magento/Config/Model/Config/Structure/ElementVisibility/ConcealInProductionWithoutScdOnDemand.php b/app/code/Magento/Config/Model/Config/Structure/ElementVisibility/ConcealInProductionWithoutScdOnDemand.php new file mode 100755 index 0000000000000..29148a244dcc6 --- /dev/null +++ b/app/code/Magento/Config/Model/Config/Structure/ElementVisibility/ConcealInProductionWithoutScdOnDemand.php @@ -0,0 +1,72 @@ + Settings > Configuration page + * when Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION is enabled + * otherwise rule from Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction is used + * @see \Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction + * + * @api + */ +class ConcealInProductionWithoutScdOnDemand implements ElementVisibilityInterface +{ + /** + * @var ConcealInProduction Element visibility rules in the Production mode + */ + private $concealInProduction; + + /** + * @var DeploymentConfig The application deployment configuration + */ + private $deploymentConfig; + + /** + * @param ConcealInProductionFactory $concealInProductionFactory + * @param DeploymentConfig $deploymentConfig Deployment configuration reader + * @param array $configs The list of form element paths with concrete visibility status. + * @param array $exemptions The list of form element paths which ignore visibility status. + */ + public function __construct( + ConcealInProductionFactory $concealInProductionFactory, + DeploymentConfig $deploymentConfig, + array $configs = [], + array $exemptions = [] + ) { + $this->concealInProduction = $concealInProductionFactory + ->create(['configs' => $configs, 'exemptions' => $exemptions]); + $this->deploymentConfig = $deploymentConfig; + } + + /** + * @inheritdoc + */ + public function isHidden($path): bool + { + if (!$this->deploymentConfig->getConfigData(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION)) { + return $this->concealInProduction->isHidden($path); + } + return false; + } + + /** + * @inheritdoc + */ + public function isDisabled($path): bool + { + if (!$this->deploymentConfig->getConfigData(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION)) { + return $this->concealInProduction->isDisabled($path); + } + return false; + } +} diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/Structure/ConcealInProductionConfigListTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/ConcealInProductionConfigListTest.php index 5cad923264e00..ba74b93d9ad76 100644 --- a/app/code/Magento/Config/Test/Unit/Model/Config/Structure/ConcealInProductionConfigListTest.php +++ b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/ConcealInProductionConfigListTest.php @@ -8,6 +8,11 @@ use Magento\Config\Model\Config\Structure\ConcealInProductionConfigList; use Magento\Framework\App\State; +/** + * @deprecated Original class has changed the location + * @see \Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction + * @see \Magento\Config\Test\Unit\Model\Config\Structure\ElementVisibility\ConcealInProductionTest + */ class ConcealInProductionConfigListTest extends \PHPUnit\Framework\TestCase { /** @@ -43,6 +48,8 @@ protected function setUp() * @param string $mageMode * @param bool $expectedResult * @dataProvider disabledDataProvider + * + * @deprecated */ public function testIsDisabled($path, $mageMode, $expectedResult) { @@ -54,6 +61,8 @@ public function testIsDisabled($path, $mageMode, $expectedResult) /** * @return array + * + * @deprecated */ public function disabledDataProvider() { @@ -78,6 +87,8 @@ public function disabledDataProvider() * @param string $mageMode * @param bool $expectedResult * @dataProvider hiddenDataProvider + * + * @deprecated */ public function testIsHidden($path, $mageMode, $expectedResult) { @@ -89,6 +100,8 @@ public function testIsHidden($path, $mageMode, $expectedResult) /** * @return array + * + * @deprecated */ public function hiddenDataProvider() { diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/Structure/ElementVisibility/ConcealInProductionTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/ElementVisibility/ConcealInProductionTest.php new file mode 100644 index 0000000000000..873d447d9868c --- /dev/null +++ b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/ElementVisibility/ConcealInProductionTest.php @@ -0,0 +1,107 @@ +stateMock = $this->getMockBuilder(State::class) + ->disableOriginalConstructor() + ->getMock(); + + $configs = [ + 'section1/group1/field1' => ElementVisibilityInterface::DISABLED, + 'section1/group1' => ElementVisibilityInterface::HIDDEN, + 'section1' => ElementVisibilityInterface::DISABLED, + 'section1/group2' => 'no', + 'section2/group1' => ElementVisibilityInterface::DISABLED, + 'section2/group2' => ElementVisibilityInterface::HIDDEN, + 'section3' => ElementVisibilityInterface::HIDDEN, + 'section3/group1/field1' => 'no', + ]; + $exemptions = [ + 'section1/group1/field3' => '', + 'section1/group2/field1' => '', + 'section2/group2/field1' => '', + 'section3/group2' => '', + ]; + + $this->model = new ConcealInProduction($this->stateMock, $configs, $exemptions); + } + + /** + * @param string $path + * @param string $mageMode + * @param bool $isDisabled + * @param bool $isHidden + * @dataProvider disabledDataProvider + * @return void + */ + public function testCheckVisibility(string $path, string $mageMode, bool $isHidden, bool $isDisabled) + { + $this->stateMock->expects($this->any()) + ->method('getMode') + ->willReturn($mageMode); + + $this->assertSame($isHidden, $this->model->isHidden($path)); + $this->assertSame($isDisabled, $this->model->isDisabled($path)); + } + + /** + * @return array + */ + public function disabledDataProvider(): array + { + return [ + //visibility of field 'section1/group1/field1' should be applied + ['section1/group1/field1', State::MODE_PRODUCTION, false, true], + ['section1/group1/field1', State::MODE_DEFAULT, false, false], + ['section1/group1/field1', State::MODE_DEVELOPER, false, false], + //visibility of group 'section1/group1' should be applied + ['section1/group1/field2', State::MODE_PRODUCTION, true, false], + ['section1/group1/field2', State::MODE_DEFAULT, false, false], + ['section1/group1/field2', State::MODE_DEVELOPER, false, false], + //exemption should be applied for section1/group2/field1 + ['section1/group2/field1', State::MODE_PRODUCTION, false, false], + ['section1/group2/field1', State::MODE_DEFAULT, false, false], + ['section1/group2/field1', State::MODE_DEVELOPER, false, false], + //as 'section1/group2' has neither Disable nor Hidden rule, this field should be visible + ['section1/group2/field2', State::MODE_PRODUCTION, false, false], + //exemption should be applied for section1/group1/field3 + ['section1/group1/field3', State::MODE_PRODUCTION, false, false], + //visibility of group 'section2/group1' should be applied + ['section2/group1/field1', State::MODE_PRODUCTION, false, true], + //exemption should be applied for section2/group2/field1 + ['section2/group2/field1', State::MODE_PRODUCTION, false, false], + //any rule should not be applied + ['section2/group3/field1', State::MODE_PRODUCTION, false, false], + //any rule should not be applied + ['section3/group1/field1', State::MODE_PRODUCTION, false, false], + //visibility of section 'section3' should be applied + ['section3/group1/field2', State::MODE_PRODUCTION, true, false], + //exception from 'section3/group2' should be applied + ['section3/group2/field1', State::MODE_PRODUCTION, false, false], + + ]; + } +} diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/Structure/ElementVisibility/ConcealInProductionWithoutScdOnDemandTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/ElementVisibility/ConcealInProductionWithoutScdOnDemandTest.php new file mode 100644 index 0000000000000..ae213c19a5337 --- /dev/null +++ b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/ElementVisibility/ConcealInProductionWithoutScdOnDemandTest.php @@ -0,0 +1,156 @@ +createMock(ConcealInProductionFactory::class); + + $this->concealInProductionMock = $this->createMock(ConcealInProduction::class); + + $this->deploymentConfigMock = $this->createMock(\Magento\Framework\App\DeploymentConfig::class); + + $configs = [ + 'section1/group1/field1' => ElementVisibilityInterface::DISABLED, + 'section1/group1' => ElementVisibilityInterface::HIDDEN, + 'section1' => ElementVisibilityInterface::DISABLED, + 'section1/group2' => 'no', + 'section2/group1' => ElementVisibilityInterface::DISABLED, + 'section2/group2' => ElementVisibilityInterface::HIDDEN, + 'section3' => ElementVisibilityInterface::HIDDEN, + 'section3/group1/field1' => 'no', + ]; + $exemptions = [ + 'section1/group1/field3' => '', + 'section1/group2/field1' => '', + 'section2/group2/field1' => '', + 'section3/group2' => '', + ]; + + $concealInProductionFactoryMock->expects($this->any()) + ->method('create') + ->with(['configs' => $configs, 'exemptions' => $exemptions]) + ->willReturn($this->concealInProductionMock); + + $this->model = new ConcealInProductionWithoutScdOnDemand( + $concealInProductionFactoryMock, + $this->deploymentConfigMock, + $configs, + $exemptions + ); + } + + /** + * @return void + */ + public function testIsHiddenScdOnDemandEnabled() + { + $path = 'section1/group1/field1'; + $this->deploymentConfigMock->expects($this->once()) + ->method('getConfigData') + ->with(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION) + ->willReturn(true); + $this->concealInProductionMock->expects($this->never()) + ->method('isHidden'); + + $this->assertFalse($this->model->isHidden($path)); + } + + /** + * @return void + */ + public function testIsDisabledScdOnDemandEnabled() + { + $path = 'section1/group1/field1'; + $this->deploymentConfigMock->expects($this->once()) + ->method('getConfigData') + ->with(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION) + ->willReturn(true); + $this->concealInProductionMock->expects($this->never()) + ->method('isDisabled'); + + $this->assertFalse($this->model->isDisabled($path)); + } + + /** + * @param bool $isHidden + * + * @dataProvider visibilityDataProvider + * @return void + */ + public function testIsHiddenScdOnDemandDisabled(bool $isHidden) + { + $path = 'section1/group1/field1'; + $this->deploymentConfigMock->expects($this->once()) + ->method('getConfigData') + ->with(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION) + ->willReturn(false); + $this->concealInProductionMock->expects($this->once()) + ->method('isHidden') + ->with($path) + ->willReturn($isHidden); + + $this->assertSame($isHidden, $this->model->isHidden($path)); + } + + /** + * @param bool $isDisabled + * + * @dataProvider visibilityDataProvider + * @return void + */ + public function testIsDisabledScdOnDemandDisabled(bool $isDisabled) + { + $path = 'section1/group1/field1'; + $this->deploymentConfigMock->expects($this->once()) + ->method('getConfigData') + ->with(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION) + ->willReturn(false); + $this->concealInProductionMock->expects($this->once()) + ->method('isDisabled') + ->with($path) + ->willReturn($isDisabled); + + $this->assertSame($isDisabled, $this->model->isDisabled($path)); + } + + /** + * @return array + */ + public function visibilityDataProvider(): array + { + return [ + [true], + [false], + ]; + } +} diff --git a/app/code/Magento/Config/etc/adminhtml/di.xml b/app/code/Magento/Config/etc/adminhtml/di.xml index c21c06c7f3e1f..5e54f177776ba 100644 --- a/app/code/Magento/Config/etc/adminhtml/di.xml +++ b/app/code/Magento/Config/etc/adminhtml/di.xml @@ -15,6 +15,8 @@ Magento\Config\Model\Config\Structure\ConcealInProductionConfigList + Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction + Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProductionWithoutScdOnDemand diff --git a/lib/internal/Magento/Framework/Locale/Deployed/Options.php b/lib/internal/Magento/Framework/Locale/Deployed/Options.php index ea892ee7fcab0..82f80b8a3b576 100644 --- a/lib/internal/Magento/Framework/Locale/Deployed/Options.php +++ b/lib/internal/Magento/Framework/Locale/Deployed/Options.php @@ -3,9 +3,14 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Framework\Locale\Deployed; +use Magento\Framework\App\DeploymentConfig; +use Magento\Framework\App\ObjectManager; use Magento\Framework\App\State; +use Magento\Framework\Config\ConfigOptionsListConstants as Constants; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Locale\AvailableLocalesInterface; use Magento\Framework\Locale\ListsInterface; @@ -45,28 +50,36 @@ class Options implements OptionInterface */ private $localeLists; + /** + * @var DeploymentConfig + */ + private $deploymentConfig; + /** * @param ListsInterface $localeLists locales list * @param State $state application state class * @param AvailableLocalesInterface $availableLocales operates with available locales * @param DesignInterface $design operates with magento design settings + * @param DeploymentConfig $deploymentConfig */ public function __construct( ListsInterface $localeLists, State $state, AvailableLocalesInterface $availableLocales, - DesignInterface $design + DesignInterface $design, + DeploymentConfig $deploymentConfig = null ) { $this->localeLists = $localeLists; $this->state = $state; $this->availableLocales = $availableLocales; $this->design = $design; + $this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->get(DeploymentConfig::class); } /** * {@inheritdoc} */ - public function getOptionLocales() + public function getOptionLocales(): array { return $this->filterLocales($this->localeLists->getOptionLocales()); } @@ -74,7 +87,7 @@ public function getOptionLocales() /** * {@inheritdoc} */ - public function getTranslatedOptionLocales() + public function getTranslatedOptionLocales(): array { return $this->filterLocales($this->localeLists->getTranslatedOptionLocales()); } @@ -82,7 +95,7 @@ public function getTranslatedOptionLocales() /** * Filter list of locales by available locales for current theme and depends on running application mode. * - * Applies filters only in production mode. + * Applies filters only in production mode when flag 'static_content_on_demand_in_production' is not enabled. * For example, if the current design theme has only one generated locale en_GB then for given array of locales: * ```php * $locales = [ @@ -113,9 +126,10 @@ public function getTranslatedOptionLocales() * @param array $locales list of locales for filtering * @return array of filtered locales */ - private function filterLocales(array $locales) + private function filterLocales(array $locales): array { - if ($this->state->getMode() != State::MODE_PRODUCTION) { + if ($this->state->getMode() != State::MODE_PRODUCTION + || $this->deploymentConfig->getConfigData(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION)) { return $locales; } diff --git a/lib/internal/Magento/Framework/Locale/Test/Unit/Deployed/OptionsTest.php b/lib/internal/Magento/Framework/Locale/Test/Unit/Deployed/OptionsTest.php index 417bbfd402549..0dd592449d77d 100644 --- a/lib/internal/Magento/Framework/Locale/Test/Unit/Deployed/OptionsTest.php +++ b/lib/internal/Magento/Framework/Locale/Test/Unit/Deployed/OptionsTest.php @@ -3,9 +3,13 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Framework\Locale\Test\Unit\Deployed; +use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\State; +use Magento\Framework\Config\ConfigOptionsListConstants as Constants; use Magento\Framework\Locale\AvailableLocalesInterface; use Magento\Framework\Locale\Deployed\Options; use Magento\Framework\Locale\ListsInterface; @@ -40,6 +44,11 @@ class OptionsTest extends \PHPUnit\Framework\TestCase */ private $localeListsMock; + /** + * @var DeploymentConfig|MockObject + */ + private $deploymentConfigMock; + /** * @var Options */ @@ -59,63 +68,123 @@ protected function setUp() ->getMockForAbstractClass(); $this->localeListsMock = $this->getMockBuilder(ListsInterface::class) ->getMockForAbstractClass(); + $this->deploymentConfigMock = $this->createMock(\Magento\Framework\App\DeploymentConfig::class); $this->model = new Options( $this->localeListsMock, $this->stateMock, $this->availableLocalesMock, - $this->designMock + $this->designMock, + $this->deploymentConfigMock ); } /** * @param string $mode + * @param int $scdOnDemand + * @param array $locales + * @return void + * + * @dataProvider getFullLocalesDataProvider + */ + public function testGetOptionLocalesFull(string $mode, int $scdOnDemand, array $locales) + { + $this->localeListsMock->expects($this->once()) + ->method('getOptionLocales') + ->willReturn($locales); + + $this->prepareGetLocalesFull($mode, $scdOnDemand); + + $this->assertEquals($locales, array_values($this->model->getOptionLocales())); + } + + /** + * @param string $mode + * @param int $scdOnDemand + * @param array $locales + * @return void + * + * @dataProvider getFullLocalesDataProvider + */ + public function testGetTranslatedOptionLocalesFull(string $mode, int $scdOnDemand, array $locales) + { + $this->localeListsMock->expects($this->once()) + ->method('getTranslatedOptionLocales') + ->willReturn($locales); + + $this->prepareGetLocalesFull($mode, $scdOnDemand); + + $this->assertEquals($locales, array_values($this->model->getTranslatedOptionLocales())); + } + + /** + * @param string $mode + * @param int $scdOnDemand * @param array $locales * @param array $expectedLocales * @param array $deployedCodes - * @dataProvider getLocaleDataProvider + * @return void + * + * @dataProvider getLimitedLocalesDataProvider */ - public function testGetOptionLocales($mode, $locales, $expectedLocales, $deployedCodes) - { + public function testGetOptionLocalesLimited( + string $mode, + int $scdOnDemand, + array $locales, + array $expectedLocales, + array $deployedCodes + ) { $this->localeListsMock->expects($this->once()) ->method('getOptionLocales') ->willReturn($locales); - $this->prepareGetLocales($mode, $deployedCodes); + $this->prepareGetLocalesLimited($mode, $scdOnDemand, $deployedCodes); $this->assertEquals($expectedLocales, array_values($this->model->getOptionLocales())); } /** * @param string $mode + * @param int $scdOnDemand * @param array $locales * @param array $expectedLocales * @param array $deployedCodes - * @dataProvider getLocaleDataProvider + * @return void + * + * @dataProvider getLimitedLocalesDataProvider */ - public function testGetTranslatedOptionLocales($mode, $locales, $expectedLocales, $deployedCodes) - { + public function testGetTranslatedOptionLocalesLimited( + string $mode, + int $scdOnDemand, + array $locales, + array $expectedLocales, + array $deployedCodes + ) { $this->localeListsMock->expects($this->once()) ->method('getTranslatedOptionLocales') ->willReturn($locales); - $this->prepareGetLocales($mode, $deployedCodes); + $this->prepareGetLocalesLimited($mode, $scdOnDemand, $deployedCodes); $this->assertEquals($expectedLocales, array_values($this->model->getTranslatedOptionLocales())); } /** - * @param $mode - * @param $deployedCodes + * @param string $mode + * @param int $scdOnDemand + * @param array $deployedCodes * @return void */ - private function prepareGetLocales($mode, $deployedCodes) + private function prepareGetLocalesLimited(string $mode, int $scdOnDemand, $deployedCodes) { $this->stateMock->expects($this->once()) ->method('getMode') ->willReturn($mode); + $this->deploymentConfigMock->expects($this->any()) + ->method('getConfigData') + ->with(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION) + ->willReturn($scdOnDemand); - if ($mode == State::MODE_PRODUCTION) { $area = 'area'; $code = 'code'; $themeMock = $this->getMockBuilder(ThemeInterface::class) @@ -133,32 +202,94 @@ private function prepareGetLocales($mode, $deployedCodes) ->method('getList') ->with($code, $area) ->willReturn($deployedCodes); - } + } + + /** + * @param string $mode + * @param int $scdOnDemand + * @return void + */ + private function prepareGetLocalesFull(string $mode, int $scdOnDemand) + { + $this->stateMock->expects($this->once()) + ->method('getMode') + ->willReturn($mode); + $this->deploymentConfigMock->expects($this->any()) + ->method('getConfigData') + ->with(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION) + ->willReturn($scdOnDemand); + + $this->designMock->expects($this->never()) + ->method('getDesignTheme'); } /** * @return array */ - public function getLocaleDataProvider() + public function getFullLocalesDataProvider(): array { + $deLocale = [ + 'value' => 'de_DE', + 'label' => 'German (German)' + ]; + $daLocale = [ + 'value' => 'da_DK', + 'label' => 'Danish (Denmark)' + ]; + return [ [ State::MODE_PRODUCTION, + 1, + [$daLocale, $deLocale], + ], + [ + State::MODE_DEVELOPER, + 0, + [$daLocale, $deLocale], + ], + [ + State::MODE_DEVELOPER, + 1, + [$deLocale], + ], + [ + State::MODE_DEFAULT, + 0, + [$daLocale], + ], + [ + State::MODE_DEFAULT, + 1, + [$daLocale, $deLocale], + ], + ]; + } + + /** + * @return array + */ + public function getLimitedLocalesDataProvider(): array + { + $deLocale = [ + 'value' => 'de_DE', + 'label' => 'German (German)' + ]; + $daLocale = [ + 'value' => 'da_DK', + 'label' => 'Danish (Denmark)' + ]; + + return [ + [ + State::MODE_PRODUCTION, + 0, [ - [ - 'value' => 'da_DK', - 'label' => 'Danish (Denmark)' - ], - [ - 'value' => 'de_DE', - 'label' => 'German (German)' - ] + $daLocale, + $deLocale ], [ - [ - 'value' => 'de_DE', - 'label' => 'German (German)' - ] + $deLocale ], [ 'de_DE' @@ -166,38 +297,17 @@ public function getLocaleDataProvider() ], [ State::MODE_PRODUCTION, + 0, [ - [ - 'value' => 'de_DE', - 'label' => 'German (German)' - ] - ], - [], - [] - ], - [ - State::MODE_DEVELOPER, - [ - [ - 'value' => 'da_DK', - 'label' => 'Danish (Denmark)' - ], - [ - 'value' => 'de_DE', - 'label' => 'German (German)' - ] + $daLocale, + $deLocale ], [ - [ - 'value' => 'da_DK', - 'label' => 'Danish (Denmark)' - ], - [ - 'value' => 'de_DE', - 'label' => 'German (German)' - ] + $daLocale, + $deLocale ], [ + 'da_DK', 'de_DE' ] ],