|
| 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\Config\Test\Unit\Model\Config\Structure\ElementVisibility; |
| 9 | + |
| 10 | +use Magento\Framework\App\DeploymentConfig; |
| 11 | +use \Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction; |
| 12 | +use \Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProductionFactory; |
| 13 | +use Magento\Framework\Config\ConfigOptionsListConstants as Constants; |
| 14 | +use Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProductionWithoutScdOnDemand; |
| 15 | +use Magento\Config\Model\Config\Structure\ElementVisibilityInterface; |
| 16 | + |
| 17 | +class ConcealInProductionWithoutScdOnDemandTest extends \PHPUnit\Framework\TestCase |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @var ConcealInProduction|\PHPUnit_Framework_MockObject_MockObject |
| 21 | + */ |
| 22 | + private $concealInProductionMock; |
| 23 | + |
| 24 | + /** |
| 25 | + * @var ConcealInProductionWithoutScdOnDemand |
| 26 | + */ |
| 27 | + private $model; |
| 28 | + |
| 29 | + /** |
| 30 | + * @var DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject |
| 31 | + */ |
| 32 | + private $deploymentConfigMock; |
| 33 | + |
| 34 | + protected function setUp() |
| 35 | + { |
| 36 | + $concealInProductionFactoryMock = $this->createMock(ConcealInProductionFactory::class); |
| 37 | + |
| 38 | + $this->concealInProductionMock = $this->createMock(ConcealInProduction::class); |
| 39 | + |
| 40 | + $this->deploymentConfigMock = $this->createMock(\Magento\Framework\App\DeploymentConfig::class); |
| 41 | + |
| 42 | + $configs = [ |
| 43 | + 'section1/group1/field1' => ElementVisibilityInterface::DISABLED, |
| 44 | + 'section1/group1' => ElementVisibilityInterface::HIDDEN, |
| 45 | + 'section1' => ElementVisibilityInterface::DISABLED, |
| 46 | + 'section1/group2' => 'no', |
| 47 | + 'section2/group1' => ElementVisibilityInterface::DISABLED, |
| 48 | + 'section2/group2' => ElementVisibilityInterface::HIDDEN, |
| 49 | + 'section3' => ElementVisibilityInterface::HIDDEN, |
| 50 | + 'section3/group1/field1' => 'no', |
| 51 | + ]; |
| 52 | + $exemptions = [ |
| 53 | + 'section1/group1/field3' => '', |
| 54 | + 'section1/group2/field1' => '', |
| 55 | + 'section2/group2/field1' => '', |
| 56 | + 'section3/group2' => '', |
| 57 | + ]; |
| 58 | + |
| 59 | + $concealInProductionFactoryMock->expects($this->any()) |
| 60 | + ->method('create') |
| 61 | + ->with(['configs' => $configs, 'exemptions' => $exemptions]) |
| 62 | + ->willReturn($this->concealInProductionMock); |
| 63 | + |
| 64 | + $this->model = new ConcealInProductionWithoutScdOnDemand( |
| 65 | + $concealInProductionFactoryMock, |
| 66 | + $this->deploymentConfigMock, |
| 67 | + $configs, |
| 68 | + $exemptions |
| 69 | + ); |
| 70 | + } |
| 71 | + |
| 72 | + public function testIsHiddenScdOnDemandEnabled(): void |
| 73 | + { |
| 74 | + $path = 'section1/group1/field1'; |
| 75 | + $this->deploymentConfigMock->expects($this->once()) |
| 76 | + ->method('getConfigData') |
| 77 | + ->with(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION) |
| 78 | + ->willReturn(true); |
| 79 | + $this->concealInProductionMock->expects($this->never()) |
| 80 | + ->method('isHidden'); |
| 81 | + |
| 82 | + $this->assertFalse($this->model->isHidden($path)); |
| 83 | + } |
| 84 | + |
| 85 | + public function testIsDisabledScdOnDemandEnabled(): void |
| 86 | + { |
| 87 | + $path = 'section1/group1/field1'; |
| 88 | + $this->deploymentConfigMock->expects($this->once()) |
| 89 | + ->method('getConfigData') |
| 90 | + ->with(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION) |
| 91 | + ->willReturn(true); |
| 92 | + $this->concealInProductionMock->expects($this->never()) |
| 93 | + ->method('isDisabled'); |
| 94 | + |
| 95 | + $this->assertFalse($this->model->isDisabled($path)); |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * @param bool $isHidden |
| 100 | + * |
| 101 | + * @dataProvider visibilityDataProvider |
| 102 | + */ |
| 103 | + public function testIsHiddenScdOnDemandDisabled($isHidden): void |
| 104 | + { |
| 105 | + $path = 'section1/group1/field1'; |
| 106 | + $this->deploymentConfigMock->expects($this->once()) |
| 107 | + ->method('getConfigData') |
| 108 | + ->with(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION) |
| 109 | + ->willReturn(false); |
| 110 | + $this->concealInProductionMock->expects($this->once()) |
| 111 | + ->method('isHidden') |
| 112 | + ->with($path) |
| 113 | + ->willReturn($isHidden); |
| 114 | + |
| 115 | + $this->assertSame($isHidden, $this->model->isHidden($path)); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * @param bool $isDisabled |
| 120 | + * |
| 121 | + * @dataProvider visibilityDataProvider |
| 122 | + */ |
| 123 | + public function testIsDisabledScdOnDemandDisabled($isDisabled): void |
| 124 | + { |
| 125 | + $path = 'section1/group1/field1'; |
| 126 | + $this->deploymentConfigMock->expects($this->once()) |
| 127 | + ->method('getConfigData') |
| 128 | + ->with(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION) |
| 129 | + ->willReturn(false); |
| 130 | + $this->concealInProductionMock->expects($this->once()) |
| 131 | + ->method('isDisabled') |
| 132 | + ->with($path) |
| 133 | + ->willReturn($isDisabled); |
| 134 | + |
| 135 | + $this->assertSame($isDisabled, $this->model->isDisabled($path)); |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * @return array |
| 140 | + */ |
| 141 | + public function visibilityDataProvider(): array |
| 142 | + { |
| 143 | + return [ |
| 144 | + [true], |
| 145 | + [false], |
| 146 | + ]; |
| 147 | + } |
| 148 | +} |
0 commit comments