DirectoryNodeTest.php 28.6 KB
Newer Older
1
2
3
<?php
namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure;

4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
8
9
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
10
 *
11
12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
15
 * The TYPO3 project - inspiring people to share!
 */
16
17
18
19
20
21
22
23
24
25
26
27

/**
 * Test case
 */
class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {

	/**
	 * @test
	 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
	 */
	public function constructorThrowsExceptionIfParentIsNull() {
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
28
		$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('dummy'), array(), '', FALSE);
29
30
31
32
33
34
35
36
		$node->__construct(array(), NULL);
	}

	/**
	 * @test
	 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
	 */
	public function constructorThrowsExceptionIfNameContainsForwardSlash() {
37
		$parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(), '', FALSE);
38
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
39
		$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('dummy'), array(), '', FALSE);
40
41
42
43
44
45
46
47
48
49
		$structure = array(
			'name' => 'foo/bar',
		);
		$node->__construct($structure, $parent);
	}

	/**
	 * @test
	 */
	public function constructorCallsCreateChildrenIfChildrenAreSet() {
50
		$parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(), '', FALSE);
51
52
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
		$node = $this->getAccessibleMock(
53
			\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
			array('createChildren'),
			array(),
			'',
			FALSE
		);
		$childArray = array(
			'foo',
		);
		$structure = array(
			'name' => 'foo',
			'children' => $childArray,
		);
		$node->expects($this->once())->method('createChildren')->with($childArray);
		$node->__construct($structure, $parent);
	}

	/**
	 * @test
	 */
	public function constructorSetsParent() {
74
		$parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(), '', FALSE);
75
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
76
		$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('dummy'), array(), '', FALSE);
77
78
79
80
		$structure = array(
			'name' => 'foo',
		);
		$node->__construct($structure, $parent);
81
		$this->assertSame($parent, $node->_call('getParent'));
82
83
84
85
86
87
	}

	/**
	 * @test
	 */
	public function constructorSetsTargetPermission() {
88
		$parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(), '', FALSE);
89
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
90
		$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('dummy'), array(), '', FALSE);
91
92
93
94
95
96
		$targetPermission = '2550';
		$structure = array(
			'name' => 'foo',
			'targetPermission' => $targetPermission,
		);
		$node->__construct($structure, $parent);
97
		$this->assertSame($targetPermission, $node->_call('getTargetPermission'));
98
99
100
101
102
103
104
	}

	/**
	 * @test
	 */
	public function constructorSetsName() {
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
105
106
		$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('dummy'), array(), '', FALSE);
		$parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class, array(), array(), '', FALSE);
107
		$name = $this->getUniqueId('test_');
108
109
110
111
112
113
114
115
116
117
		$node->__construct(array('name' => $name), $parent);
		$this->assertSame($name, $node->getName());
	}

	/**
	 * @test
	 */
	public function getStatusReturnsArray() {
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
		$node = $this->getAccessibleMock(
118
			\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
119
120
121
122
123
			array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
			array(),
			'',
			FALSE
		);
124
		$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
125
126
127
128
129
130
131
132
133
134
135
		$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
		$node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
		$this->assertInternalType('array', $node->getStatus());
	}

	/**
	 * @test
	 */
136
	public function getStatusReturnsArrayWithWarningStatusIfDirectoryNotExists() {
137
138
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
		$node = $this->getAccessibleMock(
139
			\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
140
141
142
143
144
			array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
			array(),
			'',
			FALSE
		);
145
		$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
146
147
		$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
		$node->expects($this->any())->method('exists')->will($this->returnValue(FALSE));
148
149
150
		$node->expects($this->any())->method('isDirectory')->will($this->returnValue(FALSE));
		$node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(FALSE));
		$node->expects($this->any())->method('isWritable')->will($this->returnValue(FALSE));
