23 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
35 $this->expectException(InvalidArgumentException::class);
36 $this->expectExceptionCode(1366927513);
38 $node = $this->getAccessibleMock(FileNode::class, [
'dummy'], [],
'',
false);
39 $node->__construct([],
null);
47 $this->expectException(InvalidArgumentException::class);
48 $this->expectExceptionCode(1366222207);
49 $parent = $this->createMock(\
TYPO3\CMS\Install\FolderStructure\NodeInterface::class);
51 $node = $this->getAccessibleMock(FileNode::class, [
'dummy'], [],
'',
false);
55 $node->__construct($structure, $parent);
63 $parent = $this->createMock(\
TYPO3\CMS\Install\FolderStructure\NodeInterface::class);
65 $node = $this->getAccessibleMock(FileNode::class, [
'dummy'], [],
'',
false);
69 $node->__construct($structure, $parent);
70 $this->assertSame($parent, $node->_call(
'getParent'));
78 $parent = $this->createMock(\
TYPO3\CMS\Install\FolderStructure\NodeInterface::class);
80 $node = $this->getAccessibleMock(FileNode::class, [
'dummy'], [],
'',
false);
81 $targetPermission =
'0660';
84 'targetPermission' => $targetPermission,
86 $node->__construct($structure, $parent);
87 $this->assertSame($targetPermission, $node->_call(
'getTargetPermission'));
96 $node = $this->getAccessibleMock(FileNode::class, [
'dummy'], [],
'',
false);
97 $parent = $this->createMock(\
TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
98 $name = $this->getUniqueId(
'test_');
99 $node->__construct([
'name' => $name], $parent);
100 $this->assertSame($name, $node->getName());
108 $this->expectException(InvalidArgumentException::class);
109 $this->expectExceptionCode(1380364361);
111 $node = $this->getAccessibleMock(FileNode::class, [
'dummy'], [],
'',
false);
112 $parent = $this->createMock(\
TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
115 'targetContent' =>
'foo',
116 'targetContentFile' =>
'aPath',
118 $node->__construct($structure, $parent);
127 $node = $this->getAccessibleMock(FileNode::class, [
'dummy'], [],
'',
false);
128 $parent = $this->createMock(\
TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
129 $targetContent = $this->getUniqueId(
'content_');
132 'targetContent' => $targetContent,
134 $node->__construct($structure, $parent);
135 $this->assertSame($targetContent, $node->_get(
'targetContent'));
144 $node = $this->getAccessibleMock(FileNode::class, [
'dummy'], [],
'',
false);
145 $parent = $this->createMock(\
TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
147 $targetContent = $this->getUniqueId(
'content_');
148 file_put_contents($targetFile, $targetContent);
151 'targetContentFile' => $targetFile,
153 $node->__construct($structure, $parent);
154 $this->assertSame($targetContent, $node->_get(
'targetContent'));
162 $this->expectException(InvalidArgumentException::class);
163 $this->expectExceptionCode(1380364362);
165 $node = $this->getAccessibleMock(FileNode::class, [
'dummy'], [],
'',
false);
166 $parent = $this->createMock(\
TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
170 'targetContentFile' => $targetFile,
172 $node->__construct($structure, $parent);
181 $node = $this->getAccessibleMock(FileNode::class, [
'dummy'], [],
'',
false);
182 $parent = $this->createMock(\
TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
186 $node->__construct($structure, $parent);
187 $this->assertNull($node->_get(
'targetContent'));
196 $node = $this->getAccessibleMock(
198 [
'getAbsolutePath',
'exists',
'isFile',
'isWritable',
'isPermissionCorrect',
'isContentCorrect'],
204 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
205 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
206 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
true));
207 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
208 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
209 $node->expects($this->any())->method(
'isContentCorrect')->will($this->returnValue(
true));
210 $this->assertInternalType(
'array', $node->getStatus());
219 $node = $this->getAccessibleMock(
221 [
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isFile',
'isWritable',
'isPermissionCorrect',
'isContentCorrect'],
227 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
228 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
229 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
false));
230 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
true));
231 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
232 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
233 $node->expects($this->any())->method(
'isContentCorrect')->will($this->returnValue(
true));
234 $statusArray = $node->getStatus();
244 $node = $this->getAccessibleMock(
246 [
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isFile',
'isWritable',
'isPermissionCorrect',
'isContentCorrect'],
253 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
254 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
255 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
256 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
false));
257 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
258 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
259 $node->expects($this->any())->method(
'isContentCorrect')->will($this->returnValue(
true));
260 $statusArray = $node->getStatus();
270 $node = $this->getAccessibleMock(
272 [
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isFile',
'isWritable',
'isPermissionCorrect',
'isContentCorrect'],
279 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
280 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
281 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
282 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
true));
283 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
284 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
false));
285 $node->expects($this->any())->method(
'isContentCorrect')->will($this->returnValue(
true));
286 $statusArray = $node->getStatus();
296 $node = $this->getAccessibleMock(
298 [
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isFile',
'isWritable',
'isPermissionCorrect',
'isContentCorrect'],
305 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
306 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
307 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
308 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
true));
309 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
false));
310 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
311 $node->expects($this->any())->method(
'isContentCorrect')->will($this->returnValue(
true));
312 $statusArray = $node->getStatus();
322 $node = $this->getAccessibleMock(
324 [
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isFile',
'isWritable',
'isPermissionCorrect',
'isContentCorrect'],
331 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
332 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
333 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
334 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
true));
335 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
336 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
337 $node->expects($this->any())->method(
'isContentCorrect')->will($this->returnValue(
false));
338 $statusArray = $node->getStatus();
348 $node = $this->getAccessibleMock(
350 [
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isFile',
'isWritable',
'isPermissionCorrect',
'isContentCorrect'],
357 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
358 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
359 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
360 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
true));
361 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
362 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
363 $node->expects($this->any())->method(
'isContentCorrect')->will($this->returnValue(
true));
364 $statusArray = $node->getStatus();
374 $node = $this->getAccessibleMock(
381 $uniqueReturn = [$this->getUniqueId(
'foo_')];
382 $node->expects($this->once())->method(
'fixSelf')->will($this->returnValue($uniqueReturn));
383 $this->assertSame($uniqueReturn, $node->fix());
392 $node = $this->getAccessibleMock(
394 [
'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));
403 $node->expects($this->once())->method(
'createFile')->will($this->returnValue($message));
404 $actualReturn = $node->_call(
'fixSelf');
405 $actualReturn = $actualReturn[0];
406 $this->assertSame($message, $actualReturn);
415 $node = $this->getAccessibleMock(
417 [
'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));
426 $node->expects($this->any())->method(
'createFile')->will($this->returnValue($message1));
427 $node->_set(
'targetContent',
'foo');
429 $node->expects($this->once())->method(
'setContent')->will($this->returnValue($message2));
430 $actualReturn = $node->_call(
'fixSelf');
431 $actualReturn = $actualReturn[1];
432 $this->assertSame($message2, $actualReturn);
441 $node = $this->getAccessibleMock(
443 [
'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));
452 $node->expects($this->any())->method(
'createFile')->will($this->returnValue($message));
453 $node->_set(
'targetContent',
'foo');
454 $node->expects($this->never())->method(
'setContent');
455 $node->_call(
'fixSelf');
464 $node = $this->getAccessibleMock(
466 [
'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));
475 $node->expects($this->any())->method(
'createFile')->will($this->returnValue($message));
476 $node->_set(
'targetContent',
null);
477 $node->expects($this->never())->method(
'setContent');
478 $node->_call(
'fixSelf');
487 $node = $this->getAccessibleMock(
489 [
'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));
498 $node->expects($this->once())->method(
'fixPermission')->will($this->returnValue($message));
499 $this->assertSame([$message], $node->_call(
'fixSelf'));
508 $node = $this->getAccessibleMock(
510 [
'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');
526 $node = $this->getAccessibleMock(
528 [
'exists',
'isFile',
'isPermissionCorrect'],
533 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
534 $node->expects($this->any())->method(
'isFile')->will($this->returnValue(
true));
535 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
536 $this->assertInternalType(
'array', $node->_call(
'fixSelf'));
544 $this->expectException(Exception::class);
545 $this->expectExceptionCode(1366398198);
547 $node = $this->getAccessibleMock(FileNode::class, [
'exists',
'getAbsolutePath'], [],
'',
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');
559 $node = $this->getAccessibleMock(FileNode::class, [
'exists',
'getAbsolutePath',
'getRelativePathBelowSiteRoot'], [],
'',
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));
573 $node = $this->getAccessibleMock(FileNode::class, [
'exists',
'getAbsolutePath',
'getRelativePathBelowSiteRoot'], [],
'',
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));
588 $node = $this->getAccessibleMock(FileNode::class, [
'exists',
'getAbsolutePath',
'getRelativePathBelowSiteRoot'], [],
'',
false);
591 $subPath = $path .
'/' . $this->getUniqueId(
'file_');
592 $node->expects($this->once())->method(
'exists')->will($this->returnValue(
false));
593 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($subPath));
594 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($subPath));
603 $this->expectException(Exception::class);
604 $this->expectExceptionCode(1367056363);
606 $node = $this->getAccessibleMock(FileNode::class, [
'getAbsolutePath'], [],
'',
false);
608 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
609 $node->_call(
'isContentCorrect');
618 $node = $this->getAccessibleMock(FileNode::class, [
'getAbsolutePath'], [],
'',
false);
621 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
622 $node->_set(
'targetContent',
null);
623 $this->assertTrue($node->_call(
'isContentCorrect'));
632 $node = $this->getAccessibleMock(FileNode::class, [
'getAbsolutePath'], [],
'',
false);
634 $content = $this->getUniqueId(
'content_');
635 file_put_contents($path, $content);
636 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
637 $node->_set(
'targetContent', $content);
638 $this->assertTrue($node->_call(
'isContentCorrect'));
647 $node = $this->getAccessibleMock(FileNode::class, [
'getAbsolutePath'], [],
'',
false);
649 $content = $this->getUniqueId(
'content1_');
650 $targetContent = $this->getUniqueId(
'content2_');
651 file_put_contents($path, $content);
652 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
653 $node->_set(
'targetContent', $targetContent);
654 $this->assertFalse($node->_call(
'isContentCorrect'));
662 $parent = $this->createMock(\
TYPO3\CMS\Install\FolderStructure\NodeInterface::class);
664 $node = $this->getAccessibleMock(FileNode::class, [
'getCurrentPermission',
'isWindowsOs'], [],
'',
false);
665 $node->expects($this->any())->method(
'isWindowsOs')->will($this->returnValue(
false));
666 $node->expects($this->any())->method(
'getCurrentPermission')->will($this->returnValue(
'0664'));
667 $targetPermission =
'0664';
670 'targetPermission' => $targetPermission,
672 $node->__construct($structure, $parent);
673 $this->assertTrue($node->_call(
'isPermissionCorrect'));
681 $this->expectException(Exception::class);
682 $this->expectExceptionCode(1367060201);
684 $node = $this->getAccessibleMock(FileNode::class, [
'getAbsolutePath'], [],
'',
false);
686 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
687 $node->_set(
'targetContent',
'foo');
688 $node->_call(
'setContent');
696 $this->expectException(Exception::class);
697 $this->expectExceptionCode(1367060202);
699 $node = $this->getAccessibleMock(FileNode::class, [
'getAbsolutePath'], [],
'',
false);
702 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
703 $node->_set(
'targetContent',
null);
704 $node->_call(
'setContent');
713 $node = $this->getAccessibleMock(FileNode::class, [
'getAbsolutePath',
'getRelativePathBelowSiteRoot'], [],
'',
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);
730 $node = $this->getAccessibleMock(FileNode::class, [
'getAbsolutePath',
'getRelativePathBelowSiteRoot'], [],
'',
false);
733 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
734 $targetContent = $this->getUniqueId(
'content_');
735 $node->_set(
'targetContent', $targetContent);
744 if (function_exists(
'posix_getegid') && posix_getegid() === 0) {
745 $this->markTestSkipped(
'Test skipped if run on linux as root');
748 $node = $this->getAccessibleMock(FileNode::class, [
'getAbsolutePath',
'getRelativePathBelowSiteRoot'], [],
'',
false);
750 $file =
$dir .
'/' . $this->getUniqueId(
'file_');
753 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($file));
754 $targetContent = $this->getUniqueId(
'content_');
755 $node->_set(
'targetContent', $targetContent);
765 $node = $this->getAccessibleMock(FileNode::class, [
'getAbsolutePath',
'getRelativePathBelowSiteRoot'], [],
'',
false);
768 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
769 $this->assertTrue($node->_call(
'isFile'));
779 $node = $this->getAccessibleMock(FileNode::class, [
'getAbsolutePath'], [],
'',
false);
781 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
782 $this->testFilesToDelete[] = $path;
783 $link = $this->getUniqueId(
'link_');
784 $file = $this->getUniqueId(
'file_');
785 touch($path .
'/' . $file);
786 symlink($path .
'/' . $file, $path .
'/' . $link);
787 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path .
'/' . $link));
788 $this->assertFalse($node->_call(
'isFile'));