TYPO3 CMS  TYPO3_7-6
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 
21 {
26  public function constructorThrowsExceptionIfParentIsNotNull()
27  {
29  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\RootNode::class, ['isWindowsOs'], [], '', false);
30  $falseParent = $this->getMock(
31  \TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class,
32  [],
33  [],
34  '',
35  false
36  );
37  $node->__construct([], $falseParent);
38  }
39 
44  public function constructorThrowsExceptionIfAbsolutePathIsNotSet()
45  {
47  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\RootNode::class, ['isWindowsOs'], [], '', false);
48  $structure = [
49  'type' => 'root',
50  ];
51  $node->__construct($structure, null);
52  }
53 
58  public function constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnWindows()
59  {
61  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\RootNode::class, ['isWindowsOs'], [], '', false);
62  $node
63  ->expects($this->any())
64  ->method('isWindowsOs')
65  ->will($this->returnValue(true));
66  $structure = [
67  'name' => '/bar'
68  ];
69  $node->__construct($structure, null);
70  }
71 
76  public function constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnUnix()
77  {
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/' . $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/' . $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->getMock(\TYPO3\CMS\Install\Status\ErrorStatus::class, [], [], '', false);
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)