‪TYPO3CMS  11.5
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 
30 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
31 
35 class ‪RootNodeTest extends UnitTestCase
36 {
41  {
42  $this->expectException(RootNodeException::class);
43  $this->expectExceptionCode(1366140117);
44  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
45  $falseParent = $this->createMock(RootNodeInterface::class);
46  $node->__construct([], $falseParent);
47  }
48 
53  {
54  $this->expectException(InvalidArgumentException::class);
55  $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);
70  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
71  $node
72  ->method('isWindowsOs')
73  ->willReturn(true);
74  $structure = [
75  'name' => '/bar',
76  ];
77  $node->__construct($structure, null);
78  }
79 
84  {
85  $this->expectException(InvalidArgumentException::class);
86  $this->expectExceptionCode(1366141329);
87  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
88  $node
89  ->method('isWindowsOs')
90  ->willReturn(false);
91  $structure = [
92  'name' => 'C:/bar',
93  ];
94  $node->__construct($structure, null);
95  }
96 
100  public function ‪constructorSetsParentToNull(): void
101  {
102  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
103  $node
104  ->method('isWindowsOs')
105  ->willReturn(false);
106  $structure = [
107  'name' => '/bar',
108  ];
109  $node->__construct($structure, null);
110  self::assertNull($node->_call('getParent'));
111  }
112 
117  {
118  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
119  $node
120  ->method('isWindowsOs')
121  ->willReturn(false);
122  $childName = ‪StringUtility::getUniqueId('test_');
123  $structure = [
124  'name' => '/foo',
125  'children' => [
126  [
127  'type' => DirectoryNode::class,
128  'name' => $childName,
129  ],
130  ],
131  ];
132  $node->__construct($structure, null);
133  $children = $node->_call('getChildren');
135  $child = $children[0];
136  self::assertInstanceOf(DirectoryNode::class, $child);
137  self::assertSame($childName, $child->getName());
138  }
139 
143  public function ‪constructorSetsTargetPermission(): void
144  {
145  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
146  $node
147  ->method('isWindowsOs')
148  ->willReturn(false);
149  $targetPermission = '2550';
150  $structure = [
151  'name' => '/foo',
152  'targetPermission' => $targetPermission,
153  ];
154  $node->__construct($structure, null);
155  self::assertSame($targetPermission, $node->_call('getTargetPermission'));
156  }
157 
161  public function ‪constructorSetsName(): void
162  {
163  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
164  $node
165  ->method('isWindowsOs')
166  ->willReturn(false);
167  $name = '/' . ‪StringUtility::getUniqueId('test_');
168  $node->__construct(['name' => $name], null);
169  self::assertSame($name, $node->getName());
170  }
171 
176  {
177  $node = $this->getAccessibleMock(
178  RootNode::class,
179  ['getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'],
180  [],
181  '',
182  false
183  );
184  // do not use var path here, as root nodes get checked for public path as first part
185  $path = ‪Environment::getPublicPath() . '/typo3temp/tests/' . ‪StringUtility::getUniqueId('dir_');
187  $this->testFilesToDelete[] = $path;
188  $node->method('getAbsolutePath')->willReturn($path);
189  $node->expects(self::once())->method('exists')->willReturn(true);
190  $node->expects(self::once())->method('isDirectory')->willReturn(true);
191  $node->expects(self::once())->method('isPermissionCorrect')->willReturn(true);
192  $node->expects(self::once())->method('isWritable')->willReturn(true);
193  $statusArray = $node->getStatus();
194  self::assertSame(‪FlashMessage::OK, $statusArray[0]->getSeverity());
195  }
196 
201  {
202  $node = $this->getAccessibleMock(
203  RootNode::class,
204  ['getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect', 'getChildrenStatus'],
205  [],
206  '',
207  false
208  );
209  // do not use var path here, as root nodes get checked for public path as first part
210  $path = ‪Environment::getPublicPath() . '/typo3temp/tests/' . ‪StringUtility::getUniqueId('dir_');
212  $this->testFilesToDelete[] = $path;
213  $node->method('getAbsolutePath')->willReturn($path);
214  $node->method('exists')->willReturn(true);
215  $node->method('isDirectory')->willReturn(true);
216  $node->method('isPermissionCorrect')->willReturn(true);
217  $node->method('isWritable')->willReturn(true);
218  $childStatus = new ‪FlashMessage('foo', '', ‪FlashMessage::ERROR);
219  $node->expects(self::once())->method('getChildrenStatus')->willReturn([$childStatus]);
220  $statusArray = $node->getStatus();
221  $statusSelf = $statusArray[0];
222  $statusOfChild = $statusArray[1];
223  self::assertSame(‪FlashMessage::OK, $statusSelf->getSeverity());
224  self::assertSame($childStatus, $statusOfChild);
225  }
226 
230  public function ‪getAbsolutePathReturnsGivenName(): void
231  {
232  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
233  $node
234  ->method('isWindowsOs')
235  ->willReturn(false);
236  $path = '/foo/bar';
237  $structure = [
238  'name' => $path,
239  ];
240  $node->__construct($structure, null);
241  self::assertSame($path, $node->getAbsolutePath());
242  }
243 }
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:206
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorThrowsExceptionIfParentIsNotNull
‪constructorThrowsExceptionIfParentIsNotNull()
Definition: RootNodeTest.php:40
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\getStatusReturnsArrayWithOkStatusAndCallsOwnStatusMethods
‪getStatusReturnsArrayWithOkStatusAndCallsOwnStatusMethods()
Definition: RootNodeTest.php:175
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorThrowsExceptionIfAbsolutePathIsNotSet
‪constructorThrowsExceptionIfAbsolutePathIsNotSet()
Definition: RootNodeTest.php:52
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\getAbsolutePathReturnsGivenName
‪getAbsolutePathReturnsGivenName()
Definition: RootNodeTest.php:230
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorSetsParentToNull
‪constructorSetsParentToNull()
Definition: RootNodeTest.php:100
‪TYPO3\CMS\Install\FolderStructure\RootNodeInterface
Definition: RootNodeInterface.php:21
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\getChildrenReturnsChildCreatedByConstructor
‪getChildrenReturnsChildCreatedByConstructor()
Definition: RootNodeTest.php:116
‪TYPO3\CMS\Install\FolderStructure\DirectoryNode
Definition: DirectoryNode.php:27
‪TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
Definition: InvalidArgumentException.php:23
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorSetsTargetPermission
‪constructorSetsTargetPermission()
Definition: RootNodeTest.php:143
‪TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep
‪static mkdir_deep($directory)
Definition: GeneralUtility.php:1908
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure
Definition: AbstractNodeTest.php:18
‪TYPO3\CMS\Install\FolderStructure\Exception\RootNodeException
Definition: RootNodeException.php:23
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorSetsName
‪constructorSetsName()
Definition: RootNodeTest.php:161
‪TYPO3\CMS\Install\FolderStructure\RootNode
Definition: RootNode.php:27
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\getStatusCallsGetChildrenStatusForStatus
‪getStatusCallsGetChildrenStatusForStatus()
Definition: RootNodeTest.php:200
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnUnix
‪constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnUnix()
Definition: RootNodeTest.php:83
‪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:128
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:26
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:43
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest
Definition: RootNodeTest.php:36
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Install\FolderStructure\NodeInterface
Definition: NodeInterface.php:24
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31