‪TYPO3CMS  9.5
RootNodeTest.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 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪RootNodeTest extends UnitTestCase
30 {
35  {
36  $this->expectException(RootNodeException::class);
37  $this->expectExceptionCode(1366140117);
39  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
40  $falseParent = $this->createMock(\‪TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
41  $node->__construct([], $falseParent);
42  }
43 
48  {
49  $this->expectException(InvalidArgumentException::class);
50  $this->expectExceptionCode(1366141329);
52  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
53  $structure = [
54  'type' => 'root',
55  ];
56  $node->__construct($structure, null);
57  }
58 
63  {
64  $this->expectException(InvalidArgumentException::class);
65  $this->expectExceptionCode(1366141329);
67  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
68  $node
69  ->expects($this->any())
70  ->method('isWindowsOs')
71  ->will($this->returnValue(true));
72  $structure = [
73  'name' => '/bar'
74  ];
75  $node->__construct($structure, null);
76  }
77 
82  {
83  $this->expectException(InvalidArgumentException::class);
84  $this->expectExceptionCode(1366141329);
86  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
87  $node
88  ->expects($this->any())
89  ->method('isWindowsOs')
90  ->will($this->returnValue(false));
91  $structure = [
92  'name' => 'C:/bar'
93  ];
94  $node->__construct($structure, null);
95  }
96 
101  {
103  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
104  $node
105  ->expects($this->any())
106  ->method('isWindowsOs')
107  ->will($this->returnValue(false));
108  $structure = [
109  'name' => '/bar'
110  ];
111  $node->__construct($structure, null);
112  $this->assertNull($node->_call('getParent'));
113  }
114 
119  {
121  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
122  $node
123  ->expects($this->any())
124  ->method('isWindowsOs')
125  ->will($this->returnValue(false));
126  $childName = $this->getUniqueId('test_');
127  $structure = [
128  'name' => '/foo',
129  'children' => [
130  [
131  'type' => DirectoryNode::class,
132  'name' => $childName,
133  ],
134  ],
135  ];
136  $node->__construct($structure, null);
137  $children = $node->_call('getChildren');
139  $child = $children[0];
140  $this->assertInstanceOf(DirectoryNode::class, $child);
141  $this->assertSame($childName, $child->getName());
142  }
143 
148  {
150  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
151  $node
152  ->expects($this->any())
153  ->method('isWindowsOs')
154  ->will($this->returnValue(false));
155  $targetPermission = '2550';
156  $structure = [
157  'name' => '/foo',
158  'targetPermission' => $targetPermission,
159  ];
160  $node->__construct($structure, null);
161  $this->assertSame($targetPermission, $node->_call('getTargetPermission'));
162  }
163 
167  public function ‪constructorSetsName()
168  {
170  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
171  $node
172  ->expects($this->any())
173  ->method('isWindowsOs')
174  ->will($this->returnValue(false));
175  $name = '/' . $this->getUniqueId('test_');
176  $node->__construct(['name' => $name], null);
177  $this->assertSame($name, $node->getName());
178  }
179 
184  {
186  $node = $this->getAccessibleMock(
187  RootNode::class,
188  ['getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'],
189  [],
190  '',
191  false
192  );
193  $path = ‪Environment::getVarPath() . '/tests/' . $this->getUniqueId('dir_');
194  touch($path);
195  $this->testFilesToDelete[] = $path;
196  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
197  $node->expects($this->once())->method('exists')->will($this->returnValue(true));
198  $node->expects($this->once())->method('isDirectory')->will($this->returnValue(true));
199  $node->expects($this->once())->method('isPermissionCorrect')->will($this->returnValue(true));
200  $node->expects($this->once())->method('isWritable')->will($this->returnValue(true));
201  $statusArray = $node->getStatus();
202  $this->assertSame(‪FlashMessage::OK, $statusArray[0]->getSeverity());
203  }
204 
209  {
211  $node = $this->getAccessibleMock(
212  RootNode::class,
213  ['getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect', 'getChildrenStatus'],
214  [],
215  '',
216  false
217  );
218  $path = ‪Environment::getVarPath() . '/tests/' . $this->getUniqueId('dir_');
219  touch($path);
220  $this->testFilesToDelete[] = $path;
221  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
222  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
223  $node->expects($this->any())->method('isDirectory')->will($this->returnValue(true));
224  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
225  $node->expects($this->any())->method('isWritable')->will($this->returnValue(true));
226  $childStatus = new ‪FlashMessage('foo', '', ‪FlashMessage::ERROR);
227  $node->expects($this->once())->method('getChildrenStatus')->will($this->returnValue([$childStatus]));
228  $statusArray = $node->getStatus();
229  $statusSelf = $statusArray[0];
230  $statusOfChild = $statusArray[1];
231  $this->assertSame(‪FlashMessage::OK, $statusSelf->getSeverity());
232  $this->assertSame($childStatus, $statusOfChild);
233  }
234 
239  {
241  $node = $this->getAccessibleMock(RootNode::class, ['isWindowsOs'], [], '', false);
242  $node
243  ->expects($this->any())
244  ->method('isWindowsOs')
245  ->will($this->returnValue(false));
246  $path = '/foo/bar';
247  $structure = [
248  'name' => $path,
249  ];
250  $node->__construct($structure, null);
251  $this->assertSame($path, $node->getAbsolutePath());
252  }
253 }
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorThrowsExceptionIfParentIsNotNull
‪constructorThrowsExceptionIfParentIsNotNull()
Definition: RootNodeTest.php:34
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\getStatusReturnsArrayWithOkStatusAndCallsOwnStatusMethods
‪getStatusReturnsArrayWithOkStatusAndCallsOwnStatusMethods()
Definition: RootNodeTest.php:183
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorThrowsExceptionIfAbsolutePathIsNotSet
‪constructorThrowsExceptionIfAbsolutePathIsNotSet()
Definition: RootNodeTest.php:47
‪TYPO3
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\getAbsolutePathReturnsGivenName
‪getAbsolutePathReturnsGivenName()
Definition: RootNodeTest.php:238
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorSetsParentToNull
‪constructorSetsParentToNull()
Definition: RootNodeTest.php:100
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\getChildrenReturnsChildCreatedByConstructor
‪getChildrenReturnsChildCreatedByConstructor()
Definition: RootNodeTest.php:118
‪TYPO3\CMS\Install\FolderStructure\DirectoryNode
Definition: DirectoryNode.php:25
‪TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
Definition: InvalidArgumentException.php:21
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorSetsTargetPermission
‪constructorSetsTargetPermission()
Definition: RootNodeTest.php:147
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure
Definition: AbstractNodeTest.php:2
‪TYPO3\CMS\Install\FolderStructure\Exception\RootNodeException
Definition: RootNodeException.php:21
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorSetsName
‪constructorSetsName()
Definition: RootNodeTest.php:167
‪TYPO3\CMS\Install\FolderStructure\RootNode
Definition: RootNode.php:24
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\getStatusCallsGetChildrenStatusForStatus
‪getStatusCallsGetChildrenStatusForStatus()
Definition: RootNodeTest.php:208
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnUnix
‪constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnUnix()
Definition: RootNodeTest.php:81
‪TYPO3\CMS\Core\Messaging\AbstractMessage\OK
‪const OK
Definition: AbstractMessage.php:27
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest\constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnWindows
‪constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnWindows()
Definition: RootNodeTest.php:62
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:22
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\RootNodeTest
Definition: RootNodeTest.php:30
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:29
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static string getVarPath()
Definition: Environment.php:165