‪TYPO3CMS  11.5
StateUtilityTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Prophecy\PhpUnit\ProphecyTrait;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
26 class ‪StateUtilityTest extends UnitTestCase
27 {
28  use ProphecyTrait;
29 
33  public function ‪isEnabledReturnsFalseIfNoBackendUserExists(): void
34  {
35  ‪$GLOBALS['BE_USER'] = false;
37  self::assertFalse($isEnabled);
38  }
39 
44  {
45  ‪$GLOBALS['BE_USER'] = $this->prophesize(BackendUserAuthentication::class)->reveal();
47  self::assertFalse($isEnabled);
48  }
49 
50  public function ‪tsConfigEnabledDataProvider(): array
51  {
52  return [
53  '1 module enabled' => [
54  [
55  'admPanel.' => [
56  'enable.' => [
57  'preview' => 1,
58  ],
59  ],
60  ],
61  ],
62  'all modules enabled' => [
63  [
64  'admPanel.' => [
65  'enable.' => [
66  'all' => 1,
67  ],
68  ],
69  ],
70  ],
71  ];
72  }
73 
79  public function ‪isEnabledReturnsTrueIfAtLeastOneModuleIsEnabled(array $tsConfig): void
80  {
81  $beUserProphecy = $this->prophesize(FrontendBackendUserAuthentication::class);
82  $beUserProphecy->getTSConfig()->willReturn($tsConfig);
83  ‪$GLOBALS['BE_USER'] = $beUserProphecy->reveal();
85  self::assertTrue($isEnabled);
86  }
87 
88  public function ‪tsConfigDisabledDataProvider(): array
89  {
90  return [
91  'no config set' => [
92  [],
93  ],
94  'all modules disabled' => [
95  'admPanel.' => [
96  'enable.' => [
97  'all' => 0,
98  ],
99  ],
100  ],
101  'single module configured, disabled' => [
102  'admPanel.' => [
103  'enable.' => [
104  'preview' => 0,
105  ],
106  ],
107  ],
108  ];
109  }
110 
116  public function ‪isEnabledReturnsFalseIfNoModulesEnabled(array $tsConfig): void
117  {
118  $beUserProphecy = $this->prophesize(FrontendBackendUserAuthentication::class);
119  $beUserProphecy->getTSConfig()->willReturn($tsConfig);
120  ‪$GLOBALS['BE_USER'] = $beUserProphecy->reveal();
122  self::assertFalse($isEnabled);
123  }
124 
125  public function ‪tsConfigHideDataProvider(): array
126  {
127  return [
128  'no config set' => [
129  [],
130  false,
131  ],
132  'defined as not hidden' => [
133  [
134  'admPanel.' => [
135  'hide' => '0',
136  ],
137  ],
138  false,
139  ],
140  'defined as hidden' => [
141  [
142  'admPanel.' => [
143  'hide' => '1',
144  ],
145  ],
146  true,
147  ],
148  ];
149  }
150 
157  public function ‪isHiddenForUserReturnsCorrectValue(array $tsConfig, bool $expected): void
158  {
159  $beUserProphecy = $this->prophesize(FrontendBackendUserAuthentication::class);
160  $beUserProphecy->getTSConfig()->willReturn($tsConfig);
161  ‪$GLOBALS['BE_USER'] = $beUserProphecy->reveal();
162  $isEnabled = ‪StateUtility::isHiddenForUser();
163  self::assertSame($expected, $isEnabled);
164  }
165 
170  {
171  ‪$GLOBALS['BE_USER'] = null;
172  $isEnabled = ‪StateUtility::isHiddenForUser();
173  self::assertFalse($isEnabled);
174  }
175 
176  public function ‪ucDisplayOpenDataProvider(): array
177  {
178  return [
179  'no config set' => [
180  [],
181  false,
182  ],
183  'defined as display_top=false' => [
184  [
185  'AdminPanel' => [
186  'display_top' => false,
187  ],
188  ],
189  false,
190  ],
191  'defined as display_top=true' => [
192  [
193  'AdminPanel' => [
194  'display_top' => true,
195  ],
196  ],
197  true,
198  ],
199  ];
200  }
201 
208  public function ‪isOpenForUserReturnsCorrectValue(array $uc, bool $expected): void
209  {
210  $beUser = new ‪FrontendBackendUserAuthentication();
211  $beUser->uc = $uc;
212  ‪$GLOBALS['BE_USER'] = $beUser;
213  $isOpen = ‪StateUtility::isOpen();
214  self::assertSame($expected, $isOpen);
215  }
216 
221  {
222  ‪$GLOBALS['BE_USER'] = null;
223  $isOpen = ‪StateUtility::isOpen();
224  self::assertFalse($isOpen);
225  }
226 
227  public function ‪typoScriptDataProvider(): array
228  {
229  return [
230  'no config set' => [
231  [],
232  false,
233  ],
234  'Admin Panel is disabled' => [
235  [
236  'config' => [
237  'admPanel' => '0',
238  ],
239  ],
240  false,
241  ],
242  'Admin Panel is enabled' => [
243  [
244  'config' => [
245  'admPanel' => '1',
246  ],
247  ],
248  true,
249  ],
250  ];
251  }
252 
259  public function ‪isActivatedInTypoScriptReturnsCorrectValue(array $typoScript, bool $expected): void
260  {
261  $tsfe = new \stdClass();
262  $tsfe->config = $typoScript;
263  ‪$GLOBALS['TSFE'] = $tsfe;
265  self::assertSame($expected, $isEnabled);
266  }
267 }
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility
Definition: StateUtilityTest.php:18
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\isHiddenForUserReturnsFalseIfUserIsNotAvailable
‪isHiddenForUserReturnsFalseIfUserIsNotAvailable()
Definition: StateUtilityTest.php:168
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\isEnabledReturnsFalseIfNoBackendUserInFrontendContextIsLoggedIn
‪isEnabledReturnsFalseIfNoBackendUserInFrontendContextIsLoggedIn()
Definition: StateUtilityTest.php:42
‪TYPO3\CMS\Adminpanel\Utility\StateUtility\isActivatedForUser
‪static bool isActivatedForUser()
Definition: StateUtility.php:34
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest
Definition: StateUtilityTest.php:27
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\tsConfigDisabledDataProvider
‪tsConfigDisabledDataProvider()
Definition: StateUtilityTest.php:87
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication
Definition: FrontendBackendUserAuthentication.php:31
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\isHiddenForUserReturnsCorrectValue
‪isHiddenForUserReturnsCorrectValue(array $tsConfig, bool $expected)
Definition: StateUtilityTest.php:156
‪TYPO3\CMS\Adminpanel\Utility\StateUtility\isHiddenForUser
‪static isHiddenForUser()
Definition: StateUtility.php:64
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\typoScriptDataProvider
‪typoScriptDataProvider()
Definition: StateUtilityTest.php:226
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\isOpenForUserReturnsCorrectValue
‪isOpenForUserReturnsCorrectValue(array $uc, bool $expected)
Definition: StateUtilityTest.php:207
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\isEnabledReturnsFalseIfNoBackendUserExists
‪isEnabledReturnsFalseIfNoBackendUserExists()
Definition: StateUtilityTest.php:32
‪TYPO3\CMS\Adminpanel\Utility\StateUtility
Definition: StateUtility.php:28
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\tsConfigHideDataProvider
‪tsConfigHideDataProvider()
Definition: StateUtilityTest.php:124
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\tsConfigEnabledDataProvider
‪tsConfigEnabledDataProvider()
Definition: StateUtilityTest.php:49
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\isActivatedInTypoScriptReturnsCorrectValue
‪isActivatedInTypoScriptReturnsCorrectValue(array $typoScript, bool $expected)
Definition: StateUtilityTest.php:258
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\isOpenForUserReturnsFalseIfUserIsNotAvailable
‪isOpenForUserReturnsFalseIfUserIsNotAvailable()
Definition: StateUtilityTest.php:219
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Adminpanel\Utility\StateUtility\isOpen
‪static bool isOpen()
Definition: StateUtility.php:53
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\isEnabledReturnsTrueIfAtLeastOneModuleIsEnabled
‪isEnabledReturnsTrueIfAtLeastOneModuleIsEnabled(array $tsConfig)
Definition: StateUtilityTest.php:78
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\isEnabledReturnsFalseIfNoModulesEnabled
‪isEnabledReturnsFalseIfNoModulesEnabled(array $tsConfig)
Definition: StateUtilityTest.php:115
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\ucDisplayOpenDataProvider
‪ucDisplayOpenDataProvider()
Definition: StateUtilityTest.php:175
‪TYPO3\CMS\Adminpanel\Utility\StateUtility\isActivatedInTypoScript
‪static isActivatedInTypoScript()
Definition: StateUtility.php:59