TYPO3 CMS  TYPO3_6-2
LinkNodeTest.php
Go to the documentation of this file.
1 <?php
3 
21 
25  protected $testNodesToDelete = array();
26 
30  public function tearDown() {
31  foreach ($this->testNodesToDelete as $node) {
32  if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($node, PATH_site . 'typo3temp/')) {
34  }
35  }
36  parent::tearDown();
37  }
38 
43  public function constructorThrowsExceptionIfParentIsNull() {
45  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode', array('dummy'), array(), '', FALSE);
46  $node->__construct(array(), NULL);
47  }
48 
53  public function constructorThrowsExceptionIfNameContainsForwardSlash() {
54  $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(), '', FALSE);
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 
66  public function constructorSetsParent() {
67  $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(), '', FALSE);
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 
80  public function constructorSetsName() {
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 = $this->getUniqueId('test_');
85  $node->__construct(array('name' => $name), $parent);
86  $this->assertSame($name, $node->getName());
87  }
88 
92  public function constructorSetsTarget() {
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 = '../' . $this->getUniqueId('test_');
97  $node->__construct(array('target' => $target), $parent);
98  $this->assertSame($target, $node->_call('getTarget'));
99  }
100 
104  public function getStatusReturnsArray() {
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/' . $this->getUniqueId('dir_');
114  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
115  $this->assertInternalType('array', $node->getStatus());
116  }
117 
121  public function getStatusReturnsArrayWithInformationStatusIfRunningOnWindows() {
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/' . $this->getUniqueId('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();
135  $status = $statusArray[0];
136  $this->assertInstanceOf('TYPO3\\CMS\\Install\\Status\\InfoStatus', $status);
137  }
138 
142  public function getStatusReturnsArrayWithErrorStatusIfLinkNotExists() {
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/' . $this->getUniqueId('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();
157  $status = $statusArray[0];
158  $this->assertInstanceOf('TYPO3\\CMS\\Install\\Status\\ErrorStatus', $status);
159  }
160 
164  public function getStatusReturnsArrayWithWarningStatusIfNodeIsNotALink() {
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();
178  $status = $statusArray[0];
179  $this->assertInstanceOf('\TYPO3\CMS\Install\Status\WarningStatus', $status);
180  }
181 
185  public function getStatusReturnsErrorStatusIfLinkTargetIsNotCorrect() {
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();
201  $status = $statusArray[0];
202  $this->assertInstanceOf('\TYPO3\CMS\Install\Status\ErrorStatus', $status);
203  }
204 
208  public function getStatusReturnsOkStatusIfLinkExistsAndTargetIsCorrect() {
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();
223  $status = $statusArray[0];
224  $this->assertInstanceOf('\TYPO3\CMS\Install\Status\OkStatus', $status);
225  }
226 
230  public function fixReturnsEmptyArray() {
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 
247  public function isLinkThrowsExceptionIfLinkNotExists() {
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 
257  public function isLinkReturnsTrueIfNameIsLink() {
258  if (TYPO3_OS === 'WIN') {
259  $this->markTestSkipped('Test not available on Windows OS.');
260  }
262  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
263  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('link_');
264  $target = PATH_site . $this->getUniqueId('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 
275  public function isFileReturnsFalseIfNameIsAFile() {
276  if (TYPO3_OS === 'WIN') {
277  $this->markTestSkipped('Test not available on Windows OS.');
278  }
280  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
281  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('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 
293  public function isTargetCorrectThrowsExceptionIfLinkNotExists() {
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 
304  public function isTargetCorrectThrowsExceptionIfNodeIsNotALink() {
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 
315  public function isTargetCorrectReturnsTrueIfNoExpectedLinkTargetIsSpecified() {
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 
327  public function isTargetCorrectAcceptsATargetWithATrailingSlash() {
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 
340  public function isTargetCorrectReturnsTrueIfActualTargetIsIdenticalToSpecifiedTarget() {
341  if (TYPO3_OS === 'WIN') {
342  $this->markTestSkipped('Test not available on Windows OS.');
343  }
344  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('link_');
345  $target = $this->getUniqueId('linkTarget_');
346  symlink($target, $path);
347  $this->testNodesToDelete[] = $path;
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 
365  public function isTargetCorrectReturnsFalseIfActualTargetIsNotIdenticalToSpecifiedTarget() {
366  if (TYPO3_OS === 'WIN') {
367  $this->markTestSkipped('Test not available on Windows OS.');
368  }
369  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('link_');
370  $target = $this->getUniqueId('linkTarget_');
371  symlink($target, $path);
372  $this->testNodesToDelete[] = $path;
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 }
static rmdir($path, $removeNonEmpty=FALSE)
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)