TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
LinkNodeTest.php
Go to the documentation of this file.
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  */
17 
22 {
26  public function constructorThrowsExceptionIfParentIsNull()
27  {
28  $this->expectException(InvalidArgumentException::class);
29  $this->expectExceptionCode(1380485700);
31  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['dummy'], [], '', false);
32  $node->__construct([], null);
33  }
34 
38  public function constructorThrowsExceptionIfNameContainsForwardSlash()
39  {
40  $this->expectException(InvalidArgumentException::class);
41  $this->expectExceptionCode(1380546061);
42  $parent = $this->createMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class);
44  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['dummy'], [], '', false);
45  $structure = [
46  'name' => 'foo/bar',
47  ];
48  $node->__construct($structure, $parent);
49  }
50 
54  public function constructorSetsParent()
55  {
56  $parent = $this->createMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class);
58  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['dummy'], [], '', false);
59  $structure = [
60  'name' => 'foo',
61  ];
62  $node->__construct($structure, $parent);
63  $this->assertSame($parent, $node->_call('getParent'));
64  }
65 
69  public function constructorSetsName()
70  {
72  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['dummy'], [], '', false);
73  $parent = $this->createMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
74  $name = $this->getUniqueId('test_');
75  $node->__construct(['name' => $name], $parent);
76  $this->assertSame($name, $node->getName());
77  }
78 
82  public function constructorSetsTarget()
83  {
85  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['dummy'], [], '', false);
86  $parent = $this->createMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
87  $target = '../' . $this->getUniqueId('test_');
88  $node->__construct(['target' => $target], $parent);
89  $this->assertSame($target, $node->_call('getTarget'));
90  }
91 
95  public function getStatusReturnsArray()
96  {
98  $node = $this->getAccessibleMock(
99  \TYPO3\CMS\Install\FolderStructure\LinkNode::class,
100  ['isWindowsOs', 'getAbsolutePath', 'exists'],
101  [],
102  '',
103  false
104  );
105  $path = PATH_site . 'typo3temp/var/tests/' . $this->getUniqueId('dir_');
106  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
107  $this->assertInternalType('array', $node->getStatus());
108  }
109 
113  public function getStatusReturnsArrayWithInformationStatusIfRunningOnWindows()
114  {
116  $node = $this->getAccessibleMock(
117  \TYPO3\CMS\Install\FolderStructure\LinkNode::class,
118  ['isWindowsOs', 'getAbsolutePath', 'exists'],
119  [],
120  '',
121  false
122  );
123  $path = PATH_site . 'typo3temp/var/tests/' . $this->getUniqueId('dir_');
124  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
125  $node->expects($this->once())->method('isWindowsOs')->will($this->returnValue(true));
126  $statusArray = $node->getStatus();
128  $status = $statusArray[0];
129  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\InfoStatus::class, $status);
130  }
131 
135  public function getStatusReturnsArrayWithErrorStatusIfLinkNotExists()
136  {
138  $node = $this->getAccessibleMock(
139  \TYPO3\CMS\Install\FolderStructure\LinkNode::class,
140  ['isWindowsOs', 'getAbsolutePath', 'exists'],
141  [],
142  '',
143  false
144  );
145  $path = PATH_site . 'typo3temp/var/tests/' . $this->getUniqueId('dir_');
146  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
147  $node->expects($this->any())->method('isWindowsOs')->will($this->returnValue(false));
148  $node->expects($this->once())->method('exists')->will($this->returnValue(false));
149  $statusArray = $node->getStatus();
151  $status = $statusArray[0];
152  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus::class, $status);
153  }
154 
158  public function getStatusReturnsArrayWithWarningStatusIfNodeIsNotALink()
159  {
161  $node = $this->getAccessibleMock(
162  \TYPO3\CMS\Install\FolderStructure\LinkNode::class,
163  ['isWindowsOs', 'getAbsolutePath', 'exists', 'isLink', 'getRelativePathBelowSiteRoot'],
164  [],
165  '',
166  false
167  );
168  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
169  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
170  $node->expects($this->once())->method('isLink')->will($this->returnValue(false));
171  $statusArray = $node->getStatus();
173  $status = $statusArray[0];
174  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\WarningStatus::class, $status);
175  }
176 
180  public function getStatusReturnsErrorStatusIfLinkTargetIsNotCorrect()
181  {
183  $node = $this->getAccessibleMock(
184  \TYPO3\CMS\Install\FolderStructure\LinkNode::class,
185  ['isWindowsOs', 'getAbsolutePath', 'exists', 'isLink', 'isTargetCorrect', 'getCurrentTarget', 'getRelativePathBelowSiteRoot'],
186  [],
187  '',
188  false
189  );
190  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
191  $node->expects($this->any())->method('getCurrentTarget')->will($this->returnValue(''));
192  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
193  $node->expects($this->any())->method('isLink')->will($this->returnValue(true));
194  $node->expects($this->once())->method('isLink')->will($this->returnValue(false));
195  $statusArray = $node->getStatus();
197  $status = $statusArray[0];
198  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus::class, $status);
199  }
200 
204  public function getStatusReturnsOkStatusIfLinkExistsAndTargetIsCorrect()
205  {
207  $node = $this->getAccessibleMock(
208  \TYPO3\CMS\Install\FolderStructure\LinkNode::class,
209  ['isWindowsOs', 'getAbsolutePath', 'exists', 'isLink', 'isTargetCorrect', 'getRelativePathBelowSiteRoot'],
210  [],
211  '',
212  false
213  );
214  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
215  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
216  $node->expects($this->once())->method('isLink')->will($this->returnValue(true));
217  $node->expects($this->once())->method('isTargetCorrect')->will($this->returnValue(true));
218  $statusArray = $node->getStatus();
220  $status = $statusArray[0];
221  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\OkStatus::class, $status);
222  }
223 
227  public function fixReturnsEmptyArray()
228  {
230  $node = $this->getAccessibleMock(
231  \TYPO3\CMS\Install\FolderStructure\LinkNode::class,
232  ['getRelativePathBelowSiteRoot'],
233  [],
234  '',
235  false
236  );
237  $statusArray = $node->fix();
238  $this->assertEmpty($statusArray);
239  }
240 
244  public function isLinkThrowsExceptionIfLinkNotExists()
245  {
246  $this->expectException(InvalidArgumentException::class);
247  $this->expectExceptionCode(1380556246);
249  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['exists'], [], '', false);
250  $node->expects($this->once())->method('exists')->will($this->returnValue(false));
251  $this->assertFalse($node->_call('isLink'));
252  }
253 
257  public function isLinkReturnsTrueIfNameIsLink()
258  {
260  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['exists', 'getAbsolutePath'], [], '', false);
261  $path = PATH_site . 'typo3temp/var/tests/' . $this->getUniqueId('link_');
262  $target = PATH_site . 'typo3temp/var/tests/' . $this->getUniqueId('linkTarget_');
263  touch($target);
264  symlink($target, $path);
265  $this->testFilesToDelete[] = $path;
266  $this->testFilesToDelete[] = $target;
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 
275  public function isFileReturnsFalseIfNameIsAFile()
276  {
278  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['exists', 'getAbsolutePath'], [], '', false);
279  $path = PATH_site . 'typo3temp/var/tests/' . $this->getUniqueId('file_');
280  touch($path);
281  $this->testFilesToDelete[] = $path;
282  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
283  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
284  $this->assertFalse($node->_call('isLink'));
285  }
286 
290  public function isTargetCorrectThrowsExceptionIfLinkNotExists()
291  {
292  $this->expectException(InvalidArgumentException::class);
293  $this->expectExceptionCode(1380556245);
295  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['exists'], [], '', false);
296  $node->expects($this->once())->method('exists')->will($this->returnValue(false));
297  $this->assertFalse($node->_call('isTargetCorrect'));
298  }
299 
303  public function isTargetCorrectThrowsExceptionIfNodeIsNotALink()
304  {
305  $this->expectException(InvalidArgumentException::class);
306  $this->expectExceptionCode(1380556247);
308  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['exists', 'isLink', 'getTarget'], [], '', false);
309  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
310  $node->expects($this->once())->method('isLink')->will($this->returnValue(false));
311  $this->assertTrue($node->_call('isTargetCorrect'));
312  }
313 
317  public function isTargetCorrectReturnsTrueIfNoExpectedLinkTargetIsSpecified()
318  {
320  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['exists', 'isLink', 'getTarget'], [], '', false);
321  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
322  $node->expects($this->any())->method('isLink')->will($this->returnValue(true));
323  $node->expects($this->once())->method('getTarget')->will($this->returnValue(''));
324  $this->assertTrue($node->_call('isTargetCorrect'));
325  }
326 
330  public function isTargetCorrectAcceptsATargetWithATrailingSlash()
331  {
333  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['exists', 'isLink', 'getCurrentTarget', 'getTarget'], [], '', false);
334  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
335  $node->expects($this->any())->method('isLink')->will($this->returnValue(true));
336  $node->expects($this->once())->method('getCurrentTarget')->will($this->returnValue('someLinkTarget/'));
337  $node->expects($this->once())->method('getTarget')->will($this->returnValue('someLinkTarget'));
338  $this->assertTrue($node->_call('isTargetCorrect'));
339  }
340 
345  public function isTargetCorrectReturnsTrueIfActualTargetIsIdenticalToSpecifiedTarget()
346  {
347  $path = PATH_site . 'typo3temp/var/tests/' . $this->getUniqueId('link_');
348  $target = PATH_site . 'typo3temp/var/tests/' . $this->getUniqueId('linkTarget_');
349  touch($target);
350  symlink($target, $path);
351  $this->testFilesToDelete[] = $path;
352  $this->testFilesToDelete[] = $target;
354  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class,
355  ['exists', 'isLink', 'getTarget', 'getAbsolutePath'],
356  [],
357  '',
358  false
359  );
360  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
361  $node->expects($this->any())->method('isLink')->will($this->returnValue(true));
362  $node->expects($this->once())->method('getTarget')->will($this->returnValue(str_replace('/', DIRECTORY_SEPARATOR, $target)));
363  $node->expects($this->once())->method('getAbsolutePath')->will($this->returnValue($path));
364  $this->assertTrue($node->_call('isTargetCorrect'));
365  }
366 
371  public function isTargetCorrectReturnsFalseIfActualTargetIsNotIdenticalToSpecifiedTarget()
372  {
373  $path = PATH_site . 'typo3temp/var/tests/' . $this->getUniqueId('link_');
374  $target = PATH_site . 'typo3temp/var/tests/' . $this->getUniqueId('linkTarget_');
375  touch($target);
376  symlink($target, $path);
377  $this->testFilesToDelete[] = $path;
378  $this->testFilesToDelete[] = $target;
380  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class,
381  ['exists', 'isLink', 'getTarget', 'getAbsolutePath'],
382  [],
383  '',
384  false
385  );
386  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
387  $node->expects($this->any())->method('isLink')->will($this->returnValue(true));
388  $node->expects($this->once())->method('getTarget')->will($this->returnValue('foo'));
389  $node->expects($this->once())->method('getAbsolutePath')->will($this->returnValue($path));
390  $this->assertFalse($node->_call('isTargetCorrect'));
391  }
392 }
getAccessibleMock($originalClassName, $methods=[], array $arguments=[], $mockClassName= '', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)