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