‪TYPO3CMS  ‪main
RootNodeTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
32 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
33 
34 final class ‪RootNodeTest extends UnitTestCase
35 {
36  #[Test]
38  {
39  $this->expectException(RootNodeException::class);
40  $this->expectExceptionCode(1366140117);
41  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
42  $falseParent = $this->createMock(RootNodeInterface::class);
43  $node->__construct([], $falseParent);
44  }
45 
46  #[Test]
48  {
49  $this->expectException(InvalidArgumentException::class);
50  $this->expectExceptionCode(1366141329);
51  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
52  $structure = [
53  'type' => 'root',
54  ];
55  $node->__construct($structure, null);
56  }
57 
58  #[Test]
60  {
61  $this->expectException(InvalidArgumentException::class);
62  $this->expectExceptionCode(1366141329);
63  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
64  $node
65  ->method('isWindowsOs')
66  ->willReturn(true);
67  $structure = [
68  'name' => '/bar',
69  ];
70  $node->__construct($structure, null);
71  }
72 
73  #[Test]
75  {
76  $this->expectException(InvalidArgumentException::class);
77  $this->expectExceptionCode(1366141329);
78  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
79  $node
80  ->method('isWindowsOs')
81  ->willReturn(false);
82  $structure = [
83  'name' => 'C:/bar',
84  ];
85  $node->__construct($structure, null);
86  }
87 
88  #[Test]
89  public function ‪constructorSetsParentToNull(): void
90  {
91  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
92  $node
93  ->method('isWindowsOs')
94  ->willReturn(false);
95  $structure = [
96  'name' => '/bar',
97  ];
98  $node->__construct($structure, null);
99  self::assertNull($node->_call('getParent'));
100  }
101 
102  #[Test]
104  {
105  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
106  $node
107  ->method('isWindowsOs')
108  ->willReturn(false);
109  $childName = ‪StringUtility::getUniqueId('test_');
110  $structure = [
111  'name' => '/foo',
112  'children' => [
113  [
114  'type' => DirectoryNode::class,
115  'name' => $childName,
116  ],
117  ],
118  ];
119  $node->__construct($structure, null);
120  $children = $node->_call('getChildren');
122  $child = $children[0];
123  self::assertInstanceOf(DirectoryNode::class, $child);
124  self::assertSame($childName, $child->getName());
125  }
126 
127  #[Test]
128  public function ‪constructorSetsTargetPermission(): void
129  {
130  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
131  $node
132  ->method('isWindowsOs')
133  ->willReturn(false);
134  $targetPermission = '2550';
135  $structure = [
136  'name' => '/foo',
137  'targetPermission' => $targetPermission,
138  ];
139  $node->__construct($structure, null);
140  self::assertSame($targetPermission, $node->_call('getTargetPermission'));
141  }
142 
143  #[Test]
144  public function ‪constructorSetsName(): void
145  {
146  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
147  $node
148  ->method('isWindowsOs')
149  ->willReturn(false);
150  $name = '/' . ‪StringUtility::getUniqueId('test_');
151  $node->__construct(['name' => $name], null);
152  self::assertSame($name, $node->getName());
153  }
154 
155  #[Test]
157  {
158  $node = $this->getAccessibleMock(
159  RootNode::class,
160  ['getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'],
161  [],
162  '',
163  false
164  );
165  // do not use var path here, as root nodes get checked for public path as first part
166  $testRoot = ‪Environment::getPublicPath() . '/typo3temp/tests/';
167  $this->testFilesToDelete[] = $testRoot;
168  $path = $testRoot . ‪StringUtility::getUniqueId('dir_');
170  $node->method('getAbsolutePath')->willReturn($path);
171  $node->expects(self::once())->method('exists')->willReturn(true);
172  $node->expects(self::once())->method('isDirectory')->willReturn(true);
173  $node->expects(self::once())->method('isPermissionCorrect')->willReturn(true);
174  $node->expects(self::once())->method('isWritable')->willReturn(true);
175  $statusArray = $node->getStatus();
176  self::assertSame(ContextualFeedbackSeverity::OK, $statusArray[0]->getSeverity());
177  }
178 
179  #[Test]
181  {
182  $node = $this->getAccessibleMock(
183  RootNode::class,
184  ['getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect', 'getChildrenStatus'],
185  [],
186  '',
187  false
188  );
189  // do not use var path here, as root nodes get checked for public path as first part
190  $testRoot = ‪Environment::getPublicPath() . '/typo3temp/tests/';
191  $this->testFilesToDelete[] = $testRoot;
192  $path = $testRoot . ‪StringUtility::getUniqueId('dir_');
194  $node->method('getAbsolutePath')->willReturn($path);
195  $node->method('exists')->willReturn(true);
196  $node->method('isDirectory')->willReturn(true);
197  $node->method('isPermissionCorrect')->willReturn(true);
198  $node->method('isWritable')->willReturn(true);
199  $childStatus = new ‪FlashMessage('foo', '', ContextualFeedbackSeverity::ERROR);
200  $node->expects(self::once())->method('getChildrenStatus')->willReturn([$childStatus]);
201  $statusArray = $node->getStatus();
202  $statusSelf = $statusArray[0];
203  $statusOfChild = $statusArray[1];
204  self::assertSame(ContextualFeedbackSeverity::OK, $statusSelf->getSeverity());
205  self::assertSame($childStatus, $statusOfChild);
206  }
207 
208  #[Test]
209  public function ‪getAbsolutePathReturnsGivenName(): void
210  {
211  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
212  $node
213  ->method('isWindowsOs')
214  ->willReturn(false);
215  $path = '/foo/bar';
216  $structure = [
217  'name' => $path,
218  ];
219  $node->__construct($structure, null);
220  self::assertSame($path, $node->getAbsolutePath());
221  }
222 }
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorThrowsExceptionIfParentIsNotNull
‪constructorThrowsExceptionIfParentIsNotNull()
Definition: RootNodeTest.php:37
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\getStatusReturnsArrayWithOkStatusAndCallsOwnStatusMethods
‪getStatusReturnsArrayWithOkStatusAndCallsOwnStatusMethods()
Definition: RootNodeTest.php:156
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorThrowsExceptionIfAbsolutePathIsNotSet
‪constructorThrowsExceptionIfAbsolutePathIsNotSet()
Definition: RootNodeTest.php:47
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\getAbsolutePathReturnsGivenName
‪getAbsolutePathReturnsGivenName()
Definition: RootNodeTest.php:209
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorSetsParentToNull
‪constructorSetsParentToNull()
Definition: RootNodeTest.php:89
‪TYPO3\CMS\Install\FolderStructure\RootNodeInterface
Definition: RootNodeInterface.php:21
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\getChildrenReturnsChildCreatedByConstructor
‪getChildrenReturnsChildCreatedByConstructor()
Definition: RootNodeTest.php:103
‪TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep
‪static mkdir_deep(string $directory)
Definition: GeneralUtility.php:1654
‪TYPO3\CMS\Install\FolderStructure\DirectoryNode
Definition: DirectoryNode.php:28
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
Definition: InvalidArgumentException.php:23
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorSetsTargetPermission
‪constructorSetsTargetPermission()
Definition: RootNodeTest.php:128
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure
Definition: AbstractFolderStructureTestCase.php:18
‪TYPO3\CMS\Install\FolderStructure\Exception\RootNodeException
Definition: RootNodeException.php:23
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorSetsName
‪constructorSetsName()
Definition: RootNodeTest.php:144
‪TYPO3\CMS\Install\FolderStructure\RootNode
Definition: RootNode.php:28
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\getStatusCallsGetChildrenStatusForStatus
‪getStatusCallsGetChildrenStatusForStatus()
Definition: RootNodeTest.php:180
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnUnix
‪constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnUnix()
Definition: RootNodeTest.php:74
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnWindows
‪constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnWindows()
Definition: RootNodeTest.php:59
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:27
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest
Definition: RootNodeTest.php:35
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:24
‪TYPO3\CMS\Install\FolderStructure\NodeInterface
Definition: NodeInterface.php:24
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static getUniqueId(string $prefix='')
Definition: StringUtility.php:57