Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConcealInProductionWithoutScdOnDemandTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
11 use \Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction;
12 use \Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProductionFactory;
16 
17 class ConcealInProductionWithoutScdOnDemandTest extends \PHPUnit\Framework\TestCase
18 {
22  private $concealInProductionMock;
23 
27  private $model;
28 
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,
46  'section1/group2' => 'no',
47  'section2/group1' => ElementVisibilityInterface::DISABLED,
48  'section2/group2' => 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 
103  public function testIsHiddenScdOnDemandDisabled(bool $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 
123  public function testIsDisabledScdOnDemandDisabled(bool $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 
141  public function visibilityDataProvider(): array
142  {
143  return [
144  [true],
145  [false],
146  ];
147  }
148 }