‪TYPO3CMS  9.5
AbstractNodeTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
23 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
24 
29 {
33  public function ‪getNameReturnsSetName()
34  {
36  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
37  $name = $this->getUniqueId('name_');
38  $node->_set('name', $name);
39  $this->assertSame($name, $node->getName());
40  }
41 
46  {
48  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
49  $permission = '1234';
50  $node->_set('targetPermission', $permission);
51  $this->assertSame($permission, $node->_call('getTargetPermission'));
52  }
53 
58  {
60  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
61  $children = ['1234'];
62  $node->_set('children', $children);
63  $this->assertSame($children, $node->_call('getChildren'));
64  }
65 
69  public function ‪getParentReturnsSetParent()
70  {
72  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
73  $parent = $this->createMock(\‪TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
74  $node->_set('parent', $parent);
75  $this->assertSame($parent, $node->_call('getParent'));
76  }
77 
82  {
84  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
85  $parent = $this->createMock(\‪TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
86  $parentPath = '/foo/bar';
87  $parent->expects($this->once())->method('getAbsolutePath')->will($this->returnValue($parentPath));
88  $name = $this->getUniqueId('test_');
89  $node->_set('parent', $parent);
90  $node->_set('name', $name);
91  $this->assertSame($parentPath . '/' . $name, $node->getAbsolutePath());
92  }
93 
98  {
100  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
101  $parentMock = $this->createMock(\‪TYPO3\CMS\Install\FolderStructure\NodeInterface::class);
102  $parentMock->expects($this->once())->method('isWritable');
103  $node->_set('parent', $parentMock);
104  $node->isWritable();
105  }
106 
111  {
113  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
114  $parentMock = $this->createMock(\‪TYPO3\CMS\Install\FolderStructure\NodeInterface::class);
115  $parentMock->expects($this->once())->method('isWritable')->will($this->returnValue(true));
116  $node->_set('parent', $parentMock);
117  $this->assertTrue($node->isWritable());
118  }
119 
124  {
126  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
127  $path = $this->‪getVirtualTestDir('dir_');
128  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
129  $this->assertTrue($node->_call('exists'));
130  }
131 
137  {
139  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
140  $path = ‪Environment::getVarPath() . '/tests/' . $this->getUniqueId('link_');
141  $target = ‪Environment::getVarPath() . '/tests/' . $this->getUniqueId('notExists_');
142  touch($target);
143  symlink($target, $path);
144  unlink($target);
145  $this->testFilesToDelete[] = $path;
146  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
147  $this->assertTrue($node->_call('exists'));
148  }
149 
154  {
156  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
157  $path = $this->‪getVirtualTestFilePath('dir_');
158  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
159  $this->assertFalse($node->_call('exists'));
160  }
161 
166  {
168  $node = $this->getAccessibleMock(
169  AbstractNode::class,
170  ['isPermissionCorrect', 'getAbsolutePath'],
171  [],
172  '',
173  false
174  );
175  $this->expectException(Exception::class);
176  $this->expectExceptionCode(1366744035);
177  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue(''));
178  $node->expects($this->once())->method('isPermissionCorrect')->will($this->returnValue(true));
179  $node->_call('fixPermission');
180  }
181 
186  {
187  if (function_exists('posix_getegid') && posix_getegid() === 0) {
188  $this->markTestSkipped('Test skipped if run on linux as root');
189  }
191  $node = $this->getAccessibleMock(
192  AbstractNode::class,
193  ['isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'getAbsolutePath'],
194  [],
195  '',
196  false
197  );
198  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue(''));
199  $node->expects($this->once())->method('isPermissionCorrect')->will($this->returnValue(false));
200  $path = $this->‪getVirtualTestDir('root_');
201  $subPath = $path . '/' . $this->getUniqueId('dir_');
202  mkdir($subPath);
203  chmod($path, 02000);
204  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath));
205  $node->_set('targetPermission', '2770');
206  $this->assertEquals(‪FlashMessage::NOTICE, $node->_call('fixPermission')->getSeverity());
207  chmod($path, 02770);
208  }
209 
214  {
215  if (function_exists('posix_getegid') && posix_getegid() === 0) {
216  $this->markTestSkipped('Test skipped if run on linux as root');
217  }
219  $node = $this->getAccessibleMock(
220  AbstractNode::class,
221  ['isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'getAbsolutePath'],
222  [],
223  '',
224  false
225  );
226  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue(''));
227  $node->expects($this->once())->method('isPermissionCorrect')->will($this->returnValue(false));
228  $path = $this->‪getVirtualTestDir('root_');
229  $subPath = $path . '/' . $this->getUniqueId('dir_');
230  mkdir($subPath);
231  chmod($path, 02000);
232  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath));
233  $node->_set('targetPermission', '2770');
234  $this->assertEquals(‪FlashMessage::NOTICE, $node->_call('fixPermission')->getSeverity());
235  chmod($path, 02770);
236  }
237 
242  {
244  $node = $this->getAccessibleMock(
245  AbstractNode::class,
246  ['isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'getAbsolutePath'],
247  [],
248  '',
249  false
250  );
251  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue(''));
252  $node->expects($this->once())->method('isPermissionCorrect')->will($this->returnValue(false));
253  $path = $this->‪getVirtualTestDir('root_');
254  $subPath = $path . '/' . $this->getUniqueId('dir_');
255  mkdir($subPath);
256  chmod($path, 02770);
257  $node->_set('targetPermission', '2770');
258  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath));
259  $this->assertEquals(‪FlashMessage::OK, $node->_call('fixPermission')->getSeverity());
260  $resultDirectoryPermissions = substr(decoct(fileperms($subPath)), 1);
261  $this->assertSame('2770', $resultDirectoryPermissions);
262  }
263 
268  {
270  $node = $this->getAccessibleMock(AbstractNode::class, ['isWindowsOs'], [], '', false);
271  $node->expects($this->once())->method('isWindowsOs')->will($this->returnValue(true));
272  $this->assertTrue($node->_call('isPermissionCorrect'));
273  }
274 
279  {
281  $node = $this->getAccessibleMock(AbstractNode::class, ['isWindowsOs', 'getCurrentPermission'], [], '', false);
282  $node->expects($this->any())->method('isWindowsOs')->will($this->returnValue(false));
283  $node->expects($this->any())->method('getCurrentPermission')->will($this->returnValue('foo'));
284  $node->_set('targetPermission', 'bar');
285  $this->assertFalse($node->_call('isPermissionCorrect'));
286  }
287 
292  {
294  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
295  $path = $this->‪getVirtualTestDir('dir_');
296  chmod($path, 02775);
297  clearstatcache();
298  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
299  $this->assertSame('2775', $node->_call('getCurrentPermission'));
300  }
301 
306  {
308  $node = $this->getAccessibleMock(AbstractNode::class, ['getAbsolutePath'], [], '', false);
309  $file = $this->‪getVirtualTestFilePath('file_');
310  touch($file);
311  chmod($file, 0770);
312  clearstatcache();
313  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($file));
314  $this->assertSame('0770', $node->_call('getCurrentPermission'));
315  }
316 
321  {
322  $this->expectException(InvalidArgumentException::class);
323  $this->expectExceptionCode(1366398198);
325  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
326  $node->_call('getRelativePathBelowSiteRoot', '/tmp');
327  }
328 
333  {
335  $node = $this->getAccessibleMock(
336  AbstractNode::class,
337  ['getAbsolutePath'],
338  [],
339  '',
340  false
341  );
342  $node->expects($this->once())->method('getAbsolutePath')->will($this->returnValue(‪Environment::getPublicPath()));
343  $node->_call('getRelativePathBelowSiteRoot', null);
344  }
345 
350  {
352  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
353  $result = $node->_call('getRelativePathBelowSiteRoot', ‪Environment::getPublicPath() . '/');
354  $this->assertSame('/', $result);
355  }
356 
361  {
363  $node = $this->getAccessibleMock(AbstractNode::class, ['dummy'], [], '', false);
364  $result = $node->_call('getRelativePathBelowSiteRoot', ‪Environment::getPublicPath() . '/foo/bar');
365  $this->assertSame('/foo/bar', $result);
366  }
367 }
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\fixPermissionThrowsExceptionIfPermissionAreAlreadyCorrect
‪fixPermissionThrowsExceptionIfPermissionAreAlreadyCorrect()
Definition: AbstractNodeTest.php:165
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getRelativePathBelowSiteRootThrowsExceptionIfGivenPathIsNotBelowPathSiteConstant
‪getRelativePathBelowSiteRootThrowsExceptionIfGivenPathIsNotBelowPathSiteConstant()
Definition: AbstractNodeTest.php:320
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\isPermissionCorrectReturnsFalseIfTargetPermissionAndCurrentPermissionAreNotIdentical
‪isPermissionCorrectReturnsFalseIfTargetPermissionAndCurrentPermissionAreNotIdentical()
Definition: AbstractNodeTest.php:278
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\existsReturnsFalseIfNodeNotExists
‪existsReturnsFalseIfNodeNotExists()
Definition: AbstractNodeTest.php:153
‪TYPO3\CMS\Install\Tests\Unit\FolderStructureTestCase\getVirtualTestDir
‪string getVirtualTestDir($prefix='root_')
Definition: FolderStructureTestCase.php:31
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:153
‪TYPO3
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\isWritableReturnsWritableStatusOfParent
‪isWritableReturnsWritableStatusOfParent()
Definition: AbstractNodeTest.php:110
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getChildrenReturnsSetChildren
‪getChildrenReturnsSetChildren()
Definition: AbstractNodeTest.php:57
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest
Definition: AbstractNodeTest.php:29
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getNameReturnsSetName
‪getNameReturnsSetName()
Definition: AbstractNodeTest.php:33
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\fixPermissionReturnsNoticeStatusIfPermissionsCanNotBeChanged
‪fixPermissionReturnsNoticeStatusIfPermissionsCanNotBeChanged()
Definition: AbstractNodeTest.php:213
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\existsReturnsTrueIfIsLinkAndTargetIsDead
‪existsReturnsTrueIfIsLinkAndTargetIsDead()
Definition: AbstractNodeTest.php:136
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getTargetPermissionReturnsSetTargetPermission
‪getTargetPermissionReturnsSetTargetPermission()
Definition: AbstractNodeTest.php:45
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\fixPermissionReturnsOkStatusIfPermissionCanBeFixedAndSetsPermissionToCorrectValue
‪fixPermissionReturnsOkStatusIfPermissionCanBeFixedAndSetsPermissionToCorrectValue()
Definition: AbstractNodeTest.php:241
‪TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
Definition: InvalidArgumentException.php:21
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getAbsolutePathCallsParentForPathAndAppendsOwnName
‪getAbsolutePathCallsParentForPathAndAppendsOwnName()
Definition: AbstractNodeTest.php:81
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\isWritableCallsParentIsWritable
‪isWritableCallsParentIsWritable()
Definition: AbstractNodeTest.php:97
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure
Definition: AbstractNodeTest.php:2
‪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:123
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getRelativePathBelowSiteRootReturnsSingleForwardSlashIfGivenPathEqualsPathSiteConstant
‪getRelativePathBelowSiteRootReturnsSingleForwardSlashIfGivenPathEqualsPathSiteConstant()
Definition: AbstractNodeTest.php:349
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\isPermissionCorrectReturnsTrueOnWindowsOs
‪isPermissionCorrectReturnsTrueOnWindowsOs()
Definition: AbstractNodeTest.php:267
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getCurrentPermissionReturnsCurrentFilePermission
‪getCurrentPermissionReturnsCurrentFilePermission()
Definition: AbstractNodeTest.php:305
‪TYPO3\CMS\Core\Messaging\AbstractMessage\OK
‪const OK
Definition: AbstractMessage.php:27
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getRelativePathCallsGetAbsolutePathIfPathIsNull
‪getRelativePathCallsGetAbsolutePathIfPathIsNull()
Definition: AbstractNodeTest.php:332
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:22
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getCurrentPermissionReturnsCurrentDirectoryPermission
‪getCurrentPermissionReturnsCurrentDirectoryPermission()
Definition: AbstractNodeTest.php:291
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\getRelativePathBelowSiteRootReturnsSubPath
‪getRelativePathBelowSiteRootReturnsSubPath()
Definition: AbstractNodeTest.php:360
‪TYPO3\CMS\Core\Messaging\AbstractMessage\NOTICE
‪const NOTICE
Definition: AbstractMessage.php:25
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\AbstractNodeTest\fixPermissionReturnsNoticeStatusIfPermissionCanNotBeChanged
‪fixPermissionReturnsNoticeStatusIfPermissionCanNotBeChanged()
Definition: AbstractNodeTest.php:185
‪TYPO3\CMS\Install\Tests\Unit\FolderStructureTestCase
Definition: FolderStructureTestCase.php:24
‪TYPO3\CMS\Install\FolderStructure\AbstractNode
Definition: AbstractNode.php:25
‪TYPO3\CMS\Install\FolderStructure\Exception
Definition: InvalidArgumentException.php:2
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static string getVarPath()
Definition: Environment.php:165
‪TYPO3\CMS\Install\Tests\Unit\FolderStructureTestCase\getVirtualTestFilePath
‪string getVirtualTestFilePath($prefix='file_')
Definition: FolderStructureTestCase.php:45