[TASK] Folder not writeable should be an "Error" not a "Warning"
[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 getStatusReturnsArrayWithErrorStatusIfDirectoryExistsButIsNotWritable() {
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\ErrorStatus', $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 getStatusReturnsArrayWithNoticeStatusIfDirectoryExistsButPermissionAreNotCorrectAndPermissionCheckIsRelaxed() {
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', 'getTargetPermissionRelaxed'),
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(FALSE));
280 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
281 $node->expects($this->once())->method('getTargetPermissionRelaxed')->will($this->returnValue(TRUE));
282 $statusArray = $node->getStatus();
283 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
284 $status = $statusArray[0];
285 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\NoticeStatus', $status);
286 }
287
288 /**
289 * @test
290 */
291 public function getStatusReturnsArrayWithOkStatusIfDirectoryExistsAndPermissionAreCorrect() {
292 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
293 $node = $this->getAccessibleMock(
294 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
295 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
296 array(),
297 '',
298 FALSE
299 );
300 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
301 touch ($path);
302 $this->testNodesToDelete[] = $path;
303 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
304 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
305 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
306 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
307 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
308 $statusArray = $node->getStatus();
309 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
310 $status = $statusArray[0];
311 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\OkStatus', $status);
312 }
313
314 /**
315 * @test
316 */
317 public function getStatusCallsGetStatusOnChildren() {
318 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
319 $node = $this->getAccessibleMock(
320 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
321 array('exists', 'isDirectory', 'isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'isWritable'),
322 array(),
323 '',
324 FALSE
325 );
326 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
327 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
328 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
329 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
330 $childMock1 = $this->getMock('TYPO3\\CMS\\Install\\FolderStructure\\NodeInterface', array(), array(), '', FALSE);
331 $childMock1->expects($this->once())->method('getStatus')->will($this->returnValue(array()));
332 $childMock2 = $this->getMock('TYPO3\\CMS\\Install\\FolderStructure\\NodeInterface', array(), array(), '', FALSE);
333 $childMock2->expects($this->once())->method('getStatus')->will($this->returnValue(array()));
334 $node->_set('children', array($childMock1, $childMock2));
335 $node->getStatus();
336 }
337
338 /**
339 * @test
340 */
341 public function getStatusReturnsArrayWithOwnStatusAndStatusOfChild() {
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('exists', 'isDirectory', 'isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'isWritable'),
346 array(),
347 '',
348 FALSE
349 );
350 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
351 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
352 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
353 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
354 $childMock = $this->getMock('TYPO3\\CMS\\Install\\FolderStructure\\NodeInterface', array(), array(), '', FALSE);
355 $childStatusMock = $this->getMock('TYPO3\\CMS\\Install\\Status\\ErrorStatus', array(), array(), '', FALSE);
356 $childMock->expects($this->once())->method('getStatus')->will($this->returnValue(array($childStatusMock)));
357 $node->_set('children', array($childMock));
358 $status = $node->getStatus();
359 $statusOfDirectory = $status[0];
360 $statusOfChild = $status[1];
361 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\OkStatus', $statusOfDirectory);
362 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\ErrorStatus', $statusOfChild);
363 }
364
365 /**
366 * @test
367 */
368 public function fixCallsFixSelfAndReturnsItsResult() {
369 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
370 $node = $this->getAccessibleMock(
371 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
372 array('fixSelf'),
373 array(),
374 '',
375 FALSE
376 );
377 $uniqueReturn = array(uniqid('foo_'));
378 $node->expects($this->once())->method('fixSelf')->will($this->returnValue($uniqueReturn));
379 $this->assertSame($uniqueReturn, $node->fix());
380 }
381
382 /**
383 * @test
384 */
385 public function fixCallsFixOnChildrenAndReturnsMergedResult() {
386 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
387 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('fixSelf'), array(), '', FALSE);
388 $uniqueReturnSelf = uniqid('foo_');
389 $node->expects($this->once())->method('fixSelf')->will($this->returnValue(array($uniqueReturnSelf)));
390
391 $childMock1 = $this->getMock('TYPO3\\CMS\\Install\\FolderStructure\\NodeInterface', array(), array(), '', FALSE);
392 $uniqueReturnChild1 = uniqid('foo_');
393 $childMock1->expects($this->once())->method('fix')->will($this->returnValue(array($uniqueReturnChild1)));
394
395 $childMock2 = $this->getMock('TYPO3\\CMS\\Install\\FolderStructure\\NodeInterface', array(), array(), '', FALSE);
396 $uniqueReturnChild2 = uniqid('foo_');
397 $childMock2->expects($this->once())->method('fix')->will($this->returnValue(array($uniqueReturnChild2)));
398
399 $node->_set('children', array($childMock1, $childMock2));
400
401 $this->assertSame(array($uniqueReturnSelf, $uniqueReturnChild1, $uniqueReturnChild2), $node->fix());
402 }
403
404 /**
405 * @test
406 */
407 public function fixSelfCallsCreateDirectoryIfDirectoryDoesNotExistAndReturnsResult() {
408 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
409 $node = $this->getAccessibleMock(
410 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
411 array('exists', 'createDirectory', 'getAbsolutePath', 'isDirectory', 'isPermissionCorrect'),
412 array(),
413 '',
414 FALSE
415 );
416 $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
417 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
418 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
419 $uniqueReturn = uniqid();
420 $node->expects($this->once())->method('createDirectory')->will($this->returnValue($uniqueReturn));
421 $this->assertSame(array($uniqueReturn), $node->_call('fixSelf'));
422 }
423
424 /**
425 * @test
426 */
427 public function fixSelfReturnsErrorStatusIfNodeExistsButIsNotADirectoryAndReturnsResult() {
428 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
429 $node = $this->getAccessibleMock(
430 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
431 array('exists', 'createDirectory', 'getAbsolutePath', 'isDirectory', 'isPermissionCorrect', 'fixPermission'),
432 array(),
433 '',
434 FALSE
435 );
436 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
437 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
438 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(FALSE));
439 $uniqueReturn = uniqid();
440 $node->expects($this->once())->method('fixPermission')->will($this->returnValue($uniqueReturn));
441 $this->assertSame(array($uniqueReturn), $node->_call('fixSelf'));
442 }
443
444 /**
445 * @test
446 */
447 public function fixSelfCallsFixPermissionIfDirectoryExistsButPermissionAreWrong() {
448 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
449 $node = $this->getAccessibleMock(
450 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
451 array('exists', 'createDirectory', 'getAbsolutePath', 'isDirectory', 'isPermissionCorrect', 'getRelativePathBelowSiteRoot'),
452 array(),
453 '',
454 FALSE
455 );
456 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
457 $node->expects($this->once())->method('isDirectory')->will($this->returnValue(FALSE));
458 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
459 $resultArray = $node->_call('fixSelf');
460 $this->assertInstanceOf('TYPO3\\CMS\Install\\Status\\StatusInterface', $resultArray[0]);
461 }
462
463 /**
464 * @test
465 */
466 public function fixSelfReturnsArrayOfStatusMessages() {
467 $node = $this->getAccessibleMock(
468 'TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode',
469 array('exists', 'isDirectory', 'isPermissionCorrect'),
470 array(),
471 '',
472 FALSE
473 );
474 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
475 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
476 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
477 $this->assertInternalType('array', $node->_call('fixSelf'));
478 }
479
480 /**
481 * @test
482 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception
483 */
484 public function createDirectoryThrowsExceptionIfNodeExists() {
485 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
486 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
487 $node->expects($this->once())->method('getAbsolutePath')->will($this->returnValue(''));
488 $node->expects($this->once())->method('exists')->will($this->returnValue(TRUE));
489 $node->_call('createDirectory');
490 }
491
492 /**
493 * @test
494 */
495 public function createDirectoryCreatesDirectory() {
496 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
497 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
498 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
499 $this->testNodesToDelete[] = $path;
500 $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
501 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
502 $node->_call('createDirectory');
503 $this->assertTrue(is_dir($path));
504 }
505
506 /**
507 * @test
508 */
509 public function createDirectoryReturnsOkStatusIfDirectoryWasCreated() {
510 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
511 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
512 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
513 $this->testNodesToDelete[] = $path;
514 $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
515 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
516 $this->assertInstanceOf('TYPO3\\CMS\Install\\Status\\StatusInterface', $node->_call('createDirectory'));
517 }
518
519 /**
520 * @test
521 */
522 public function createDirectoryReturnsErrorStatusIfDirectoryWasNotCreated() {
523 if (TYPO3_OS === 'WIN') {
524 $this->markTestSkipped('Test not available on Windows OS.');
525 }
526 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
527 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
528 $path = PATH_site . 'typo3temp/' . uniqid('root_');
529 mkdir($path);
530 chmod($path, octdec(2550));
531 $subPath = $path . '/' . uniqid('dir_');
532 $this->testNodesToDelete[] = $path;
533 $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
534 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath));
535 $this->assertInstanceOf('TYPO3\\CMS\Install\\Status\\StatusInterface', $node->_call('createDirectory'));
536 }
537
538 /**
539 * @test
540 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
541 */
542 public function createChildrenThrowsExceptionIfAChildTypeIsNotSet() {
543 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
544 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
545 $brokenStructure = array(
546 array(
547 'name' => 'foo',
548 ),
549 );
550 $node->_call('createChildren', $brokenStructure);
551 }
552
553 /**
554 * @test
555 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
556 */
557 public function createChildrenThrowsExceptionIfAChildNameIsNotSet() {
558 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
559 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
560 $brokenStructure = array(
561 array(
562 'type' => 'foo',
563 ),
564 );
565 $node->_call('createChildren', $brokenStructure);
566 }
567
568 /**
569 * @test
570 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
571 */
572 public function createChildrenThrowsExceptionForMultipleChildrenWithSameName() {
573 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
574 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
575 $brokenStructure = array(
576 array(
577 'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
578 'name' => 'foo',
579 ),
580 array(
581 'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
582 'name' => 'foo',
583 ),
584 );
585 $node->_call('createChildren', $brokenStructure);
586 }
587
588 /**
589 * @test
590 */
591 public function getChildrenReturnsCreatedChild() {
592 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
593 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('dummy'), array(), '', FALSE);
594 $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(), '', FALSE);
595 $childName = uniqid('test_');
596 $structure = array(
597 'name' => 'foo',
598 'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
599 'children' => array(
600 array(
601 'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
602 'name' => $childName,
603 ),
604 ),
605 );
606 $node->__construct($structure, $parent);
607 $children = $node->_call('getChildren');
608 /** @var $child \TYPO3\CMS\Install\FolderStructure\NodeInterface */
609 $child = $children[0];
610 $this->assertInstanceOf('TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode', $children[0]);
611 $this->assertSame($childName, $child->getName());
612 }
613
614 /**
615 * @test
616 */
617 public function isWritableReturnsFalseIfNodeDoesNotExist() {
618 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
619 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('getAbsolutePath'), array(), '', FALSE);
620 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
621 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
622 $this->assertFalse($node->isWritable());
623 }
624
625 /**
626 * @test
627 */
628 public function isWritableReturnsTrueIfNodeExistsAndFileCanBeCreated() {
629 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
630 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('getAbsolutePath'), array(), '', FALSE);
631 $path = PATH_site . 'typo3temp/' . uniqid('root_');
632 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
633 $this->testNodesToDelete[] = $path;
634 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
635 $this->assertTrue($node->isWritable());
636 }
637
638 /**
639 * @test
640 */
641 public function isWritableReturnsFalseIfNodeExistsButFileCanNotBeCreated() {
642 if (TYPO3_OS === 'WIN') {
643 $this->markTestSkipped('Test not available on Windows OS.');
644 }
645 if (function_exists('posix_getegid') && posix_getegid() === 0) {
646 $this->markTestSkipped('Test skipped if run on linux as root');
647 }
648 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
649 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('getAbsolutePath'), array(), '', FALSE);
650 $path = PATH_site . 'typo3temp/' . uniqid('root_');
651 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
652 $this->testNodesToDelete[] = $path;
653 chmod($path, octdec(2550));
654 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
655 $this->assertFalse($node->isWritable());
656 }
657
658 /**
659 * @test
660 */
661 public function isDirectoryReturnsTrueIfNameIsADirectory() {
662 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
663 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('getAbsolutePath'), array(), '', FALSE);
664 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
665 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
666 $this->testNodesToDelete[] = $path;
667 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
668 $this->assertTrue($node->_call('isDirectory'));
669 }
670
671 /**
672 * @test
673 */
674 public function isDirectoryReturnsFalseIfNameIsALinkToADirectory() {
675 if (TYPO3_OS === 'WIN') {
676 $this->markTestSkipped('Test not available on Windows OS.');
677 }
678 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
679 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('getAbsolutePath'), array(), '', FALSE);
680 $path = PATH_site . 'typo3temp/' . uniqid('root_');
681 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
682 $this->testNodesToDelete[] = $path;
683 $link = uniqid('link_');
684 $dir = uniqid('dir_');
685 mkdir($path . '/' . $dir);
686 symlink($path . '/' . $dir, $path . '/' . $link);
687 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path . '/' . $link));
688 $this->assertFalse($node->_call('isDirectory'));
689 }
690 }
691 ?>