[TASK] Shorten the extend class in all unit tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / beuser / Tests / Unit / Controller / BackendUserControllerTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Beuser\Tests\Unit\Controller;
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
18 use TYPO3\CMS\Beuser\Controller\BackendUserController;
19 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21
22 /**
23 * Test case
24 */
25 class BackendUserControllerTest extends UnitTestCase
26 {
27 /**
28 * @var BackendUserController|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface
29 */
30 protected $subject;
31
32 protected function setUp()
33 {
34 $GLOBALS['BE_USER'] = $this->createMock(BackendUserAuthentication::class);
35 $GLOBALS['BE_USER']->uc = [
36 'recentSwitchedToUsers' => []
37 ];
38
39 $this->subject = $this->getAccessibleMock(BackendUserController::class, ['dummy'], [], '', false);
40 }
41
42 /**
43 * @test
44 */
45 public function generateListOfLatestSwitchedUsersReturnsCorrectAmountAndOrder()
46 {
47 $items = range(1, BackendUserController::RECENT_USERS_LIMIT + 5);
48 $expected = array_reverse(array_slice($items, -BackendUserController::RECENT_USERS_LIMIT));
49 foreach ($items as $id) {
50 $GLOBALS['BE_USER']->uc['recentSwitchedToUsers'] = $this->subject->_call('generateListOfMostRecentSwitchedUsers', $id);
51 }
52
53 static::assertCount(BackendUserController::RECENT_USERS_LIMIT, $GLOBALS['BE_USER']->uc['recentSwitchedToUsers']);
54 static::assertSame($expected, $GLOBALS['BE_USER']->uc['recentSwitchedToUsers']);
55 }
56
57 /**
58 * @test
59 */
60 public function listOfLatestSwitchedUsersDoesNotContainTheSameUserTwice()
61 {
62 $GLOBALS['BE_USER']->uc['recentSwitchedToUsers'] = $this->subject->_call('generateListOfMostRecentSwitchedUsers', 100);
63 $GLOBALS['BE_USER']->uc['recentSwitchedToUsers'] = $this->subject->_call('generateListOfMostRecentSwitchedUsers', 100);
64
65 static::assertCount(1, $GLOBALS['BE_USER']->uc['recentSwitchedToUsers']);
66 }
67 }