‪TYPO3CMS  10.4
RootNodeTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
27 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 
33 class ‪RootNodeTest extends UnitTestCase
34 {
39  {
40  $this->expectException(RootNodeException::class);
41  $this->expectExceptionCode(1366140117);
43  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
44  $falseParent = $this->createMock(RootNodeInterface::class);
45  $node->__construct([], $falseParent);
46  }
47 
52  {
53  $this->expectException(InvalidArgumentException::class);
54  $this->expectExceptionCode(1366141329);
56  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
57  $structure = [
58  'type' => 'root',
59  ];
60  $node->__construct($structure, null);
61  }
62 
67  {
68  $this->expectException(InvalidArgumentException::class);
69  $this->expectExceptionCode(1366141329);
71  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
72  $node
73  ->expects(self::any())
74  ->method('isWindowsOs')
75  ->willReturn(true);
76  $structure = [
77  'name' => '/bar'
78  ];
79  $node->__construct($structure, null);
80  }
81 
86  {
87  $this->expectException(InvalidArgumentException::class);
88  $this->expectExceptionCode(1366141329);
90  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
91  $node
92  ->expects(self::any())
93  ->method('isWindowsOs')
94  ->willReturn(false);
95  $structure = [
96  'name' => 'C:/bar'
97  ];
98  $node->__construct($structure, null);
99  }
100 
105  {
107  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
108  $node
109  ->expects(self::any())
110  ->method('isWindowsOs')
111  ->willReturn(false);
112  $structure = [
113  'name' => '/bar'
114  ];
115  $node->__construct($structure, null);
116  self::assertNull($node->_call('getParent'));
117  }
118 
123  {
125  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
126  $node
127  ->expects(self::any())
128  ->method('isWindowsOs')
129  ->willReturn(false);
130  $childName = ‪StringUtility::getUniqueId('test_');
131  $structure = [
132  'name' => '/foo',
133  'children' => [
134  [
135  'type' => DirectoryNode::class,
136  'name' => $childName,
137  ],
138  ],
139  ];
140  $node->__construct($structure, null);
141  $children = $node->_call('getChildren');
143  $child = $children[0];
144  self::assertInstanceOf(DirectoryNode::class, $child);
145  self::assertSame($childName, $child->getName());
146  }
147 
152  {
154  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
155  $node
156  ->expects(self::any())
157  ->method('isWindowsOs')
158  ->willReturn(false);
159  $targetPermission = '2550';
160  $structure = [
161  'name' => '/foo',
162  'targetPermission' => $targetPermission,
163  ];
164  $node->__construct($structure, null);
165  self::assertSame($targetPermission, $node->_call('getTargetPermission'));
166  }
167 
171  public function ‪constructorSetsName()
172  {
174  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
175  $node
176  ->expects(self::any())
177  ->method('isWindowsOs')
178  ->willReturn(false);
179  $name = '/' . ‪StringUtility::getUniqueId('test_');
180  $node->__construct(['name' => $name], null);
181  self::assertSame($name, $node->getName());
182  }
183 
188  {
190  $node = $this->getAccessibleMock(
191  RootNode::class,
192  ['getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'],
193  [],
194  '',
195  false
196  );
197  // do not use var path here, as root nodes get checked for public path as first part
198  $path = ‪Environment::getPublicPath() . '/typo3temp/tests/' . ‪StringUtility::getUniqueId('dir_');
200  $this->testFilesToDelete[] = $path;
201  $node->expects(self::any())->method('getAbsolutePath')->willReturn($path);
202  $node->expects(self::once())->method('exists')->willReturn(true);
203  $node->expects(self::once())->method('isDirectory')->willReturn(true);
204  $node->expects(self::once())->method('isPermissionCorrect')->willReturn(true);
205  $node->expects(self::once())->method('isWritable')->willReturn(true);
206  $statusArray = $node->getStatus();
207  self::assertSame(‪FlashMessage::OK, $statusArray[0]->getSeverity());
208  }
209 
214  {
216  $node = $this->getAccessibleMock(
217  RootNode::class,
218  ['getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect', 'getChildrenStatus'],
219  [],
220  '',
221  false
222  );
223  // do not use var path here, as root nodes get checked for public path as first part
224  $path = ‪Environment::getPublicPath() . '/typo3temp/tests/' . ‪StringUtility::getUniqueId('dir_');
226  $this->testFilesToDelete[] = $path;
227  $node->expects(self::any())->method('getAbsolutePath')->willReturn($path);
228  $node->expects(self::any())->method('exists')->willReturn(true);
229  $node->expects(self::any())->method('isDirectory')->willReturn(true);
230  $node->expects(self::any())->method('isPermissionCorrect')->willReturn(true);
231  $node->expects(self::any())->method('isWritable')->willReturn(true);
232  $childStatus = new ‪FlashMessage('foo', '', ‪FlashMessage::ERROR);
233  $node->expects(self::once())->method('getChildrenStatus')->willReturn([$childStatus]);
234  $statusArray = $node->getStatus();
235  $statusSelf = $statusArray[0];
236  $statusOfChild = $statusArray[1];
237  self::assertSame(‪FlashMessage::OK, $statusSelf->getSeverity());
238  self::assertSame($childStatus, $statusOfChild);
239  }
240 
245  {
247  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
248  $node
249  ->expects(self::any())
250  ->method('isWindowsOs')
251  ->willReturn(false);
252  $path = '/foo/bar';
253  $structure = [
254  'name' => $path,
255  ];
256  $node->__construct($structure, null);
257  self::assertSame($path, $node->getAbsolutePath());
258  }
259 }
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:180
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorThrowsExceptionIfParentIsNotNull
‪constructorThrowsExceptionIfParentIsNotNull()
Definition: RootNodeTest.php:38
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\getStatusReturnsArrayWithOkStatusAndCallsOwnStatusMethods
‪getStatusReturnsArrayWithOkStatusAndCallsOwnStatusMethods()
Definition: RootNodeTest.php:187
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorThrowsExceptionIfAbsolutePathIsNotSet
‪constructorThrowsExceptionIfAbsolutePathIsNotSet()
Definition: RootNodeTest.php:51
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\getAbsolutePathReturnsGivenName
‪getAbsolutePathReturnsGivenName()
Definition: RootNodeTest.php:244
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorSetsParentToNull
‪constructorSetsParentToNull()
Definition: RootNodeTest.php:104
‪TYPO3\CMS\Install\FolderStructure\RootNodeInterface
Definition: RootNodeInterface.php:22
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\getChildrenReturnsChildCreatedByConstructor
‪getChildrenReturnsChildCreatedByConstructor()
Definition: RootNodeTest.php:122
‪TYPO3\CMS\Install\FolderStructure\DirectoryNode
Definition: DirectoryNode.php:27
‪TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
Definition: InvalidArgumentException.php:24
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorSetsTargetPermission
‪constructorSetsTargetPermission()
Definition: RootNodeTest.php:151
‪TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep
‪static mkdir_deep($directory)
Definition: GeneralUtility.php:2022
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure
Definition: AbstractNodeTest.php:16
‪TYPO3\CMS\Install\FolderStructure\Exception\RootNodeException
Definition: RootNodeException.php:24
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorSetsName
‪constructorSetsName()
Definition: RootNodeTest.php:171
‪TYPO3\CMS\Install\FolderStructure\RootNode
Definition: RootNode.php:27
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\getStatusCallsGetChildrenStatusForStatus
‪getStatusCallsGetChildrenStatusForStatus()
Definition: RootNodeTest.php:213
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnUnix
‪constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnUnix()
Definition: RootNodeTest.php:85
‪TYPO3\CMS\Core\Messaging\AbstractMessage\OK
‪const OK
Definition: AbstractMessage.php:29
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnWindows
‪constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnWindows()
Definition: RootNodeTest.php:66
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:92
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest
Definition: RootNodeTest.php:34
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31