‪TYPO3CMS  10.4
AbstractNodeTest.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 
33 {
37  public function ‪getNameReturnsSetName()
38  {
40  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
41  $name = ‪StringUtility::getUniqueId('name_');
42  $node->_set('name', $name);
43  self::assertSame($name, $node->getName());
44  }
45 
50  {
52  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
53  $permission = '1234';
54  $node->_set('targetPermission', $permission);
55  self::assertSame($permission, $node->_call('getTargetPermission'));
56  }
57 
62  {
64  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
65  $children = ['1234'];
66  $node->_set('children', $children);
67  self::assertSame($children, $node->_call('getChildren'));
68  }
69 
73  public function ‪getParentReturnsSetParent()
74  {
76  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
77  $parent = $this->createMock(RootNodeInterface::class);
78  $node->_set('parent', $parent);
79  self::assertSame($parent, $node->_call('getParent'));
80  }
81 
86  {
88  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
89  $parent = $this->createMock(RootNodeInterface::class);
90  $parentPath = '/foo/bar';
91  $parent->expects(self::once())->method('getAbsolutePath')->willReturn($parentPath);
92  $name = ‪StringUtility::getUniqueId('test_');
93  $node->_set('parent', $parent);
94  $node->_set('name', $name);
95  self::assertSame($parentPath . '/' . $name, $node->getAbsolutePath());
96  }
97 
102  {
104  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
105  $parentMock = $this->createMock(NodeInterface::class);
106  $parentMock->expects(self::once())->method('isWritable');
107  $node->_set('parent', $parentMock);
108  $node->isWritable();
109  }
110 
115  {
117  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
118  $parentMock = $this->createMock(NodeInterface::class);
119  $parentMock->expects(self::once())->method('isWritable')->willReturn(true);
120  $node->_set('parent', $parentMock);
121  self::assertTrue($node->isWritable());
122  }
123 
128  {
130  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
131  $path = $this->‪getVirtualTestDir('dir_');
132  $node->expects(self::any())->method('getAbsolutePath')->willReturn($path);
133  self::assertTrue($node->_call('exists'));
134  }
135 
141  {
143  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
144  $path = ‪Environment::getVarPath() . '/tests/' . ‪StringUtility::getUniqueId('link_');
145  $target = ‪Environment::getVarPath() . '/tests/' . ‪StringUtility::getUniqueId('notExists_');
146  touch($target);
147  symlink($target, $path);
148  unlink($target);
149  $this->testFilesToDelete[] = $path;
150  $node->expects(self::any())->method('getAbsolutePath')->willReturn($path);
151  self::assertTrue($node->_call('exists'));
152  }
153 
158  {
160  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
161  $path = $this->‪getVirtualTestFilePath('dir_');
162  $node->expects(self::any())->method('getAbsolutePath')->willReturn($path);
163  self::assertFalse($node->_call('exists'));
164  }
165 
170  {
172  $node = $this->getAccessibleMock(
173  AbstractNode::class,
174  ['isPermissionCorrect', 'getAbsolutePath'],
175  [],
176  '',
177  false
178  );
179  $this->expectException(Exception::class);
180  $this->expectExceptionCode(1366744035);
181  $node->expects(self::any())->method('getAbsolutePath')->willReturn('');
182  $node->expects(self::once())->method('isPermissionCorrect')->willReturn(true);
183  $node->_call('fixPermission');
184  }
185 
190  {
191  if (function_exists('posix_getegid') && posix_getegid() === 0) {
192  self::markTestSkipped('Test skipped if run on linux as root');
193  }
195  $node = $this->getAccessibleMock(
196  AbstractNode::class,
197  ['isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'getAbsolutePath'],
198  [],
199  '',
200  false
201  );
202  $node->expects(self::any())->method('getRelativePathBelowSiteRoot')->willReturn('');
203  $node->expects(self::once())->method('isPermissionCorrect')->willReturn(false);
204  $path = $this->‪getVirtualTestDir('root_');
205  $subPath = $path . '/' . ‪StringUtility::getUniqueId('dir_');
206  mkdir($subPath);
207  chmod($path, 02000);
208  $node->expects(self::any())->method('getAbsolutePath')->willReturn($subPath);
209  $node->_set('targetPermission', '2770');
210  self::assertEquals(‪FlashMessage::NOTICE, $node->_call('fixPermission')->getSeverity());
211  chmod($path, 02770);
212  }
213 
218  {
219  if (function_exists('posix_getegid') && posix_getegid() === 0) {
220  self::markTestSkipped('Test skipped if run on linux as root');
221  }
223  $node = $this->getAccessibleMock(
224  AbstractNode::class,
225  ['isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'getAbsolutePath'],
226  [],
227  '',
228  false
229  );
230  $node->expects(self::any())->method('getRelativePathBelowSiteRoot')->willReturn('');
231  $node->expects(self::once())->method('isPermissionCorrect')->willReturn(false);
232  $path = $this->‪getVirtualTestDir('root_');
233  $subPath = $path . '/' . ‪StringUtility::getUniqueId('dir_');
234  mkdir($subPath);
235  chmod($path, 02000);
236  $node->expects(self::any())->method('getAbsolutePath')->willReturn($subPath);
237  $node->_set('targetPermission', '2770');
238  self::assertEquals(‪FlashMessage::NOTICE, $node->_call('fixPermission')->getSeverity());
239  chmod($path, 02770);
240  }
241 
246  {
248  $node = $this->getAccessibleMock(
249  AbstractNode::class,
250  ['isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'getAbsolutePath'],
251  [],
252  '',
253  false
254  );
255  $node->expects(self::any())->method('getRelativePathBelowSiteRoot')->willReturn('');
256  $node->expects(self::once())->method('isPermissionCorrect')->willReturn(false);
257  $path = $this->‪getVirtualTestDir('root_');
258  $subPath = $path . '/' . ‪StringUtility::getUniqueId('dir_');
259  mkdir($subPath);
260  chmod($path, 02770);
261  $node->_set('targetPermission', '2770');
262  $node->expects(self::any())->method('getAbsolutePath')->willReturn($subPath);
263  self::assertEquals(‪FlashMessage::OK, $node->_call('fixPermission')->getSeverity());
264  $resultDirectoryPermissions = substr(decoct(fileperms($subPath)), 1);
265  self::assertSame('2770', $resultDirectoryPermissions);
266  }
267 
272  {
274  $node = $this->getAccessibleMock(AbstractNode::class, ['isWindowsOs'], [], '', false);
275  $node->expects(self::once())->method('isWindowsOs')->willReturn(true);
276  self::assertTrue($node->_call('isPermissionCorrect'));
277  }
278 
283  {
285  $node = $this->getAccessibleMock(AbstractNode::class, ['isWindowsOs', 'getCurrentPermission'], [], '', false);
286  $node->expects(self::any())->method('isWindowsOs')->willReturn(false);
287  $node->expects(self::any())->method('getCurrentPermission')->willReturn('foo');
288  $node->_set('targetPermission', 'bar');
289  self::assertFalse($node->_call('isPermissionCorrect'));
290  }
291 
296  {
298  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
299  $path = $this->‪getVirtualTestDir('dir_');
300  chmod($path, 02775);
301  clearstatcache();
302  $node->expects(self::any())->method('getAbsolutePath')->willReturn($path);
303  self::assertSame('2775', $node->_call('getCurrentPermission'));
304  }
305 
310  {
312  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
313  $file = $this->‪getVirtualTestFilePath('file_');
314  touch($file);
315  chmod($file, 0770);
316  clearstatcache();
317  $node->expects(self::any())->method('getAbsolutePath')->willReturn($file);
318  self::assertSame('0770', $node->_call('getCurrentPermission'));
319  }
320 
325  {
326  $this->expectException(InvalidArgumentException::class);
327  $this->expectExceptionCode(1366398198);
329  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
330  $node->_call('getRelativePathBelowSiteRoot', '/tmp');
331  }
332 
337  {
339  $node = $this->getAccessibleMock(
340  AbstractNode::class,
341  ['getAbsolutePath'],
342  [],
343  '',
344  false
345  );
346  $node->expects(self::once())->method('getAbsolutePath')->willReturn(‪Environment::getPublicPath());
347  $node->_call('getRelativePathBelowSiteRoot', null);
348  }
349 
354  {
356  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
357  $result = $node->_call('getRelativePathBelowSiteRoot', ‪Environment::getPublicPath() . '/');
358  self::assertSame('/', $result);
359  }
360 
365  {
367  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
368  $result = $node->_call('getRelativePathBelowSiteRoot', ‪Environment::getPublicPath() . '/foo/bar');
369  self::assertSame('/foo/bar', $result);
370  }
371 }
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\fixPermissionThrowsExceptionIfPermissionAreAlreadyCorrect
‪fixPermissionThrowsExceptionIfPermissionAreAlreadyCorrect()
Definition: AbstractNodeTest.php:169
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getRelativePathBelowSiteRootThrowsExceptionIfGivenPathIsNotBelowPathSiteConstant
‪getRelativePathBelowSiteRootThrowsExceptionIfGivenPathIsNotBelowPathSiteConstant()
Definition: AbstractNodeTest.php:324
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\isPermissionCorrectReturnsFalseIfTargetPermissionAndCurrentPermissionAreNotIdentical
‪isPermissionCorrectReturnsFalseIfTargetPermissionAndCurrentPermissionAreNotIdentical()
Definition: AbstractNodeTest.php:282
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\existsReturnsFalseIfNodeNotExists
‪existsReturnsFalseIfNodeNotExists()
Definition: AbstractNodeTest.php:157
‪TYPO3\CMS\Install\Tests\Unit\FolderStructureTestCase\getVirtualTestDir
‪string getVirtualTestDir($prefix='root_')
Definition: FolderStructureTestCase.php:34
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:180
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\isWritableReturnsWritableStatusOfParent
‪isWritableReturnsWritableStatusOfParent()
Definition: AbstractNodeTest.php:114
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getChildrenReturnsSetChildren
‪getChildrenReturnsSetChildren()
Definition: AbstractNodeTest.php:61
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest
Definition: AbstractNodeTest.php:33
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getNameReturnsSetName
‪getNameReturnsSetName()
Definition: AbstractNodeTest.php:37
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\fixPermissionReturnsNoticeStatusIfPermissionsCanNotBeChanged
‪fixPermissionReturnsNoticeStatusIfPermissionsCanNotBeChanged()
Definition: AbstractNodeTest.php:217
‪TYPO3\CMS\Install\FolderStructure\RootNodeInterface
Definition: RootNodeInterface.php:22
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\existsReturnsTrueIfIsLinkAndTargetIsDead
‪existsReturnsTrueIfIsLinkAndTargetIsDead()
Definition: AbstractNodeTest.php:140
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getTargetPermissionReturnsSetTargetPermission
‪getTargetPermissionReturnsSetTargetPermission()
Definition: AbstractNodeTest.php:49
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\fixPermissionReturnsOkStatusIfPermissionCanBeFixedAndSetsPermissionToCorrectValue
‪fixPermissionReturnsOkStatusIfPermissionCanBeFixedAndSetsPermissionToCorrectValue()
Definition: AbstractNodeTest.php:245
‪TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
Definition: InvalidArgumentException.php:24
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getAbsolutePathCallsParentForPathAndAppendsOwnName
‪getAbsolutePathCallsParentForPathAndAppendsOwnName()
Definition: AbstractNodeTest.php:85
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\isWritableCallsParentIsWritable
‪isWritableCallsParentIsWritable()
Definition: AbstractNodeTest.php:101
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure
Definition: AbstractNodeTest.php:16
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getParentReturnsSetParent
‪getParentReturnsSetParent()
Definition: AbstractNodeTest.php:73
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\existsReturnsTrueIfNodeExists
‪existsReturnsTrueIfNodeExists()
Definition: AbstractNodeTest.php:127
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getRelativePathBelowSiteRootReturnsSingleForwardSlashIfGivenPathEqualsPathSiteConstant
‪getRelativePathBelowSiteRootReturnsSingleForwardSlashIfGivenPathEqualsPathSiteConstant()
Definition: AbstractNodeTest.php:353
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\isPermissionCorrectReturnsTrueOnWindowsOs
‪isPermissionCorrectReturnsTrueOnWindowsOs()
Definition: AbstractNodeTest.php:271
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getCurrentPermissionReturnsCurrentFilePermission
‪getCurrentPermissionReturnsCurrentFilePermission()
Definition: AbstractNodeTest.php:309
‪TYPO3\CMS\Core\Messaging\AbstractMessage\OK
‪const OK
Definition: AbstractMessage.php:29
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getRelativePathCallsGetAbsolutePathIfPathIsNull
‪getRelativePathCallsGetAbsolutePathIfPathIsNull()
Definition: AbstractNodeTest.php:336
‪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\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getCurrentPermissionReturnsCurrentDirectoryPermission
‪getCurrentPermissionReturnsCurrentDirectoryPermission()
Definition: AbstractNodeTest.php:295
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getRelativePathBelowSiteRootReturnsSubPath
‪getRelativePathBelowSiteRootReturnsSubPath()
Definition: AbstractNodeTest.php:364
‪TYPO3\CMS\Core\Messaging\AbstractMessage\NOTICE
‪const NOTICE
Definition: AbstractMessage.php:27
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\fixPermissionReturnsNoticeStatusIfPermissionCanNotBeChanged
‪fixPermissionReturnsNoticeStatusIfPermissionCanNotBeChanged()
Definition: AbstractNodeTest.php:189
‪TYPO3\CMS\Install\Tests\Unit\FolderStructureTestCase
Definition: FolderStructureTestCase.php:27
‪TYPO3\CMS\Install\FolderStructure\AbstractNode
Definition: AbstractNode.php:27
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Install\FolderStructure\NodeInterface
Definition: NodeInterface.php:24
‪TYPO3\CMS\Install\FolderStructure\Exception
Definition: InvalidArgumentException.php:16
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static string getVarPath()
Definition: Environment.php:192
‪TYPO3\CMS\Install\Tests\Unit\FolderStructureTestCase\getVirtualTestFilePath
‪string getVirtualTestFilePath($prefix='file_')
Definition: FolderStructureTestCase.php:48