2 namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
20 class DirectoryNodeTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
24 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
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
::class, array('dummy'), array(), '', FALSE);
29 $node->__construct(array(), NULL);
34 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
36 public function constructorThrowsExceptionIfNameContainsForwardSlash() {
37 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface
::class, 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
::class, array('dummy'), array(), '', FALSE);
43 $node->__construct($structure, $parent);
49 public function constructorCallsCreateChildrenIfChildrenAreSet() {
50 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface
::class, 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
::class,
54 array('createChildren'),
64 'children' => $childArray,
66 $node->expects($this->once())->method('createChildren')->with($childArray);
67 $node->__construct($structure, $parent);
73 public function constructorSetsParent() {
74 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface
::class, 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
::class, array('dummy'), array(), '', FALSE);
80 $node->__construct($structure, $parent);
81 $this->assertSame($parent, $node->_call('getParent'));
87 public function constructorSetsTargetPermission() {
88 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface
::class, 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
::class, array('dummy'), array(), '', FALSE);
91 $targetPermission = '2550';
94 'targetPermission' => $targetPermission,
96 $node->__construct($structure, $parent);
97 $this->assertSame($targetPermission, $node->_call('getTargetPermission'));
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
::class, array('dummy'), array(), '', FALSE);
106 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface
::class, array(), array(), '', FALSE);
107 $name = $this->getUniqueId('test_');
108 $node->__construct(array('name' => $name), $parent);
109 $this->assertSame($name, $node->getName());
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
::class,
119 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
124 $path = PATH_site
. 'typo3temp/' . $this->getUniqueId('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());
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
::class,
140 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
145 $path = PATH_site
. 'typo3temp/' . $this->getUniqueId('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
::class, $status);
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
::class,
164 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
169 $path = PATH_site
. 'typo3temp/' . $this->getUniqueId('dir_');
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
::class, $status);
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
::class,
190 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
195 $path = PATH_site
. 'typo3temp/' . $this->getUniqueId('dir_');
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
::class, $status);
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
::class,
216 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
221 $path = PATH_site
. 'typo3temp/' . $this->getUniqueId('dir_');
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
::class, $status);
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
::class,
242 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
247 $path = PATH_site
. 'typo3temp/' . $this->getUniqueId('dir_');
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
::class, $status);
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
::class,
268 array('exists', 'isDirectory', 'isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'isWritable'),
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
::class, array(), array(), '', FALSE);
278 $childMock1->expects($this->once())->method('getStatus')->will($this->returnValue(array()));
279 $childMock2 = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface
::class, array(), array(), '', FALSE);
280 $childMock2->expects($this->once())->method('getStatus')->will($this->returnValue(array()));
281 $node->_set('children', array($childMock1, $childMock2));
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
::class,
292 array('exists', 'isDirectory', 'isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'isWritable'),
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
::class, array(), array(), '', FALSE);
302 $childStatusMock = $this->getMock(\TYPO3\CMS\Install\Status\ErrorStatus
::class, 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
::class, $statusOfDirectory);
309 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus
::class, $statusOfChild);
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
::class,
324 $uniqueReturn = array($this->getUniqueId('foo_'));
325 $node->expects($this->once())->method('fixSelf')->will($this->returnValue($uniqueReturn));
326 $this->assertSame($uniqueReturn, $node->fix());
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
::class, array('fixSelf'), array(), '', FALSE);
335 $uniqueReturnSelf = $this->getUniqueId('foo_');
336 $node->expects($this->once())->method('fixSelf')->will($this->returnValue(array($uniqueReturnSelf)));
338 $childMock1 = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface
::class, array(), array(), '', FALSE);
339 $uniqueReturnChild1 = $this->getUniqueId('foo_');
340 $childMock1->expects($this->once())->method('fix')->will($this->returnValue(array($uniqueReturnChild1)));
342 $childMock2 = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface
::class, array(), array(), '', FALSE);
343 $uniqueReturnChild2 = $this->getUniqueId('foo_');
344 $childMock2->expects($this->once())->method('fix')->will($this->returnValue(array($uniqueReturnChild2)));
346 $node->_set('children', array($childMock1, $childMock2));
348 $this->assertSame(array($uniqueReturnSelf, $uniqueReturnChild1, $uniqueReturnChild2), $node->fix());
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
::class,
358 array('exists', 'createDirectory', 'isPermissionCorrect'),
363 $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
364 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
365 $uniqueReturn = $this->getUniqueId();
366 $node->expects($this->once())->method('createDirectory')->will($this->returnValue($uniqueReturn));
367 $this->assertSame(array($uniqueReturn), $node->_call('fixSelf'));
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
::class,
377 array('exists', 'isWritable', 'getRelativePathBelowSiteRoot', 'isDirectory', 'getAbsolutePath'),
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
::class, $result[0]);
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
::class,
398 array('exists', 'isWritable', 'fixPermission'),
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'));
411 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception
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
::class, 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');
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
::class, array('exists', 'getAbsolutePath'), array(), '', FALSE);
427 $path = PATH_site
. 'typo3temp/' . $this->getUniqueId('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));
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
::class, array('exists', 'getAbsolutePath'), array(), '', FALSE);
441 $path = PATH_site
. 'typo3temp/' . $this->getUniqueId('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
::class, $node->_call('createDirectory'));
451 public function createDirectoryReturnsErrorStatusIfDirectoryWasNotCreated() {
452 if (TYPO3_OS
=== 'WIN') {
453 $this->markTestSkipped('Test not available on Windows OS.');
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
::class, array('exists', 'getAbsolutePath'), array(), '', FALSE);
457 $path = PATH_site
. 'typo3temp/' . $this->getUniqueId('root_');
460 $subPath = $path . '/' . $this->getUniqueId('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
::class, $node->_call('createDirectory'));
469 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
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
::class, array('dummy'), array(), '', FALSE);
474 $brokenStructure = array(
479 $node->_call('createChildren', $brokenStructure);
484 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
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
::class, array('dummy'), array(), '', FALSE);
489 $brokenStructure = array(
494 $node->_call('createChildren', $brokenStructure);
499 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
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
::class, array('dummy'), array(), '', FALSE);
504 $brokenStructure = array(
506 'type' => \TYPO3\CMS\Install\FolderStructure\DirectoryNode
::class,
510 'type' => \TYPO3\CMS\Install\FolderStructure\DirectoryNode
::class,
514 $node->_call('createChildren', $brokenStructure);
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
::class, array('dummy'), array(), '', FALSE);
523 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface
::class, array(), array(), '', FALSE);
524 $childName = $this->getUniqueId('test_');
527 'type' => \TYPO3\CMS\Install\FolderStructure\DirectoryNode
::class,
530 'type' => \TYPO3\CMS\Install\FolderStructure\DirectoryNode
::class,
531 'name' => $childName,
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
::class, $children[0]);
540 $this->assertSame($childName, $child->getName());
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
::class, array('getAbsolutePath'), array(), '', FALSE);
549 $path = PATH_site
. 'typo3temp/' . $this->getUniqueId('dir_');
550 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
551 $this->assertFalse($node->isWritable());
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
::class, array('getAbsolutePath'), array(), '', FALSE);
560 $path = PATH_site
. 'typo3temp/' . $this->getUniqueId('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());
570 public function isWritableReturnsFalseIfNodeExistsButFileCanNotBeCreated() {
571 if (TYPO3_OS
=== 'WIN') {
572 $this->markTestSkipped('Test not available on Windows OS.');
574 if (function_exists('posix_getegid') && posix_getegid() === 0) {
575 $this->markTestSkipped('Test skipped if run on linux as root');
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
::class, array('getAbsolutePath'), array(), '', FALSE);
579 $path = PATH_site
. 'typo3temp/' . $this->getUniqueId('root_');
580 \TYPO3\CMS\Core\Utility\GeneralUtility
::mkdir_deep($path);
581 $this->testFilesToDelete
[] = $path;
583 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
584 $this->assertFalse($node->isWritable());
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
::class, array('getAbsolutePath'), array(), '', FALSE);
593 $path = PATH_site
. 'typo3temp/' . $this->getUniqueId('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'));
603 public function isDirectoryReturnsTrueIfNameIsALinkToADirectory() {
604 if (TYPO3_OS
=== 'WIN') {
605 $this->markTestSkipped('Test not available on Windows OS.');
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
::class, array('getAbsolutePath'), array(), '', FALSE);
609 $path = PATH_site
. 'typo3temp/' . $this->getUniqueId('root_');
610 \TYPO3\CMS\Core\Utility\GeneralUtility
::mkdir_deep($path);
611 $this->testFilesToDelete
[] = $path;
612 $link = $this->getUniqueId('link_');
613 $dir = $this->getUniqueId('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->assertTrue($node->_call('isDirectory'));