[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Tests / Unit / FolderStructure / LinkNodeTest.php
1 <?php
2 namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Test case
19 */
20 class LinkNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
21
22 /**
23 * @var array Directories or files in typo3temp/ created during tests to delete afterwards
24 */
25 protected $testNodesToDelete = array();
26
27 /**
28 * Tear down
29 */
30 public function tearDown() {
31 foreach ($this->testNodesToDelete as $node) {
32 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($node, PATH_site . 'typo3temp/')) {
33 \TYPO3\CMS\Core\Utility\GeneralUtility::rmdir($node, TRUE);
34 }
35 }
36 parent::tearDown();
37 }
38
39 /**
40 * @test
41 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
42 */
43 public function constructorThrowsExceptionIfParentIsNull() {
44 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
45 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode', array('dummy'), array(), '', FALSE);
46 $node->__construct(array(), NULL);
47 }
48
49 /**
50 * @test
51 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
52 */
53 public function constructorThrowsExceptionIfNameContainsForwardSlash() {
54 $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(), '', FALSE);
55 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
56 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode', array('dummy'), array(), '', FALSE);
57 $structure = array(
58 'name' => 'foo/bar',
59 );
60 $node->__construct($structure, $parent);
61 }
62
63 /**
64 * @test
65 */
66 public function constructorSetsParent() {
67 $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(), '', FALSE);
68 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
69 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode', array('dummy'), array(), '', FALSE);
70 $structure = array(
71 'name' => 'foo',
72 );
73 $node->__construct($structure, $parent);
74 $this->assertSame($parent, $node->_call('getParent'));
75 }
76
77 /**
78 * @test
79 */
80 public function constructorSetsName() {
81 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
82 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode', array('dummy'), array(), '', FALSE);
83 $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\RootNodeInterface', array(), array(), '', FALSE);
84 $name = uniqid('test_');
85 $node->__construct(array('name' => $name), $parent);
86 $this->assertSame($name, $node->getName());
87 }
88
89 /**
90 * @test
91 */
92 public function constructorSetsTarget() {
93 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
94 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode', array('dummy'), array(), '', FALSE);
95 $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\RootNodeInterface', array(), array(), '', FALSE);
96 $target = '../' . uniqid('test_');
97 $node->__construct(array('target' => $target), $parent);
98 $this->assertSame($target, $node->_call('getTarget'));
99 }
100
101 /**
102 * @test
103 */
104 public function getStatusReturnsArray() {
105 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
106 $node = $this->getAccessibleMock(
107 'TYPO3\\CMS\\Install\\FolderStructure\\LinkNode',
108 array('isWindowsOs', 'getAbsolutePath', 'exists'),
109 array(),
110 '',
111 FALSE
112 );
113 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
114 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
115 $this->assertInternalType('array', $node->getStatus());
116 }
117
118 /**
119 * @test
120 */
121 public function getStatusReturnsArrayWithInformationStatusIfRunningOnWindows() {
122 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
123 $node = $this->getAccessibleMock(
124 'TYPO3\\CMS\\Install\\FolderStructure\\LinkNode',
125 array('isWindowsOs', 'getAbsolutePath', 'exists'),
126 array(),
127 '',
128 FALSE
129 );
130 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
131 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
132 $node->expects($this->once())->method('isWindowsOs')->will($this->returnValue(TRUE));
133 $statusArray = $node->getStatus();
134 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
135 $status = $statusArray[0];
136 $this->assertInstanceOf('TYPO3\\CMS\\Install\\Status\\InfoStatus', $status);
137 }
138
139 /**
140 * @test
141 */
142 public function getStatusReturnsArrayWithErrorStatusIfLinkNotExists() {
143 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
144 $node = $this->getAccessibleMock(
145 'TYPO3\\CMS\\Install\\FolderStructure\\LinkNode',
146 array('isWindowsOs', 'getAbsolutePath', 'exists'),
147 array(),
148 '',
149 FALSE
150 );
151 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
152 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
153 $node->expects($this->any())->method('isWindowsOs')->will($this->returnValue(FALSE));
154 $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
155 $statusArray = $node->getStatus();
156 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
157 $status = $statusArray[0];
158 $this->assertInstanceOf('TYPO3\\CMS\\Install\\Status\\ErrorStatus', $status);
159 }
160
161 /**
162 * @test
163 */
164 public function getStatusReturnsArrayWithWarningStatusIfNodeIsNotALink() {
165 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
166 $node = $this->getAccessibleMock(
167 'TYPO3\\CMS\\Install\\FolderStructure\\LinkNode',
168 array('isWindowsOs', 'getAbsolutePath', 'exists', 'isLink', 'getRelativePathBelowSiteRoot'),
169 array(),
170 '',
171 FALSE
172 );
173 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
174 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
175 $node->expects($this->once())->method('isLink')->will($this->returnValue(FALSE));
176 $statusArray = $node->getStatus();
177 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
178 $status = $statusArray[0];
179 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\WarningStatus', $status);
180 }
181
182 /**
183 * @test
184 */
185 public function getStatusReturnsErrorStatusIfLinkTargetIsNotCorrect() {
186 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
187 $node = $this->getAccessibleMock(
188 'TYPO3\\CMS\\Install\\FolderStructure\\LinkNode',
189 array('isWindowsOs', 'getAbsolutePath', 'exists', 'isLink', 'isTargetCorrect', 'getCurrentTarget', 'getRelativePathBelowSiteRoot'),
190 array(),
191 '',
192 FALSE
193 );
194 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
195 $node->expects($this->any())->method('getCurrentTarget')->will($this->returnValue(''));
196 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
197 $node->expects($this->any())->method('isLink')->will($this->returnValue(TRUE));
198 $node->expects($this->once())->method('isLink')->will($this->returnValue(FALSE));
199 $statusArray = $node->getStatus();
200 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
201 $status = $statusArray[0];
202 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\ErrorStatus', $status);
203 }
204
205 /**
206 * @test
207 */
208 public function getStatusReturnsOkStatusIfLinkExistsAndTargetIsCorrect() {
209 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
210 $node = $this->getAccessibleMock(
211 'TYPO3\\CMS\\Install\\FolderStructure\\LinkNode',
212 array('isWindowsOs', 'getAbsolutePath', 'exists', 'isLink', 'isTargetCorrect', 'getRelativePathBelowSiteRoot'),
213 array(),
214 '',
215 FALSE
216 );
217 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
218 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
219 $node->expects($this->once())->method('isLink')->will($this->returnValue(TRUE));
220 $node->expects($this->once())->method('isTargetCorrect')->will($this->returnValue(TRUE));
221 $statusArray = $node->getStatus();
222 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
223 $status = $statusArray[0];
224 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\OkStatus', $status);
225 }
226
227 /**
228 * @test
229 */
230 public function fixReturnsEmptyArray() {
231 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
232 $node = $this->getAccessibleMock(
233 'TYPO3\\CMS\\Install\\FolderStructure\\LinkNode',
234 array('getRelativePathBelowSiteRoot'),
235 array(),
236 '',
237 FALSE
238 );
239 $statusArray = $node->fix();
240 $this->assertEmpty($statusArray);
241 }
242
243 /**
244 * @test
245 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
246 */
247 public function isLinkThrowsExceptionIfLinkNotExists() {
248 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
249 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode', array('exists'), array(), '', FALSE);
250 $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
251 $this->assertFalse($node->_call('isLink'));
252 }
253
254 /**
255 * @test
256 */
257 public function isLinkReturnsTrueIfNameIsLink() {
258 if (TYPO3_OS === 'WIN') {
259 $this->markTestSkipped('Test not available on Windows OS.');
260 }
261 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
262 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
263 $path = PATH_site . 'typo3temp/' . uniqid('link_');
264 $target = PATH_site . uniqid('linkTarget_');
265 symlink($target, $path);
266 $this->testNodesToDelete[] = $path;
267 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
268 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
269 $this->assertTrue($node->_call('isLink'));
270 }
271
272 /**
273 * @test
274 */
275 public function isFileReturnsFalseIfNameIsAFile() {
276 if (TYPO3_OS === 'WIN') {
277 $this->markTestSkipped('Test not available on Windows OS.');
278 }
279 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
280 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
281 $path = PATH_site . 'typo3temp/' . uniqid('file_');
282 touch($path);
283 $this->testNodesToDelete[] = $path;
284 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
285 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
286 $this->assertFalse($node->_call('isLink'));
287 }
288
289 /**
290 * @test
291 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
292 */
293 public function isTargetCorrectThrowsExceptionIfLinkNotExists() {
294 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
295 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode', array('exists'), array(), '', FALSE);
296 $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
297 $this->assertFalse($node->_call('isTargetCorrect'));
298 }
299
300 /**
301 * @test
302 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
303 */
304 public function isTargetCorrectThrowsExceptionIfNodeIsNotALink() {
305 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
306 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode', array('exists', 'isLink', 'getTarget'), array(), '', FALSE);
307 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
308 $node->expects($this->once())->method('isLink')->will($this->returnValue(FALSE));
309 $this->assertTrue($node->_call('isTargetCorrect'));
310 }
311
312 /**
313 * @test
314 */
315 public function isTargetCorrectReturnsTrueIfNoExpectedLinkTargetIsSpecified() {
316 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
317 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode', array('exists', 'isLink', 'getTarget'), array(), '', FALSE);
318 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
319 $node->expects($this->any())->method('isLink')->will($this->returnValue(TRUE));
320 $node->expects($this->once())->method('getTarget')->will($this->returnValue(''));
321 $this->assertTrue($node->_call('isTargetCorrect'));
322 }
323
324 /**
325 * @test
326 */
327 public function isTargetCorrectAcceptsATargetWithATrailingSlash() {
328 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
329 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode', array('exists', 'isLink', 'getCurrentTarget', 'getTarget'), array(), '', FALSE);
330 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
331 $node->expects($this->any())->method('isLink')->will($this->returnValue(TRUE));
332 $node->expects($this->once())->method('getCurrentTarget')->will($this->returnValue('someLinkTarget'));
333 $node->expects($this->once())->method('getTarget')->will($this->returnValue('someLinkTarget/'));
334 $this->assertTrue($node->_call('isTargetCorrect'));
335 }
336
337 /**
338 * @test
339 */
340 public function isTargetCorrectReturnsTrueIfActualTargetIsIdenticalToSpecifiedTarget() {
341 if (TYPO3_OS === 'WIN') {
342 $this->markTestSkipped('Test not available on Windows OS.');
343 }
344 $path = PATH_site . 'typo3temp/' . uniqid('link_');
345 $target = uniqid('linkTarget_');
346 symlink($target, $path);
347 $this->testNodesToDelete[] = $path;
348 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
349 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode',
350 array('exists', 'isLink', 'getTarget', 'getAbsolutePath'),
351 array(),
352 '',
353 FALSE
354 );
355 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
356 $node->expects($this->any())->method('isLink')->will($this->returnValue(TRUE));
357 $node->expects($this->once())->method('getTarget')->will($this->returnValue($target));
358 $node->expects($this->once())->method('getAbsolutePath')->will($this->returnValue($path));
359 $this->assertTrue($node->_call('isTargetCorrect'));
360 }
361
362 /**
363 * @test
364 */
365 public function isTargetCorrectReturnsFalseIfActualTargetIsNotIdenticalToSpecifiedTarget() {
366 if (TYPO3_OS === 'WIN') {
367 $this->markTestSkipped('Test not available on Windows OS.');
368 }
369 $path = PATH_site . 'typo3temp/' . uniqid('link_');
370 $target = uniqid('linkTarget_');
371 symlink($target, $path);
372 $this->testNodesToDelete[] = $path;
373 /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
374 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode',
375 array('exists', 'isLink', 'getTarget', 'getAbsolutePath'),
376 array(),
377 '',
378 FALSE
379 );
380 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
381 $node->expects($this->any())->method('isLink')->will($this->returnValue(TRUE));
382 $node->expects($this->once())->method('getTarget')->will($this->returnValue('foo'));
383 $node->expects($this->once())->method('getAbsolutePath')->will($this->returnValue($path));
384 $this->assertFalse($node->_call('isTargetCorrect'));
385 }
386
387 }