2 namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure;
26 public function constructorThrowsExceptionIfParentIsNull()
29 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array(
'dummy'), array(),
'',
false);
30 $node->__construct(array(), null);
37 public function constructorThrowsExceptionIfNameContainsForwardSlash()
39 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(),
'',
false);
41 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array(
'dummy'), array(),
'',
false);
45 $node->__construct($structure, $parent);
51 public function constructorCallsCreateChildrenIfChildrenAreSet()
53 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(),
'',
false);
55 $node = $this->getAccessibleMock(
56 \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
57 array(
'createChildren'),
67 'children' => $childArray,
69 $node->expects($this->once())->method(
'createChildren')->with($childArray);
70 $node->__construct($structure, $parent);
76 public function constructorSetsParent()
78 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(),
'',
false);
80 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array(
'dummy'), array(),
'',
false);
84 $node->__construct($structure, $parent);
85 $this->assertSame($parent, $node->_call(
'getParent'));
91 public function constructorSetsTargetPermission()
93 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(),
'',
false);
95 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array(
'dummy'), array(),
'',
false);
96 $targetPermission =
'2550';
99 'targetPermission' => $targetPermission,
101 $node->__construct($structure, $parent);
102 $this->assertSame($targetPermission, $node->_call(
'getTargetPermission'));
108 public function constructorSetsName()
111 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array(
'dummy'), array(),
'',
false);
112 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class, array(), array(),
'',
false);
113 $name = $this->getUniqueId(
'test_');
114 $node->__construct(array(
'name' => $name), $parent);
115 $this->assertSame($name, $node->getName());
121 public function getStatusReturnsArray()
124 $node = $this->getAccessibleMock(
125 \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
126 array(
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isDirectory',
'isWritable',
'isPermissionCorrect'),
132 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
133 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
134 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
135 $node->expects($this->any())->method(
'isDirectory')->will($this->returnValue(
true));
136 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
137 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
138 $this->assertInternalType(
'array', $node->getStatus());
144 public function getStatusReturnsArrayWithWarningStatusIfDirectoryNotExists()
147 $node = $this->getAccessibleMock(
148 \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
149 array(
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isDirectory',
'isWritable',
'isPermissionCorrect'),
155 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
156 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
157 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
false));
158 $node->expects($this->any())->method(
'isDirectory')->will($this->returnValue(
false));
159 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
false));
160 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
false));
161 $statusArray = $node->getStatus();
163 $status = $statusArray[0];
164 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\WarningStatus::class, $status);
170 public function getStatusReturnsArrayWithErrorStatusIfNodeIsNotADirectory()
173 $node = $this->getAccessibleMock(
174 \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
175 array(
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isDirectory',
'isWritable',
'isPermissionCorrect'),
182 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
183 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
184 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
185 $node->expects($this->any())->method(
'isDirectory')->will($this->returnValue(
false));
186 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
187 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
188 $statusArray = $node->getStatus();
190 $status = $statusArray[0];
191 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus::class, $status);
197 public function getStatusReturnsArrayWithErrorStatusIfDirectoryExistsButIsNotWritable()
200 $node = $this->getAccessibleMock(
201 \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
202 array(
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isDirectory',
'isWritable',
'isPermissionCorrect'),
209 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
210 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
211 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
212 $node->expects($this->any())->method(
'isDirectory')->will($this->returnValue(
true));
213 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
214 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
false));
215 $statusArray = $node->getStatus();
217 $status = $statusArray[0];
218 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus::class, $status);
224 public function getStatusReturnsArrayWithNoticeStatusIfDirectoryExistsButPermissionAreNotCorrect()
227 $node = $this->getAccessibleMock(
228 \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
229 array(
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isDirectory',
'isWritable',
'isPermissionCorrect'),
236 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
237 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
238 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
239 $node->expects($this->any())->method(
'isDirectory')->will($this->returnValue(
true));
240 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
false));
241 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
242 $statusArray = $node->getStatus();
244 $status = $statusArray[0];
245 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\NoticeStatus::class, $status);
251 public function getStatusReturnsArrayWithOkStatusIfDirectoryExistsAndPermissionAreCorrect()
254 $node = $this->getAccessibleMock(
255 \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
256 array(
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isDirectory',
'isWritable',
'isPermissionCorrect'),
263 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
264 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
265 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
266 $node->expects($this->any())->method(
'isDirectory')->will($this->returnValue(
true));
267 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
268 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
269 $statusArray = $node->getStatus();
271 $status = $statusArray[0];
272 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\OkStatus::class, $status);
278 public function getStatusCallsGetStatusOnChildren()
281 $node = $this->getAccessibleMock(
282 \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
283 array(
'exists',
'isDirectory',
'isPermissionCorrect',
'getRelativePathBelowSiteRoot',
'isWritable'),
288 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
289 $node->expects($this->any())->method(
'isDirectory')->will($this->returnValue(
true));
290 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
291 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
292 $childMock1 = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(),
'',
false);
293 $childMock1->expects($this->once())->method(
'getStatus')->will($this->returnValue(array()));
294 $childMock2 = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(),
'',
false);
295 $childMock2->expects($this->once())->method(
'getStatus')->will($this->returnValue(array()));
296 $node->_set(
'children', array($childMock1, $childMock2));
303 public function getStatusReturnsArrayWithOwnStatusAndStatusOfChild()
306 $node = $this->getAccessibleMock(
307 \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
308 array(
'exists',
'isDirectory',
'isPermissionCorrect',
'getRelativePathBelowSiteRoot',
'isWritable'),
313 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
314 $node->expects($this->any())->method(
'isDirectory')->will($this->returnValue(
true));
315 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
316 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
317 $childMock = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(),
'',
false);
318 $childStatusMock = $this->getMock(\TYPO3\CMS\Install\Status\ErrorStatus::class, array(), array(),
'',
false);
319 $childMock->expects($this->once())->method(
'getStatus')->will($this->returnValue(array($childStatusMock)));
320 $node->_set(
'children', array($childMock));
321 $status = $node->getStatus();
322 $statusOfDirectory = $status[0];
323 $statusOfChild = $status[1];
324 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\OkStatus::class, $statusOfDirectory);
325 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus::class, $statusOfChild);
331 public function fixCallsFixSelfAndReturnsItsResult()
334 $node = $this->getAccessibleMock(
335 \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
341 $uniqueReturn = array($this->getUniqueId(
'foo_'));
342 $node->expects($this->once())->method(
'fixSelf')->will($this->returnValue($uniqueReturn));
343 $this->assertSame($uniqueReturn, $node->fix());
349 public function fixCallsFixOnChildrenAndReturnsMergedResult()
352 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array(
'fixSelf'), array(),
'',
false);
353 $uniqueReturnSelf = $this->getUniqueId(
'foo_');
354 $node->expects($this->once())->method(
'fixSelf')->will($this->returnValue(array($uniqueReturnSelf)));
356 $childMock1 = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(),
'',
false);
357 $uniqueReturnChild1 = $this->getUniqueId(
'foo_');
358 $childMock1->expects($this->once())->method(
'fix')->will($this->returnValue(array($uniqueReturnChild1)));
360 $childMock2 = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(),
'',
false);
361 $uniqueReturnChild2 = $this->getUniqueId(
'foo_');
362 $childMock2->expects($this->once())->method(
'fix')->will($this->returnValue(array($uniqueReturnChild2)));
364 $node->_set(
'children', array($childMock1, $childMock2));
366 $this->assertSame(array($uniqueReturnSelf, $uniqueReturnChild1, $uniqueReturnChild2), $node->fix());
372 public function fixSelfCallsCreateDirectoryIfDirectoryDoesNotExistAndReturnsResult()
375 $node = $this->getAccessibleMock(
376 \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
377 array(
'exists',
'createDirectory',
'isPermissionCorrect'),
382 $node->expects($this->once())->method(
'exists')->will($this->returnValue(
false));
383 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
384 $uniqueReturn = $this->getUniqueId();
385 $node->expects($this->once())->method(
'createDirectory')->will($this->returnValue($uniqueReturn));
386 $this->assertSame(array($uniqueReturn), $node->_call(
'fixSelf'));
392 public function fixSelfReturnsErrorStatusIfNodeExistsButIsNotADirectoryAndReturnsResult()
395 $node = $this->getAccessibleMock(
396 \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
397 array(
'exists',
'isWritable',
'getRelativePathBelowSiteRoot',
'isDirectory',
'getAbsolutePath'),
402 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
403 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
404 $node->expects($this->any())->method(
'isDirectory')->will($this->returnValue(
false));
405 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue(
''));
406 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue(
''));
407 $result = $node->_call(
'fixSelf');
408 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus::class, $result[0]);
414 public function fixSelfCallsFixPermissionIfDirectoryExistsButIsNotWritable()
417 $node = $this->getAccessibleMock(
418 \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
419 array(
'exists',
'isWritable',
'fixPermission'),
424 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
425 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
false));
426 $node->expects($this->once())->method(
'fixPermission')->will($this->returnValue(
true));
427 $this->assertSame(array(
true), $node->_call(
'fixSelf'));
434 public function createDirectoryThrowsExceptionIfNodeExists()
437 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array(
'exists',
'getAbsolutePath'), array(),
'',
false);
438 $node->expects($this->once())->method(
'getAbsolutePath')->will($this->returnValue(
''));
439 $node->expects($this->once())->method(
'exists')->will($this->returnValue(
true));
440 $node->_call(
'createDirectory');
446 public function createDirectoryCreatesDirectory()
449 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array(
'exists',
'getAbsolutePath',
'getRelativePathBelowSiteRoot'), array(),
'',
false);
451 $node->expects($this->once())->method(
'exists')->will($this->returnValue(
false));
452 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
453 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
454 $node->_call(
'createDirectory');
455 $this->assertTrue(is_dir($path));
461 public function createDirectoryReturnsOkStatusIfDirectoryWasCreated()
464 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array(
'exists',
'getAbsolutePath',
'getRelativePathBelowSiteRoot'), array(),
'',
false);
466 $node->expects($this->once())->method(
'exists')->will($this->returnValue(
false));
467 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
468 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
469 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\StatusInterface::class, $node->_call(
'createDirectory'));
475 public function createDirectoryReturnsErrorStatusIfDirectoryWasNotCreated()
477 if (TYPO3_OS ===
'WIN') {
478 $this->markTestSkipped(
'Test not available on Windows OS.');
481 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array(
'exists',
'getAbsolutePath',
'getRelativePathBelowSiteRoot'), array(),
'',
false);
484 $subPath = $path .
'/' . $this->getUniqueId(
'dir_');
485 $node->expects($this->once())->method(
'exists')->will($this->returnValue(
false));
486 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($subPath));
487 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($subPath));
488 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\StatusInterface::class, $node->_call(
'createDirectory'));
495 public function createChildrenThrowsExceptionIfAChildTypeIsNotSet()
498 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array(
'dummy'), array(),
'',
false);
499 $brokenStructure = array(
504 $node->_call(
'createChildren', $brokenStructure);
511 public function createChildrenThrowsExceptionIfAChildNameIsNotSet()
514 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array(
'dummy'), array(),
'',
false);
515 $brokenStructure = array(
520 $node->_call(
'createChildren', $brokenStructure);
527 public function createChildrenThrowsExceptionForMultipleChildrenWithSameName()
530 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array(
'dummy'), array(),
'',
false);
531 $brokenStructure = array(
533 'type' => \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
537 'type' => \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
541 $node->_call(
'createChildren', $brokenStructure);
547 public function getChildrenReturnsCreatedChild()
550 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array(
'dummy'), array(),
'',
false);
551 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(),
'',
false);
552 $childName = $this->getUniqueId(
'test_');
555 'type' => \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
558 'type' => \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
559 'name' => $childName,
563 $node->__construct($structure, $parent);
564 $children = $node->_call(
'getChildren');
566 $child = $children[0];
567 $this->assertInstanceOf(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, $children[0]);
568 $this->assertSame($childName, $child->getName());
574 public function isWritableReturnsFalseIfNodeDoesNotExist()
577 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array(
'getAbsolutePath'), array(),
'',
false);
579 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
580 $this->assertFalse($node->isWritable());
586 public function isWritableReturnsTrueIfNodeExistsAndFileCanBeCreated()
589 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array(
'getAbsolutePath'), array(),
'',
false);
591 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
592 $this->assertTrue($node->isWritable());
598 public function isWritableReturnsFalseIfNodeExistsButFileCanNotBeCreated()
600 if (TYPO3_OS ===
'WIN') {
601 $this->markTestSkipped(
'Test not available on Windows OS.');
603 if (function_exists(
'posix_getegid') && posix_getegid() === 0) {
604 $this->markTestSkipped(
'Test skipped if run on linux as root');
607 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array(
'getAbsolutePath'), array(),
'',
false);
610 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
611 $this->assertFalse($node->isWritable());
617 public function isDirectoryReturnsTrueIfNameIsADirectory()
620 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array(
'getAbsolutePath'), array(),
'',
false);
622 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
623 $this->assertTrue($node->_call(
'isDirectory'));
630 public function isDirectoryReturnsFalseIfNameIsALinkToADirectory()
632 if (TYPO3_OS ===
'WIN') {
633 $this->markTestSkipped(
'Test not available on Windows OS.');
636 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array(
'getAbsolutePath'), array(),
'',
false);
637 $path = PATH_site .
'typo3temp/' . $this->getUniqueId(
'root_');
638 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
639 $this->testFilesToDelete[] = $path;
640 $link = $this->getUniqueId(
'link_');
641 $dir = $this->getUniqueId(
'dir_');
642 mkdir($path .
'/' . $dir);
643 symlink($path .
'/' . $dir, $path .
'/' . $link);
644 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path .
'/' . $link));
645 $this->assertFalse($node->_call(
'isDirectory'));