‪TYPO3CMS  ‪main
AbstractNodeTest.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 
29 
31 {
35  public function ‪getNameReturnsSetName(): void
36  {
37  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
38  $name = ‪StringUtility::getUniqueId('name_');
39  $node->_set('name', $name);
40  self::assertSame($name, $node->getName());
41  }
42 
47  {
48  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
49  $permission = '1234';
50  $node->_set('targetPermission', $permission);
51  self::assertSame($permission, $node->_call('getTargetPermission'));
52  }
53 
57  public function ‪getChildrenReturnsSetChildren(): void
58  {
59  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
60  $children = ['1234'];
61  $node->_set('children', $children);
62  self::assertSame($children, $node->_call('getChildren'));
63  }
64 
68  public function ‪getParentReturnsSetParent(): void
69  {
70  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
71  $parent = $this->createMock(RootNodeInterface::class);
72  $node->_set('parent', $parent);
73  self::assertSame($parent, $node->_call('getParent'));
74  }
75 
80  {
81  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
82  $parent = $this->createMock(RootNodeInterface::class);
83  $parentPath = '/foo/bar';
84  $parent->expects(self::once())->method('getAbsolutePath')->willReturn($parentPath);
85  $name = ‪StringUtility::getUniqueId('test_');
86  $node->_set('parent', $parent);
87  $node->_set('name', $name);
88  self::assertSame($parentPath . '/' . $name, $node->getAbsolutePath());
89  }
90 
94  public function ‪isWritableCallsParentIsWritable(): void
95  {
96  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
97  $parentMock = $this->createMock(NodeInterface::class);
98  $parentMock->expects(self::once())->method('isWritable');
99  $node->_set('parent', $parentMock);
100  $node->isWritable();
101  }
102 
107  {
108  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
109  $parentMock = $this->createMock(NodeInterface::class);
110  $parentMock->expects(self::once())->method('isWritable')->willReturn(true);
111  $node->_set('parent', $parentMock);
112  self::assertTrue($node->isWritable());
113  }
114 
118  public function ‪existsReturnsTrueIfNodeExists(): void
119  {
120  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
121  $path = $this->‪getTestDirectory('dir_');
122  $node->method('getAbsolutePath')->willReturn($path);
123  self::assertTrue($node->_call('exists'));
124  }
125 
130  {
131  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
132  $testRoot = ‪Environment::getVarPath() . '/tests/';
133  $this->testFilesToDelete[] = $testRoot;
135  $path = $testRoot . ‪StringUtility::getUniqueId('link_');
136  $target = $testRoot . ‪StringUtility::getUniqueId('notExists_');
137  touch($target);
138  symlink($target, $path);
139  unlink($target);
140  $node->method('getAbsolutePath')->willReturn($path);
141  self::assertTrue($node->_call('exists'));
142  }
143 
147  public function ‪existsReturnsFalseIfNodeNotExists(): void
148  {
149  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
150  $path = $this->‪getTestFilePath('dir_');
151  $node->method('getAbsolutePath')->willReturn($path);
152  self::assertFalse($node->_call('exists'));
153  }
154 
159  {
160  $node = $this->getAccessibleMock(
161  AbstractNode::class,
162  ['isPermissionCorrect', 'getAbsolutePath'],
163  [],
164  '',
165  false
166  );
167  $this->expectException(Exception::class);
168  $this->expectExceptionCode(1366744035);
169  $node->method('getAbsolutePath')->willReturn('');
170  $node->expects(self::once())->method('isPermissionCorrect')->willReturn(true);
171  $node->_call('fixPermission');
172  }
173 
178  {
179  $node = $this->getAccessibleMock(
180  AbstractNode::class,
181  ['isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'getAbsolutePath'],
182  [],
183  '',
184  false
185  );
186  $node->method('getRelativePathBelowSiteRoot')->willReturn('');
187  $node->expects(self::once())->method('isPermissionCorrect')->willReturn(false);
188  $path = $this->‪getTestDirectory();
189  $subPath = $path . '/' . ‪StringUtility::getUniqueId('dir_');
190  mkdir($subPath);
191  chmod($path, 02770);
192  $node->_set('targetPermission', '2770');
193  $node->method('getAbsolutePath')->willReturn($subPath);
194  self::assertEquals(ContextualFeedbackSeverity::OK, $node->_call('fixPermission')->getSeverity());
195  $resultDirectoryPermissions = substr(decoct(fileperms($subPath)), 1);
196  self::assertSame('2770', $resultDirectoryPermissions);
197  }
198 
203  {
204  $node = $this->getAccessibleMock(AbstractNode::class, ['isWindowsOs'], [], '', false);
205  $node->expects(self::once())->method('isWindowsOs')->willReturn(true);
206  self::assertTrue($node->_call('isPermissionCorrect'));
207  }
208 
213  {
214  $node = $this->getAccessibleMock(AbstractNode::class, ['isWindowsOs', 'getCurrentPermission'], [], '', false);
215  $node->method('isWindowsOs')->willReturn(false);
216  $node->method('getCurrentPermission')->willReturn('foo');
217  $node->_set('targetPermission', 'bar');
218  self::assertFalse($node->_call('isPermissionCorrect'));
219  }
220 
225  {
226  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
227  $path = $this->‪getTestDirectory('dir_');
228  chmod($path, 00444);
229  clearstatcache();
230  $node->method('getAbsolutePath')->willReturn($path);
231  self::assertSame('0444', $node->_call('getCurrentPermission'));
232  }
233 
238  {
239  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
240  $file = $this->‪getTestFilePath('file_');
241  touch($file);
242  chmod($file, 0770);
243  clearstatcache();
244  $node->method('getAbsolutePath')->willReturn($file);
245  self::assertSame('0770', $node->_call('getCurrentPermission'));
246  }
247 
252  {
253  $this->expectException(InvalidArgumentException::class);
254  $this->expectExceptionCode(1366398198);
255  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
256  $node->_call('getRelativePathBelowSiteRoot', '/tmp');
257  }
258 
263  {
264  $node = $this->getAccessibleMock(
265  AbstractNode::class,
266  ['getAbsolutePath'],
267  [],
268  '',
269  false
270  );
271  $node->expects(self::once())->method('getAbsolutePath')->willReturn(‪Environment::getPublicPath());
272  $node->_call('getRelativePathBelowSiteRoot', null);
273  }
274 
279  {
280  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
281  $result = $node->_call('getRelativePathBelowSiteRoot', ‪Environment::getPublicPath() . '/');
282  self::assertSame('/', $result);
283  }
284 
289  {
290  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
291  $result = $node->_call('getRelativePathBelowSiteRoot', ‪Environment::getPublicPath() . '/foo/bar');
292  self::assertSame('/foo/bar', $result);
293  }
294 }
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\fixPermissionThrowsExceptionIfPermissionAreAlreadyCorrect
‪fixPermissionThrowsExceptionIfPermissionAreAlreadyCorrect()
Definition: AbstractNodeTest.php:158
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractFolderStructureTestCase\getTestDirectory
‪getTestDirectory($prefix='root_')
Definition: AbstractFolderStructureTestCase.php:33
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getRelativePathBelowSiteRootThrowsExceptionIfGivenPathIsNotBelowPathSiteConstant
‪getRelativePathBelowSiteRootThrowsExceptionIfGivenPathIsNotBelowPathSiteConstant()
Definition: AbstractNodeTest.php:251
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\isPermissionCorrectReturnsFalseIfTargetPermissionAndCurrentPermissionAreNotIdentical
‪isPermissionCorrectReturnsFalseIfTargetPermissionAndCurrentPermissionAreNotIdentical()
Definition: AbstractNodeTest.php:212
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\existsReturnsFalseIfNodeNotExists
‪existsReturnsFalseIfNodeNotExists()
Definition: AbstractNodeTest.php:147
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\isWritableReturnsWritableStatusOfParent
‪isWritableReturnsWritableStatusOfParent()
Definition: AbstractNodeTest.php:106
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getChildrenReturnsSetChildren
‪getChildrenReturnsSetChildren()
Definition: AbstractNodeTest.php:57
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest
Definition: AbstractNodeTest.php:31
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getNameReturnsSetName
‪getNameReturnsSetName()
Definition: AbstractNodeTest.php:35
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractFolderStructureTestCase\getTestFilePath
‪non empty string getTestFilePath($prefix='file_')
Definition: AbstractFolderStructureTestCase.php:48
‪TYPO3\CMS\Install\FolderStructure\RootNodeInterface
Definition: RootNodeInterface.php:22
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\existsReturnsTrueIfIsLinkAndTargetIsDead
‪existsReturnsTrueIfIsLinkAndTargetIsDead()
Definition: AbstractNodeTest.php:129
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static getVarPath()
Definition: Environment.php:197
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getTargetPermissionReturnsSetTargetPermission
‪getTargetPermissionReturnsSetTargetPermission()
Definition: AbstractNodeTest.php:46
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\fixPermissionReturnsOkStatusIfPermissionCanBeFixedAndSetsPermissionToCorrectValue
‪fixPermissionReturnsOkStatusIfPermissionCanBeFixedAndSetsPermissionToCorrectValue()
Definition: AbstractNodeTest.php:177
‪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\AbstractNodeTest\getAbsolutePathCallsParentForPathAndAppendsOwnName
‪getAbsolutePathCallsParentForPathAndAppendsOwnName()
Definition: AbstractNodeTest.php:79
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractFolderStructureTestCase
Definition: AbstractFolderStructureTestCase.php:26
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\isWritableCallsParentIsWritable
‪isWritableCallsParentIsWritable()
Definition: AbstractNodeTest.php:94
‪TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep
‪static mkdir_deep($directory)
Definition: GeneralUtility.php:1638
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure
Definition: AbstractFolderStructureTestCase.php:18
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getParentReturnsSetParent
‪getParentReturnsSetParent()
Definition: AbstractNodeTest.php:68
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\existsReturnsTrueIfNodeExists
‪existsReturnsTrueIfNodeExists()
Definition: AbstractNodeTest.php:118
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getRelativePathBelowSiteRootReturnsSingleForwardSlashIfGivenPathEqualsPathSiteConstant
‪getRelativePathBelowSiteRootReturnsSingleForwardSlashIfGivenPathEqualsPathSiteConstant()
Definition: AbstractNodeTest.php:278
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\isPermissionCorrectReturnsTrueOnWindowsOs
‪isPermissionCorrectReturnsTrueOnWindowsOs()
Definition: AbstractNodeTest.php:202
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getCurrentPermissionReturnsCurrentFilePermission
‪getCurrentPermissionReturnsCurrentFilePermission()
Definition: AbstractNodeTest.php:237
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getRelativePathCallsGetAbsolutePathIfPathIsNull
‪getRelativePathCallsGetAbsolutePathIfPathIsNull()
Definition: AbstractNodeTest.php:262
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getCurrentPermissionReturnsCurrentDirectoryPermission
‪getCurrentPermissionReturnsCurrentDirectoryPermission()
Definition: AbstractNodeTest.php:224
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getRelativePathBelowSiteRootReturnsSubPath
‪getRelativePathBelowSiteRootReturnsSubPath()
Definition: AbstractNodeTest.php:288
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Install\FolderStructure\AbstractNode
Definition: AbstractNode.php:28
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:24
‪TYPO3\CMS\Install\FolderStructure\NodeInterface
Definition: NodeInterface.php:24
‪TYPO3\CMS\Install\FolderStructure\Exception
Definition: InvalidArgumentException.php:16
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static getUniqueId(string $prefix='')
Definition: StringUtility.php:57