‪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 
20 use PHPUnit\Framework\Attributes\Test;
30 
32 {
33  #[Test]
34  public function ‪getNameReturnsSetName(): void
35  {
36  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
37  $name = ‪StringUtility::getUniqueId('name_');
38  $node->_set('name', $name);
39  self::assertSame($name, $node->getName());
40  }
41 
42  #[Test]
44  {
45  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
46  $permission = '1234';
47  $node->_set('targetPermission', $permission);
48  self::assertSame($permission, $node->_call('getTargetPermission'));
49  }
50 
51  #[Test]
52  public function ‪getChildrenReturnsSetChildren(): void
53  {
54  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
55  $children = ['1234'];
56  $node->_set('children', $children);
57  self::assertSame($children, $node->_call('getChildren'));
58  }
59 
60  #[Test]
61  public function ‪getParentReturnsSetParent(): void
62  {
63  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
64  $parent = $this->createMock(RootNodeInterface::class);
65  $node->_set('parent', $parent);
66  self::assertSame($parent, $node->_call('getParent'));
67  }
68 
69  #[Test]
71  {
72  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
73  $parent = $this->createMock(RootNodeInterface::class);
74  $parentPath = '/foo/bar';
75  $parent->expects(self::once())->method('getAbsolutePath')->willReturn($parentPath);
76  $name = ‪StringUtility::getUniqueId('test_');
77  $node->_set('parent', $parent);
78  $node->_set('name', $name);
79  self::assertSame($parentPath . '/' . $name, $node->getAbsolutePath());
80  }
81 
82  #[Test]
83  public function ‪isWritableCallsParentIsWritable(): void
84  {
85  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
86  $parentMock = $this->createMock(NodeInterface::class);
87  $parentMock->expects(self::once())->method('isWritable');
88  $node->_set('parent', $parentMock);
89  $node->isWritable();
90  }
91 
92  #[Test]
94  {
95  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
96  $parentMock = $this->createMock(NodeInterface::class);
97  $parentMock->expects(self::once())->method('isWritable')->willReturn(true);
98  $node->_set('parent', $parentMock);
99  self::assertTrue($node->isWritable());
100  }
101 
102  #[Test]
103  public function ‪existsReturnsTrueIfNodeExists(): void
104  {
105  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
106  $path = $this->‪getTestDirectory('dir_');
107  $node->method('getAbsolutePath')->willReturn($path);
108  self::assertTrue($node->_call('exists'));
109  }
110 
111  #[Test]
113  {
114  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
115  $testRoot = ‪Environment::getVarPath() . '/tests/';
116  $this->testFilesToDelete[] = $testRoot;
118  $path = $testRoot . ‪StringUtility::getUniqueId('link_');
119  $target = $testRoot . ‪StringUtility::getUniqueId('notExists_');
120  touch($target);
121  symlink($target, $path);
122  unlink($target);
123  $node->method('getAbsolutePath')->willReturn($path);
124  self::assertTrue($node->_call('exists'));
125  }
126 
127  #[Test]
128  public function ‪existsReturnsFalseIfNodeNotExists(): void
129  {
130  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
131  $path = $this->‪getTestFilePath('dir_');
132  $node->method('getAbsolutePath')->willReturn($path);
133  self::assertFalse($node->_call('exists'));
134  }
135 
136  #[Test]
138  {
139  $node = $this->getAccessibleMock(
140  AbstractNode::class,
141  ['isPermissionCorrect', 'getAbsolutePath'],
142  [],
143  '',
144  false
145  );
146  $this->expectException(Exception::class);
147  $this->expectExceptionCode(1366744035);
148  $node->method('getAbsolutePath')->willReturn('');
149  $node->expects(self::once())->method('isPermissionCorrect')->willReturn(true);
150  $node->_call('fixPermission');
151  }
152 
153  #[Test]
155  {
156  $node = $this->getAccessibleMock(
157  AbstractNode::class,
158  ['isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'getAbsolutePath'],
159  [],
160  '',
161  false
162  );
163  $node->method('getRelativePathBelowSiteRoot')->willReturn('');
164  $node->expects(self::once())->method('isPermissionCorrect')->willReturn(false);
165  $path = $this->‪getTestDirectory();
166  $subPath = $path . '/' . ‪StringUtility::getUniqueId('dir_');
167  mkdir($subPath);
168  chmod($path, 02770);
169  $node->_set('targetPermission', '2770');
170  $node->method('getAbsolutePath')->willReturn($subPath);
171  self::assertEquals(ContextualFeedbackSeverity::OK, $node->_call('fixPermission')->getSeverity());
172  $resultDirectoryPermissions = substr(decoct(fileperms($subPath)), 1);
173  self::assertSame('2770', $resultDirectoryPermissions);
174  }
175 
176  #[Test]
178  {
179  $node = $this->getAccessibleMock(AbstractNode::class, ['isWindowsOs'], [], '', false);
180  $node->expects(self::once())->method('isWindowsOs')->willReturn(true);
181  self::assertTrue($node->_call('isPermissionCorrect'));
182  }
183 
184  #[Test]
186  {
187  $node = $this->getAccessibleMock(AbstractNode::class, ['isWindowsOs', 'getCurrentPermission'], [], '', false);
188  $node->method('isWindowsOs')->willReturn(false);
189  $node->method('getCurrentPermission')->willReturn('foo');
190  $node->_set('targetPermission', 'bar');
191  self::assertFalse($node->_call('isPermissionCorrect'));
192  }
193 
194  #[Test]
196  {
197  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
198  $path = $this->‪getTestDirectory('dir_');
199  chmod($path, 00444);
200  clearstatcache();
201  $node->method('getAbsolutePath')->willReturn($path);
202  self::assertSame('0444', $node->_call('getCurrentPermission'));
203  }
204 
205  #[Test]
207  {
208  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
209  $file = $this->‪getTestFilePath('file_');
210  touch($file);
211  chmod($file, 0770);
212  clearstatcache();
213  $node->method('getAbsolutePath')->willReturn($file);
214  self::assertSame('0770', $node->_call('getCurrentPermission'));
215  }
216 
217  #[Test]
219  {
220  $this->expectException(InvalidArgumentException::class);
221  $this->expectExceptionCode(1366398198);
222  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
223  $node->_call('getRelativePathBelowSiteRoot', '/tmp');
224  }
225 
226  #[Test]
228  {
229  $node = $this->getAccessibleMock(
230  AbstractNode::class,
231  ['getAbsolutePath'],
232  [],
233  '',
234  false
235  );
236  $node->expects(self::once())->method('getAbsolutePath')->willReturn(‪Environment::getPublicPath());
237  $node->_call('getRelativePathBelowSiteRoot', null);
238  }
239 
240  #[Test]
242  {
243  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
244  $result = $node->_call('getRelativePathBelowSiteRoot', ‪Environment::getPublicPath() . '/');
245  self::assertSame('/', $result);
246  }
247 
248  #[Test]
250  {
251  $node = $this->getAccessibleMock(AbstractNode::class, null, [], '', false);
252  $result = $node->_call('getRelativePathBelowSiteRoot', ‪Environment::getPublicPath() . '/foo/bar');
253  self::assertSame('/foo/bar', $result);
254  }
255 }
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\fixPermissionThrowsExceptionIfPermissionAreAlreadyCorrect
‪fixPermissionThrowsExceptionIfPermissionAreAlreadyCorrect()
Definition: AbstractNodeTest.php:137
‪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:218
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\isPermissionCorrectReturnsFalseIfTargetPermissionAndCurrentPermissionAreNotIdentical
‪isPermissionCorrectReturnsFalseIfTargetPermissionAndCurrentPermissionAreNotIdentical()
Definition: AbstractNodeTest.php:185
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\existsReturnsFalseIfNodeNotExists
‪existsReturnsFalseIfNodeNotExists()
Definition: AbstractNodeTest.php:128
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\isWritableReturnsWritableStatusOfParent
‪isWritableReturnsWritableStatusOfParent()
Definition: AbstractNodeTest.php:93
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getChildrenReturnsSetChildren
‪getChildrenReturnsSetChildren()
Definition: AbstractNodeTest.php:52
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest
Definition: AbstractNodeTest.php:32
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getNameReturnsSetName
‪getNameReturnsSetName()
Definition: AbstractNodeTest.php:34
‪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:21
‪TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep
‪static mkdir_deep(string $directory)
Definition: GeneralUtility.php:1654
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\existsReturnsTrueIfIsLinkAndTargetIsDead
‪existsReturnsTrueIfIsLinkAndTargetIsDead()
Definition: AbstractNodeTest.php:112
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static getVarPath()
Definition: Environment.php:197
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getTargetPermissionReturnsSetTargetPermission
‪getTargetPermissionReturnsSetTargetPermission()
Definition: AbstractNodeTest.php:43
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\fixPermissionReturnsOkStatusIfPermissionCanBeFixedAndSetsPermissionToCorrectValue
‪fixPermissionReturnsOkStatusIfPermissionCanBeFixedAndSetsPermissionToCorrectValue()
Definition: AbstractNodeTest.php:154
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
Definition: InvalidArgumentException.php:23
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getAbsolutePathCallsParentForPathAndAppendsOwnName
‪getAbsolutePathCallsParentForPathAndAppendsOwnName()
Definition: AbstractNodeTest.php:70
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractFolderStructureTestCase
Definition: AbstractFolderStructureTestCase.php:26
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\isWritableCallsParentIsWritable
‪isWritableCallsParentIsWritable()
Definition: AbstractNodeTest.php:83
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure
Definition: AbstractFolderStructureTestCase.php:18
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getParentReturnsSetParent
‪getParentReturnsSetParent()
Definition: AbstractNodeTest.php:61
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\existsReturnsTrueIfNodeExists
‪existsReturnsTrueIfNodeExists()
Definition: AbstractNodeTest.php:103
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getRelativePathBelowSiteRootReturnsSingleForwardSlashIfGivenPathEqualsPathSiteConstant
‪getRelativePathBelowSiteRootReturnsSingleForwardSlashIfGivenPathEqualsPathSiteConstant()
Definition: AbstractNodeTest.php:241
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\isPermissionCorrectReturnsTrueOnWindowsOs
‪isPermissionCorrectReturnsTrueOnWindowsOs()
Definition: AbstractNodeTest.php:177
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getCurrentPermissionReturnsCurrentFilePermission
‪getCurrentPermissionReturnsCurrentFilePermission()
Definition: AbstractNodeTest.php:206
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getRelativePathCallsGetAbsolutePathIfPathIsNull
‪getRelativePathCallsGetAbsolutePathIfPathIsNull()
Definition: AbstractNodeTest.php:227
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getCurrentPermissionReturnsCurrentDirectoryPermission
‪getCurrentPermissionReturnsCurrentDirectoryPermission()
Definition: AbstractNodeTest.php:195
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getRelativePathBelowSiteRootReturnsSubPath
‪getRelativePathBelowSiteRootReturnsSubPath()
Definition: AbstractNodeTest.php:249
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪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