TYPO3 CMS  TYPO3_6-2
FileNodeTest.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\\FileNode', 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\\FileNode', 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\\FileNode', 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 constructorSetsTargetPermission() {
81  $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(), '', FALSE);
83  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('dummy'), array(), '', FALSE);
84  $targetPermission = '0660';
85  $structure = array(
86  'name' => 'foo',
87  'targetPermission' => $targetPermission,
88  );
89  $node->__construct($structure, $parent);
90  $this->assertSame($targetPermission, $node->_call('getTargetPermission'));
91  }
92 
96  public function constructorSetsName() {
98  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('dummy'), array(), '', FALSE);
99  $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\RootNodeInterface', array(), array(), '', FALSE);
100  $name = $this->getUniqueId('test_');
101  $node->__construct(array('name' => $name), $parent);
102  $this->assertSame($name, $node->getName());
103  }
104 
109  public function constructorThrowsExceptionIfBothTargetContentAndTargetContentFileAreSet() {
111  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('dummy'), array(), '', FALSE);
112  $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\RootNodeInterface', array(), array(), '', FALSE);
113  $structure = array(
114  'name' => 'foo',
115  'targetContent' => 'foo',
116  'targetContentFile' => 'aPath',
117  );
118  $node->__construct($structure, $parent);
119  }
120 
124  public function constructorSetsTargetContent() {
126  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('dummy'), array(), '', FALSE);
127  $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\RootNodeInterface', array(), array(), '', FALSE);
128  $targetContent = $this->getUniqueId('content_');
129  $structure = array(
130  'name' => 'foo',
131  'targetContent' => $targetContent,
132  );
133  $node->__construct($structure, $parent);
134  $this->assertSame($targetContent, $node->_get('targetContent'));
135  }
136 
140  public function constructorSetsTargetContentToContentOfTargetContentFile() {
142  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('dummy'), array(), '', FALSE);
143  $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\RootNodeInterface', array(), array(), '', FALSE);
144  $targetFile = PATH_site . 'typo3temp/' . $this->getUniqueId('test_');
145  $targetContent = $this->getUniqueId('content_');
146  file_put_contents($targetFile, $targetContent);
147  $this->testNodesToDelete[] = $targetFile;
148  $structure = array(
149  'name' => 'foo',
150  'targetContentFile' => $targetFile,
151  );
152  $node->__construct($structure, $parent);
153  $this->assertSame($targetContent, $node->_get('targetContent'));
154  }
155 
160  public function constructorThrowsExceptionIfTargetContentFileDoesNotExist() {
162  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('dummy'), array(), '', FALSE);
163  $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\RootNodeInterface', array(), array(), '', FALSE);
164  $targetFile = PATH_site . 'typo3temp/' . $this->getUniqueId('test_');
165  $structure = array(
166  'name' => 'foo',
167  'targetContentFile' => $targetFile,
168  );
169  $node->__construct($structure, $parent);
170  }
171 
175  public function targetContentIsNullIfNotGiven() {
177  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('dummy'), array(), '', FALSE);
178  $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\RootNodeInterface', array(), array(), '', FALSE);
179  $structure = array(
180  'name' => 'foo',
181  );
182  $node->__construct($structure, $parent);
183  $this->assertNull($node->_get('targetContent'));
184  }
185 
189  public function getStatusReturnsArray() {
191  $node = $this->getAccessibleMock(
192  'TYPO3\\CMS\\Install\\FolderStructure\\FileNode',
193  array('getAbsolutePath', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'),
194  array(),
195  '',
196  FALSE
197  );
198  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
199  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
200  $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
201  $node->expects($this->any())->method('isFile')->will($this->returnValue(TRUE));
202  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
203  $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
204  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(TRUE));
205  $this->assertInternalType('array', $node->getStatus());
206  }
207 
211  public function getStatusReturnsArrayWithWarningStatusIFileNotExists() {
213  $node = $this->getAccessibleMock(
214  'TYPO3\\CMS\\Install\\FolderStructure\\FileNode',
215  array('getAbsolutePath', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'),
216  array(),
217  '',
218  FALSE
219  );
220  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
221  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
222  $node->expects($this->any())->method('exists')->will($this->returnValue(FALSE));
223  $node->expects($this->any())->method('isFile')->will($this->returnValue(TRUE));
224  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
225  $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
226  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(TRUE));
227  $statusArray = $node->getStatus();
229  $status = $statusArray[0];
230  $this->assertInstanceOf('\TYPO3\CMS\Install\Status\WarningStatus', $status);
231  }
232 
236  public function getStatusReturnsArrayWithErrorStatusIfNodeIsNotAFile() {
238  $node = $this->getAccessibleMock(
239  'TYPO3\\CMS\\Install\\FolderStructure\\FileNode',
240  array('getAbsolutePath', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'),
241  array(),
242  '',
243  FALSE
244  );
245  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
246  touch($path);
247  $this->testNodesToDelete[] = $path;
248  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
249  $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
250  $node->expects($this->any())->method('isFile')->will($this->returnValue(FALSE));
251  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
252  $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
253  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(TRUE));
254  $statusArray = $node->getStatus();
256  $status = $statusArray[0];
257  $this->assertInstanceOf('\TYPO3\CMS\Install\Status\ErrorStatus', $status);
258  }
259 
263  public function getStatusReturnsArrayNoticeStatusIfFileExistsButIsNotWritable() {
265  $node = $this->getAccessibleMock(
266  'TYPO3\\CMS\\Install\\FolderStructure\\FileNode',
267  array('getAbsolutePath', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'),
268  array(),
269  '',
270  FALSE
271  );
272  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
273  touch($path);
274  $this->testNodesToDelete[] = $path;
275  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
276  $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
277  $node->expects($this->any())->method('isFile')->will($this->returnValue(TRUE));
278  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
279  $node->expects($this->any())->method('isWritable')->will($this->returnValue(FALSE));
280  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(TRUE));
281  $statusArray = $node->getStatus();
283  $status = $statusArray[0];
284  $this->assertInstanceOf('\TYPO3\CMS\Install\Status\NoticeStatus', $status);
285  }
286 
290  public function getStatusReturnsArrayWithNoticeStatusIfFileExistsButPermissionAreNotCorrect() {
292  $node = $this->getAccessibleMock(
293  'TYPO3\\CMS\\Install\\FolderStructure\\FileNode',
294  array('getAbsolutePath', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'),
295  array(),
296  '',
297  FALSE
298  );
299  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
300  touch ($path);
301  $this->testNodesToDelete[] = $path;
302  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
303  $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
304  $node->expects($this->any())->method('isFile')->will($this->returnValue(TRUE));
305  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(FALSE));
306  $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
307  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(TRUE));
308  $statusArray = $node->getStatus();
310  $status = $statusArray[0];
311  $this->assertInstanceOf('\TYPO3\CMS\Install\Status\NoticeStatus', $status);
312  }
313 
317  public function getStatusReturnsArrayWithNoticeStatusIfFileExistsButContentIsNotCorrect() {
319  $node = $this->getAccessibleMock(
320  'TYPO3\\CMS\\Install\\FolderStructure\\FileNode',
321  array('getAbsolutePath', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'),
322  array(),
323  '',
324  FALSE
325  );
326  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
327  touch($path);
328  $this->testNodesToDelete[] = $path;
329  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
330  $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
331  $node->expects($this->any())->method('isFile')->will($this->returnValue(TRUE));
332  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
333  $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
334  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(FALSE));
335  $statusArray = $node->getStatus();
337  $status = $statusArray[0];
338  $this->assertInstanceOf('\TYPO3\CMS\Install\Status\NoticeStatus', $status);
339  }
340 
344  public function getStatusReturnsArrayWithOkStatusIfFileExistsAndPermissionAreCorrect() {
346  $node = $this->getAccessibleMock(
347  'TYPO3\\CMS\\Install\\FolderStructure\\FileNode',
348  array('getAbsolutePath', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'),
349  array(),
350  '',
351  FALSE
352  );
353  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
354  touch($path);
355  $this->testNodesToDelete[] = $path;
356  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
357  $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
358  $node->expects($this->any())->method('isFile')->will($this->returnValue(TRUE));
359  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
360  $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
361  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(TRUE));
362  $statusArray = $node->getStatus();
364  $status = $statusArray[0];
365  $this->assertInstanceOf('\TYPO3\CMS\Install\Status\OkStatus', $status);
366  }
367 
371  public function fixCallsFixSelfAndReturnsItsResult() {
373  $node = $this->getAccessibleMock(
374  'TYPO3\\CMS\\Install\\FolderStructure\\FileNode',
375  array('fixSelf'),
376  array(),
377  '',
378  FALSE
379  );
380  $uniqueReturn = array($this->getUniqueId('foo_'));
381  $node->expects($this->once())->method('fixSelf')->will($this->returnValue($uniqueReturn));
382  $this->assertSame($uniqueReturn, $node->fix());
383  }
384 
388  public function fixSelfCallsCreateFileIfFileDoesNotExistAndReturnsResult() {
390  $node = $this->getAccessibleMock(
391  'TYPO3\\CMS\\Install\\FolderStructure\\FileNode',
392  array('exists', 'createFile', 'setContent', 'getAbsolutePath', 'isFile', 'isPermissionCorrect'),
393  array(),
394  '',
395  FALSE
396  );
397  $node->expects($this->any())->method('exists')->will($this->returnValue(FALSE));
398  $node->expects($this->any())->method('isFile')->will($this->returnValue(TRUE));
399  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
400  $uniqueReturn = $this->getUniqueId();
401  $node->expects($this->once())->method('createFile')->will($this->returnValue($uniqueReturn));
402  $actualReturn = $node->_call('fixSelf');
403  $actualReturn = $actualReturn[0];
404  $this->assertSame($uniqueReturn, $actualReturn);
405  }
406 
410  public function fixSelfCallsSetsContentIfFileCreationWasSuccessfulAndTargetContentIsNotNullAndReturnsResult() {
412  $node = $this->getAccessibleMock(
413  'TYPO3\\CMS\\Install\\FolderStructure\\FileNode',
414  array('exists', 'createFile', 'setContent', 'getAbsolutePath', 'isFile', 'isPermissionCorrect'),
415  array(),
416  '',
417  FALSE
418  );
419  $node->expects($this->any())->method('exists')->will($this->returnValue(FALSE));
420  $node->expects($this->any())->method('isFile')->will($this->returnValue(TRUE));
421  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
422  $uniqueReturn = $this->getUniqueId();
423  $createFileStatus = $this->getMock('TYPO3\\CMS\\Install\\Status\\OkStatus', array(), array(), '', FALSE);
424  $node->expects($this->any())->method('createFile')->will($this->returnValue($createFileStatus));
425  $node->_set('targetContent', 'foo');
426  $node->expects($this->once())->method('setContent')->will($this->returnValue($uniqueReturn));
427  $actualReturn = $node->_call('fixSelf');
428  $actualReturn = $actualReturn[1];
429  $this->assertSame($uniqueReturn, $actualReturn);
430  }
431 
435  public function fixSelfDoesNotCallSetContentIfFileCreationFailed() {
437  $node = $this->getAccessibleMock(
438  'TYPO3\\CMS\\Install\\FolderStructure\\FileNode',
439  array('exists', 'createFile', 'setContent', 'getAbsolutePath', 'isFile', 'isPermissionCorrect'),
440  array(),
441  '',
442  FALSE
443  );
444  $node->expects($this->any())->method('exists')->will($this->returnValue(FALSE));
445  $node->expects($this->any())->method('isFile')->will($this->returnValue(TRUE));
446  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
447  $createFileStatus = $this->getMock('TYPO3\\CMS\\Install\\Status\\ErrorStatus', array(), array(), '', FALSE);
448  $node->expects($this->any())->method('createFile')->will($this->returnValue($createFileStatus));
449  $node->_set('targetContent', 'foo');
450  $node->expects($this->never())->method('setContent');
451  $node->_call('fixSelf');
452  }
453 
457  public function fixSelfDoesNotCallSetContentIfFileTargetContentIsNull() {
459  $node = $this->getAccessibleMock(
460  'TYPO3\\CMS\\Install\\FolderStructure\\FileNode',
461  array('exists', 'createFile', 'setContent', 'getAbsolutePath', 'isFile', 'isPermissionCorrect'),
462  array(),
463  '',
464  FALSE
465  );
466  $node->expects($this->any())->method('exists')->will($this->returnValue(FALSE));
467  $node->expects($this->any())->method('isFile')->will($this->returnValue(TRUE));
468  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
469  $createFileStatus = $this->getMock('TYPO3\\CMS\\Install\\Status\\OkStatus', array(), array(), '', FALSE);
470  $node->expects($this->any())->method('createFile')->will($this->returnValue($createFileStatus));
471  $node->_set('targetContent', NULL);
472  $node->expects($this->never())->method('setContent');
473  $node->_call('fixSelf');
474  }
475 
479  public function fixSelfReturnsErrorStatusIfNodeExistsButIsNotAFileAndReturnsResult() {
481  $node = $this->getAccessibleMock(
482  'TYPO3\\CMS\\Install\\FolderStructure\\FileNode',
483  array('exists', 'createFile', 'getAbsolutePath', 'isFile', 'isPermissionCorrect', 'fixPermission'),
484  array(),
485  '',
486  FALSE
487  );
488  $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
489  $node->expects($this->any())->method('isFile')->will($this->returnValue(TRUE));
490  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(FALSE));
491  $uniqueReturn = $this->getUniqueId();
492  $node->expects($this->once())->method('fixPermission')->will($this->returnValue($uniqueReturn));
493  $this->assertSame(array($uniqueReturn), $node->_call('fixSelf'));
494  }
495 
499  public function fixSelfCallsFixPermissionIfFileExistsButPermissionAreWrong() {
501  $node = $this->getAccessibleMock(
502  'TYPO3\\CMS\\Install\\FolderStructure\\FileNode',
503  array('exists', 'createFile', 'getAbsolutePath', 'isFile', 'isPermissionCorrect', 'getRelativePathBelowSiteRoot'),
504  array(),
505  '',
506  FALSE
507  );
508  $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
509  $node->expects($this->once())->method('isFile')->will($this->returnValue(FALSE));
510  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
511  $resultArray = $node->_call('fixSelf');
512  $this->assertInstanceOf('TYPO3\\CMS\Install\\Status\\StatusInterface', $resultArray[0]);
513  }
514 
519  $node = $this->getAccessibleMock(
520  'TYPO3\\CMS\\Install\\FolderStructure\\FileNode',
521  array('exists', 'isFile', 'isPermissionCorrect'),
522  array(),
523  '',
524  FALSE
525  );
526  $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
527  $node->expects($this->any())->method('isFile')->will($this->returnValue(TRUE));
528  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
529  $this->assertInternalType('array', $node->_call('fixSelf'));
530  }
531 
536  public function createFileThrowsExceptionIfNodeExists() {
538  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
539  $node->expects($this->once())->method('getAbsolutePath')->will($this->returnValue(''));
540  $node->expects($this->once())->method('exists')->will($this->returnValue(TRUE));
541  $node->_call('createFile');
542  }
543 
547  public function createFileReturnsOkStatusIfFileWasCreated() {
549  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
550  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('file_');
551  $this->testNodesToDelete[] = $path;
552  $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
553  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
554  $this->assertInstanceOf('TYPO3\\CMS\Install\\Status\\StatusInterface', $node->_call('createFile'));
555  }
556 
560  public function createFileCreatesFile() {
562  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
563  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('file_');
564  $this->testNodesToDelete[] = $path;
565  $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
566  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
567  $node->_call('createFile');
568  $this->assertTrue(is_file($path));
569  }
570 
574  public function createFileReturnsErrorStatusIfFileWasNotCreated() {
575  if (TYPO3_OS === 'WIN') {
576  $this->markTestSkipped('Test not available on Windows OS.');
577  }
579  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('exists', 'getAbsolutePath'), array(), '', FALSE);
580  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('root_');
581  mkdir($path);
582  chmod($path, 02550);
583  $subPath = $path . '/' . $this->getUniqueId('file_');
584  $this->testNodesToDelete[] = $path;
585  $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE));
586  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath));
587  $this->assertInstanceOf('TYPO3\\CMS\Install\\Status\\StatusInterface', $node->_call('createFile'));
588  }
589 
594  public function isContentCorrectThrowsExceptionIfTargetIsNotAFile() {
596  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getAbsolutePath'), array(), '', FALSE);
597  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
598  mkdir($path);
599  $this->testNodesToDelete[] = $path;
600  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
601  $node->_call('isContentCorrect');
602  }
603 
607  public function isContentCorrectReturnsTrueIfTargetContentPropertyIsNull() {
609  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getAbsolutePath'), array(), '', FALSE);
610  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('file_');
611  touch($path);
612  $this->testNodesToDelete[] = $path;
613  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
614  $node->_set('targetContent', NULL);
615  $this->assertTrue($node->_call('isContentCorrect'));
616  }
617 
621  public function isContentCorrectReturnsTrueIfTargetContentEqualsCurrentContent() {
623  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getAbsolutePath'), array(), '', FALSE);
624  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('file_');
625  $content = $this->getUniqueId('content_');
626  file_put_contents($path, $content);
627  $this->testNodesToDelete[] = $path;
628  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
629  $node->_set('targetContent', $content);
630  $this->assertTrue($node->_call('isContentCorrect'));
631  }
632 
636  public function isContentCorrectReturnsFalseIfTargetContentNotEqualsCurrentContent() {
638  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getAbsolutePath'), array(), '', FALSE);
639  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('file_');
640  $content = $this->getUniqueId('content1_');
641  $targetContent = $this->getUniqueId('content2_');
642  file_put_contents($path, $content);
643  $this->testNodesToDelete[] = $path;
644  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
645  $node->_set('targetContent', $targetContent);
646  $this->assertFalse($node->_call('isContentCorrect'));
647  }
648 
652  public function isPermissionCorrectReturnsTrueIfTargetPermissionAndCurrentPermissionAreIdentical() {
653  $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\NodeInterface', array(), array(), '', FALSE);
655  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getCurrentPermission', 'isWindowsOs'), array(), '', FALSE);
656  $node->expects($this->any())->method('isWindowsOs')->will($this->returnValue(FALSE));
657  $node->expects($this->any())->method('getCurrentPermission')->will($this->returnValue('0664'));
658  $targetPermission = '0664';
659  $structure = array(
660  'name' => 'foo',
661  'targetPermission' => $targetPermission,
662  );
663  $node->__construct($structure, $parent);
664  $this->assertTrue($node->_call('isPermissionCorrect'));
665  }
666 
671  public function setContentThrowsExceptionIfTargetIsNotAFile() {
673  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getAbsolutePath'), array(), '', FALSE);
674  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
675  mkdir($path);
676  $this->testNodesToDelete[] = $path;
677  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
678  $node->_set('targetContent', 'foo');
679  $node->_call('setContent');
680  }
681 
686  public function setContentThrowsExceptionIfTargetContentIsNull() {
688  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getAbsolutePath'), array(), '', FALSE);
689  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('file_');
690  touch($path);
691  $this->testNodesToDelete[] = $path;
692  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
693  $node->_set('targetContent', NULL);
694  $node->_call('setContent');
695  }
696 
700  public function setContentSetsContentToFile() {
702  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getAbsolutePath', 'getRelativePathBelowSiteRoot'), array(), '', FALSE);
703  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('file_');
704  touch($path);
705  $this->testNodesToDelete[] = $path;
706  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
707  $targetContent = $this->getUniqueId('content_');
708  $node->_set('targetContent', $targetContent);
709  $node->_call('setContent');
710  $resultContent = file_get_contents($path);
711  $this->assertSame($targetContent, $resultContent);
712  }
713 
717  public function setContentReturnsOkStatusIfContentWasSuccessfullySet() {
719  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getAbsolutePath', 'getRelativePathBelowSiteRoot'), array(), '', FALSE);
720  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('file_');
721  touch($path);
722  $this->testNodesToDelete[] = $path;
723  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
724  $targetContent = $this->getUniqueId('content_');
725  $node->_set('targetContent', $targetContent);
726  $this->assertInstanceOf('TYPO3\\CMS\\Install\\Status\\OkStatus', $node->_call('setContent'));
727  }
728 
732  public function setContentReturnsErrorStatusIfContentCanNotBeSetSet() {
733  if (TYPO3_OS === 'WIN') {
734  $this->markTestSkipped('Test not available on Windows OS.');
735  }
736  if (function_exists('posix_getegid') && posix_getegid() === 0) {
737  $this->markTestSkipped('Test skipped if run on linux as root');
738  }
740  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getAbsolutePath', 'getRelativePathBelowSiteRoot'), array(), '', FALSE);
741  $dir = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
742  mkdir($dir);
743  $file = $dir . '/' . $this->getUniqueId('file_');
744  touch($file);
745  chmod($file, 0440);
746  $this->testNodesToDelete[] = $dir;
747  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($file));
748  $targetContent = $this->getUniqueId('content_');
749  $node->_set('targetContent', $targetContent);
750  $this->assertInstanceOf('TYPO3\\CMS\\Install\\Status\\ErrorStatus', $node->_call('setContent'));
751  }
752 
756  public function isFileReturnsTrueIfNameIsFile() {
758  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getAbsolutePath'), array(), '', FALSE);
759  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('file_');
760  touch($path);
761  $this->testNodesToDelete[] = $path;
762  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
763  $this->assertTrue($node->_call('isFile'));
764  }
765 
769  public function isFileReturnsFalseIfNameIsALinkFile() {
770  if (TYPO3_OS === 'WIN') {
771  $this->markTestSkipped('Test not available on Windows OS.');
772  }
774  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getAbsolutePath'), array(), '', FALSE);
775  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('root_');
777  $this->testNodesToDelete[] = $path;
778  $link = $this->getUniqueId('link_');
779  $file = $this->getUniqueId('file_');
780  touch($path . '/' . $file);
781  symlink($path . '/' . $file, $path . '/' . $link);
782  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path . '/' . $link));
783  $this->assertFalse($node->_call('isFile'));
784  }
785 }
static mkdir_deep($directory, $deepDirectory='')
static rmdir($path, $removeNonEmpty=FALSE)
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)