[BUGFIX] Add missing namespace parts
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Controller / LoginControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Controller\LoginController;
18 use TYPO3\CMS\Backend\LoginProvider\UsernamePasswordLoginProvider;
19
20 /**
21 * Class LoginControllerTest
22 */
23 class LoginControllerTest extends \TYPO3\Components\TestingFramework\Core\Unit\UnitTestCase
24 {
25 /**
26 * @var LoginController|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\Components\TestingFramework\Core\AccessibleObjectInterface
27 */
28 protected $loginControllerMock;
29
30 /**
31 * @throws \InvalidArgumentException
32 */
33 protected function setUp()
34 {
35 $this->loginControllerMock = $this->getAccessibleMock(LoginController::class, ['dummy'], [], '', false);
36 }
37
38 /**
39 * @test
40 */
41 public function validateAndSortLoginProvidersDetectsMissingProviderConfiguration()
42 {
43 $this->expectException(\RuntimeException::class);
44 $this->expectExceptionCode(1433417281);
45 unset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['backend']['loginProviders']);
46 $this->loginControllerMock->_call('validateAndSortLoginProviders');
47 }
48
49 /**
50 * @test
51 */
52 public function validateAndSortLoginProvidersDetectsNonArrayProviderConfiguration()
53 {
54 $this->expectException(\RuntimeException::class);
55 $this->expectExceptionCode(1433417281);
56 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['backend']['loginProviders'] = 'foo';
57 $this->loginControllerMock->_call('validateAndSortLoginProviders');
58 }
59
60 /**
61 * @test
62 */
63 public function validateAndSortLoginProvidersDetectsIfNoProviderIsRegistered()
64 {
65 $this->expectException(\RuntimeException::class);
66 $this->expectExceptionCode(1433417281);
67 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['backend']['loginProviders'] = [];
68 $this->loginControllerMock->_call('validateAndSortLoginProviders');
69 }
70
71 /**
72 * @test
73 */
74 public function validateAndSortLoginProvidersDetectsMissingConfigurationForProvider()
75 {
76 $this->expectException(\RuntimeException::class);
77 $this->expectExceptionCode(1433416043);
78 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['backend']['loginProviders'] = [
79 1433419736 => []
80 ];
81 $this->loginControllerMock->_call('validateAndSortLoginProviders');
82 }
83
84 /**
85 * @test
86 */
87 public function validateAndSortLoginProvidersDetectsWrongProvider()
88 {
89 $this->expectException(\RuntimeException::class);
90 $this->expectExceptionCode(1460977275);
91 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['backend']['loginProviders'] = [
92 1433419736 => [
93 'provider' => \stdClass::class
94 ]
95 ];
96 $this->loginControllerMock->_call('validateAndSortLoginProviders');
97 }
98
99 /**
100 * @test
101 */
102 public function validateAndSortLoginProvidersDetectsMissingLabel()
103 {
104 $this->expectException(\RuntimeException::class);
105 $this->expectExceptionCode(1433416044);
106 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['backend']['loginProviders'] = [
107 1433419736 => [
108 'provider' => UsernamePasswordLoginProvider::class,
109 'sorting' => 30,
110 'icon-class' => 'foo'
111 ]
112 ];
113 $this->loginControllerMock->_call('validateAndSortLoginProviders');
114 }
115
116 /**
117 * @test
118 */
119 public function validateAndSortLoginProvidersDetectsMissingIconClass()
120 {
121 $this->expectException(\RuntimeException::class);
122 $this->expectExceptionCode(1433416045);
123 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['backend']['loginProviders'] = [
124 1433419736 => [
125 'provider' => UsernamePasswordLoginProvider::class,
126 'sorting' => 30,
127 'label' => 'foo'
128 ]
129 ];
130 $this->loginControllerMock->_call('validateAndSortLoginProviders');
131 }
132
133 /**
134 * @test
135 */
136 public function validateAndSortLoginProvidersDetectsMissingSorting()
137 {
138 $this->expectException(\RuntimeException::class);
139 $this->expectExceptionCode(1433416046);
140 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['backend']['loginProviders'] = [
141 1433419736 => [
142 'provider' => UsernamePasswordLoginProvider::class,
143 'label' => 'foo',
144 'icon-class' => 'foo'
145 ]
146 ];
147 $this->loginControllerMock->_call('validateAndSortLoginProviders');
148 }
149 }