‪TYPO3CMS  ‪main
SwitchUserControllerTest.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;
21 use PHPUnit\Framework\MockObject\MockObject;
24 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
27 final class ‪SwitchUserControllerTest extends UnitTestCase
28 {
32  protected const ‪RECENT_USERS_LIMIT = 3;
33 
34  protected ‪SwitchUserController&MockObject&AccessibleObjectInterface ‪$subject;
35 
36  protected function ‪setUp(): void
37  {
38  parent::setUp();
39  ‪$GLOBALS['BE_USER'] = $this->createMock(BackendUserAuthentication::class);
40  ‪$GLOBALS['BE_USER']->uc = [
41  'recentSwitchedToUsers' => [],
42  ];
43  $this->subject = $this->getAccessibleMock(SwitchUserController::class, null, [], '', false);
44  }
45 
46  #[Test]
48  {
49  $items = range(1, self::RECENT_USERS_LIMIT + 5);
50  $expected = array_reverse(array_slice($items, -self::RECENT_USERS_LIMIT));
51  foreach ($items as $id) {
52  ‪$GLOBALS['BE_USER']->uc['recentSwitchedToUsers'] = $this->subject->_call('generateListOfMostRecentSwitchedUsers', $id);
53  }
54 
55  self::assertCount(self::RECENT_USERS_LIMIT, ‪$GLOBALS['BE_USER']->uc['recentSwitchedToUsers']);
56  self::assertSame($expected, ‪$GLOBALS['BE_USER']->uc['recentSwitchedToUsers']);
57  }
58 
59  #[Test]
61  {
62  ‪$GLOBALS['BE_USER']->uc['recentSwitchedToUsers'] = $this->subject->_call('generateListOfMostRecentSwitchedUsers', 100);
63 
64  self::assertCount(1, ‪$GLOBALS['BE_USER']->uc['recentSwitchedToUsers']);
65  }
66 }
‪TYPO3\CMS\Backend\Tests\Unit\Controller\SwitchUserControllerTest
Definition: SwitchUserControllerTest.php:28
‪TYPO3\CMS\Backend\Tests\Unit\Controller\SwitchUserControllerTest\listOfLatestSwitchedUsersDoesNotContainTheSameUserTwice
‪listOfLatestSwitchedUsersDoesNotContainTheSameUserTwice()
Definition: SwitchUserControllerTest.php:60
‪TYPO3\CMS\Backend\Tests\Unit\Controller\SwitchUserControllerTest\generateListOfLatestSwitchedUsersReturnsCorrectAmountAndOrder
‪generateListOfLatestSwitchedUsersReturnsCorrectAmountAndOrder()
Definition: SwitchUserControllerTest.php:47
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Tests\Unit\Controller\SwitchUserControllerTest\setUp
‪setUp()
Definition: SwitchUserControllerTest.php:36
‪TYPO3\CMS\Backend\Tests\Unit\Controller
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Controller\SwitchUserController
Definition: SwitchUserController.php:40
‪TYPO3\CMS\Backend\Tests\Unit\Controller\SwitchUserControllerTest\$subject
‪SwitchUserController &MockObject &AccessibleObjectInterface $subject
Definition: SwitchUserControllerTest.php:34
‪TYPO3\CMS\Backend\Tests\Unit\Controller\SwitchUserControllerTest\RECENT_USERS_LIMIT
‪const RECENT_USERS_LIMIT
Definition: SwitchUserControllerTest.php:32