[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / setup / Tests / Unit / SetupModuleControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Setup\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\Core\Messaging\FlashMessage;
18 use TYPO3\CMS\Setup\Controller\SetupModuleController;
19
20 /**
21 * Class SetupModuleControllerTest
22 */
23 class SetupModuleControllerTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
24 {
25 /**
26 * @test
27 * @return void
28 */
29 public function addFlashMessagesAddsMessagesIfSetupIsUpdated()
30 {
31 $setupModuleControllerMock = $this->getAccessibleMock(
32 SetupModuleController::class,
33 ['getFlashMessage', 'enqueueFlashMessages'],
34 [],
35 '',
36 false
37 );
38 $setupModuleControllerMock->_set('setupIsUpdated', true);
39
40 $setupModuleControllerMock
41 ->expects($this->atMost(2))
42 ->method('getFlashMessage')
43 ->withConsecutive(
44 ['setupWasUpdated', 'UserSettings'],
45 ['activateChanges', '']
46 );
47
48 $setupModuleControllerMock->_call('addFlashMessages');
49 }
50
51 /**
52 * @test
53 * @return void
54 */
55 public function addFlashMessagesAddsMessageIfSettingsAreResetToDefault()
56 {
57 $setupModuleControllerMock = $this->getAccessibleMock(
58 SetupModuleController::class,
59 ['getFlashMessage', 'enqueueFlashMessages'],
60 [],
61 '',
62 false
63 );
64 $setupModuleControllerMock->_set('settingsAreResetToDefault', true);
65
66 $setupModuleControllerMock
67 ->expects($this->atMost(2))
68 ->method('getFlashMessage')
69 ->withConsecutive(
70 ['settingsAreReset', 'resetConfiguration'],
71 ['activateChanges', '']
72 );
73
74 $setupModuleControllerMock->_call('addFlashMessages');
75 }
76
77 /**
78 * @test
79 * @return void
80 */
81 public function addFlashMessagesAddsMessageIfPasswordWasSuccessfullyUpdated()
82 {
83 $setupModuleControllerMock = $this->getAccessibleMock(
84 SetupModuleController::class,
85 ['getFlashMessage', 'enqueueFlashMessages'],
86 [],
87 '',
88 false
89 );
90 $setupModuleControllerMock->_set('passwordIsSubmitted', true);
91 $setupModuleControllerMock->_set('passwordIsUpdated', SetupModuleController::PASSWORD_UPDATED);
92
93 $setupModuleControllerMock
94 ->expects($this->once())
95 ->method('getFlashMessage')
96 ->withConsecutive(
97 ['newPassword_ok', 'newPassword']
98 );
99
100 $setupModuleControllerMock->_call('addFlashMessages');
101 }
102
103 /**
104 * @test
105 * @return void
106 */
107 public function addFlashMessagesAddsMessageIfOldPasswordWasWrong()
108 {
109 $setupModuleControllerMock = $this->getAccessibleMock(
110 SetupModuleController::class,
111 ['getFlashMessage', 'enqueueFlashMessages'],
112 [],
113 '',
114 false
115 );
116 $setupModuleControllerMock->_set('passwordIsSubmitted', true);
117 $setupModuleControllerMock->_set('passwordIsUpdated', SetupModuleController::PASSWORD_OLD_WRONG);
118
119 $setupModuleControllerMock
120 ->expects($this->once())
121 ->method('getFlashMessage')
122 ->withConsecutive(
123 ['oldPassword_failed', 'newPassword']
124 );
125
126 $setupModuleControllerMock->_call('addFlashMessages');
127 }
128
129 /**
130 * @test
131 * @return void
132 */
133 public function addFlashMessagesAddsMessageIfPasswordsNotTheSame()
134 {
135 $setupModuleControllerMock = $this->getAccessibleMock(
136 SetupModuleController::class,
137 ['getFlashMessage', 'enqueueFlashMessages'],
138 [],
139 '',
140 false
141 );
142 $setupModuleControllerMock->_set('passwordIsSubmitted', true);
143 $setupModuleControllerMock->_set('passwordIsUpdated', SetupModuleController::PASSWORD_NOT_THE_SAME);
144
145 $setupModuleControllerMock
146 ->expects($this->once())
147 ->method('getFlashMessage')
148 ->withConsecutive(
149 ['newPassword_failed', 'newPassword']
150 );
151
152 $setupModuleControllerMock->_call('addFlashMessages');
153 }
154
155 /**
156 * @test
157 * @return void
158 */
159 public function addFlashMessagesAddsMessagesToQueue()
160 {
161 $setupModuleControllerMock = $this->getAccessibleMock(
162 SetupModuleController::class,
163 ['getFlashMessage', 'enqueueFlashMessages'],
164 [],
165 '',
166 false
167 );
168
169 $setupModuleControllerMock->_set('settingsAreResetToDefault', true);
170 $flashMessage1 = new FlashMessage('foo', 'bar');
171 $flashMessage2 = new FlashMessage('bar', 'foo');
172 $setupModuleControllerMock
173 ->expects($this->atMost(2))
174 ->method('getFlashMessage')
175 ->withConsecutive(
176 ['settingsAreReset', 'resetConfiguration'],
177 ['activateChanges', '']
178 )->willReturnOnConsecutiveCalls(
179 $flashMessage1,
180 $flashMessage2
181 );
182
183 $setupModuleControllerMock
184 ->expects($this->once())
185 ->method('enqueueFlashMessages')
186 ->with([$flashMessage1, $flashMessage2]);
187 $setupModuleControllerMock->_call('addFlashMessages');
188 }
189 }