[FEATURE] Add SQL Logging to AdminPanel
[Packages/TYPO3.CMS.git] / typo3 / sysext / adminpanel / Tests / Unit / Utility / StateUtilityTest.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Adminpanel\Tests\Unit\Utility;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use TYPO3\CMS\Adminpanel\Utility\StateUtility;
20 use TYPO3\CMS\Backend\FrontendBackendUserAuthentication;
21 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23
24 class StateUtilityTest extends UnitTestCase
25 {
26
27 /**
28 * @test
29 */
30 public function isEnabledReturnsFalseIfNoBackendUserExists(): void
31 {
32 $GLOBALS['BE_USER'] = false;
33 $isEnabled = StateUtility::isActivated();
34 self::assertFalse($isEnabled);
35 }
36
37 /**
38 * @test
39 */
40 public function isEnabledReturnsFalseIfNoBackendUserInFrontendContextIsLoggedIn(): void
41 {
42 $GLOBALS['BE_USER'] = $this->prophesize(BackendUserAuthentication::class)->reveal();
43 $isEnabled = StateUtility::isActivated();
44 self::assertFalse($isEnabled);
45 }
46
47 public function tsConfigEnabledDataProvider(): array
48 {
49 return [
50 '1 module enabled' => [
51 [
52 'admPanel.' => [
53 'enable.' => [
54 'preview' => 1
55 ]
56 ]
57 ]
58 ],
59 'all modules enabled' => [
60 [
61 'admPanel.' => [
62 'enable.' => [
63 'all' => 1
64 ]
65 ]
66 ]
67 ]
68 ];
69 }
70
71 /**
72 * @test
73 * @dataProvider tsConfigEnabledDataProvider
74 * @param array $tsConfig
75 */
76 public function isEnabledReturnsTrueIfAtLeastOneModuleIsEnabled(array $tsConfig): void
77 {
78 $beUserProphecy = $this->prophesize(FrontendBackendUserAuthentication::class);
79 $beUserProphecy->getTSConfig()->willReturn($tsConfig);
80 $GLOBALS['BE_USER'] = $beUserProphecy->reveal();
81 $isEnabled = StateUtility::isActivated();
82 self::assertTrue($isEnabled);
83 }
84
85 public function tsConfigDisabledDataProvider(): array
86 {
87 return [
88 'no config set' => [
89 []
90 ],
91 'all modules disabled' => [
92 'admPanel.' => [
93 'enable.' => [
94 'all' => 0
95 ]
96 ]
97 ],
98 'single module configured, disabled' => [
99 'admPanel.' => [
100 'enable.' => [
101 'preview' => 0
102 ]
103 ]
104 ]
105 ];
106 }
107
108 /**
109 * @test
110 * @dataProvider tsConfigDisabledDataProvider
111 * @param array $tsConfig
112 */
113 public function isEnabledReturnsFalseIfNoModulesEnabled(array $tsConfig): void
114 {
115 $beUserProphecy = $this->prophesize(FrontendBackendUserAuthentication::class);
116 $beUserProphecy->getTSConfig()->willReturn($tsConfig);
117 $GLOBALS['BE_USER'] = $beUserProphecy->reveal();
118 $isEnabled = StateUtility::isActivated();
119 self::assertFalse($isEnabled);
120 }
121 }