151
152
153
		$statusArray = $node->getStatus();
		/** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
		$status = $statusArray[0];
154
		$this->assertInstanceOf(\TYPO3\CMS\Install\Status\WarningStatus::class, $status);
155
156
157
158
159
160
161
162
	}

	/**
	 * @test
	 */
	public function getStatusReturnsArrayWithErrorStatusIfNodeIsNotADirectory() {
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
		$node = $this->getAccessibleMock(
163
			\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
164
165
166
167
168
			array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
			array(),
			'',
			FALSE
		);
169
		$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
170
		touch ($path);
171
		$this->testFilesToDelete[] = $path;
172
173
174
175
176
177
178
179
		$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
		$node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isDirectory')->will($this->returnValue(FALSE));
		$node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
		$statusArray = $node->getStatus();
		/** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
		$status = $statusArray[0];
180
		$this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus::class, $status);
181
182
183
184
185
	}

	/**
	 * @test
	 */
186
	public function getStatusReturnsArrayWithErrorStatusIfDirectoryExistsButIsNotWritable() {
187
188
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
		$node = $this->getAccessibleMock(
189
			\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
190
191
192
193
194
			array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
			array(),
			'',
			FALSE
		);
195
		$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
196
		touch ($path);
197
		$this->testFilesToDelete[] = $path;
198
199
200
201
202
203
204
205
		$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
		$node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isWritable')->will($this->returnValue(FALSE));
		$statusArray = $node->getStatus();
		/** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
		$status = $statusArray[0];
206
		$this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus::class, $status);
207
208
209
210
211
	}

	/**
	 * @test
	 */
212
	public function getStatusReturnsArrayWithNoticeStatusIfDirectoryExistsButPermissionAreNotCorrect() {
213
214
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
		$node = $this->getAccessibleMock(
215
			\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
216
217
218
219
220
			array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
			array(),
			'',
			FALSE
		);
221
		$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
222
		touch ($path);
223
		$this->testFilesToDelete[] = $path;
224
225
226
227
228
229
230
231
		$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
		$node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(FALSE));
		$node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
		$statusArray = $node->getStatus();
		/** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
		$status = $statusArray[0];
232
		$this->assertInstanceOf(\TYPO3\CMS\Install\Status\NoticeStatus::class, $status);
233
234
	}

235
236
237
238
239
240
	/**
	 * @test
	 */
	public function getStatusReturnsArrayWithOkStatusIfDirectoryExistsAndPermissionAreCorrect() {
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
		$node = $this->getAccessibleMock(
241
			\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
242
243
244
245
246
			array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
			array(),
			'',
			FALSE
		);
247
		$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
248
		touch ($path);
249
		$this->testFilesToDelete[] = $path;
250
251
252
253
254
255
256
257
		$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
		$node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
		$statusArray = $node->getStatus();
		/** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
		$status = $statusArray[0];
258
		$this->assertInstanceOf(\TYPO3\CMS\Install\Status\OkStatus::class, $status);
259
260
261
262
263
264
265
266
	}

	/**
	 * @test
	 */
	public function getStatusCallsGetStatusOnChildren() {
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
		$node = $this->getAccessibleMock(
267
			\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
268
269
270
271
272
273
274
275
276
			array('exists', 'isDirectory', 'isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'isWritable'),
			array(),
			'',
			FALSE
		);
		$node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
277
		$childMock1 = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(), '', FALSE);
278
		$childMock1->expects($this->once())->method('getStatus')->will($this->returnValue(array()));
279
		$childMock2 = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(), '', FALSE);
280
281
282
283
284
285
286
287
288
289
290
		$childMock2->expects($this->once())->method('getStatus')->will($this->returnValue(array()));
		$node->_set('children', array($childMock1, $childMock2));
		$node->getStatus();
	}

	/**
	 * @test
	 */
	public function getStatusReturnsArrayWithOwnStatusAndStatusOfChild() {
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
		$node = $this->getAccessibleMock(
291
			\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
292
293
294
295
296
297
298
299
300
			array('exists', 'isDirectory', 'isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'isWritable'),
			array(),
			'',
			FALSE
		);
		$node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
301
302
		$childMock = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(), '', FALSE);
		$childStatusMock = $this->getMock(\TYPO3\CMS\Install\Status\ErrorStatus::class, array(), array(), '', FALSE);
303
304
305
306
307
		$childMock->expects($this->once())->method('getStatus')->will($this->returnValue(array($childStatusMock)));
		$node->_set('children', array($childMock));
		$status = $node->getStatus();
		$statusOfDirectory = $status[0];
		$statusOfChild = $status[1];
308
309
		$this->assertInstanceOf(\TYPO3\CMS\Install\Status\OkStatus::class, $statusOfDirectory);
		$this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus::class, $statusOfChild);
310
311
312
313
314
315
316
317
	}

	/**
	 * @test
	 */
	public function fixCallsFixSelfAndReturnsItsResult() {
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
		$node = $this->getAccessibleMock(
318
			\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
319
320
321
322
323
			array('fixSelf'),
			array(),
			'',
			FALSE
		);
324
		$uniqueReturn = array($this->getUniqueId('foo_'));
325
326
327
328
329
330
331
332
333
		$node->expects($this->once())->method('fixSelf')->will($this->returnValue($uniqueReturn));
		$this->assertSame($uniqueReturn, $node->fix());
	}

	/**
	 * @test
	 */
	public function fixCallsFixOnChildrenAndReturnsMergedResult() {
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
334
		$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('fixSelf'), array(), '', FALSE);
335
		$uniqueReturnSelf = $this->getUniqueId('foo_');
336
337
		$node->expects($this->once())->method('fixSelf')->will($this->returnValue(array($uniqueReturnSelf)));

338
		$childMock1 = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(), '', FALSE);
