‪TYPO3CMS  10.4
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 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 class ‪StateUtilityTest extends UnitTestCase
26 {
27 
32  {
33  ‪$GLOBALS['BE_USER'] = false;
35  self::assertFalse($isEnabled);
36  }
37 
42  {
43  ‪$GLOBALS['BE_USER'] = $this->prophesize(BackendUserAuthentication::class)->reveal();
45  self::assertFalse($isEnabled);
46  }
47 
48  public function ‪tsConfigEnabledDataProvider(): array
49  {
50  return [
51  '1 module enabled' => [
52  [
53  'admPanel.' => [
54  'enable.' => [
55  'preview' => 1
56  ]
57  ]
58  ]
59  ],
60  'all modules enabled' => [
61  [
62  'admPanel.' => [
63  'enable.' => [
64  'all' => 1
65  ]
66  ]
67  ]
68  ]
69  ];
70  }
71 
77  public function ‪isEnabledReturnsTrueIfAtLeastOneModuleIsEnabled(array $tsConfig): void
78  {
79  $beUserProphecy = $this->prophesize(FrontendBackendUserAuthentication::class);
80  $beUserProphecy->getTSConfig()->willReturn($tsConfig);
81  ‪$GLOBALS['BE_USER'] = $beUserProphecy->reveal();
83  self::assertTrue($isEnabled);
84  }
85 
86  public function ‪tsConfigDisabledDataProvider(): array
87  {
88  return [
89  'no config set' => [
90  []
91  ],
92  'all modules disabled' => [
93  'admPanel.' => [
94  'enable.' => [
95  'all' => 0
96  ]
97  ]
98  ],
99  'single module configured, disabled' => [
100  'admPanel.' => [
101  'enable.' => [
102  'preview' => 0
103  ]
104  ]
105  ]
106  ];
107  }
108 
114  public function ‪isEnabledReturnsFalseIfNoModulesEnabled(array $tsConfig): void
115  {
116  $beUserProphecy = $this->prophesize(FrontendBackendUserAuthentication::class);
117  $beUserProphecy->getTSConfig()->willReturn($tsConfig);
118  ‪$GLOBALS['BE_USER'] = $beUserProphecy->reveal();
120  self::assertFalse($isEnabled);
121  }
122 
123  public function ‪tsConfigHideDataProvider(): array
124  {
125  return [
126  'no config set' => [
127  [],
128  false
129  ],
130  'defined as not hidden' => [
131  [
132  'admPanel.' => [
133  'hide' => '0'
134  ]
135  ],
136  false
137  ],
138  'defined as hidden' => [
139  [
140  'admPanel.' => [
141  'hide' => '1'
142  ]
143  ],
144  true
145  ]
146  ];
147  }
148 
155  public function ‪isHiddenForUserReturnsCorrectValue(array $tsConfig, bool $expected): void
156  {
157  $beUserProphecy = $this->prophesize(FrontendBackendUserAuthentication::class);
158  $beUserProphecy->getTSConfig()->willReturn($tsConfig);
159  ‪$GLOBALS['BE_USER'] = $beUserProphecy->reveal();
160  $isEnabled = ‪StateUtility::isHiddenForUser();
161  self::assertSame($expected, $isEnabled);
162  }
163 
168  {
169  ‪$GLOBALS['BE_USER'] = null;
170  $isEnabled = ‪StateUtility::isHiddenForUser();
171  self::assertFalse($isEnabled);
172  }
173 
174  public function ‪ucDisplayOpenDataProvider(): array
175  {
176  return [
177  'no config set' => [
178  [],
179  false
180  ],
181  'defined as display_top=false' => [
182  [
183  'AdminPanel' => [
184  'display_top' => false
185  ]
186  ],
187  false
188  ],
189  'defined as display_top=true' => [
190  [
191  'AdminPanel' => [
192  'display_top' => true
193  ]
194  ],
195  true
196  ],
197  ];
198  }
199 
206  public function ‪isOpenForUserReturnsCorrectValue(array $uc, bool $expected): void
207  {
208  $beUser = new ‪FrontendBackendUserAuthentication();
209  $beUser->uc = $uc;
210  ‪$GLOBALS['BE_USER'] = $beUser;
211  $isOpen = ‪StateUtility::isOpen();
212  self::assertSame($expected, $isOpen);
213  }
214 
219  {
220  ‪$GLOBALS['BE_USER'] = null;
221  $isOpen = ‪StateUtility::isOpen();
222  self::assertFalse($isOpen);
223  }
224 
225  public function ‪typoScriptDataProvider(): array
226  {
227  return [
228  'no config set' => [
229  [],
230  false
231  ],
232  'Admin Panel is disabled' => [
233  [
234  'config' => [
235  'admPanel' => '0'
236  ]
237  ],
238  false
239  ],
240  'Admin Panel is enabled' => [
241  [
242  'config' => [
243  'admPanel' => '1'
244  ]
245  ],
246  true
247  ],
248  ];
249  }
250 
257  public function ‪isActivatedInTypoScriptReturnsCorrectValue(array $typoScript, bool $expected): void
258  {
259  $tsfe = new \stdClass();
260  $tsfe->config = $typoScript;
261  ‪$GLOBALS['TSFE'] = $tsfe;
263  self::assertSame($expected, $isEnabled);
264  }
265 }
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility
Definition: StateUtilityTest.php:18
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\isHiddenForUserReturnsFalseIfUserIsNotAvailable
‪isHiddenForUserReturnsFalseIfUserIsNotAvailable()
Definition: StateUtilityTest.php:167
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\isEnabledReturnsFalseIfNoBackendUserInFrontendContextIsLoggedIn
‪isEnabledReturnsFalseIfNoBackendUserInFrontendContextIsLoggedIn()
Definition: StateUtilityTest.php:41
‪TYPO3\CMS\Adminpanel\Utility\StateUtility\isActivatedForUser
‪static bool isActivatedForUser()
Definition: StateUtility.php:34
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest
Definition: StateUtilityTest.php:26
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\tsConfigDisabledDataProvider
‪tsConfigDisabledDataProvider()
Definition: StateUtilityTest.php:86
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication
Definition: FrontendBackendUserAuthentication.php:31
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\isHiddenForUserReturnsCorrectValue
‪isHiddenForUserReturnsCorrectValue(array $tsConfig, bool $expected)
Definition: StateUtilityTest.php:155
‪TYPO3\CMS\Adminpanel\Utility\StateUtility\isHiddenForUser
‪static isHiddenForUser()
Definition: StateUtility.php:64
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\typoScriptDataProvider
‪typoScriptDataProvider()
Definition: StateUtilityTest.php:225
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\isOpenForUserReturnsCorrectValue
‪isOpenForUserReturnsCorrectValue(array $uc, bool $expected)
Definition: StateUtilityTest.php:206
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\isEnabledReturnsFalseIfNoBackendUserExists
‪isEnabledReturnsFalseIfNoBackendUserExists()
Definition: StateUtilityTest.php:31
‪TYPO3\CMS\Adminpanel\Utility\StateUtility
Definition: StateUtility.php:28
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\tsConfigHideDataProvider
‪tsConfigHideDataProvider()
Definition: StateUtilityTest.php:123
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\tsConfigEnabledDataProvider
‪tsConfigEnabledDataProvider()
Definition: StateUtilityTest.php:48
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\isActivatedInTypoScriptReturnsCorrectValue
‪isActivatedInTypoScriptReturnsCorrectValue(array $typoScript, bool $expected)
Definition: StateUtilityTest.php:257
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\isOpenForUserReturnsFalseIfUserIsNotAvailable
‪isOpenForUserReturnsFalseIfUserIsNotAvailable()
Definition: StateUtilityTest.php:218
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪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:77
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\isEnabledReturnsFalseIfNoModulesEnabled
‪isEnabledReturnsFalseIfNoModulesEnabled(array $tsConfig)
Definition: StateUtilityTest.php:114
‪TYPO3\CMS\Adminpanel\Tests\Unit\Utility\StateUtilityTest\ucDisplayOpenDataProvider
‪ucDisplayOpenDataProvider()
Definition: StateUtilityTest.php:174
‪TYPO3\CMS\Adminpanel\Utility\StateUtility\isActivatedInTypoScript
‪static isActivatedInTypoScript()
Definition: StateUtility.php:59