Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConcealInProductionTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 
14 class ConcealInProductionTest extends \PHPUnit\Framework\TestCase
15 {
19  private $stateMock;
20 
24  private $model;
25 
26  protected function setUp()
27  {
28  $this->stateMock = $this->getMockBuilder(State::class)
29  ->disableOriginalConstructor()
30  ->getMock();
31 
32  $configs = [
33  'section1/group1/field1' => ElementVisibilityInterface::DISABLED,
34  'section1/group1' => ElementVisibilityInterface::HIDDEN,
36  'section1/group2' => 'no',
37  'section2/group1' => ElementVisibilityInterface::DISABLED,
38  'section2/group2' => ElementVisibilityInterface::HIDDEN,
40  'section3/group1/field1' => 'no',
41  ];
42  $exemptions = [
43  'section1/group1/field3' => '',
44  'section1/group2/field1' => '',
45  'section2/group2/field1' => '',
46  'section3/group2' => '',
47  ];
48 
49  $this->model = new ConcealInProduction($this->stateMock, $configs, $exemptions);
50  }
51 
59  public function testCheckVisibility(string $path, string $mageMode, bool $isHidden, bool $isDisabled): void
60  {
61  $this->stateMock->expects($this->any())
62  ->method('getMode')
63  ->willReturn($mageMode);
64 
65  $this->assertSame($isHidden, $this->model->isHidden($path));
66  $this->assertSame($isDisabled, $this->model->isDisabled($path));
67  }
68 
72  public function disabledDataProvider(): array
73  {
74  return [
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 
104  ];
105  }
106 }
testCheckVisibility(string $path, string $mageMode, bool $isHidden, bool $isDisabled)