[FEATURE] Add userGroups to backendUser model
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Domain / Model / BackendUserTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Domain\Model;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012 Felix Kopp <felix-source@phorax.com>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28 /**
29 * Testcase for \TYPO3\CMS\Extbase\Domain\Model\BackendUser.
30 *
31 * @author Felix Kopp <felix-source@phorax.com>
32 * @author Oliver Klee <typo3-coding@oliverklee.de>
33 * @api
34 */
35 class BackendUserTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
36
37 /**
38 * @var \TYPO3\CMS\Extbase\Domain\Model\BackendUser
39 */
40 protected $fixture = NULL;
41
42 public function setUp() {
43 $this->fixture = new \TYPO3\CMS\Extbase\Domain\Model\BackendUser();
44 }
45
46 public function tearDown() {
47 unset($this->fixture);
48 }
49
50 /**
51 * @test
52 */
53 public function getUserNameInitiallyReturnsEmptyString() {
54 $this->assertSame('', $this->fixture->getUserName());
55 }
56
57 /**
58 * @test
59 */
60 public function setUserNameSetsUserName() {
61 $userName = 'don.juan';
62 $this->fixture->setUserName($userName);
63 $this->assertSame($userName, $this->fixture->getUserName());
64 }
65
66 /**
67 * @test
68 */
69 public function getIsAdministratorInitiallyReturnsFalse() {
70 $this->assertFalse($this->fixture->getIsAdministrator());
71 }
72
73 /**
74 * @test
75 */
76 public function setIsAdministratorCanSetIsAdministratorToTrue() {
77 $this->fixture->setIsAdministrator(TRUE);
78 $this->assertTrue($this->fixture->getIsAdministrator());
79 }
80
81 /**
82 * @test
83 */
84 public function getBackendUserGroupsInitiallyReturnsEmptyStorage() {
85 $this->assertEquals(new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(), $this->fixture->getBackendUserGroups());
86 }
87
88 /**
89 * @test
90 */
91 public function setBackendUserGroupsSetsBackendUserGroups() {
92 $backendUserGroups = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
93 $group1 = new \TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup();
94 $backendUserGroups->attach($group1);
95
96 $this->fixture->setBackendUserGroups($backendUserGroups);
97 $this->assertSame(
98 $backendUserGroups,
99 $this->fixture->getBackendUserGroups()
100 );
101 }
102
103 /**
104 * @test
105 */
106 public function addBackendUserGroupAddsBackendUserGroup() {
107 $group1 = new \TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup();
108
109 $this->fixture->addBackendUserGroup($group1);
110 $this->assertTrue($this->fixture->getBackendUserGroups()->contains($group1));
111 }
112
113 /**
114 * @test
115 */
116 public function removeBackendUserGroupRemovesBackendUserGroup() {
117 $group1 = new \TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup();
118
119 $this->fixture->addBackendUserGroup($group1);
120 $this->fixture->removeBackendUserGroup($group1);
121 $this->assertFalse($this->fixture->getBackendUserGroups()->contains($group1));
122 }
123
124 /**
125 * @test
126 */
127 public function removeAllBackendUserGroupsRemovesAllBackendUserGroups() {
128 $group1 = new \TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup();
129 $group2 = new \TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup();
130
131 $this->fixture->addBackendUserGroup($group1);
132 $this->fixture->addBackendUserGroup($group2);
133 $this->fixture->removeAllBackendUserGroups();
134
135 $this->assertFalse($this->fixture->getBackendUserGroups()->contains($group1));
136 $this->assertFalse($this->fixture->getBackendUserGroups()->contains($group2));
137 }
138
139 /**
140 * @test
141 */
142 public function getIsDisabledInitiallyReturnsFalse() {
143 $this->assertFalse($this->fixture->getIsDisabled());
144 }
145
146 /**
147 * @test
148 */
149 public function setIsDisabledCanSetIsDisabledToTrue() {
150 $this->fixture->setIsDisabled(TRUE);
151 $this->assertTrue($this->fixture->getIsDisabled());
152 }
153
154 /**
155 * @test
156 */
157 public function getStartDateAndTimeInitiallyReturnsNull() {
158 $this->assertNull($this->fixture->getStartDateAndTime());
159 }
160
161 /**
162 * @test
163 */
164 public function setStartDateAndTimeSetsStartDateAndTime() {
165 $date = new \DateTime();
166 $this->fixture->setStartDateAndTime($date);
167 $this->assertSame($date, $this->fixture->getStartDateAndTime());
168 }
169
170 /**
171 * @test
172 */
173 public function getEndDateAndTimeInitiallyReturnsNull() {
174 $this->assertNull($this->fixture->getEndDateAndTime());
175 }
176
177 /**
178 * @test
179 */
180 public function setEndDateAndTimeSetsEndDateAndTime() {
181 $date = new \DateTime();
182 $this->fixture->setEndDateAndTime($date);
183 $this->assertSame($date, $this->fixture->getEndDateAndTime());
184 }
185
186 /**
187 * @test
188 */
189 public function isActivatedInitiallyReturnsTrue() {
190 $this->assertTrue($this->fixture->isActivated());
191 }
192
193 /**
194 * @test
195 */
196 public function isActivatedForDisabledReturnsFalse() {
197 $this->fixture->setIsDisabled(TRUE);
198 $this->assertFalse($this->fixture->isActivated());
199 }
200
201 /**
202 * @test
203 */
204 public function isActivatedForStartDateAndTimeInFutureReturnsFalse() {
205 $tomorrow = new \DateTime('tomorrow');
206 $this->fixture->setStartDateAndTime($tomorrow);
207 $this->assertFalse($this->fixture->isActivated());
208 }
209
210 /**
211 * @test
212 */
213 public function isActivatedForStartDateAndTimeInPastReturnsTrue() {
214 $yesterday = new \DateTime('yesterday');
215 $this->fixture->setStartDateAndTime($yesterday);
216 $this->assertTrue($this->fixture->isActivated());
217 }
218
219 /**
220 * @test
221 */
222 public function isActivatedForEndDateAndTimeInFutureReturnsTrue() {
223 $tomorrow = new \DateTime('tomorrow');
224 $this->fixture->setEndDateAndTime($tomorrow);
225 $this->assertTrue($this->fixture->isActivated());
226 }
227
228 /**
229 * @test
230 */
231 public function isActivatedForEndDateAndTimeInPastReturnsFalse() {
232 $yesterday = new \DateTime('yesterday');
233 $this->fixture->setEndDateAndTime($yesterday);
234 $this->assertFalse($this->fixture->isActivated());
235 }
236
237 /**
238 * @test
239 */
240 public function isActivatedForStartDateAndTimeInPastEndDateAndTimeInFutureReturnsTrue() {
241 $yesterday = new \DateTime('yesterday');
242 $this->fixture->setStartDateAndTime($yesterday);
243 $tomorrow = new \DateTime('tomorrow');
244 $this->fixture->setEndDateAndTime($tomorrow);
245 $this->assertTrue($this->fixture->isActivated());
246 }
247
248 /**
249 * @test
250 */
251 public function isActivatedForStartDateAndTimeInPastEndDateAndTimeInPastReturnsFalse() {
252 $yesterday = new \DateTime('yesterday');
253 $this->fixture->setStartDateAndTime($yesterday);
254 $this->fixture->setEndDateAndTime($yesterday);
255 $this->assertFalse($this->fixture->isActivated());
256 }
257
258 /**
259 * @test
260 */
261 public function isActivatedForStartDateAndTimeInFutureEndDateAndTimeInFutureReturnsFalse() {
262 $tomorrow = new \DateTime('tomorrow');
263 $this->fixture->setStartDateAndTime($tomorrow);
264 $this->fixture->setEndDateAndTime($tomorrow);
265 $this->assertFalse($this->fixture->isActivated());
266 }
267
268 /**
269 * @test
270 */
271 public function getEmailInitiallyReturnsEmptyString() {
272 $this->assertSame('', $this->fixture->getEmail());
273 }
274
275 /**
276 * @test
277 */
278 public function setEmailSetsEmail() {
279 $email = 'don.juan@example.com';
280 $this->fixture->setEmail($email);
281 $this->assertSame($email, $this->fixture->getEmail());
282 }
283
284 /**
285 * @test
286 */
287 public function getRealNameInitiallyReturnsEmptyString() {
288 $this->assertSame('', $this->fixture->getRealName());
289 }
290
291 /**
292 * @test
293 */
294 public function setRealNameSetsRealName() {
295 $realName = 'Don Juan';
296 $this->fixture->setRealName($realName);
297 $this->assertSame($realName, $this->fixture->getRealName());
298 }
299
300 /**
301 * @test
302 */
303 public function getIpLockIsDisabledInitiallyReturnsFalse() {
304 $this->assertFalse($this->fixture->getIpLockIsDisabled());
305 }
306
307 /**
308 * @test
309 */
310 public function setIpLockIsDisabledCanSetIpLockIsDisabledToTrue() {
311 $this->fixture->setIpLockIsDisabled(TRUE);
312 $this->assertTrue($this->fixture->getIpLockIsDisabled());
313 }
314
315 /**
316 * @test
317 */
318 public function getLastLoginDateAndTimeInitiallyReturnsNull() {
319 $this->assertNull($this->fixture->getLastLoginDateAndTime());
320 }
321
322 /**
323 * @test
324 */
325 public function setLastLoginDateAndTimeSetsLastLoginDateAndTime() {
326 $date = new \DateTime();
327 $this->fixture->setLastLoginDateAndTime($date);
328 $this->assertSame($date, $this->fixture->getLastLoginDateAndTime());
329 }
330
331 /**
332 * @test
333 */
334 public function getFileMountsInitiallyReturnsEmpty() {
335 $this->assertSame(0, $this->fixture->getFileMounts()->count());
336 }
337
338 /**
339 * @test
340 */
341 public function setFileMountsSetsFileMounts() {
342 $fileMounts = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
343 $this->fixture->setFileMounts($fileMounts);
344
345 $this->assertSame(
346 $fileMounts,
347 $this->fixture->getFileMounts()
348 );
349 }
350
351 /**
352 * @test
353 */
354 public function addFileMountAddsFileMount() {
355 $fileMount = new \TYPO3\CMS\Extbase\Domain\Model\FileMount();
356
357 $this->fixture->addFileMount($fileMount);
358 $this->assertTrue($this->fixture->getFileMounts()->contains($fileMount));
359 }
360
361 /**
362 * @test
363 */
364 public function removeFileMountRemovesFileMount() {
365 $fileMount = new \TYPO3\CMS\Extbase\Domain\Model\FileMount();
366
367 $this->fixture->addFileMount($fileMount);
368 $this->fixture->removeFileMount($fileMount);
369 $this->assertFalse($this->fixture->getFileMounts()->contains($fileMount));
370 }
371
372 /**
373 * @test
374 */
375 public function removeAllFileMountsRemovesAllFileMounts() {
376 $fileMount = new \TYPO3\CMS\Extbase\Domain\Model\FileMount();
377 $fileMount2 = new \TYPO3\CMS\Extbase\Domain\Model\FileMount();
378
379 $this->fixture->addFileMount($fileMount);
380 $this->fixture->addFileMount($fileMount2);
381 $this->fixture->removeAllFileMounts();
382
383 $this->assertFalse($this->fixture->getFileMounts()->contains($fileMount));
384 $this->assertFalse($this->fixture->getFileMounts()->contains($fileMount2));
385 }
386 }
387
388 ?>