25 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
37 $this->expectException(InvalidArgumentException::class);
38 $this->expectExceptionCode(1366222203);
40 $node = $this->getAccessibleMock(DirectoryNode::class, [
'dummy'], [],
'',
false);
41 $node->__construct([],
null);
49 $this->expectException(InvalidArgumentException::class);
50 $this->expectExceptionCode(1366226639);
51 $parent = $this->createMock(NodeInterface::class);
53 $node = $this->getAccessibleMock(DirectoryNode::class, [
'dummy'], [],
'',
false);
57 $node->__construct($structure, $parent);
65 $parent = $this->createMock(NodeInterface::class);
67 $node = $this->getAccessibleMock(
79 'children' => $childArray,
81 $node->expects($this->once())->method(
'createChildren')->with($childArray);
82 $node->__construct($structure, $parent);
90 $parent = $this->createMock(NodeInterface::class);
92 $node = $this->getAccessibleMock(DirectoryNode::class, [
'dummy'], [],
'',
false);
96 $node->__construct($structure, $parent);
97 $this->assertSame($parent, $node->_call(
'getParent'));
105 $parent = $this->createMock(NodeInterface::class);
107 $node = $this->getAccessibleMock(DirectoryNode::class, [
'dummy'], [],
'',
false);
108 $targetPermission =
'2550';
111 'targetPermission' => $targetPermission,
113 $node->__construct($structure, $parent);
114 $this->assertSame($targetPermission, $node->_call(
'getTargetPermission'));
123 $node = $this->getAccessibleMock(DirectoryNode::class, [
'dummy'], [],
'',
false);
124 $parent = $this->createMock(RootNodeInterface::class);
125 $name = $this->getUniqueId(
'test_');
126 $node->__construct([
'name' => $name], $parent);
127 $this->assertSame($name, $node->getName());
136 $node = $this->getAccessibleMock(
137 DirectoryNode::class,
138 [
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isDirectory',
'isWritable',
'isPermissionCorrect'],
144 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
145 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
146 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
147 $node->expects($this->any())->method(
'isDirectory')->will($this->returnValue(
true));
148 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
149 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
150 $this->assertInternalType(
'array', $node->getStatus());
159 $node = $this->getAccessibleMock(
160 DirectoryNode::class,
161 [
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isDirectory',
'isWritable',
'isPermissionCorrect'],
167 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
168 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
169 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
false));
170 $node->expects($this->any())->method(
'isDirectory')->will($this->returnValue(
false));
171 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
false));
172 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
false));
173 $statusArray = $node->getStatus();
183 $node = $this->getAccessibleMock(
184 DirectoryNode::class,
185 [
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isDirectory',
'isWritable',
'isPermissionCorrect'],
192 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
193 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
194 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
195 $node->expects($this->any())->method(
'isDirectory')->will($this->returnValue(
false));
196 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
197 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
198 $statusArray = $node->getStatus();
208 $node = $this->getAccessibleMock(
209 DirectoryNode::class,
210 [
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isDirectory',
'isWritable',
'isPermissionCorrect'],
217 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
218 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
219 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
220 $node->expects($this->any())->method(
'isDirectory')->will($this->returnValue(
true));
221 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
222 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
false));
223 $statusArray = $node->getStatus();
233 $node = $this->getAccessibleMock(
234 DirectoryNode::class,
235 [
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isDirectory',
'isWritable',
'isPermissionCorrect'],
242 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
243 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
244 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
245 $node->expects($this->any())->method(
'isDirectory')->will($this->returnValue(
true));
246 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
false));
247 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
248 $statusArray = $node->getStatus();
258 $node = $this->getAccessibleMock(
259 DirectoryNode::class,
260 [
'getAbsolutePath',
'getRelativePathBelowSiteRoot',
'exists',
'isDirectory',
'isWritable',
'isPermissionCorrect'],
267 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
268 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
269 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
270 $node->expects($this->any())->method(
'isDirectory')->will($this->returnValue(
true));
271 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
272 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
273 $statusArray = $node->getStatus();
283 $node = $this->getAccessibleMock(
284 DirectoryNode::class,
285 [
'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->createMock(NodeInterface::class);
295 $childMock1->expects($this->once())->method(
'getStatus')->will($this->returnValue([]));
296 $childMock2 = $this->createMock(NodeInterface::class);
297 $childMock2->expects($this->once())->method(
'getStatus')->will($this->returnValue([]));
298 $node->_set(
'children', [$childMock1, $childMock2]);
308 $node = $this->getAccessibleMock(
309 DirectoryNode::class,
310 [
'exists',
'isDirectory',
'isPermissionCorrect',
'getRelativePathBelowSiteRoot',
'isWritable'],
315 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
316 $node->expects($this->any())->method(
'isDirectory')->will($this->returnValue(
true));
317 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
318 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
319 $childMock = $this->createMock(NodeInterface::class);
321 $childMock->expects($this->once())->method(
'getStatus')->will($this->returnValue([$childMessage]));
322 $node->_set(
'children', [$childMock]);
323 $status = $node->getStatus();
324 $statusOfDirectory = $status[0];
325 $statusOfChild = $status[1];
327 $this->assertSame($childMessage, $statusOfChild);
336 $node = $this->getAccessibleMock(
337 DirectoryNode::class,
343 $uniqueReturn = [$this->getUniqueId(
'foo_')];
344 $node->expects($this->once())->method(
'fixSelf')->will($this->returnValue($uniqueReturn));
345 $this->assertSame($uniqueReturn, $node->fix());
354 $node = $this->getAccessibleMock(DirectoryNode::class, [
'fixSelf'], [],
'',
false);
355 $uniqueReturnSelf = $this->getUniqueId(
'foo_');
356 $node->expects($this->once())->method(
'fixSelf')->will($this->returnValue([$uniqueReturnSelf]));
358 $childMock1 = $this->createMock(NodeInterface::class);
359 $uniqueReturnChild1 = $this->getUniqueId(
'foo_');
360 $childMock1->expects($this->once())->method(
'fix')->will($this->returnValue([$uniqueReturnChild1]));
362 $childMock2 = $this->createMock(NodeInterface::class);
363 $uniqueReturnChild2 = $this->getUniqueId(
'foo_');
364 $childMock2->expects($this->once())->method(
'fix')->will($this->returnValue([$uniqueReturnChild2]));
366 $node->_set(
'children', [$childMock1, $childMock2]);
368 $this->assertSame([$uniqueReturnSelf, $uniqueReturnChild1, $uniqueReturnChild2], $node->fix());
377 $node = $this->getAccessibleMock(
378 DirectoryNode::class,
379 [
'exists',
'createDirectory',
'isPermissionCorrect'],
384 $node->expects($this->once())->method(
'exists')->will($this->returnValue(
false));
385 $node->expects($this->any())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
387 $node->expects($this->once())->method(
'createDirectory')->will($this->returnValue($uniqueReturn));
388 $this->assertSame([$uniqueReturn], $node->_call(
'fixSelf'));
397 $node = $this->getAccessibleMock(
398 DirectoryNode::class,
399 [
'exists',
'isWritable',
'getRelativePathBelowSiteRoot',
'isDirectory',
'getAbsolutePath'],
404 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
405 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
406 $node->expects($this->any())->method(
'isDirectory')->will($this->returnValue(
false));
407 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue(
''));
408 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue(
''));
409 $result = $node->_call(
'fixSelf');
419 $node = $this->getAccessibleMock(
420 DirectoryNode::class,
421 [
'exists',
'isWritable',
'fixPermission'],
426 $node->expects($this->any())->method(
'exists')->will($this->returnValue(
true));
427 $node->expects($this->any())->method(
'isWritable')->will($this->returnValue(
false));
429 $node->expects($this->once())->method(
'fixPermission')->will($this->returnValue($message));
430 $this->assertSame([$message], $node->_call(
'fixSelf'));
438 $this->expectException(Exception::class);
439 $this->expectExceptionCode(1366740091);
441 $node = $this->getAccessibleMock(DirectoryNode::class, [
'exists',
'getAbsolutePath'], [],
'',
false);
442 $node->expects($this->once())->method(
'getAbsolutePath')->will($this->returnValue(
''));
443 $node->expects($this->once())->method(
'exists')->will($this->returnValue(
true));
444 $node->_call(
'createDirectory');
453 $node = $this->getAccessibleMock(DirectoryNode::class, [
'exists',
'getAbsolutePath',
'getRelativePathBelowSiteRoot'], [],
'',
false);
455 $node->expects($this->once())->method(
'exists')->will($this->returnValue(
false));
456 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
457 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
458 $node->_call(
'createDirectory');
459 $this->assertTrue(is_dir($path));
468 $node = $this->getAccessibleMock(DirectoryNode::class, [
'exists',
'getAbsolutePath',
'getRelativePathBelowSiteRoot'], [],
'',
false);
470 $node->expects($this->once())->method(
'exists')->will($this->returnValue(
false));
471 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
472 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($path));
473 $this->assertSame(
FlashMessage::OK, $node->_call(
'createDirectory')->getSeverity());
482 $node = $this->getAccessibleMock(DirectoryNode::class, [
'exists',
'getAbsolutePath',
'getRelativePathBelowSiteRoot'], [],
'',
false);
485 $subPath = $path .
'/' . $this->getUniqueId(
'dir_');
486 $node->expects($this->once())->method(
'exists')->will($this->returnValue(
false));
487 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($subPath));
488 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue($subPath));
497 $this->expectException(InvalidArgumentException::class);
498 $this->expectExceptionCode(1366222204);
500 $node = $this->getAccessibleMock(DirectoryNode::class, [
'dummy'], [],
'',
false);
506 $node->_call(
'createChildren', $brokenStructure);
514 $this->expectException(InvalidArgumentException::class);
515 $this->expectExceptionCode(1366222205);
517 $node = $this->getAccessibleMock(DirectoryNode::class, [
'dummy'], [],
'',
false);
523 $node->_call(
'createChildren', $brokenStructure);
531 $this->expectException(InvalidArgumentException::class);
532 $this->expectExceptionCode(1366222206);
534 $node = $this->getAccessibleMock(DirectoryNode::class, [
'dummy'], [],
'',
false);
537 'type' => DirectoryNode::class,
541 'type' => DirectoryNode::class,
545 $node->_call(
'createChildren', $brokenStructure);
554 $node = $this->getAccessibleMock(DirectoryNode::class, [
'dummy'], [],
'',
false);
555 $parent = $this->createMock(NodeInterface::class);
556 $childName = $this->getUniqueId(
'test_');
559 'type' => DirectoryNode::class,
562 'type' => DirectoryNode::class,
563 'name' => $childName,
567 $node->__construct($structure, $parent);
568 $children = $node->_call(
'getChildren');
570 $child = $children[0];
571 $this->assertInstanceOf(DirectoryNode::class, $children[0]);
572 $this->assertSame($childName, $child->getName());
581 $node = $this->getAccessibleMock(DirectoryNode::class, [
'getAbsolutePath'], [],
'',
false);
583 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
584 $this->assertFalse($node->isWritable());
593 $node = $this->getAccessibleMock(DirectoryNode::class, [
'getAbsolutePath'], [],
'',
false);
595 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
596 $this->assertTrue($node->isWritable());
604 if (function_exists(
'posix_getegid') && posix_getegid() === 0) {
605 $this->markTestSkipped(
'Test skipped if run on linux as root');
608 $node = $this->getAccessibleMock(DirectoryNode::class, [
'getAbsolutePath'], [],
'',
false);
611 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
612 $this->assertFalse($node->isWritable());
621 $node = $this->getAccessibleMock(DirectoryNode::class, [
'getAbsolutePath'], [],
'',
false);
623 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
624 $this->assertTrue($node->_call(
'isDirectory'));
634 $node = $this->getAccessibleMock(DirectoryNode::class, [
'getAbsolutePath'], [],
'',
false);
636 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
637 $this->testFilesToDelete[] = $path;
638 $link = $this->getUniqueId(
'link_');
639 $dir = $this->getUniqueId(
'dir_');
640 mkdir($path .
'/' .
$dir);
641 symlink($path .
'/' .
$dir, $path .
'/' . $link);
642 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path .
'/' . $link));
643 $this->assertFalse($node->_call(
'isDirectory'));