TYPO3 CMS  TYPO3_7-6
LinkNodeTest.php
Go to the documentation of this file.
1 <?php
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 
21 {
26  public function constructorThrowsExceptionIfParentIsNull()
27  {
29  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['dummy'], [], '', false);
30  $node->__construct([], null);
31  }
32 
37  public function constructorThrowsExceptionIfNameContainsForwardSlash()
38  {
39  $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, [], [], '', false);
41  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['dummy'], [], '', false);
42  $structure = [
43  'name' => 'foo/bar',
44  ];
45  $node->__construct($structure, $parent);
46  }
47 
51  public function constructorSetsParent()
52  {
53  $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, [], [], '', false);
55  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['dummy'], [], '', false);
56  $structure = [
57  'name' => 'foo',
58  ];
59  $node->__construct($structure, $parent);
60  $this->assertSame($parent, $node->_call('getParent'));
61  }
62 
66  public function constructorSetsName()
67  {
69  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['dummy'], [], '', false);
70  $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class, [], [], '', false);
71  $name = $this->getUniqueId('test_');
72  $node->__construct(['name' => $name], $parent);
73  $this->assertSame($name, $node->getName());
74  }
75 
79  public function constructorSetsTarget()
80  {
82  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['dummy'], [], '', false);
83  $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class, [], [], '', false);
84  $target = '../' . $this->getUniqueId('test_');
85  $node->__construct(['target' => $target], $parent);
86  $this->assertSame($target, $node->_call('getTarget'));
87  }
88 
92  public function getStatusReturnsArray()
93  {
95  $node = $this->getAccessibleMock(
96  \TYPO3\CMS\Install\FolderStructure\LinkNode::class,
97  ['isWindowsOs', 'getAbsolutePath', 'exists'],
98  [],
99  '',
100  false
101  );
102  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
103  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
104  $this->assertInternalType('array', $node->getStatus());
105  }
106 
110  public function getStatusReturnsArrayWithInformationStatusIfRunningOnWindows()
111  {
113  $node = $this->getAccessibleMock(
114  \TYPO3\CMS\Install\FolderStructure\LinkNode::class,
115  ['isWindowsOs', 'getAbsolutePath', 'exists'],
116  [],
117  '',
118  false
119  );
120  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
121  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
122  $node->expects($this->once())->method('isWindowsOs')->will($this->returnValue(true));
123  $statusArray = $node->getStatus();
125  $status = $statusArray[0];
126  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\InfoStatus::class, $status);
127  }
128 
132  public function getStatusReturnsArrayWithErrorStatusIfLinkNotExists()
133  {
135  $node = $this->getAccessibleMock(
136  \TYPO3\CMS\Install\FolderStructure\LinkNode::class,
137  ['isWindowsOs', 'getAbsolutePath', 'exists'],
138  [],
139  '',
140  false
141  );
142  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
143  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
144  $node->expects($this->any())->method('isWindowsOs')->will($this->returnValue(false));
145  $node->expects($this->once())->method('exists')->will($this->returnValue(false));
146  $statusArray = $node->getStatus();
148  $status = $statusArray[0];
149  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus::class, $status);
150  }
151 
155  public function getStatusReturnsArrayWithWarningStatusIfNodeIsNotALink()
156  {
158  $node = $this->getAccessibleMock(
159  \TYPO3\CMS\Install\FolderStructure\LinkNode::class,
160  ['isWindowsOs', 'getAbsolutePath', 'exists', 'isLink', 'getRelativePathBelowSiteRoot'],
161  [],
162  '',
163  false
164  );
165  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
166  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
167  $node->expects($this->once())->method('isLink')->will($this->returnValue(false));
168  $statusArray = $node->getStatus();
170  $status = $statusArray[0];
171  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\WarningStatus::class, $status);
172  }
173 
177  public function getStatusReturnsErrorStatusIfLinkTargetIsNotCorrect()
178  {
180  $node = $this->getAccessibleMock(
181  \TYPO3\CMS\Install\FolderStructure\LinkNode::class,
182  ['isWindowsOs', 'getAbsolutePath', 'exists', 'isLink', 'isTargetCorrect', 'getCurrentTarget', 'getRelativePathBelowSiteRoot'],
183  [],
184  '',
185  false
186  );
187  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
188  $node->expects($this->any())->method('getCurrentTarget')->will($this->returnValue(''));
189  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
190  $node->expects($this->any())->method('isLink')->will($this->returnValue(true));
191  $node->expects($this->once())->method('isLink')->will($this->returnValue(false));
192  $statusArray = $node->getStatus();
194  $status = $statusArray[0];
195  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus::class, $status);
196  }
197 
201  public function getStatusReturnsOkStatusIfLinkExistsAndTargetIsCorrect()
202  {
204  $node = $this->getAccessibleMock(
205  \TYPO3\CMS\Install\FolderStructure\LinkNode::class,
206  ['isWindowsOs', 'getAbsolutePath', 'exists', 'isLink', 'isTargetCorrect', 'getRelativePathBelowSiteRoot'],
207  [],
208  '',
209  false
210  );
211  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
212  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
213  $node->expects($this->once())->method('isLink')->will($this->returnValue(true));
214  $node->expects($this->once())->method('isTargetCorrect')->will($this->returnValue(true));
215  $statusArray = $node->getStatus();
217  $status = $statusArray[0];
218  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\OkStatus::class, $status);
219  }
220 
224  public function fixReturnsEmptyArray()
225  {
227  $node = $this->getAccessibleMock(
228  \TYPO3\CMS\Install\FolderStructure\LinkNode::class,
229  ['getRelativePathBelowSiteRoot'],
230  [],
231  '',
232  false
233  );
234  $statusArray = $node->fix();
235  $this->assertEmpty($statusArray);
236  }
237 
242  public function isLinkThrowsExceptionIfLinkNotExists()
243  {
245  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['exists'], [], '', false);
246  $node->expects($this->once())->method('exists')->will($this->returnValue(false));
247  $this->assertFalse($node->_call('isLink'));
248  }
249 
253  public function isLinkReturnsTrueIfNameIsLink()
254  {
255  if (TYPO3_OS === 'WIN') {
256  $this->markTestSkipped('Test not available on Windows OS.');
257  }
259  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['exists', 'getAbsolutePath'], [], '', false);
260  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('link_');
261  $target = PATH_site . $this->getUniqueId('linkTarget_');
262  symlink($target, $path);
263  $this->testFilesToDelete[] = $path;
264  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
265  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
266  $this->assertTrue($node->_call('isLink'));
267  }
268 
272  public function isFileReturnsFalseIfNameIsAFile()
273  {
274  if (TYPO3_OS === 'WIN') {
275  $this->markTestSkipped('Test not available on Windows OS.');
276  }
278  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['exists', 'getAbsolutePath'], [], '', false);
279  $path = PATH_site . 'typo3temp/' . $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 
291  public function isTargetCorrectThrowsExceptionIfLinkNotExists()
292  {
294  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['exists'], [], '', false);
295  $node->expects($this->once())->method('exists')->will($this->returnValue(false));
296  $this->assertFalse($node->_call('isTargetCorrect'));
297  }
298 
303  public function isTargetCorrectThrowsExceptionIfNodeIsNotALink()
304  {
306  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['exists', 'isLink', 'getTarget'], [], '', 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 
315  public function isTargetCorrectReturnsTrueIfNoExpectedLinkTargetIsSpecified()
316  {
318  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['exists', 'isLink', 'getTarget'], [], '', false);
319  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
320  $node->expects($this->any())->method('isLink')->will($this->returnValue(true));
321  $node->expects($this->once())->method('getTarget')->will($this->returnValue(''));
322  $this->assertTrue($node->_call('isTargetCorrect'));
323  }
324 
328  public function isTargetCorrectAcceptsATargetWithATrailingSlash()
329  {
331  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class, ['exists', 'isLink', 'getCurrentTarget', 'getTarget'], [], '', false);
332  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
333  $node->expects($this->any())->method('isLink')->will($this->returnValue(true));
334  $node->expects($this->once())->method('getCurrentTarget')->will($this->returnValue('someLinkTarget/'));
335  $node->expects($this->once())->method('getTarget')->will($this->returnValue('someLinkTarget'));
336  $this->assertTrue($node->_call('isTargetCorrect'));
337  }
338 
343  public function isTargetCorrectReturnsTrueIfActualTargetIsIdenticalToSpecifiedTarget()
344  {
345  if (TYPO3_OS === 'WIN') {
346  $this->markTestSkipped('Test not available on Windows OS.');
347  }
348  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('link_');
349  $target = $this->getUniqueId('linkTarget_');
350  symlink($target, $path);
351  $this->testFilesToDelete[] = $path;
353  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\LinkNode::class,
354  ['exists', 'isLink', 'getTarget', 'getAbsolutePath'],
355  [],
356  '',
357  false
358  );
359  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
360  $node->expects($this->any())->method('isLink')->will($this->returnValue(true));
361  $node->expects($this->once())->method('getTarget')->will($this->returnValue($target));
362  $node->expects($this->once())->method('getAbsolutePath')->will($this->returnValue($path));
363  $this->assertTrue($node->_call('isTargetCorrect'));
364  }
365 
370  public function isTargetCorrectReturnsFalseIfActualTargetIsNotIdenticalToSpecifiedTarget()
371  {
372  if (TYPO3_OS === 'WIN') {
373  $this->markTestSkipped('Test not available on Windows OS.');
374  }
375  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('link_');
376  $target = $this->getUniqueId('linkTarget_');
377  symlink($target, $path);
378  $this->testFilesToDelete[] = $path;
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)