339
		$uniqueReturnChild1 = $this->getUniqueId('foo_');
340
341
		$childMock1->expects($this->once())->method('fix')->will($this->returnValue(array($uniqueReturnChild1)));

342
		$childMock2 = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(), '', FALSE);
343
		$uniqueReturnChild2 = $this->getUniqueId('foo_');
344
345
346
347
348
349
350
351
352
353
354
355
356
		$childMock2->expects($this->once())->method('fix')->will($this->returnValue(array($uniqueReturnChild2)));

		$node->_set('children', array($childMock1, $childMock2));

		$this->assertSame(array($uniqueReturnSelf, $uniqueReturnChild1, $uniqueReturnChild2), $node->fix());
	}

	/**
	 * @test
	 */
	public function fixSelfCallsCreateDirectoryIfDirectoryDoesNotExistAndReturnsResult() {
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
		$node = $this->getAccessibleMock(
357
			\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
358
			array('exists', 'createDirectory', 'isPermissionCorrect'),
359
360
361
362
363
364
			array(),
			'',
			FALSE
		);
		$node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
		$node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
365
		$uniqueReturn = $this->getUniqueId();
366
367
368
369
370
371
372
373
374
375
		$node->expects($this->once())->method('createDirectory')->will($this->returnValue($uniqueReturn));
		$this->assertSame(array($uniqueReturn), $node->_call('fixSelf'));
	}

	/**
	 * @test
	 */
	public function fixSelfReturnsErrorStatusIfNodeExistsButIsNotADirectoryAndReturnsResult() {
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
		$node = $this->getAccessibleMock(
376
			\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
377
			array('exists', 'isWritable', 'getRelativePathBelowSiteRoot', 'isDirectory', 'getAbsolutePath'),
378
379
380
381
382
			array(),
			'',
			FALSE
		);
		$node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
383
384
385
386
387
		$node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
		$node->expects($this->any())->method('isDirectory')->will($this->returnValue(FALSE));
		$node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue(''));
		$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue(''));
		$result = $node->_call('fixSelf');
388
		$this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus::class, $result[0]);
