Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SettingCheckerTest.php
Go to the documentation of this file.
1 <?php
7 
14 
18 class SettingCheckerTest extends \PHPUnit\Framework\TestCase
19 {
23  private $configMock;
24 
28  private $placeholderMock;
29 
33  private $scopeCodeResolverMock;
34 
38  private $checker;
39 
43  private $env;
44 
45  public function setUp()
46  {
47  $this->configMock = $this->getMockBuilder(DeploymentConfig::class)
48  ->disableOriginalConstructor()
49  ->getMock();
50  $this->placeholderMock = $this->getMockBuilder(PlaceholderInterface::class)
51  ->getMockForAbstractClass();
52  $this->scopeCodeResolverMock = $this->getMockBuilder(Config\ScopeCodeResolver::class)
53  ->disableOriginalConstructor()
54  ->getMock();
55  $placeholderFactoryMock = $this->getMockBuilder(PlaceholderFactory::class)
56  ->disableOriginalConstructor()
57  ->getMock();
58  $this->env = $_ENV;
59 
60  $placeholderFactoryMock->expects($this->once())
61  ->method('create')
63  ->willReturn($this->placeholderMock);
64 
65  $this->checker = new SettingChecker($this->configMock, $placeholderFactoryMock, $this->scopeCodeResolverMock);
66  }
67 
77  public function testIsReadonly($path, $scope, $scopeCode, $confValue, array $variables, $expectedResult)
78  {
79  $this->placeholderMock->expects($this->once())
80  ->method('isApplicable')
81  ->willReturn(true);
82  $this->placeholderMock->expects($this->once())
83  ->method('generate')
84  ->with($path, $scope, $scopeCode)
85  ->willReturn('SOME_PLACEHOLDER');
86  $this->scopeCodeResolverMock->expects($this->any())
87  ->method('resolve')
88  ->willReturnMap(
89  [
90  ['website', 'myWebsite', ($scopeCode ? $scopeCode : '')]
91  ]
92  );
93 
94  $_ENV = array_merge($this->env, $variables);
95 
96  $this->configMock->expects($this->any())
97  ->method('get')
98  ->willReturnMap([
99  [
100  'system/' . $scope . "/" . ($scopeCode ? $scopeCode . '/' : '') . $path,
101  null,
102  $confValue
103  ],
104  ]);
105 
106  $this->assertSame($expectedResult, $this->checker->isReadOnly($path, $scope, $scopeCode));
107  }
108 
112  public function isReadonlyDataProvider()
113  {
114  return [
115  [
116  'path' => 'general/web/locale',
117  'scope' => 'website',
118  'scopeCode' => 'myWebsite',
119  'confValue' => 'value',
120  'variables' => [],
121  'expectedResult' => true,
122  ],
123  [
124  'path' => 'general/web/locale',
125  'scope' => 'website',
126  'scopeCode' => 'myWebsite',
127  'confValue' => null,
128  'variables' => ['SOME_PLACEHOLDER' => 'value'],
129  'expectedResult' => true,
130  ],
131  [
132  'path' => 'general/web/locale',
133  'scope' => 'website',
134  'scopeCode' => 'myWebsite',
135  'confValue' => null,
136  'variables' => [],
137  'expectedResult' => false,
138  ]
139  ];
140  }
141 
142  protected function tearDown()
143  {
144  $_ENV = $this->env;
145  }
146 }
testIsReadonly($path, $scope, $scopeCode, $confValue, array $variables, $expectedResult)