‪TYPO3CMS  9.5
AdminPanelInitiatorTest.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Prophecy\Argument;
19 use Prophecy\Prophecy\ObjectProphecy;
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
22 use Psr\Http\Server\RequestHandlerInterface;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 
33 class ‪AdminPanelInitiatorTest extends UnitTestCase
34 {
38  protected ‪$resetSingletonInstances = true;
39 
43  public function ‪processCallsInitialize(): void
44  {
45  $tsConfig = [
46  'admPanel.' => [
47  'enable.' => [
48  'all',
49  ],
50  ],
51  ];
52  $uc = [
53  'AdminPanel' => [
54  'display_top' => true
55  ]
56  ];
57  $userAuthentication = $this->prophesize(FrontendBackendUserAuthentication::class);
58  $userAuthentication->getTSConfig()->willReturn($tsConfig);
59  $userAuthentication->uc = $uc;
60  ‪$GLOBALS['BE_USER'] = $userAuthentication->reveal();
61 
62  $tsfe = $this->prophesize(TypoScriptFrontendController::class);
63  ‪$GLOBALS['TSFE'] = $tsfe;
64 
65  $controller = $this->prophesize(MainController::class);
66  GeneralUtility::setSingletonInstance(MainController::class, $controller->reveal());
67  $handler = $this->‪prophesizeHandler();
68  $request = $this->prophesize(ServerRequestInterface::class);
69  $request->withAttribute(Argument::cetera())->willReturn($request);
70  // Act
71  $adminPanelInitiator = new ‪AdminPanelInitiator();
72  $adminPanelInitiator->process(
73  $request->reveal(),
74  $handler->reveal()
75  );
76  // Assert
77  $controller->initialize(Argument::any())->shouldHaveBeenCalled();
78  }
79 
84  {
85  $tsConfig = [
86  'admPanel.' => [
87  'enable.' => [
88  'all',
89  ],
90  ],
91  ];
92  $uc = [
93  'AdminPanel' => [
94  'display_top' => false
95  ]
96  ];
97  $this->‪checkAdminPanelDoesNotCallInitialize($tsConfig, $uc);
98  }
99 
104  {
105  $tsConfig = [
106  'admPanel.' => [],
107  ];
108  $uc = [
109  'AdminPanel' => [
110  'display_top' => true
111  ]
112  ];
113  $this->‪checkAdminPanelDoesNotCallInitialize($tsConfig, $uc);
114  }
115 
121  protected function ‪checkAdminPanelDoesNotCallInitialize($tsConfig, $uc): void
122  {
123  $userAuthentication = $this->prophesize(FrontendBackendUserAuthentication::class);
124  $userAuthentication->getTSConfig()->willReturn($tsConfig);
125  $userAuthentication->uc = $uc;
126  ‪$GLOBALS['BE_USER'] = $userAuthentication->reveal();
127 
128  $tsfe = $this->prophesize(TypoScriptFrontendController::class);
129  ‪$GLOBALS['TSFE'] = $tsfe;
130 
131  $controller = $this->prophesize(MainController::class);
132  GeneralUtility::setSingletonInstance(MainController::class, $controller->reveal());
133  $handler = $this->‪prophesizeHandler();
134  $request = $this->prophesize(ServerRequestInterface::class);
135  // Act
136  $adminPanelInitiator = new ‪AdminPanelInitiator();
137  $adminPanelInitiator->process(
138  $request->reveal(),
139  $handler->reveal()
140  );
141  // Assert
142  $controller->initialize(Argument::any())->shouldNotHaveBeenCalled();
143  }
144 
148  protected function ‪prophesizeHandler()
149  {
150  $handler = $this->prophesize(RequestHandlerInterface::class);
151  $handler
152  ->handle(Argument::any())
153  ->willReturn(
154  $this->prophesize(ResponseInterface::class)->reveal()
155  );
156  return $handler;
157  }
158 }
‪TYPO3\CMS\Adminpanel\Controller\MainController
Definition: MainController.php:45
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware
Definition: AdminPanelInitiatorTest.php:3
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware\AdminPanelInitiatorTest\processCallsInitialize
‪processCallsInitialize()
Definition: AdminPanelInitiatorTest.php:42
‪TYPO3\CMS\Adminpanel\Middleware\AdminPanelInitiator
Definition: AdminPanelInitiator.php:34
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication
Definition: FrontendBackendUserAuthentication.php:35
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware\AdminPanelInitiatorTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: AdminPanelInitiatorTest.php:37
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware\AdminPanelInitiatorTest\processDoesNotCallInitializeIfAdminPanelIsNotEnabledInUC
‪processDoesNotCallInitializeIfAdminPanelIsNotEnabledInUC()
Definition: AdminPanelInitiatorTest.php:82
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:97
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware\AdminPanelInitiatorTest\processDoesNotCallInitializeIfNoAdminPanelModuleIsEnabled
‪processDoesNotCallInitializeIfNoAdminPanelModuleIsEnabled()
Definition: AdminPanelInitiatorTest.php:102
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware\AdminPanelInitiatorTest
Definition: AdminPanelInitiatorTest.php:34
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware\AdminPanelInitiatorTest\checkAdminPanelDoesNotCallInitialize
‪checkAdminPanelDoesNotCallInitialize($tsConfig, $uc)
Definition: AdminPanelInitiatorTest.php:120
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware\AdminPanelInitiatorTest\prophesizeHandler
‪ObjectProphecy RequestHandlerInterface prophesizeHandler()
Definition: AdminPanelInitiatorTest.php:147