389
390
391
392
393
	}

	/**
	 * @test
	 */
394
	public function fixSelfCallsFixPermissionIfDirectoryExistsButIsNotWritable() {
395
396
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
		$node = $this->getAccessibleMock(
397
			\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
398
			array('exists', 'isWritable', 'fixPermission'),
399
400
401
402
403
			array(),
			'',
			FALSE
		);
		$node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
404
405
406
		$node->expects($this->any())->method('isWritable')->will($this->returnValue(FALSE));
		$node->expects($this->once())->method('fixPermission')->will($this->returnValue(TRUE));
		$this->assertSame(array(TRUE), $node->_call('fixSelf'));
407
408
409
410
411
412
413
414
	}

	/**
	 * @test
	 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception
	 */
	public function createDirectoryThrowsExceptionIfNodeExists() {
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
415
		$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('exists', 'getAbsolutePath'), array(), '', FALSE);
416
417
418
419
420
421
422
423
424
425
		$node->expects($this->once())->method('getAbsolutePath')->will($this->returnValue(''));
		$node->expects($this->once())->method('exists')->will($this->returnValue(TRUE));
		$node->_call('createDirectory');
	}

	/**
	 * @test
	 */
	public function createDirectoryCreatesDirectory() {
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
426
		$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('exists', 'getAbsolutePath'), array(), '', FALSE);
427
		$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
428
		$this->testFilesToDelete[] = $path;
429
430
431
432
433
434
435
436
437
438
439
		$node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
		$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
		$node->_call('createDirectory');
		$this->assertTrue(is_dir($path));
	}

	/**
	 * @test
	 */
	public function createDirectoryReturnsOkStatusIfDirectoryWasCreated() {
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
440
		$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('exists', 'getAbsolutePath'), array(), '', FALSE);
441
		$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
442
		$this->testFilesToDelete[] = $path;
443
444
		$node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
		$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
445
		$this->assertInstanceOf(\TYPO3\CMS\Install\Status\StatusInterface::class, $node->_call('createDirectory'));
446
447
448
449
450
451
452
453
454
455
	}

	/**
	 * @test
	 */
	public function createDirectoryReturnsErrorStatusIfDirectoryWasNotCreated() {
		if (TYPO3_OS === 'WIN') {
			$this->markTestSkipped('Test not available on Windows OS.');
		}
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
456
		$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('exists', 'getAbsolutePath'), array(), '', FALSE);
457
		$path = PATH_site . 'typo3temp/' . $this->getUniqueId('root_');
458
		mkdir($path);
459
		chmod($path, 02550);
460
		$subPath = $path . '/' . $this->getUniqueId('dir_');
461
		$this->testFilesToDelete[] = $path;
462
463
		$node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
		$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath));
464
		$this->assertInstanceOf(\TYPO3\CMS\Install\Status\StatusInterface::class, $node->_call('createDirectory'));
465
466
467
468
469
470
471
472
	}

	/**
	 * @test
	 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
	 */
	public function createChildrenThrowsExceptionIfAChildTypeIsNotSet() {
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
473
		$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('dummy'), array(), '', FALSE);
474
475
476
477
478
479
480
481
482
483
484
485
486
487
		$brokenStructure = array(
			array(
				'name' => 'foo',
			),
		);
		$node->_call('createChildren', $brokenStructure);
	}

	/**
	 * @test
	 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
	 */
	public function createChildrenThrowsExceptionIfAChildNameIsNotSet() {
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
488
		$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('dummy'), array(), '', FALSE);
489
490
491
492
493
494
495
496
497
498
499
500
501
502
		$brokenStructure = array(
			array(
				'type' => 'foo',
			),
		);
		$node->_call('createChildren', $brokenStructure);
	}

	/**
	 * @test
	 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
	 */
	public function createChildrenThrowsExceptionForMultipleChildrenWithSameName() {
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
503
		$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('dummy'), array(), '', FALSE);
