TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
RootNodeTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure;
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  */
18 
23 {
27  public function constructorThrowsExceptionIfParentIsNotNull()
28  {
29  $this->expectException(RootNodeException::class);
30  $this->expectExceptionCode(1366140117);
32  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\RootNode::class, ['isWindowsOs'], [], '', false);
33  $falseParent = $this->createMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
34  $node->__construct([], $falseParent);
35  }
36 
40  public function constructorThrowsExceptionIfAbsolutePathIsNotSet()
41  {
42  $this->expectException(InvalidArgumentException::class);
43  $this->expectExceptionCode(1366141329);
45  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\RootNode::class, ['isWindowsOs'], [], '', false);
46  $structure = [
47  'type' => 'root',
48  ];
49  $node->__construct($structure, null);
50  }
51 
55  public function constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnWindows()
56  {
57  $this->expectException(InvalidArgumentException::class);
58  $this->expectExceptionCode(1366141329);
60  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\RootNode::class, ['isWindowsOs'], [], '', false);
61  $node
62  ->expects($this->any())
63  ->method('isWindowsOs')
64  ->will($this->returnValue(true));
65  $structure = [
66  'name' => '/bar'
67  ];
68  $node->__construct($structure, null);
69  }
70 
74  public function constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnUnix()
75  {
76  $this->expectException(InvalidArgumentException::class);
77  $this->expectExceptionCode(1366141329);
79  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\RootNode::class, ['isWindowsOs'], [], '', false);
80  $node
81  ->expects($this->any())
82  ->method('isWindowsOs')
83  ->will($this->returnValue(false));
84  $structure = [
85  'name' => 'C:/bar'
86  ];
87  $node->__construct($structure, null);
88  }
89 
93  public function constructorSetsParentToNull()
94  {
96  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\RootNode::class, ['isWindowsOs'], [], '', false);
97  $node
98  ->expects($this->any())
99  ->method('isWindowsOs')
100  ->will($this->returnValue(false));
101  $structure = [
102  'name' => '/bar'
103  ];
104  $node->__construct($structure, null);
105  $this->assertNull($node->_call('getParent'));
106  }
107 
111  public function getChildrenReturnsChildCreatedByConstructor()
112  {
114  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\RootNode::class, ['isWindowsOs'], [], '', false);
115  $node
116  ->expects($this->any())
117  ->method('isWindowsOs')
118  ->will($this->returnValue(false));
119  $childName = $this->getUniqueId('test_');
120  $structure = [
121  'name' => '/foo',
122  'children' => [
123  [
124  'type' => \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
125  'name' => $childName,
126  ],
127  ],
128  ];
129  $node->__construct($structure, null);
130  $children = $node->_call('getChildren');
132  $child = $children[0];
133  $this->assertInstanceOf(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, $child);
134  $this->assertSame($childName, $child->getName());
135  }
136 
140  public function constructorSetsTargetPermission()
141  {
143  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\RootNode::class, ['isWindowsOs'], [], '', false);
144  $node
145  ->expects($this->any())
146  ->method('isWindowsOs')
147  ->will($this->returnValue(false));
148  $targetPermission = '2550';
149  $structure = [
150  'name' => '/foo',
151  'targetPermission' => $targetPermission,
152  ];
153  $node->__construct($structure, null);
154  $this->assertSame($targetPermission, $node->_call('getTargetPermission'));
155  }
156 
160  public function constructorSetsName()
161  {
163  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\RootNode::class, ['isWindowsOs'], [], '', false);
164  $node
165  ->expects($this->any())
166  ->method('isWindowsOs')
167  ->will($this->returnValue(false));
168  $name = '/' . $this->getUniqueId('test_');
169  $node->__construct(['name' => $name], null);
170  $this->assertSame($name, $node->getName());
171  }
172 
176  public function getStatusReturnsArrayWithOkStatusAndCallsOwnStatusMethods()
177  {
179  $node = $this->getAccessibleMock(
180  \TYPO3\CMS\Install\FolderStructure\RootNode::class,
181  ['getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'],
182  [],
183  '',
184  false
185  );
186  $path = PATH_site . 'typo3temp/var/tests/' . $this->getUniqueId('dir_');
187  touch($path);
188  $this->testFilesToDelete[] = $path;
189  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
190  $node->expects($this->once())->method('exists')->will($this->returnValue(true));
191  $node->expects($this->once())->method('isDirectory')->will($this->returnValue(true));
192  $node->expects($this->once())->method('isPermissionCorrect')->will($this->returnValue(true));
193  $node->expects($this->once())->method('isWritable')->will($this->returnValue(true));
194  $statusArray = $node->getStatus();
196  $status = $statusArray[0];
197  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\OkStatus::class, $status);
198  }
199 
203  public function getStatusCallsGetChildrenStatusForStatus()
204  {
206  $node = $this->getAccessibleMock(
207  \TYPO3\CMS\Install\FolderStructure\RootNode::class,
208  ['getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect', 'getChildrenStatus'],
209  [],
210  '',
211  false
212  );
213  $path = PATH_site . 'typo3temp/var/tests/' . $this->getUniqueId('dir_');
214  touch($path);
215  $this->testFilesToDelete[] = $path;
216  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
217  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
218  $node->expects($this->any())->method('isDirectory')->will($this->returnValue(true));
219  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
220  $node->expects($this->any())->method('isWritable')->will($this->returnValue(true));
221  $childStatusMock = $this->createMock(\TYPO3\CMS\Install\Status\ErrorStatus::class);
222  $node->expects($this->once())->method('getChildrenStatus')->will($this->returnValue([$childStatusMock]));
223  $statusArray = $node->getStatus();
225  $statusSelf = $statusArray[0];
226  $statusOfChild = $statusArray[1];
227  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\OkStatus::class, $statusSelf);
228  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus::class, $statusOfChild);
229  }
230 
234  public function getAbsolutePathReturnsGivenName()
235  {
237  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\RootNode::class, ['isWindowsOs'], [], '', false);
238  $node
239  ->expects($this->any())
240  ->method('isWindowsOs')
241  ->will($this->returnValue(false));
242  $path = '/foo/bar';
243  $structure = [
244  'name' => $path,
245  ];
246  $node->__construct($structure, null);
247  $this->assertSame($path, $node->getAbsolutePath());
248  }
249 }
getAccessibleMock($originalClassName, $methods=[], array $arguments=[], $mockClassName= '', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)