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