504
505
		$brokenStructure = array(
			array(
506
				'type' => \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
507
508
509
				'name' => 'foo',
			),
			array(
510
				'type' => \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
511
512
513
514
515
516
517
518
519
520
521
				'name' => 'foo',
			),
		);
		$node->_call('createChildren', $brokenStructure);
	}

	/**
	 * @test
	 */
	public function getChildrenReturnsCreatedChild() {
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
522
523
		$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('dummy'), array(), '', FALSE);
		$parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(), '', FALSE);
524
		$childName = $this->getUniqueId('test_');
525
526
		$structure = array(
			'name' => 'foo',
527
			'type' => \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
528
529
			'children' => array(
				array(
530
					'type' => \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
531
532
533
534
535
					'name' => $childName,
				),
			),
		);
		$node->__construct($structure, $parent);
536
		$children = $node->_call('getChildren');
537
538
		/** @var $child \TYPO3\CMS\Install\FolderStructure\NodeInterface */
		$child = $children[0];
539
		$this->assertInstanceOf(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, $children[0]);
540
541
542
543
544
545
546
547
		$this->assertSame($childName, $child->getName());
	}

	/**
	 * @test
	 */
	public function isWritableReturnsFalseIfNodeDoesNotExist() {
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
548
		$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('getAbsolutePath'), array(), '', FALSE);
549
		$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
550
551
552
553
554
555
556
557
558
		$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
		$this->assertFalse($node->isWritable());
	}

	/**
	 * @test
	 */
	public function isWritableReturnsTrueIfNodeExistsAndFileCanBeCreated() {
		/** @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::class, array('getAbsolutePath'), array(), '', FALSE);
560
		$path = PATH_site . 'typo3temp/' . $this->getUniqueId('root_');
561
		\TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
562
		$this->testFilesToDelete[] = $path;
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
		$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
		$this->assertTrue($node->isWritable());
	}

	/**
	 * @test
	 */
	public function isWritableReturnsFalseIfNodeExistsButFileCanNotBeCreated() {
		if (TYPO3_OS === 'WIN') {
			$this->markTestSkipped('Test not available on Windows OS.');
		}
		if (function_exists('posix_getegid') && posix_getegid() === 0) {
			$this->markTestSkipped('Test skipped if run on linux as root');
		}
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
578
		$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('getAbsolutePath'), array(), '', FALSE);
579
		$path = PATH_site . 'typo3temp/' . $this->getUniqueId('root_');
580
		\TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
581
		$this->testFilesToDelete[] = $path;
582
		chmod($path, 02550);
583
584
585
586
587
588
589
590
591
		$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
		$this->assertFalse($node->isWritable());
	}

	/**
	 * @test
	 */
	public function isDirectoryReturnsTrueIfNameIsADirectory() {
		/** @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::class, array('getAbsolutePath'), array(), '', FALSE);
593
		$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
594
		\TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
595
		$this->testFilesToDelete[] = $path;
596
597
598
599
600
601
602
		$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
		$this->assertTrue($node->_call('isDirectory'));
	}

	/**
	 * @test
	 */
603
	public function isDirectoryReturnsFalseIfNameIsALinkToADirectory() {
604
605
606
607
		if (TYPO3_OS === 'WIN') {
			$this->markTestSkipped('Test not available on Windows OS.');
		}
		/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
608
		$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('getAbsolutePath'), array(), '', FALSE);
609
		$path = PATH_site . 'typo3temp/' . $this->getUniqueId('root_');
610
		\TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
611
		$this->testFilesToDelete[] = $path;
612
613
		$link = $this->getUniqueId('link_');
		$dir = $this->getUniqueId('dir_');
614
615
616
		mkdir($path . '/' . $dir);
		symlink($path . '/' . $dir, $path . '/' . $link);
		$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path . '/' . $link));
617
		$this->assertFalse($node->_call('isDirectory'));
618
	}
619

620
}