‪TYPO3CMS  11.5
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\MockObject\MockObject;
23 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
26 class ‪SwitchUserControllerTest extends UnitTestCase
27 {
31  protected const ‪RECENT_USERS_LIMIT = 3;
32 
36  protected ‪$subject;
37 
38  protected function ‪setUp(): void
39  {
40  parent::setUp();
41  ‪$GLOBALS['BE_USER'] = $this->createMock(BackendUserAuthentication::class);
42  ‪$GLOBALS['BE_USER']->uc = [
43  'recentSwitchedToUsers' => [],
44  ];
45  $this->subject = $this->getAccessibleMock(SwitchUserController::class, ['dummy'], [], '', false);
46  }
47 
52  {
53  $items = range(1, self::RECENT_USERS_LIMIT + 5);
54  $expected = array_reverse(array_slice($items, -self::RECENT_USERS_LIMIT));
55  foreach ($items as $id) {
56  ‪$GLOBALS['BE_USER']->uc['recentSwitchedToUsers'] = $this->subject->_call('generateListOfMostRecentSwitchedUsers', $id);
57  }
58 
59  self::assertCount(self::RECENT_USERS_LIMIT, ‪$GLOBALS['BE_USER']->uc['recentSwitchedToUsers']);
60  self::assertSame($expected, ‪$GLOBALS['BE_USER']->uc['recentSwitchedToUsers']);
61  }
62 
67  {
68  ‪$GLOBALS['BE_USER']->uc['recentSwitchedToUsers'] = $this->subject->_call('generateListOfMostRecentSwitchedUsers', 100);
69 
70  self::assertCount(1, ‪$GLOBALS['BE_USER']->uc['recentSwitchedToUsers']);
71  }
72 }
‪TYPO3\CMS\Backend\Tests\Unit\Controller\SwitchUserControllerTest
Definition: SwitchUserControllerTest.php:27
‪TYPO3\CMS\Backend\Tests\Unit\Controller\SwitchUserControllerTest\listOfLatestSwitchedUsersDoesNotContainTheSameUserTwice
‪listOfLatestSwitchedUsersDoesNotContainTheSameUserTwice()
Definition: SwitchUserControllerTest.php:65
‪TYPO3\CMS\Backend\Tests\Unit\Controller\SwitchUserControllerTest\generateListOfLatestSwitchedUsersReturnsCorrectAmountAndOrder
‪generateListOfLatestSwitchedUsersReturnsCorrectAmountAndOrder()
Definition: SwitchUserControllerTest.php:50
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Tests\Unit\Controller\SwitchUserControllerTest\$subject
‪SwitchUserController MockObject AccessibleObjectInterface $subject
Definition: SwitchUserControllerTest.php:35
‪TYPO3\CMS\Backend\Tests\Unit\Controller\SwitchUserControllerTest\setUp
‪setUp()
Definition: SwitchUserControllerTest.php:37
‪TYPO3\CMS\Backend\Tests\Unit\Controller
Definition: EditDocumentControllerTest.php:18
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Controller\SwitchUserController
Definition: SwitchUserController.php:38
‪TYPO3\CMS\Backend\Tests\Unit\Controller\SwitchUserControllerTest\RECENT_USERS_LIMIT
‪const RECENT_USERS_LIMIT
Definition: SwitchUserControllerTest.php:31