[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Tests / Unit / FolderStructure / DirectoryNodeTest.php
1 <?php
2 namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure;
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 /**
18 * Test case
19 */
20 class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
21
22 /**
23 * @var array Directories or files in typo3temp/ created during tests to delete afterwards
24 */
25 protected $testNodesToDelete = array();
26
27 /**
28 * Tear down
29 */
30 public function tearDown() {
31 foreach ($this->testNodesToDelete as $node) {
32 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($node, PATH_site . 'typo3temp/')) {
33 \TYPO3\CMS\Core\Utility\GeneralUtility::rmdir($node, TRUE);
34 }
35 }
36 parent::tearDown();
37 }
38
39 /**
40 * @test
41 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
42 */
43 public function constructorThrowsExceptionIfParentIsNull() {
44 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
45 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
46 $node->__construct(array(), NULL);
47 }
48
49 /**
50 * @test
51 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
52 */
53 public function constructorThrowsExceptionIfNameContainsForwardSlash() {
54 $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(), '', FALSE);
55 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
56 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
57 $structure = array(
58 'name' => 'foo/bar',
59 );
60 $node->__construct($structure, $parent);
61 }
62
63 /**
64 * @test
65 */
66 public function constructorCallsCreateChildrenIfChildrenAreSet() {
67 $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(), '', FALSE);
68 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
69 $node = $this->getAccessibleMock(
70 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
71 array('createChildren'),
72 array(),
73 '',
74 FALSE
75 );
76 $childArray = array(
77 'foo',
78 );
79 $structure = array(
80 'name' => 'foo',
81 'children' => $childArray,
82 );
83 $node->expects($this->once())->method('createChildren')->with($childArray);
84 $node->__construct($structure, $parent);
85 }
86
87 /**
88 * @test
89 */
90 public function constructorSetsParent() {
91 $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(), '', FALSE);
92 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
93 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
94 $structure = array(
95 'name' => 'foo',
96 );
97 $node->__construct($structure, $parent);
98 $this->assertSame($parent, $node->_call('getParent'));
99 }
100
101 /**
102 * @test
103 */
104 public function constructorSetsTargetPermission() {
105 $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(), '', FALSE);
106 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
107 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
108 $targetPermission = '2550';
109 $structure = array(
110 'name' => 'foo',
111 'targetPermission' => $targetPermission,
112 );
113 $node->__construct($structure, $parent);
114 $this->assertSame($targetPermission, $node->_call('getTargetPermission'));
115 }
116
117 /**
118 * @test
119 */
120 public function constructorSetsName() {
121 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
122 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
123 $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\RootNodeInterface', array(), array(), '', FALSE);
124 $name = uniqid('test_');
125 $node->__construct(array('name' => $name), $parent);
126 $this->assertSame($name, $node->getName());
127 }
128
129 /**
130 * @test
131 */
132 public function getStatusReturnsArray() {
133 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
134 $node = $this->getAccessibleMock(
135 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
136 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
137 array(),
138 '',
139 FALSE
140 );
141 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
142 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
143 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
144 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
145 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
146 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
147 $this->assertInternalType('array', $node->getStatus());
148 }
149
150 /**
151 * @test
152 */
153 public function getStatusReturnsArrayWithWarningStatusIfDirectoryNotExists() {
154 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
155 $node = $this->getAccessibleMock(
156 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
157 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
158 array(),
159 '',
160 FALSE
161 );
162 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
163 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
164 $node->expects($this->any())->method('exists')->will($this->returnValue(FALSE));
165 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(FALSE));
166 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(FALSE));
167 $node->expects($this->any())->method('isWritable')->will($this->returnValue(FALSE));
168 $statusArray = $node->getStatus();
169 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
170 $status = $statusArray[0];
171 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\WarningStatus', $status);
172 }
173
174 /**
175 * @test
176 */
177 public function getStatusReturnsArrayWithErrorStatusIfNodeIsNotADirectory() {
178 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
179 $node = $this->getAccessibleMock(
180 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
181 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
182 array(),
183 '',
184 FALSE
185 );
186 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
187 touch ($path);
188 $this->testNodesToDelete[] = $path;
189 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
190 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
191 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(FALSE));
192 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
193 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
194 $statusArray = $node->getStatus();
195 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
196 $status = $statusArray[0];
197 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\ErrorStatus', $status);
198 }
199
200 /**
201 * @test
202 */
203 public function getStatusReturnsArrayWithErrorStatusIfDirectoryExistsButIsNotWritable() {
204 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
205 $node = $this->getAccessibleMock(
206 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
207 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
208 array(),
209 '',
210 FALSE
211 );
212 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
213 touch ($path);
214 $this->testNodesToDelete[] = $path;
215 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
216 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
217 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
218 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
219 $node->expects($this->any())->method('isWritable')->will($this->returnValue(FALSE));
220 $statusArray = $node->getStatus();
221 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
222 $status = $statusArray[0];
223 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\ErrorStatus', $status);
224 }
225
226 /**
227 * @test
228 */
229 public function getStatusReturnsArrayWithNoticeStatusIfDirectoryExistsButPermissionAreNotCorrect() {
230 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
231 $node = $this->getAccessibleMock(
232 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
233 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
234 array(),
235 '',
236 FALSE
237 );
238 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
239 touch ($path);
240 $this->testNodesToDelete[] = $path;
241 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
242 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
243 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
244 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(FALSE));
245 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
246 $statusArray = $node->getStatus();
247 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
248 $status = $statusArray[0];
249 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\NoticeStatus', $status);
250 }
251
252 /**
253 * @test
254 */
255 public function getStatusReturnsArrayWithOkStatusIfDirectoryExistsAndPermissionAreCorrect() {
256 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
257 $node = $this->getAccessibleMock(
258 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
259 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
260 array(),
261 '',
262 FALSE
263 );
264 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
265 touch ($path);
266 $this->testNodesToDelete[] = $path;
267 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
268 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
269 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
270 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
271 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
272 $statusArray = $node->getStatus();
273 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
274 $status = $statusArray[0];
275 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\OkStatus', $status);
276 }
277
278 /**
279 * @test
280 */
281 public function getStatusCallsGetStatusOnChildren() {
282 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
283 $node = $this->getAccessibleMock(
284 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
285 array('exists', 'isDirectory', 'isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'isWritable'),
286 array(),
287 '',
288 FALSE
289 );
290 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
291 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
292 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
293 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
294 $childMock1 = $this->getMock('TYPO3\\CMS\\Install\\FolderStructure\\NodeInterface', array(), array(), '', FALSE);
295 $childMock1->expects($this->once())->method('getStatus')->will($this->returnValue(array()));
296 $childMock2 = $this->getMock('TYPO3\\CMS\\Install\\FolderStructure\\NodeInterface', array(), array(), '', FALSE);
297 $childMock2->expects($this->once())->method('getStatus')->will($this->returnValue(array()));
298 $node->_set('children', array($childMock1, $childMock2));
299 $node->getStatus();
300 }
301
302 /**
303 * @test
304 */
305 public function getStatusReturnsArrayWithOwnStatusAndStatusOfChild() {
306 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
307 $node = $this->getAccessibleMock(
308 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
309 array('exists', 'isDirectory', 'isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'isWritable'),
310 array(),
311 '',
312 FALSE
313 );
314 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
315 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
316 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
317 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
318 $childMock = $this->getMock('TYPO3\\CMS\\Install\\FolderStructure\\NodeInterface', array(), array(), '', FALSE);
319 $childStatusMock = $this->getMock('TYPO3\\CMS\\Install\\Status\\ErrorStatus', array(), array(), '', FALSE);
320 $childMock->expects($this->once())->method('getStatus')->will($this->returnValue(array($childStatusMock)));
321 $node->_set('children', array($childMock));
322 $status = $node->getStatus();
323 $statusOfDirectory = $status[0];
324 $statusOfChild = $status[1];
325 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\OkStatus', $statusOfDirectory);
326 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\ErrorStatus', $statusOfChild);
327 }
328
329 /**
330 * @test
331 */
332 public function fixCallsFixSelfAndReturnsItsResult() {
333 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
334 $node = $this->getAccessibleMock(
335 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
336 array('fixSelf'),
337 array(),
338 '',
339 FALSE
340 );
341 $uniqueReturn = array(uniqid('foo_'));
342 $node->expects($this->once())->method('fixSelf')->will($this->returnValue($uniqueReturn));
343 $this->assertSame($uniqueReturn, $node->fix());
344 }
345
346 /**
347 * @test
348 */
349 public function fixCallsFixOnChildrenAndReturnsMergedResult() {
350 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
351 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('fixSelf'), array(), '', FALSE);
352 $uniqueReturnSelf = uniqid('foo_');
353 $node->expects($this->once())->method('fixSelf')->will($this->returnValue(array($uniqueReturnSelf)));
354
355 $childMock1 = $this->getMock('TYPO3\\CMS\\Install\\FolderStructure\\NodeInterface', array(), array(), '', FALSE);
356 $uniqueReturnChild1 = uniqid('foo_');
357 $childMock1->expects($this->once())->method('fix')->will($this->returnValue(array($uniqueReturnChild1)));
358
359 $childMock2 = $this->getMock('TYPO3\\CMS\\Install\\FolderStructure\\NodeInterface', array(), array(), '', FALSE);
360 $uniqueReturnChild2 = uniqid('foo_');
361 $childMock2->expects($this->once())->method('fix')->will($this->returnValue(array($uniqueReturnChild2)));
362
363 $node->_set('children', array($childMock1, $childMock2));
364
365 $this->assertSame(array($uniqueReturnSelf, $uniqueReturnChild1, $uniqueReturnChild2), $node->fix());
366 }
367
368 /**
369 * @test
370 */
371 public function fixSelfCallsCreateDirectoryIfDirectoryDoesNotExistAndReturnsResult() {
372 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
373 $node = $this->getAccessibleMock(
374 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
375 array('exists', 'createDirectory', 'isPermissionCorrect'),
376 array(),
377 '',
378 FALSE
379 );
380 $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
381 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
382 $uniqueReturn = uniqid();
383 $node->expects($this->once())->method('createDirectory')->will($this->returnValue($uniqueReturn));
384 $this->assertSame(array($uniqueReturn), $node->_call('fixSelf'));
385 }
386
387 /**
388 * @test
389 */
390 public function fixSelfReturnsErrorStatusIfNodeExistsButIsNotADirectoryAndReturnsResult() {
391 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
392 $node = $this->getAccessibleMock(
393 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
394 array('exists', 'isWritable', 'getRelativePathBelowSiteRoot', 'isDirectory', 'getAbsolutePath'),
395 array(),
396 '',
397 FALSE
398 );
399 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
400 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
401 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(FALSE));
402 $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue(''));
403 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue(''));
404 $result = $node->_call('fixSelf');
405 $this->assertInstanceOf('TYPO3\\CMS\\Install\\Status\\ErrorStatus', $result[0]);
406 }
407
408 /**
409 * @test
410 */
411 public function fixSelfCallsFixPermissionIfDirectoryExistsButIsNotWritable() {
412 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
413 $node = $this->getAccessibleMock(
414 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
415 array('exists', 'isWritable', 'fixPermission'),
416 array(),
417 '',
418 FALSE
419 );
420 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
421 $node->expects($this->any())->method('isWritable')->will($this->returnValue(FALSE));
422 $node->expects($this->once())->method('fixPermission')->will($this->returnValue(TRUE));
423 $this->assertSame(array(TRUE), $node->_call('fixSelf'));
424 }
425
426 /**
427 * @test
428 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception
429 */
430 public function createDirectoryThrowsExceptionIfNodeExists() {
431 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
432 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
433 $node->expects($this->once())->method('getAbsolutePath')->will($this->returnValue(''));
434 $node->expects($this->once())->method('exists')->will($this->returnValue(TRUE));
435 $node->_call('createDirectory');
436 }
437
438 /**
439 * @test
440 */
441 public function createDirectoryCreatesDirectory() {
442 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
443 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
444 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
445 $this->testNodesToDelete[] = $path;
446 $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
447 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
448 $node->_call('createDirectory');
449 $this->assertTrue(is_dir($path));
450 }
451
452 /**
453 * @test
454 */
455 public function createDirectoryReturnsOkStatusIfDirectoryWasCreated() {
456 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
457 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
458 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
459 $this->testNodesToDelete[] = $path;
460 $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
461 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
462 $this->assertInstanceOf('TYPO3\\CMS\Install\\Status\\StatusInterface', $node->_call('createDirectory'));
463 }
464
465 /**
466 * @test
467 */
468 public function createDirectoryReturnsErrorStatusIfDirectoryWasNotCreated() {
469 if (TYPO3_OS === 'WIN') {
470 $this->markTestSkipped('Test not available on Windows OS.');
471 }
472 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
473 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
474 $path = PATH_site . 'typo3temp/' . uniqid('root_');
475 mkdir($path);
476 chmod($path, 02550);
477 $subPath = $path . '/' . uniqid('dir_');
478 $this->testNodesToDelete[] = $path;
479 $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
480 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath));
481 $this->assertInstanceOf('TYPO3\\CMS\Install\\Status\\StatusInterface', $node->_call('createDirectory'));
482 }
483
484 /**
485 * @test
486 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
487 */
488 public function createChildrenThrowsExceptionIfAChildTypeIsNotSet() {
489 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
490 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
491 $brokenStructure = array(
492 array(
493 'name' => 'foo',
494 ),
495 );
496 $node->_call('createChildren', $brokenStructure);
497 }
498
499 /**
500 * @test
501 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
502 */
503 public function createChildrenThrowsExceptionIfAChildNameIsNotSet() {
504 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
505 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
506 $brokenStructure = array(
507 array(
508 'type' => 'foo',
509 ),
510 );
511 $node->_call('createChildren', $brokenStructure);
512 }
513
514 /**
515 * @test
516 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
517 */
518 public function createChildrenThrowsExceptionForMultipleChildrenWithSameName() {
519 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
520 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
521 $brokenStructure = array(
522 array(
523 'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
524 'name' => 'foo',
525 ),
526 array(
527 'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
528 'name' => 'foo',
529 ),
530 );
531 $node->_call('createChildren', $brokenStructure);
532 }
533
534 /**
535 * @test
536 */
537 public function getChildrenReturnsCreatedChild() {
538 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
539 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
540 $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(), '', FALSE);
541 $childName = uniqid('test_');
542 $structure = array(
543 'name' => 'foo',
544 'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
545 'children' => array(
546 array(
547 'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
548 'name' => $childName,
549 ),
550 ),
551 );
552 $node->__construct($structure, $parent);
553 $children = $node->_call('getChildren');
554 /** @var $child \TYPO3\CMS\Install\FolderStructure\NodeInterface */
555 $child = $children[0];
556 $this->assertInstanceOf('TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode', $children[0]);
557 $this->assertSame($childName, $child->getName());
558 }
559
560 /**
561 * @test
562 */
563 public function isWritableReturnsFalseIfNodeDoesNotExist() {
564 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
565 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('getAbsolutePath'), array(), '', FALSE);
566 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
567 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
568 $this->assertFalse($node->isWritable());
569 }
570
571 /**
572 * @test
573 */
574 public function isWritableReturnsTrueIfNodeExistsAndFileCanBeCreated() {
575 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
576 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('getAbsolutePath'), array(), '', FALSE);
577 $path = PATH_site . 'typo3temp/' . uniqid('root_');
578 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
579 $this->testNodesToDelete[] = $path;
580 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
581 $this->assertTrue($node->isWritable());
582 }
583
584 /**
585 * @test
586 */
587 public function isWritableReturnsFalseIfNodeExistsButFileCanNotBeCreated() {
588 if (TYPO3_OS === 'WIN') {
589 $this->markTestSkipped('Test not available on Windows OS.');
590 }
591 if (function_exists('posix_getegid') && posix_getegid() === 0) {
592 $this->markTestSkipped('Test skipped if run on linux as root');
593 }
594 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
595 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('getAbsolutePath'), array(), '', FALSE);
596 $path = PATH_site . 'typo3temp/' . uniqid('root_');
597 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
598 $this->testNodesToDelete[] = $path;
599 chmod($path, 02550);
600 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
601 $this->assertFalse($node->isWritable());
602 }
603
604 /**
605 * @test
606 */
607 public function isDirectoryReturnsTrueIfNameIsADirectory() {
608 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
609 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('getAbsolutePath'), array(), '', FALSE);
610 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
611 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
612 $this->testNodesToDelete[] = $path;
613 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
614 $this->assertTrue($node->_call('isDirectory'));
615 }
616
617 /**
618 * @test
619 */
620 public function isDirectoryReturnsFalseIfNameIsALinkToADirectory() {
621 if (TYPO3_OS === 'WIN') {
622 $this->markTestSkipped('Test not available on Windows OS.');
623 }
624 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
625 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('getAbsolutePath'), array(), '', FALSE);
626 $path = PATH_site . 'typo3temp/' . uniqid('root_');
627 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
628 $this->testNodesToDelete[] = $path;
629 $link = uniqid('link_');
630 $dir = uniqid('dir_');
631 mkdir($path . '/' . $dir);
632 symlink($path . '/' . $dir, $path . '/' . $link);
633 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path . '/' . $link));
634 $this->assertFalse($node->_call('isDirectory'));
635 }
636 }