31 foreach ($this->testNodesToDelete as $node) {
32 if (\
TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($node, PATH_site .
'typo3temp/')) {
43 public function constructorThrowsExceptionIfParentIsNull() {
45 $node = $this->
getAccessibleMock(
'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array(
'dummy'), array(),
'', FALSE);
46 $node->__construct(array(), NULL);
53 public function constructorThrowsExceptionIfNameContainsForwardSlash() {
54 $parent = $this->getMock(
'TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(),
'', FALSE);
56 $node = $this->
getAccessibleMock(
'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array(
'dummy'), array(),
'', FALSE);
60 $node->__construct($structure, $parent);
66 public function constructorCallsCreateChildrenIfChildrenAreSet() {
67 $parent = $this->getMock(
'TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(),
'', FALSE);
70 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
71 array(
'createChildren'),
81 'children' => $childArray,
83 $node->expects($this->once())->method(
'createChildren')->with($childArray);
84 $node->__construct($structure, $parent);
90 public function constructorSetsParent() {
91 $parent = $this->getMock(
'TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(),
'', FALSE);
93 $node = $this->
getAccessibleMock(
'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array(
'dummy'), array(),
'', FALSE);
97 $node->__construct($structure, $parent);
98 $this->assertSame($parent, $node->_call(
'getParent'));
104 public function constructorSetsTargetPermission() {
105 $parent = $this->getMock(
'TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(),
'', FALSE);
107 $node = $this->
getAccessibleMock(
'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array(
'dummy'), array(),
'', FALSE);
108 $targetPermission =
'2550';
111 'targetPermission' => $targetPermission,
113 $node->__construct($structure, $parent);
114 $this->assertSame($targetPermission, $node->_call(
'getTargetPermission'));
120 public function constructorSetsName() {
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);
125 $node->__construct(array(
'name' => $name), $parent);
126 $this->assertSame($name, $node->getName());
132 public function getStatusReturnsArray() {
135 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
136 array(
'getAbsolutePath',
'exists',
'isDirectory',
'isWritable',
'isPermissionCorrect'),
141 $path = PATH_site .
'typo3temp/' . $this->
getUniqueId(
'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());
153 public function getStatusReturnsArrayWithWarningStatusIfDirectoryNotExists() {
156 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
157 array(
'getAbsolutePath',
'exists',
'isDirectory',
'isWritable',
'isPermissionCorrect'),
162 $path = PATH_site .
'typo3temp/' . $this->
getUniqueId(
'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();
170 $status = $statusArray[0];
171 $this->assertInstanceOf(
'\TYPO3\CMS\Install\Status\WarningStatus', $status);
177 public function getStatusReturnsArrayWithErrorStatusIfNodeIsNotADirectory() {
180 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
181 array(
'getAbsolutePath',
'exists',
'isDirectory',
'isWritable',
'isPermissionCorrect'),
186 $path = PATH_site .
'typo3temp/' . $this->
getUniqueId(
'dir_');
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();
196 $status = $statusArray[0];
197 $this->assertInstanceOf(
'\TYPO3\CMS\Install\Status\ErrorStatus', $status);
203 public function getStatusReturnsArrayWithErrorStatusIfDirectoryExistsButIsNotWritable() {
206 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
207 array(
'getAbsolutePath',
'exists',
'isDirectory',
'isWritable',
'isPermissionCorrect'),
212 $path = PATH_site .
'typo3temp/' . $this->
getUniqueId(
'dir_');
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();
222 $status = $statusArray[0];
223 $this->assertInstanceOf(
'\TYPO3\CMS\Install\Status\ErrorStatus', $status);
229 public function getStatusReturnsArrayWithNoticeStatusIfDirectoryExistsButPermissionAreNotCorrect() {
232 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
233 array(
'getAbsolutePath',
'exists',
'isDirectory',
'isWritable',
'isPermissionCorrect'),
238 $path = PATH_site .
'typo3temp/' . $this->
getUniqueId(
'dir_');
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();
248 $status = $statusArray[0];
249 $this->assertInstanceOf(
'\TYPO3\CMS\Install\Status\NoticeStatus', $status);
255 public function getStatusReturnsArrayWithOkStatusIfDirectoryExistsAndPermissionAreCorrect() {
258 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
259 array(
'getAbsolutePath',
'exists',
'isDirectory',
'isWritable',
'isPermissionCorrect'),
264 $path = PATH_site .
'typo3temp/' . $this->
getUniqueId(
'dir_');
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();
274 $status = $statusArray[0];
275 $this->assertInstanceOf(
'\TYPO3\CMS\Install\Status\OkStatus', $status);
281 public function getStatusCallsGetStatusOnChildren() {
284 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
285 array(
'exists',
'isDirectory',
'isPermissionCorrect',
'getRelativePathBelowSiteRoot',
'isWritable'),
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));
305 public function getStatusReturnsArrayWithOwnStatusAndStatusOfChild() {
308 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
309 array(
'exists',
'isDirectory',
'isPermissionCorrect',
'getRelativePathBelowSiteRoot',
'isWritable'),
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);
332 public function fixCallsFixSelfAndReturnsItsResult() {
335 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
342 $node->expects($this->once())->method(
'fixSelf')->will($this->returnValue($uniqueReturn));
343 $this->assertSame($uniqueReturn, $node->fix());
349 public function fixCallsFixOnChildrenAndReturnsMergedResult() {
351 $node = $this->
getAccessibleMock(
'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array(
'fixSelf'), array(),
'', FALSE);
353 $node->expects($this->once())->method(
'fixSelf')->will($this->returnValue(array($uniqueReturnSelf)));
355 $childMock1 = $this->getMock(
'TYPO3\\CMS\\Install\\FolderStructure\\NodeInterface', array(), array(),
'', FALSE);
357 $childMock1->expects($this->once())->method(
'fix')->will($this->returnValue(array($uniqueReturnChild1)));
359 $childMock2 = $this->getMock(
'TYPO3\\CMS\\Install\\FolderStructure\\NodeInterface', array(), array(),
'', FALSE);
361 $childMock2->expects($this->once())->method(
'fix')->will($this->returnValue(array($uniqueReturnChild2)));
363 $node->_set(
'children', array($childMock1, $childMock2));
365 $this->assertSame(array($uniqueReturnSelf, $uniqueReturnChild1, $uniqueReturnChild2), $node->fix());
371 public function fixSelfCallsCreateDirectoryIfDirectoryDoesNotExistAndReturnsResult() {
374 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
375 array(
'exists',
'createDirectory',
'isPermissionCorrect'),
380 $node->expects($this->once())->method(
'exists')->will($this->returnValue(FALSE));
381 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(TRUE));
383 $node->expects($this->once())->method(
'createDirectory')->will($this->returnValue($uniqueReturn));
384 $this->assertSame(array($uniqueReturn), $node->_call(
'fixSelf'));
390 public function fixSelfReturnsErrorStatusIfNodeExistsButIsNotADirectoryAndReturnsResult() {
393 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
394 array(
'exists',
'isWritable',
'getRelativePathBelowSiteRoot',
'isDirectory',
'getAbsolutePath'),
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]);
411 public function fixSelfCallsFixPermissionIfDirectoryExistsButIsNotWritable() {
414 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
415 array(
'exists',
'isWritable',
'fixPermission'),
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'));
430 public function createDirectoryThrowsExceptionIfNodeExists() {
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');
441 public function createDirectoryCreatesDirectory() {
443 $node = $this->
getAccessibleMock(
'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array(
'exists',
'getAbsolutePath'), array(),
'', FALSE);
444 $path = PATH_site .
'typo3temp/' . $this->
getUniqueId(
'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));
455 public function createDirectoryReturnsOkStatusIfDirectoryWasCreated() {
457 $node = $this->
getAccessibleMock(
'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array(
'exists',
'getAbsolutePath'), array(),
'', FALSE);
458 $path = PATH_site .
'typo3temp/' . $this->
getUniqueId(
'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'));
468 public function createDirectoryReturnsErrorStatusIfDirectoryWasNotCreated() {
469 if (TYPO3_OS ===
'WIN') {
470 $this->markTestSkipped(
'Test not available on Windows OS.');
473 $node = $this->
getAccessibleMock(
'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array(
'exists',
'getAbsolutePath'), array(),
'', FALSE);
474 $path = PATH_site .
'typo3temp/' . $this->
getUniqueId(
'root_');
477 $subPath = $path .
'/' . $this->
getUniqueId(
'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'));
488 public function createChildrenThrowsExceptionIfAChildTypeIsNotSet() {
490 $node = $this->
getAccessibleMock(
'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array(
'dummy'), array(),
'', FALSE);
491 $brokenStructure = array(
496 $node->_call(
'createChildren', $brokenStructure);
503 public function createChildrenThrowsExceptionIfAChildNameIsNotSet() {
505 $node = $this->
getAccessibleMock(
'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array(
'dummy'), array(),
'', FALSE);
506 $brokenStructure = array(
511 $node->_call(
'createChildren', $brokenStructure);
518 public function createChildrenThrowsExceptionForMultipleChildrenWithSameName() {
520 $node = $this->
getAccessibleMock(
'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array(
'dummy'), array(),
'', FALSE);
521 $brokenStructure = array(
523 'type' =>
'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
527 'type' =>
'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
531 $node->_call(
'createChildren', $brokenStructure);
537 public function getChildrenReturnsCreatedChild() {
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);
544 'type' =>
'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
547 'type' =>
'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
548 'name' => $childName,
552 $node->__construct($structure, $parent);
553 $children = $node->_call(
'getChildren');
555 $child = $children[0];
556 $this->assertInstanceOf(
'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode', $children[0]);
557 $this->assertSame($childName, $child->getName());
563 public function isWritableReturnsFalseIfNodeDoesNotExist() {
565 $node = $this->
getAccessibleMock(
'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array(
'getAbsolutePath'), array(),
'', FALSE);
566 $path = PATH_site .
'typo3temp/' . $this->
getUniqueId(
'dir_');
567 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
568 $this->assertFalse($node->isWritable());
574 public function isWritableReturnsTrueIfNodeExistsAndFileCanBeCreated() {
576 $node = $this->
getAccessibleMock(
'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array(
'getAbsolutePath'), array(),
'', FALSE);
577 $path = PATH_site .
'typo3temp/' . $this->
getUniqueId(
'root_');
579 $this->testNodesToDelete[] = $path;
580 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
581 $this->assertTrue($node->isWritable());
587 public function isWritableReturnsFalseIfNodeExistsButFileCanNotBeCreated() {
588 if (TYPO3_OS ===
'WIN') {
589 $this->markTestSkipped(
'Test not available on Windows OS.');
591 if (function_exists(
'posix_getegid') && posix_getegid() === 0) {
592 $this->markTestSkipped(
'Test skipped if run on linux as root');
595 $node = $this->
getAccessibleMock(
'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array(
'getAbsolutePath'), array(),
'', FALSE);
596 $path = PATH_site .
'typo3temp/' . $this->
getUniqueId(
'root_');
598 $this->testNodesToDelete[] = $path;
600 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
601 $this->assertFalse($node->isWritable());
607 public function isDirectoryReturnsTrueIfNameIsADirectory() {
609 $node = $this->
getAccessibleMock(
'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array(
'getAbsolutePath'), array(),
'', FALSE);
610 $path = PATH_site .
'typo3temp/' . $this->
getUniqueId(
'dir_');
612 $this->testNodesToDelete[] = $path;
613 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
614 $this->assertTrue($node->_call(
'isDirectory'));
620 public function isDirectoryReturnsFalseIfNameIsALinkToADirectory() {
621 if (TYPO3_OS ===
'WIN') {
622 $this->markTestSkipped(
'Test not available on Windows OS.');
625 $node = $this->
getAccessibleMock(
'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array(
'getAbsolutePath'), array(),
'', FALSE);
626 $path = PATH_site .
'typo3temp/' . $this->
getUniqueId(
'root_');
628 $this->testNodesToDelete[] = $path;
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'));
static mkdir_deep($directory, $deepDirectory='')
static rmdir($path, $removeNonEmpty=FALSE)
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren't numeric.