‪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 
31 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
32 
33 class ‪RootNodeTest extends UnitTestCase
34 {
39  {
40  $this->expectException(RootNodeException::class);
41  $this->expectExceptionCode(1366140117);
42  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
43  $falseParent = $this->createMock(RootNodeInterface::class);
44  $node->__construct([], $falseParent);
45  }
46 
51  {
52  $this->expectException(InvalidArgumentException::class);
53  $this->expectExceptionCode(1366141329);
54  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
55  $structure = [
56  'type' => 'root',
57  ];
58  $node->__construct($structure, null);
59  }
60 
65  {
66  $this->expectException(InvalidArgumentException::class);
67  $this->expectExceptionCode(1366141329);
68  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
69  $node
70  ->method('isWindowsOs')
71  ->willReturn(true);
72  $structure = [
73  'name' => '/bar',
74  ];
75  $node->__construct($structure, null);
76  }
77 
82  {
83  $this->expectException(InvalidArgumentException::class);
84  $this->expectExceptionCode(1366141329);
85  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
86  $node
87  ->method('isWindowsOs')
88  ->willReturn(false);
89  $structure = [
90  'name' => 'C:/bar',
91  ];
92  $node->__construct($structure, null);
93  }
94 
98  public function ‪constructorSetsParentToNull(): void
99  {
100  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
101  $node
102  ->method('isWindowsOs')
103  ->willReturn(false);
104  $structure = [
105  'name' => '/bar',
106  ];
107  $node->__construct($structure, null);
108  self::assertNull($node->_call('getParent'));
109  }
110 
115  {
116  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
117  $node
118  ->method('isWindowsOs')
119  ->willReturn(false);
120  $childName = ‪StringUtility::getUniqueId('test_');
121  $structure = [
122  'name' => '/foo',
123  'children' => [
124  [
125  'type' => DirectoryNode::class,
126  'name' => $childName,
127  ],
128  ],
129  ];
130  $node->__construct($structure, null);
131  $children = $node->_call('getChildren');
133  $child = $children[0];
134  self::assertInstanceOf(DirectoryNode::class, $child);
135  self::assertSame($childName, $child->getName());
136  }
137 
141  public function ‪constructorSetsTargetPermission(): void
142  {
143  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
144  $node
145  ->method('isWindowsOs')
146  ->willReturn(false);
147  $targetPermission = '2550';
148  $structure = [
149  'name' => '/foo',
150  'targetPermission' => $targetPermission,
151  ];
152  $node->__construct($structure, null);
153  self::assertSame($targetPermission, $node->_call('getTargetPermission'));
154  }
155 
159  public function ‪constructorSetsName(): void
160  {
161  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
162  $node
163  ->method('isWindowsOs')
164  ->willReturn(false);
165  $name = '/' . ‪StringUtility::getUniqueId('test_');
166  $node->__construct(['name' => $name], null);
167  self::assertSame($name, $node->getName());
168  }
169 
174  {
175  $node = $this->getAccessibleMock(
176  RootNode::class,
177  ['getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'],
178  [],
179  '',
180  false
181  );
182  // do not use var path here, as root nodes get checked for public path as first part
183  $testRoot = ‪Environment::getPublicPath() . '/typo3temp/tests/';
184  $this->testFilesToDelete[] = $testRoot;
185  $path = $testRoot . ‪StringUtility::getUniqueId('dir_');
187  $node->method('getAbsolutePath')->willReturn($path);
188  $node->expects(self::once())->method('exists')->willReturn(true);
189  $node->expects(self::once())->method('isDirectory')->willReturn(true);
190  $node->expects(self::once())->method('isPermissionCorrect')->willReturn(true);
191  $node->expects(self::once())->method('isWritable')->willReturn(true);
192  $statusArray = $node->getStatus();
193  self::assertSame(ContextualFeedbackSeverity::OK, $statusArray[0]->getSeverity());
194  }
195 
200  {
201  $node = $this->getAccessibleMock(
202  RootNode::class,
203  ['getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect', 'getChildrenStatus'],
204  [],
205  '',
206  false
207  );
208  // do not use var path here, as root nodes get checked for public path as first part
209  $testRoot = ‪Environment::getPublicPath() . '/typo3temp/tests/';
210  $this->testFilesToDelete[] = $testRoot;
211  $path = $testRoot . ‪StringUtility::getUniqueId('dir_');
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', '', ContextualFeedbackSeverity::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(ContextualFeedbackSeverity::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\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorThrowsExceptionIfParentIsNotNull
‪constructorThrowsExceptionIfParentIsNotNull()
Definition: RootNodeTest.php:38
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\getStatusReturnsArrayWithOkStatusAndCallsOwnStatusMethods
‪getStatusReturnsArrayWithOkStatusAndCallsOwnStatusMethods()
Definition: RootNodeTest.php:173
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorThrowsExceptionIfAbsolutePathIsNotSet
‪constructorThrowsExceptionIfAbsolutePathIsNotSet()
Definition: RootNodeTest.php:50
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪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:98
‪TYPO3\CMS\Install\FolderStructure\RootNodeInterface
Definition: RootNodeInterface.php:22
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\getChildrenReturnsChildCreatedByConstructor
‪getChildrenReturnsChildCreatedByConstructor()
Definition: RootNodeTest.php:114
‪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:24
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorSetsTargetPermission
‪constructorSetsTargetPermission()
Definition: RootNodeTest.php:141
‪TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep
‪static mkdir_deep($directory)
Definition: GeneralUtility.php:1734
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure
Definition: AbstractNodeTest.php:18
‪TYPO3\CMS\Install\FolderStructure\Exception\RootNodeException
Definition: RootNodeException.php:24
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorSetsName
‪constructorSetsName()
Definition: RootNodeTest.php:159
‪TYPO3\CMS\Install\FolderStructure\RootNode
Definition: RootNode.php:28
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\getStatusCallsGetChildrenStatusForStatus
‪getStatusCallsGetChildrenStatusForStatus()
Definition: RootNodeTest.php:199
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnUnix
‪constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnUnix()
Definition: RootNodeTest.php:81
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnWindows
‪constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnWindows()
Definition: RootNodeTest.php:64
‪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:34
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪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:29