2 namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure;
26 public function constructorThrowsExceptionIfParentIsNull()
29 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::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\FileNode::class, array(
'dummy'), array(),
'',
false);
45 $node->__construct($structure, $parent);
51 public function constructorSetsParent()
53 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(),
'',
false);
55 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'dummy'), array(),
'',
false);
59 $node->__construct($structure, $parent);
60 $this->assertSame($parent, $node->_call(
'getParent'));
66 public function constructorSetsTargetPermission()
68 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(),
'',
false);
70 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'dummy'), array(),
'',
false);
71 $targetPermission =
'0660';
74 'targetPermission' => $targetPermission,
76 $node->__construct($structure, $parent);
77 $this->assertSame($targetPermission, $node->_call(
'getTargetPermission'));
83 public function constructorSetsName()
86 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'dummy'), array(),
'',
false);
87 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class, array(), array(),
'',
false);
88 $name = $this->getUniqueId(
'test_');
89 $node->__construct(array(
'name' => $name), $parent);
90 $this->assertSame($name, $node->getName());
97 public function constructorThrowsExceptionIfBothTargetContentAndTargetContentFileAreSet()
100 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'dummy'), array(),
'',
false);
101 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class, array(), array(),
'',
false);
104 'targetContent' =>
'foo',
105 'targetContentFile' =>
'aPath',
107 $node->__construct($structure, $parent);
113 public function constructorSetsTargetContent()
116 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'dummy'), array(),
'',
false);
117 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class, array(), array(),
'',
false);
118 $targetContent = $this->getUniqueId(
'content_');
121 'targetContent' => $targetContent,
123 $node->__construct($structure, $parent);
124 $this->assertSame($targetContent, $node->_get(
'targetContent'));
130 public function constructorSetsTargetContentToContentOfTargetContentFile()
133 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'dummy'), array(),
'',
false);
134 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class, array(), array(),
'',
false);
136 $targetContent = $this->getUniqueId(
'content_');
137 file_put_contents($targetFile, $targetContent);
140 'targetContentFile' => $targetFile,
142 $node->__construct($structure, $parent);
143 $this->assertSame($targetContent, $node->_get(
'targetContent'));
150 public function constructorThrowsExceptionIfTargetContentFileDoesNotExist()
153 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'dummy'), array(),
'',
false);
154 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class, array(), array(),
'',
false);
158 'targetContentFile' => $targetFile,
160 $node->__construct($structure, $parent);
166 public function targetContentIsNullIfNotGiven()
169 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'dummy'), array(),
'',
false);
170 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class, array(), array(),
'',
false);
174 $node->__construct($structure, $parent);
175 $this->assertNull($node->_get(
'targetContent'));
181 public function getStatusReturnsArray()
184 $node = $this->getAccessibleMock(
185 \TYPO3\CMS\Install\FolderStructure\FileNode::class,
186 array(
'getAbsolutePath',
'exists',
'isFile',
'isWritable',
'isPermissionCorrect',
'isContentCorrect'),
191 $path = PATH_site .
'typo3temp/' . $this->getUniqueId(
'dir_');
192 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
193 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
194 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
true));
195 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
196 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
197 $node->expects($this->any())->method(
'isContentCorrect')->will($this->returnValue(
true));
198 $this->assertInternalType(
'array', $node->getStatus());
204 public function getStatusReturnsArrayWithWarningStatusIFileNotExists()
207 $node = $this->getAccessibleMock(
208 \TYPO3\CMS\Install\FolderStructure\FileNode::class,
209 array(
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isFile',
'isWritable',
'isPermissionCorrect',
'isContentCorrect'),
215 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
216 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
217 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
false));
218 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
true));
219 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
220 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
221 $node->expects($this->any())->method(
'isContentCorrect')->will($this->returnValue(
true));
222 $statusArray = $node->getStatus();
224 $status = $statusArray[0];
225 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\WarningStatus::class, $status);
231 public function getStatusReturnsArrayWithErrorStatusIfNodeIsNotAFile()
234 $node = $this->getAccessibleMock(
235 \TYPO3\CMS\Install\FolderStructure\FileNode::class,
236 array(
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isFile',
'isWritable',
'isPermissionCorrect',
'isContentCorrect'),
243 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
244 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
245 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
246 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
false));
247 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
248 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
249 $node->expects($this->any())->method(
'isContentCorrect')->will($this->returnValue(
true));
250 $statusArray = $node->getStatus();
252 $status = $statusArray[0];
253 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus::class, $status);
259 public function getStatusReturnsArrayNoticeStatusIfFileExistsButIsNotWritable()
262 $node = $this->getAccessibleMock(
263 \TYPO3\CMS\Install\FolderStructure\FileNode::class,
264 array(
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isFile',
'isWritable',
'isPermissionCorrect',
'isContentCorrect'),
271 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
272 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
273 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
274 $node->expects($this->any())->method(
'isFile')->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(
false));
277 $node->expects($this->any())->method(
'isContentCorrect')->will($this->returnValue(
true));
278 $statusArray = $node->getStatus();
280 $status = $statusArray[0];
281 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\NoticeStatus::class, $status);
287 public function getStatusReturnsArrayWithNoticeStatusIfFileExistsButPermissionAreNotCorrect()
290 $node = $this->getAccessibleMock(
291 \TYPO3\CMS\Install\FolderStructure\FileNode::class,
292 array(
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isFile',
'isWritable',
'isPermissionCorrect',
'isContentCorrect'),
299 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
300 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
301 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
302 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
true));
303 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
false));
304 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
305 $node->expects($this->any())->method(
'isContentCorrect')->will($this->returnValue(
true));
306 $statusArray = $node->getStatus();
308 $status = $statusArray[0];
309 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\NoticeStatus::class, $status);
315 public function getStatusReturnsArrayWithNoticeStatusIfFileExistsButContentIsNotCorrect()
318 $node = $this->getAccessibleMock(
319 \TYPO3\CMS\Install\FolderStructure\FileNode::class,
320 array(
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isFile',
'isWritable',
'isPermissionCorrect',
'isContentCorrect'),
327 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
328 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
329 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
330 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
true));
331 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
332 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
333 $node->expects($this->any())->method(
'isContentCorrect')->will($this->returnValue(
false));
334 $statusArray = $node->getStatus();
336 $status = $statusArray[0];
337 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\NoticeStatus::class, $status);
343 public function getStatusReturnsArrayWithOkStatusIfFileExistsAndPermissionAreCorrect()
346 $node = $this->getAccessibleMock(
347 \TYPO3\CMS\Install\FolderStructure\FileNode::class,
348 array(
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isFile',
'isWritable',
'isPermissionCorrect',
'isContentCorrect'),
355 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
356 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
357 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
358 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
true));
359 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
360 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
361 $node->expects($this->any())->method(
'isContentCorrect')->will($this->returnValue(
true));
362 $statusArray = $node->getStatus();
364 $status = $statusArray[0];
365 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\OkStatus::class, $status);
371 public function fixCallsFixSelfAndReturnsItsResult()
374 $node = $this->getAccessibleMock(
375 \TYPO3\CMS\Install\FolderStructure\FileNode::class,
381 $uniqueReturn = array($this->getUniqueId(
'foo_'));
382 $node->expects($this->once())->method(
'fixSelf')->will($this->returnValue($uniqueReturn));
383 $this->assertSame($uniqueReturn, $node->fix());
389 public function fixSelfCallsCreateFileIfFileDoesNotExistAndReturnsResult()
392 $node = $this->getAccessibleMock(
393 \TYPO3\CMS\Install\FolderStructure\FileNode::class,
394 array(
'exists',
'createFile',
'setContent',
'getAbsolutePath',
'isFile',
'isPermissionCorrect'),
399 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
false));
400 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
true));
401 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
402 $uniqueReturn = $this->getUniqueId();
403 $node->expects($this->once())->method(
'createFile')->will($this->returnValue($uniqueReturn));
404 $actualReturn = $node->_call(
'fixSelf');
405 $actualReturn = $actualReturn[0];
406 $this->assertSame($uniqueReturn, $actualReturn);
412 public function fixSelfCallsSetsContentIfFileCreationWasSuccessfulAndTargetContentIsNotNullAndReturnsResult()
415 $node = $this->getAccessibleMock(
416 \TYPO3\CMS\Install\FolderStructure\FileNode::class,
417 array(
'exists',
'createFile',
'setContent',
'getAbsolutePath',
'isFile',
'isPermissionCorrect'),
422 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
false));
423 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
true));
424 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
425 $uniqueReturn = $this->getUniqueId();
426 $createFileStatus = $this->getMock(\TYPO3\CMS\Install\Status\OkStatus::class, array(), array(),
'',
false);
427 $node->expects($this->any())->method(
'createFile')->will($this->returnValue($createFileStatus));
428 $node->_set(
'targetContent',
'foo');
429 $node->expects($this->once())->method(
'setContent')->will($this->returnValue($uniqueReturn));
430 $actualReturn = $node->_call(
'fixSelf');
431 $actualReturn = $actualReturn[1];
432 $this->assertSame($uniqueReturn, $actualReturn);
438 public function fixSelfDoesNotCallSetContentIfFileCreationFailed()
441 $node = $this->getAccessibleMock(
442 \TYPO3\CMS\Install\FolderStructure\FileNode::class,
443 array(
'exists',
'createFile',
'setContent',
'getAbsolutePath',
'isFile',
'isPermissionCorrect'),
448 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
false));
449 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
true));
450 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
451 $createFileStatus = $this->getMock(\TYPO3\CMS\Install\Status\ErrorStatus::class, array(), array(),
'',
false);
452 $node->expects($this->any())->method(
'createFile')->will($this->returnValue($createFileStatus));
453 $node->_set(
'targetContent',
'foo');
454 $node->expects($this->never())->method(
'setContent');
455 $node->_call(
'fixSelf');
461 public function fixSelfDoesNotCallSetContentIfFileTargetContentIsNull()
464 $node = $this->getAccessibleMock(
465 \TYPO3\CMS\Install\FolderStructure\FileNode::class,
466 array(
'exists',
'createFile',
'setContent',
'getAbsolutePath',
'isFile',
'isPermissionCorrect'),
471 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
false));
472 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
true));
473 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
474 $createFileStatus = $this->getMock(\TYPO3\CMS\Install\Status\OkStatus::class, array(), array(),
'',
false);
475 $node->expects($this->any())->method(
'createFile')->will($this->returnValue($createFileStatus));
476 $node->_set(
'targetContent', null);
477 $node->expects($this->never())->method(
'setContent');
478 $node->_call(
'fixSelf');
484 public function fixSelfReturnsErrorStatusIfNodeExistsButIsNotAFileAndReturnsResult()
487 $node = $this->getAccessibleMock(
488 \TYPO3\CMS\Install\FolderStructure\FileNode::class,
489 array(
'exists',
'createFile',
'getAbsolutePath',
'isFile',
'isPermissionCorrect',
'fixPermission'),
494 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
495 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
true));
496 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
false));
497 $uniqueReturn = $this->getUniqueId();
498 $node->expects($this->once())->method(
'fixPermission')->will($this->returnValue($uniqueReturn));
499 $this->assertSame(array($uniqueReturn), $node->_call(
'fixSelf'));
505 public function fixSelfCallsFixPermissionIfFileExistsButPermissionAreWrong()
508 $node = $this->getAccessibleMock(
509 \TYPO3\CMS\Install\FolderStructure\FileNode::class,
510 array(
'exists',
'createFile',
'getAbsolutePath',
'isFile',
'isPermissionCorrect',
'getRelativePathBelowSiteRoot'),
515 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
516 $node->expects($this->once())->method(
'isFile')->will($this->returnValue(
false));
517 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
518 $resultArray = $node->_call(
'fixSelf');
519 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\StatusInterface::class, $resultArray[0]);
527 $node = $this->getAccessibleMock(
528 \TYPO3\CMS\Install\FolderStructure\FileNode::class,
529 array(
'exists',
'isFile',
'isPermissionCorrect'),
534 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
535 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
true));
536 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
537 $this->assertInternalType(
'array', $node->_call(
'fixSelf'));
544 public function createFileThrowsExceptionIfNodeExists()
547 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'exists',
'getAbsolutePath'), array(),
'',
false);
548 $node->expects($this->once())->method(
'getAbsolutePath')->will($this->returnValue(
''));
549 $node->expects($this->once())->method(
'exists')->will($this->returnValue(
true));
550 $node->_call(
'createFile');
556 public function createFileReturnsOkStatusIfFileWasCreated()
559 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'exists',
'getAbsolutePath',
'getRelativePathBelowSiteRoot'), array(),
'',
false);
561 $node->expects($this->once())->method(
'exists')->will($this->returnValue(
false));
562 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
563 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
564 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\StatusInterface::class, $node->_call(
'createFile'));
570 public function createFileCreatesFile()
573 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'exists',
'getAbsolutePath',
'getRelativePathBelowSiteRoot'), array(),
'',
false);
575 $node->expects($this->once())->method(
'exists')->will($this->returnValue(
false));
576 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
577 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
578 $node->_call(
'createFile');
579 $this->assertTrue(is_file($path));
585 public function createFileReturnsErrorStatusIfFileWasNotCreated()
587 if (TYPO3_OS ===
'WIN') {
588 $this->markTestSkipped(
'Test not available on Windows OS.');
591 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'exists',
'getAbsolutePath',
'getRelativePathBelowSiteRoot'), array(),
'',
false);
594 $subPath = $path .
'/' . $this->getUniqueId(
'file_');
595 $node->expects($this->once())->method(
'exists')->will($this->returnValue(
false));
596 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($subPath));
597 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($subPath));
598 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\StatusInterface::class, $node->_call(
'createFile'));
605 public function isContentCorrectThrowsExceptionIfTargetIsNotAFile()
608 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'getAbsolutePath'), array(),
'',
false);
610 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
611 $node->_call(
'isContentCorrect');
617 public function isContentCorrectReturnsTrueIfTargetContentPropertyIsNull()
620 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'getAbsolutePath'), array(),
'',
false);
623 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
624 $node->_set(
'targetContent', null);
625 $this->assertTrue($node->_call(
'isContentCorrect'));
631 public function isContentCorrectReturnsTrueIfTargetContentEqualsCurrentContent()
634 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'getAbsolutePath'), array(),
'',
false);
636 $content = $this->getUniqueId(
'content_');
637 file_put_contents($path, $content);
638 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
639 $node->_set(
'targetContent', $content);
640 $this->assertTrue($node->_call(
'isContentCorrect'));
646 public function isContentCorrectReturnsFalseIfTargetContentNotEqualsCurrentContent()
649 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'getAbsolutePath'), array(),
'',
false);
651 $content = $this->getUniqueId(
'content1_');
652 $targetContent = $this->getUniqueId(
'content2_');
653 file_put_contents($path, $content);
654 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
655 $node->_set(
'targetContent', $targetContent);
656 $this->assertFalse($node->_call(
'isContentCorrect'));
662 public function isPermissionCorrectReturnsTrueIfTargetPermissionAndCurrentPermissionAreIdentical()
664 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(),
'',
false);
666 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'getCurrentPermission',
'isWindowsOs'), array(),
'',
false);
667 $node->expects($this->any())->method(
'isWindowsOs')->will($this->returnValue(
false));
668 $node->expects($this->any())->method(
'getCurrentPermission')->will($this->returnValue(
'0664'));
669 $targetPermission =
'0664';
672 'targetPermission' => $targetPermission,
674 $node->__construct($structure, $parent);
675 $this->assertTrue($node->_call(
'isPermissionCorrect'));
682 public function setContentThrowsExceptionIfTargetIsNotAFile()
685 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'getAbsolutePath'), array(),
'',
false);
687 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
688 $node->_set(
'targetContent',
'foo');
689 $node->_call(
'setContent');
696 public function setContentThrowsExceptionIfTargetContentIsNull()
699 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'getAbsolutePath'), array(),
'',
false);
702 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
703 $node->_set(
'targetContent', null);
704 $node->_call(
'setContent');
710 public function setContentSetsContentToFile()
713 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'getAbsolutePath',
'getRelativePathBelowSiteRoot'), array(),
'',
false);
716 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
717 $targetContent = $this->getUniqueId(
'content_');
718 $node->_set(
'targetContent', $targetContent);
719 $node->_call(
'setContent');
720 $resultContent = file_get_contents($path);
721 $this->assertSame($targetContent, $resultContent);
727 public function setContentReturnsOkStatusIfContentWasSuccessfullySet()
730 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'getAbsolutePath',
'getRelativePathBelowSiteRoot'), array(),
'',
false);
733 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
734 $targetContent = $this->getUniqueId(
'content_');
735 $node->_set(
'targetContent', $targetContent);
736 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\OkStatus::class, $node->_call(
'setContent'));
742 public function setContentReturnsErrorStatusIfContentCanNotBeSetSet()
744 if (TYPO3_OS ===
'WIN') {
745 $this->markTestSkipped(
'Test not available on Windows OS.');
747 if (function_exists(
'posix_getegid') && posix_getegid() === 0) {
748 $this->markTestSkipped(
'Test skipped if run on linux as root');
751 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'getAbsolutePath',
'getRelativePathBelowSiteRoot'), array(),
'',
false);
753 $file = $dir .
'/' . $this->getUniqueId(
'file_');
756 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($file));
757 $targetContent = $this->getUniqueId(
'content_');
758 $node->_set(
'targetContent', $targetContent);
759 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus::class, $node->_call(
'setContent'));
765 public function isFileReturnsTrueIfNameIsFile()
768 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'getAbsolutePath',
'getRelativePathBelowSiteRoot'), array(),
'',
false);
771 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
772 $this->assertTrue($node->_call(
'isFile'));
779 public function isFileReturnsFalseIfNameIsALinkFile()
781 if (TYPO3_OS ===
'WIN') {
782 $this->markTestSkipped(
'Test not available on Windows OS.');
785 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, array(
'getAbsolutePath'), array(),
'',
false);
786 $path = PATH_site .
'typo3temp/' . $this->getUniqueId(
'root_');
787 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
788 $this->testFilesToDelete[] = $path;
789 $link = $this->getUniqueId(
'link_');
790 $file = $this->getUniqueId(
'file_');
791 touch($path .
'/' . $file);
792 symlink($path .
'/' . $file, $path .
'/' . $link);
793 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path .
'/' . $link));
794 $this->assertFalse($node->_call(
'isFile'));