‪TYPO3CMS  10.4
AdminPanelInitiatorTest.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\Argument;
21 use Prophecy\Prophecy\ObjectProphecy;
22 use Psr\Http\Message\ResponseInterface;
23 use Psr\Http\Message\ServerRequestInterface;
24 use Psr\Http\Server\RequestHandlerInterface;
29 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
30 
34 class ‪AdminPanelInitiatorTest extends UnitTestCase
35 {
39  protected ‪$resetSingletonInstances = true;
40 
44  public function ‪processCallsInitialize(): void
45  {
46  $tsConfig = [
47  'admPanel.' => [
48  'enable.' => [
49  'all',
50  ],
51  ],
52  ];
53  $uc = [
54  'AdminPanel' => [
55  'display_top' => true
56  ]
57  ];
58  $userAuthentication = $this->prophesize(FrontendBackendUserAuthentication::class);
59  $userAuthentication->getTSConfig()->willReturn($tsConfig);
60  $userAuthentication->uc = $uc;
61  ‪$GLOBALS['BE_USER'] = $userAuthentication->reveal();
62 
63  $controller = $this->prophesize(MainController::class);
64  GeneralUtility::setSingletonInstance(MainController::class, $controller->reveal());
65  $handler = $this->‪prophesizeHandler();
66  $request = $this->prophesize(ServerRequestInterface::class);
67  $request->withAttribute(Argument::cetera())->willReturn($request);
68  $controller->initialize($request->reveal())->willReturn($request);
69 
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  $controller = $this->prophesize(MainController::class);
129  GeneralUtility::setSingletonInstance(MainController::class, $controller->reveal());
130  $handler = $this->‪prophesizeHandler();
131  $request = $this->prophesize(ServerRequestInterface::class);
132  // Act
133  $adminPanelInitiator = new ‪AdminPanelInitiator();
134  $adminPanelInitiator->process(
135  $request->reveal(),
136  $handler->reveal()
137  );
138  // Assert
139  $controller->initialize(Argument::any())->shouldNotHaveBeenCalled();
140  }
141 
145  protected function ‪prophesizeHandler()
146  {
147  $handler = $this->prophesize(RequestHandlerInterface::class);
148  $handler
149  ->handle(Argument::any())
150  ->willReturn(
151  $this->prophesize(ResponseInterface::class)->reveal()
152  );
153  return $handler;
154  }
155 }
‪TYPO3\CMS\Adminpanel\Controller\MainController
Definition: MainController.php:47
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware
Definition: AdminPanelInitiatorTest.php:18
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware\AdminPanelInitiatorTest\processCallsInitialize
‪processCallsInitialize()
Definition: AdminPanelInitiatorTest.php:43
‪TYPO3\CMS\Adminpanel\Middleware\AdminPanelInitiator
Definition: AdminPanelInitiator.php:35
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication
Definition: FrontendBackendUserAuthentication.php:31
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware\AdminPanelInitiatorTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: AdminPanelInitiatorTest.php:38
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware\AdminPanelInitiatorTest\processDoesNotCallInitializeIfAdminPanelIsNotEnabledInUC
‪processDoesNotCallInitializeIfAdminPanelIsNotEnabledInUC()
Definition: AdminPanelInitiatorTest.php:82
‪$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:35
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware\AdminPanelInitiatorTest\checkAdminPanelDoesNotCallInitialize
‪checkAdminPanelDoesNotCallInitialize($tsConfig, $uc)
Definition: AdminPanelInitiatorTest.php:120
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware\AdminPanelInitiatorTest\prophesizeHandler
‪ObjectProphecy RequestHandlerInterface prophesizeHandler()
Definition: AdminPanelInitiatorTest.php:144