‪TYPO3CMS  ‪main
LoginControllerTest.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\Attributes\Test;
37 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
38 
39 final class ‪LoginControllerTest extends UnitTestCase
40 {
41  #[Test]
43  {
44  ‪$GLOBALS['LANG'] = $this->createMock(LanguageService::class);
45  ‪$GLOBALS['BE_USER'] = $this->createMock(BackendUserAuthentication::class);
46 
47  $formProtectionFactory = $this->createMock(FormProtectionFactory::class);
48  $formProtectionFactory->method('createFromRequest')->willReturn($this->createMock(BackendFormProtection::class));
49  $loginControllerMock = $this->getAccessibleMock(
50  LoginController::class,
51  ['isLoginInProgress', 'redirectToUrl'],
52  [
53  new ‪Typo3Information(),
55  $this->createMock(PageRenderer::class),
56  $this->createMock(UriBuilder::class),
57  new ‪Features(),
58  new ‪Context(),
59  $this->createMock(LoginProviderResolver::class),
62  $formProtectionFactory,
63  new ‪Locales(),
64  ],
65  );
66 
67  ‪$GLOBALS['BE_USER']->user['uid'] = 1;
68  $loginControllerMock->method('isLoginInProgress')->willReturn(true);
69  $loginControllerMock->_set('loginRefresh', false);
70 
71  $loginControllerMock->expects(self::once())->method('redirectToUrl');
72  $loginControllerMock->_call(
73  'checkRedirect',
74  new ‪ServerRequest(),
75  $this->createMock(PageRenderer::class)
76  );
77  }
78 
79  #[Test]
81  {
82  ‪$GLOBALS['BE_USER'] = $this->createMock(BackendUserAuthentication::class);
83  $loginControllerMock = $this->getAccessibleMock(
84  LoginController::class,
85  ['redirectToUrl'],
86  [],
87  '',
88  false
89  );
90 
91  ‪$GLOBALS['BE_USER']->user['uid'] = null;
92 
93  $loginControllerMock->expects(self::never())->method('redirectToUrl');
94  $loginControllerMock->_call(
95  'checkRedirect',
96  new ‪ServerRequest(),
97  $this->createMock(PageRenderer::class)
98  );
99  }
100 }
‪TYPO3\CMS\Core\Information\Typo3Information
Definition: Typo3Information.php:28
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:47
‪TYPO3\CMS\Core\FormProtection\BackendFormProtection
Definition: BackendFormProtection.php:75
‪TYPO3\CMS\Core\Localization\Locales
Definition: Locales.php:36
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:54
‪TYPO3\CMS\Backend\LoginProvider\LoginProviderResolver
Definition: LoginProviderResolver.php:37
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:44
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Backend\Tests\Unit\Controller\LoginControllerTest\checkRedirectDoesNotRedirectIfNoUserIsFound
‪checkRedirectDoesNotRedirectIfNoUserIsFound()
Definition: LoginControllerTest.php:80
‪TYPO3\CMS\Core\Configuration\Features
Definition: Features.php:56
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Tests\Unit\Controller\LoginControllerTest
Definition: LoginControllerTest.php:40
‪TYPO3\CMS\Backend\Tests\Unit\Controller
‪TYPO3\CMS\Core\FormProtection\FormProtectionFactory
Definition: FormProtectionFactory.php:43
‪TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher
Definition: NoopEventDispatcher.php:29
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Backend\Controller\LoginController
Definition: LoginController.php:61
‪TYPO3\CMS\Backend\Tests\Unit\Controller\LoginControllerTest\checkRedirectRedirectsIfLoginIsInProgressAndUserWasFound
‪checkRedirectRedirectsIfLoginIsInProgressAndUserWasFound()
Definition: LoginControllerTest.php:42
‪TYPO3\CMS\Core\Routing\BackendEntryPointResolver
Definition: BackendEntryPointResolver.php:29