[TASK] ext:install Protect some methods in FolderStructure
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Tests / Unit / FolderStructure / DirectoryNodeTest.php
1 <?php
2 namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Test case
29 */
30 class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
31
32 /**
33 * @var array Directories or files in typo3temp/ created during tests to delete afterwards
34 */
35 protected $testNodesToDelete = array();
36
37 /**
38 * Tear down
39 */
40 public function tearDown() {
41 foreach ($this->testNodesToDelete as $node) {
42 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($node, PATH_site . 'typo3temp/')) {
43 \TYPO3\CMS\Core\Utility\GeneralUtility::rmdir($node, TRUE);
44 }
45 }
46 }
47
48 /**
49 * @test
50 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
51 */
52 public function constructorThrowsExceptionIfParentIsNull() {
53 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
54 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
55 $node->__construct(array(), NULL);
56 }
57
58 /**
59 * @test
60 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
61 */
62 public function constructorThrowsExceptionIfNameContainsForwardSlash() {
63 $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(), '', FALSE);
64 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
65 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
66 $structure = array(
67 'name' => 'foo/bar',
68 );
69 $node->__construct($structure, $parent);
70 }
71
72 /**
73 * @test
74 */
75 public function constructorCallsCreateChildrenIfChildrenAreSet() {
76 $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(), '', FALSE);
77 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
78 $node = $this->getAccessibleMock(
79 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
80 array('createChildren'),
81 array(),
82 '',
83 FALSE
84 );
85 $childArray = array(
86 'foo',
87 );
88 $structure = array(
89 'name' => 'foo',
90 'children' => $childArray,
91 );
92 $node->expects($this->once())->method('createChildren')->with($childArray);
93 $node->__construct($structure, $parent);
94 }
95
96 /**
97 * @test
98 */
99 public function constructorSetsParent() {
100 $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(), '', FALSE);
101 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
102 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
103 $structure = array(
104 'name' => 'foo',
105 );
106 $node->__construct($structure, $parent);
107 $this->assertSame($parent, $node->_call('getParent'));
108 }
109
110 /**
111 * @test
112 */
113 public function constructorSetsTargetPermission() {
114 $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(), '', FALSE);
115 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
116 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
117 $targetPermission = '2550';
118 $structure = array(
119 'name' => 'foo',
120 'targetPermission' => $targetPermission,
121 );
122 $node->__construct($structure, $parent);
123 $this->assertSame($targetPermission, $node->_call('getTargetPermission'));
124 }
125
126 /**
127 * @test
128 */
129 public function constructorSetsName() {
130 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
131 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
132 $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\RootNodeInterface', array(), array(), '', FALSE);
133 $name = uniqid('test_');
134 $node->__construct(array('name' => $name), $parent);
135 $this->assertSame($name, $node->getName());
136 }
137
138 /**
139 * @test
140 */
141 public function getStatusReturnsArray() {
142 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
143 $node = $this->getAccessibleMock(
144 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
145 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
146 array(),
147 '',
148 FALSE
149 );
150 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
151 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
152 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
153 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
154 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
155 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
156 $this->assertInternalType('array', $node->getStatus());
157 }
158
159 /**
160 * @test
161 */
162 public function getStatusReturnsArrayWithWarningStatusIfDirectoryNotExists() {
163 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
164 $node = $this->getAccessibleMock(
165 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
166 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
167 array(),
168 '',
169 FALSE
170 );
171 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
172 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
173 $node->expects($this->any())->method('exists')->will($this->returnValue(FALSE));
174 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
175 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
176 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
177 $statusArray = $node->getStatus();
178 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
179 $status = $statusArray[0];
180 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\WarningStatus', $status);
181 }
182
183 /**
184 * @test
185 */
186 public function getStatusReturnsArrayWithErrorStatusIfNodeIsNotADirectory() {
187 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
188 $node = $this->getAccessibleMock(
189 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
190 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
191 array(),
192 '',
193 FALSE
194 );
195 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
196 touch ($path);
197 $this->testNodesToDelete[] = $path;
198 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
199 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
200 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(FALSE));
201 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
202 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
203 $statusArray = $node->getStatus();
204 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
205 $status = $statusArray[0];
206 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\ErrorStatus', $status);
207 }
208
209 /**
210 * @test
211 */
212 public function getStatusReturnsArrayWithWarningStatusIfDirectoryExistsButIsNotWritable() {
213 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
214 $node = $this->getAccessibleMock(
215 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
216 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
217 array(),
218 '',
219 FALSE
220 );
221 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
222 touch ($path);
223 $this->testNodesToDelete[] = $path;
224 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
225 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
226 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
227 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
228 $node->expects($this->any())->method('isWritable')->will($this->returnValue(FALSE));
229 $statusArray = $node->getStatus();
230 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
231 $status = $statusArray[0];
232 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\WarningStatus', $status);
233 }
234
235 /**
236 * @test
237 */
238 public function getStatusReturnsArrayWithWarningStatusIfDirectoryExistsButPermissionAreNotCorrect() {
239 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
240 $node = $this->getAccessibleMock(
241 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
242 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
243 array(),
244 '',
245 FALSE
246 );
247 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
248 touch ($path);
249 $this->testNodesToDelete[] = $path;
250 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
251 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
252 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
253 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(FALSE));
254 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
255 $statusArray = $node->getStatus();
256 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
257 $status = $statusArray[0];
258 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\WarningStatus', $status);
259 }
260
261 /**
262 * @test
263 */
264 public function getStatusReturnsArrayWithOkStatusIfDirectoryExistsAndPermissionAreCorrect() {
265 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
266 $node = $this->getAccessibleMock(
267 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
268 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
269 array(),
270 '',
271 FALSE
272 );
273 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
274 touch ($path);
275 $this->testNodesToDelete[] = $path;
276 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
277 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
278 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
279 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
280 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
281 $statusArray = $node->getStatus();
282 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
283 $status = $statusArray[0];
284 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\OkStatus', $status);
285 }
286
287 /**
288 * @test
289 */
290 public function getStatusCallsGetStatusOnChildren() {
291 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
292 $node = $this->getAccessibleMock(
293 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
294 array('exists', 'isDirectory', 'isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'isWritable'),
295 array(),
296 '',
297 FALSE
298 );
299 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
300 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
301 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
302 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
303 $childMock1 = $this->getMock('TYPO3\\CMS\\Install\\FolderStructure\\NodeInterface', array(), array(), '', FALSE);
304 $childMock1->expects($this->once())->method('getStatus')->will($this->returnValue(array()));
305 $childMock2 = $this->getMock('TYPO3\\CMS\\Install\\FolderStructure\\NodeInterface', array(), array(), '', FALSE);
306 $childMock2->expects($this->once())->method('getStatus')->will($this->returnValue(array()));
307 $node->_set('children', array($childMock1, $childMock2));
308 $node->getStatus();
309 }
310
311 /**
312 * @test
313 */
314 public function getStatusReturnsArrayWithOwnStatusAndStatusOfChild() {
315 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
316 $node = $this->getAccessibleMock(
317 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
318 array('exists', 'isDirectory', 'isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'isWritable'),
319 array(),
320 '',
321 FALSE
322 );
323 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
324 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
325 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
326 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
327 $childMock = $this->getMock('TYPO3\\CMS\\Install\\FolderStructure\\NodeInterface', array(), array(), '', FALSE);
328 $childStatusMock = $this->getMock('TYPO3\\CMS\\Install\\Status\\ErrorStatus', array(), array(), '', FALSE);
329 $childMock->expects($this->once())->method('getStatus')->will($this->returnValue(array($childStatusMock)));
330 $node->_set('children', array($childMock));
331 $status = $node->getStatus();
332 $statusOfDirectory = $status[0];
333 $statusOfChild = $status[1];
334 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\OkStatus', $statusOfDirectory);
335 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\ErrorStatus', $statusOfChild);
336 }
337
338 /**
339 * @test
340 */
341 public function fixCallsFixSelfAndReturnsItsResult() {
342 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
343 $node = $this->getAccessibleMock(
344 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
345 array('fixSelf'),
346 array(),
347 '',
348 FALSE
349 );
350 $uniqueReturn = array(uniqid('foo_'));
351 $node->expects($this->once())->method('fixSelf')->will($this->returnValue($uniqueReturn));
352 $this->assertSame($uniqueReturn, $node->fix());
353 }
354
355 /**
356 * @test
357 */
358 public function fixCallsFixOnChildrenAndReturnsMergedResult() {
359 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
360 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('fixSelf'), array(), '', FALSE);
361 $uniqueReturnSelf = uniqid('foo_');
362 $node->expects($this->once())->method('fixSelf')->will($this->returnValue(array($uniqueReturnSelf)));
363
364 $childMock1 = $this->getMock('TYPO3\\CMS\\Install\\FolderStructure\\NodeInterface', array(), array(), '', FALSE);
365 $uniqueReturnChild1 = uniqid('foo_');
366 $childMock1->expects($this->once())->method('fix')->will($this->returnValue(array($uniqueReturnChild1)));
367
368 $childMock2 = $this->getMock('TYPO3\\CMS\\Install\\FolderStructure\\NodeInterface', array(), array(), '', FALSE);
369 $uniqueReturnChild2 = uniqid('foo_');
370 $childMock2->expects($this->once())->method('fix')->will($this->returnValue(array($uniqueReturnChild2)));
371
372 $node->_set('children', array($childMock1, $childMock2));
373
374 $this->assertSame(array($uniqueReturnSelf, $uniqueReturnChild1, $uniqueReturnChild2), $node->fix());
375 }
376
377 /**
378 * @test
379 */
380 public function fixSelfCallsCreateDirectoryIfDirectoryDoesNotExistAndReturnsResult() {
381 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
382 $node = $this->getAccessibleMock(
383 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
384 array('exists', 'createDirectory', 'getAbsolutePath', 'isDirectory', 'isPermissionCorrect'),
385 array(),
386 '',
387 FALSE
388 );
389 $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
390 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
391 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
392 $uniqueReturn = uniqid();
393 $node->expects($this->once())->method('createDirectory')->will($this->returnValue($uniqueReturn));
394 $this->assertSame(array($uniqueReturn), $node->_call('fixSelf'));
395 }
396
397 /**
398 * @test
399 */
400 public function fixSelfReturnsErrorStatusIfNodeExistsButIsNotADirectoryAndReturnsResult() {
401 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
402 $node = $this->getAccessibleMock(
403 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
404 array('exists', 'createDirectory', 'getAbsolutePath', 'isDirectory', 'isPermissionCorrect', 'fixPermission'),
405 array(),
406 '',
407 FALSE
408 );
409 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
410 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
411 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(FALSE));
412 $uniqueReturn = uniqid();
413 $node->expects($this->once())->method('fixPermission')->will($this->returnValue($uniqueReturn));
414 $this->assertSame(array($uniqueReturn), $node->_call('fixSelf'));
415 }
416
417 /**
418 * @test
419 */
420 public function fixSelfCallsFixPermissionIfDirectoryExistsButPermissionAreWrong() {
421 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
422 $node = $this->getAccessibleMock(
423 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
424 array('exists', 'createDirectory', 'getAbsolutePath', 'isDirectory', 'isPermissionCorrect', 'getRelativePathBelowSiteRoot'),
425 array(),
426 '',
427 FALSE
428 );
429 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
430 $node->expects($this->once())->method('isDirectory')->will($this->returnValue(FALSE));
431 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
432 $resultArray = $node->_call('fixSelf');
433 $this->assertInstanceOf('TYPO3\\CMS\Install\\Status\\StatusInterface', $resultArray[0]);
434 }
435
436 /**
437 * @test
438 */
439 public function fixSelfReturnsArrayOfStatusMessages() {
440 $node = $this->getAccessibleMock(
441 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
442 array('exists', 'isDirectory', 'isPermissionCorrect'),
443 array(),
444 '',
445 FALSE
446 );
447 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
448 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
449 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
450 $this->assertInternalType('array', $node->_call('fixSelf'));
451 }
452
453 /**
454 * @test
455 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception
456 */
457 public function createDirectoryThrowsExceptionIfNodeExists() {
458 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
459 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
460 $node->expects($this->once())->method('getAbsolutePath')->will($this->returnValue(''));
461 $node->expects($this->once())->method('exists')->will($this->returnValue(TRUE));
462 $node->_call('createDirectory');
463 }
464
465 /**
466 * @test
467 */
468 public function createDirectoryCreatesDirectory() {
469 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
470 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
471 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
472 $this->testNodesToDelete[] = $path;
473 $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
474 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
475 $node->_call('createDirectory');
476 $this->assertTrue(is_dir($path));
477 }
478
479 /**
480 * @test
481 */
482 public function createDirectoryReturnsOkStatusIfDirectoryWasCreated() {
483 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
484 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
485 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
486 $this->testNodesToDelete[] = $path;
487 $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
488 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
489 $this->assertInstanceOf('TYPO3\\CMS\Install\\Status\\StatusInterface', $node->_call('createDirectory'));
490 }
491
492 /**
493 * @test
494 */
495 public function createDirectoryReturnsErrorStatusIfDirectoryWasNotCreated() {
496 if (TYPO3_OS === 'WIN') {
497 $this->markTestSkipped('Test not available on Windows OS.');
498 }
499 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
500 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
501 $path = PATH_site . 'typo3temp/' . uniqid('root_');
502 mkdir($path);
503 chmod($path, octdec(2550));
504 $subPath = $path . '/' . uniqid('dir_');
505 $this->testNodesToDelete[] = $path;
506 $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
507 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath));
508 $this->assertInstanceOf('TYPO3\\CMS\Install\\Status\\StatusInterface', $node->_call('createDirectory'));
509 }
510
511 /**
512 * @test
513 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
514 */
515 public function createChildrenThrowsExceptionIfAChildTypeIsNotSet() {
516 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
517 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
518 $brokenStructure = array(
519 array(
520 'name' => 'foo',
521 ),
522 );
523 $node->_call('createChildren', $brokenStructure);
524 }
525
526 /**
527 * @test
528 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
529 */
530 public function createChildrenThrowsExceptionIfAChildNameIsNotSet() {
531 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
532 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
533 $brokenStructure = array(
534 array(
535 'type' => 'foo',
536 ),
537 );
538 $node->_call('createChildren', $brokenStructure);
539 }
540
541 /**
542 * @test
543 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
544 */
545 public function createChildrenThrowsExceptionForMultipleChildrenWithSameName() {
546 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
547 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
548 $brokenStructure = array(
549 array(
550 'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
551 'name' => 'foo',
552 ),
553 array(
554 'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
555 'name' => 'foo',
556 ),
557 );
558 $node->_call('createChildren', $brokenStructure);
559 }
560
561 /**
562 * @test
563 */
564 public function getChildrenReturnsCreatedChild() {
565 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
566 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
567 $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(), '', FALSE);
568 $childName = uniqid('test_');
569 $structure = array(
570 'name' => 'foo',
571 'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
572 'children' => array(
573 array(
574 'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
575 'name' => $childName,
576 ),
577 ),
578 );
579 $node->__construct($structure, $parent);
580 $children = $node->_call('getChildren');
581 /** @var $child \TYPO3\CMS\Install\FolderStructure\NodeInterface */
582 $child = $children[0];
583 $this->assertInstanceOf('TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode', $children[0]);
584 $this->assertSame($childName, $child->getName());
585 }
586
587 /**
588 * @test
589 */
590 public function isWritableReturnsFalseIfNodeDoesNotExist() {
591 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
592 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('getAbsolutePath'), array(), '', FALSE);
593 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
594 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
595 $this->assertFalse($node->isWritable());
596 }
597
598 /**
599 * @test
600 */
601 public function isWritableReturnsTrueIfNodeExistsAndFileCanBeCreated() {
602 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
603 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('getAbsolutePath'), array(), '', FALSE);
604 $path = PATH_site . 'typo3temp/' . uniqid('root_');
605 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
606 $this->testNodesToDelete[] = $path;
607 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
608 $this->assertTrue($node->isWritable());
609 }
610
611 /**
612 * @test
613 */
614 public function isWritableReturnsFalseIfNodeExistsButFileCanNotBeCreated() {
615 if (TYPO3_OS === 'WIN') {
616 $this->markTestSkipped('Test not available on Windows OS.');
617 }
618 if (function_exists('posix_getegid') && posix_getegid() === 0) {
619 $this->markTestSkipped('Test skipped if run on linux as root');
620 }
621 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
622 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('getAbsolutePath'), array(), '', FALSE);
623 $path = PATH_site . 'typo3temp/' . uniqid('root_');
624 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
625 $this->testNodesToDelete[] = $path;
626 chmod($path, octdec(2550));
627 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
628 $this->assertFalse($node->isWritable());
629 }
630
631 /**
632 * @test
633 */
634 public function isDirectoryReturnsTrueIfNameIsADirectory() {
635 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
636 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('getAbsolutePath'), array(), '', FALSE);
637 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
638 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
639 $this->testNodesToDelete[] = $path;
640 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
641 $this->assertTrue($node->_call('isDirectory'));
642 }
643
644 /**
645 * @test
646 */
647 public function isDirectoryReturnsFalseIfNameIsALinkToADirectory() {
648 if (TYPO3_OS === 'WIN') {
649 $this->markTestSkipped('Test not available on Windows OS.');
650 }
651 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
652 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('getAbsolutePath'), array(), '', FALSE);
653 $path = PATH_site . 'typo3temp/' . uniqid('root_');
654 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
655 $this->testNodesToDelete[] = $path;
656 $link = uniqid('link_');
657 $dir = uniqid('dir_');
658 mkdir($path . '/' . $dir);
659 symlink($path . '/' . $dir, $path . '/' . $link);
660 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path . '/' . $link));
661 $this->assertFalse($node->_call('isDirectory'));
662 }
663 }
664 ?>