‪TYPO3CMS  11.5
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 PHPUnit\Framework\MockObject\MockObject;
21 use Psr\Http\Message\ResponseInterface;
22 use Psr\Http\Message\ServerRequestInterface;
23 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->getMockBuilder(FrontendBackendUserAuthentication::class)->getMock();
58  $userAuthentication->expects(self::once())->method('getTSConfig')->willReturn($tsConfig);
59  $userAuthentication->uc = $uc;
60  ‪$GLOBALS['BE_USER'] = $userAuthentication;
61 
62  $controller = $this->getMockBuilder(MainController::class)->disableOriginalConstructor()->getMock();
63  GeneralUtility::setSingletonInstance(MainController::class, $controller);
64  $handler = $this->‪prophesizeHandler();
65  $request = $this->getMockBuilder(ServerRequestInterface::class)->getMock();
66  $request->expects(self::any())->method('withAttribute')->withAnyParameters()->willReturn($request);
67  $controller->expects(self::once())->method('initialize')->with($request)->willReturn($request);
68 
69  $adminPanelInitiator = new ‪AdminPanelInitiator();
70  $adminPanelInitiator->process($request, $handler);
71  }
72 
77  {
78  $tsConfig = [
79  'admPanel.' => [
80  'enable.' => [
81  'all',
82  ],
83  ],
84  ];
85  $uc = [
86  'AdminPanel' => [
87  'display_top' => false,
88  ],
89  ];
90  $this->‪checkAdminPanelDoesNotCallInitialize($tsConfig, $uc);
91  }
92 
97  {
98  $tsConfig = [
99  'admPanel.' => [],
100  ];
101  $uc = [
102  'AdminPanel' => [
103  'display_top' => true,
104  ],
105  ];
106  $this->‪checkAdminPanelDoesNotCallInitialize($tsConfig, $uc);
107  }
108 
113  protected function ‪checkAdminPanelDoesNotCallInitialize(array $tsConfig, array $uc): void
114  {
115  $userAuthentication = $this->getMockBuilder(FrontendBackendUserAuthentication::class)->getMock();
116  $userAuthentication->expects(self::once())->method('getTSConfig')->willReturn($tsConfig);
117  $userAuthentication->uc = $uc;
118  ‪$GLOBALS['BE_USER'] = $userAuthentication;
119 
120  $controller = $this->getMockBuilder(MainController::class)->disableOriginalConstructor()->getMock();
121  GeneralUtility::setSingletonInstance(MainController::class, $controller);
122  $handler = $this->‪prophesizeHandler();
123  $request = $this->getMockBuilder(ServerRequestInterface::class)->getMock();
124 
125  $adminPanelInitiator = new ‪AdminPanelInitiator();
126  $adminPanelInitiator->process($request, $handler);
127 
128  $controller->expects(self::never())->method('initialize');
129  }
130 
134  protected function ‪prophesizeHandler(): MockObject
135  {
136  $response = $this->getMockBuilder(ResponseInterface::class)->getMock();
137 
138  $handler = $this->getMockBuilder(RequestHandlerInterface::class)->onlyMethods(['handle'])->getMock();
139  $handler->expects(self::any())->method('handle')->withAnyParameters()->willReturn($response);
140  return $handler;
141  }
142 }
‪TYPO3\CMS\Adminpanel\Controller\MainController
Definition: MainController.php:46
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware
Definition: AdminPanelInitiatorTest.php:18
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware\AdminPanelInitiatorTest\processCallsInitialize
‪processCallsInitialize()
Definition: AdminPanelInitiatorTest.php:42
‪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:37
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware\AdminPanelInitiatorTest\processDoesNotCallInitializeIfAdminPanelIsNotEnabledInUC
‪processDoesNotCallInitializeIfAdminPanelIsNotEnabledInUC()
Definition: AdminPanelInitiatorTest.php:75
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware\AdminPanelInitiatorTest\processDoesNotCallInitializeIfNoAdminPanelModuleIsEnabled
‪processDoesNotCallInitializeIfNoAdminPanelModuleIsEnabled()
Definition: AdminPanelInitiatorTest.php:95
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware\AdminPanelInitiatorTest
Definition: AdminPanelInitiatorTest.php:34
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware\AdminPanelInitiatorTest\prophesizeHandler
‪RequestHandlerInterface &MockObject prophesizeHandler()
Definition: AdminPanelInitiatorTest.php:133
‪TYPO3\CMS\Adminpanel\Tests\Unit\Middleware\AdminPanelInitiatorTest\checkAdminPanelDoesNotCallInitialize
‪checkAdminPanelDoesNotCallInitialize(array $tsConfig, array $uc)
Definition: AdminPanelInitiatorTest.php:112