TYPO3 CMS  TYPO3_7-6
FileNodeTest.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\FileNode::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\FileNode::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\FileNode::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 constructorSetsTargetPermission()
67  {
68  $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, [], [], '', false);
70  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['dummy'], [], '', false);
71  $targetPermission = '0660';
72  $structure = [
73  'name' => 'foo',
74  'targetPermission' => $targetPermission,
75  ];
76  $node->__construct($structure, $parent);
77  $this->assertSame($targetPermission, $node->_call('getTargetPermission'));
78  }
79 
83  public function constructorSetsName()
84  {
86  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['dummy'], [], '', false);
87  $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class, [], [], '', false);
88  $name = $this->getUniqueId('test_');
89  $node->__construct(['name' => $name], $parent);
90  $this->assertSame($name, $node->getName());
91  }
92 
97  public function constructorThrowsExceptionIfBothTargetContentAndTargetContentFileAreSet()
98  {
100  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['dummy'], [], '', false);
101  $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class, [], [], '', false);
102  $structure = [
103  'name' => 'foo',
104  'targetContent' => 'foo',
105  'targetContentFile' => 'aPath',
106  ];
107  $node->__construct($structure, $parent);
108  }
109 
113  public function constructorSetsTargetContent()
114  {
116  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['dummy'], [], '', false);
117  $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class, [], [], '', false);
118  $targetContent = $this->getUniqueId('content_');
119  $structure = [
120  'name' => 'foo',
121  'targetContent' => $targetContent,
122  ];
123  $node->__construct($structure, $parent);
124  $this->assertSame($targetContent, $node->_get('targetContent'));
125  }
126 
130  public function constructorSetsTargetContentToContentOfTargetContentFile()
131  {
133  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['dummy'], [], '', false);
134  $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class, [], [], '', false);
135  $targetFile = $this->getVirtualTestFilePath('test_');
136  $targetContent = $this->getUniqueId('content_');
137  file_put_contents($targetFile, $targetContent);
138  $structure = [
139  'name' => 'foo',
140  'targetContentFile' => $targetFile,
141  ];
142  $node->__construct($structure, $parent);
143  $this->assertSame($targetContent, $node->_get('targetContent'));
144  }
145 
150  public function constructorThrowsExceptionIfTargetContentFileDoesNotExist()
151  {
153  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['dummy'], [], '', false);
154  $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class, [], [], '', false);
155  $targetFile = $this->getVirtualTestFilePath('test_');
156  $structure = [
157  'name' => 'foo',
158  'targetContentFile' => $targetFile,
159  ];
160  $node->__construct($structure, $parent);
161  }
162 
166  public function targetContentIsNullIfNotGiven()
167  {
169  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['dummy'], [], '', false);
170  $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class, [], [], '', false);
171  $structure = [
172  'name' => 'foo',
173  ];
174  $node->__construct($structure, $parent);
175  $this->assertNull($node->_get('targetContent'));
176  }
177 
181  public function getStatusReturnsArray()
182  {
184  $node = $this->getAccessibleMock(
185  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
186  ['getAbsolutePath', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
187  [],
188  '',
189  false
190  );
191  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
192  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
193  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
194  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
195  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
196  $node->expects($this->any())->method('isWritable')->will($this->returnValue(true));
197  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(true));
198  $this->assertInternalType('array', $node->getStatus());
199  }
200 
204  public function getStatusReturnsArrayWithWarningStatusIFileNotExists()
205  {
207  $node = $this->getAccessibleMock(
208  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
209  ['getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
210  [],
211  '',
212  false
213  );
214  $path = $this->getVirtualTestDir('dir_');
215  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
216  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
217  $node->expects($this->any())->method('exists')->will($this->returnValue(false));
218  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
219  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
220  $node->expects($this->any())->method('isWritable')->will($this->returnValue(true));
221  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(true));
222  $statusArray = $node->getStatus();
224  $status = $statusArray[0];
225  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\WarningStatus::class, $status);
226  }
227 
231  public function getStatusReturnsArrayWithErrorStatusIfNodeIsNotAFile()
232  {
234  $node = $this->getAccessibleMock(
235  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
236  ['getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
237  [],
238  '',
239  false
240  );
241  $path = $this->getVirtualTestFilePath('dir_');
242  touch($path);
243  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
244  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
245  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
246  $node->expects($this->any())->method('isFile')->will($this->returnValue(false));
247  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
248  $node->expects($this->any())->method('isWritable')->will($this->returnValue(true));
249  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(true));
250  $statusArray = $node->getStatus();
252  $status = $statusArray[0];
253  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus::class, $status);
254  }
255 
259  public function getStatusReturnsArrayNoticeStatusIfFileExistsButIsNotWritable()
260  {
262  $node = $this->getAccessibleMock(
263  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
264  ['getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
265  [],
266  '',
267  false
268  );
269  $path = $this->getVirtualTestFilePath('dir_');
270  touch($path);
271  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
272  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
273  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
274  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
275  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
276  $node->expects($this->any())->method('isWritable')->will($this->returnValue(false));
277  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(true));
278  $statusArray = $node->getStatus();
280  $status = $statusArray[0];
281  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\NoticeStatus::class, $status);
282  }
283 
287  public function getStatusReturnsArrayWithNoticeStatusIfFileExistsButPermissionAreNotCorrect()
288  {
290  $node = $this->getAccessibleMock(
291  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
292  ['getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
293  [],
294  '',
295  false
296  );
297  $path = $this->getVirtualTestFilePath('dir_');
298  touch($path);
299  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
300  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
301  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
302  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
303  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(false));
304  $node->expects($this->any())->method('isWritable')->will($this->returnValue(true));
305  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(true));
306  $statusArray = $node->getStatus();
308  $status = $statusArray[0];
309  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\NoticeStatus::class, $status);
310  }
311 
315  public function getStatusReturnsArrayWithNoticeStatusIfFileExistsButContentIsNotCorrect()
316  {
318  $node = $this->getAccessibleMock(
319  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
320  ['getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
321  [],
322  '',
323  false
324  );
325  $path = $this->getVirtualTestFilePath('dir_');
326  touch($path);
327  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
328  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
329  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
330  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
331  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
332  $node->expects($this->any())->method('isWritable')->will($this->returnValue(true));
333  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(false));
334  $statusArray = $node->getStatus();
336  $status = $statusArray[0];
337  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\NoticeStatus::class, $status);
338  }
339 
343  public function getStatusReturnsArrayWithOkStatusIfFileExistsAndPermissionAreCorrect()
344  {
346  $node = $this->getAccessibleMock(
347  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
348  ['getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
349  [],
350  '',
351  false
352  );
353  $path = $this->getVirtualTestFilePath('dir_');
354  touch($path);
355  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
356  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->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::class, $status);
366  }
367 
371  public function fixCallsFixSelfAndReturnsItsResult()
372  {
374  $node = $this->getAccessibleMock(
375  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
376  ['fixSelf'],
377  [],
378  '',
379  false
380  );
381  $uniqueReturn = [$this->getUniqueId('foo_')];
382  $node->expects($this->once())->method('fixSelf')->will($this->returnValue($uniqueReturn));
383  $this->assertSame($uniqueReturn, $node->fix());
384  }
385 
389  public function fixSelfCallsCreateFileIfFileDoesNotExistAndReturnsResult()
390  {
392  $node = $this->getAccessibleMock(
393  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
394  ['exists', 'createFile', 'setContent', 'getAbsolutePath', 'isFile', 'isPermissionCorrect'],
395  [],
396  '',
397  false
398  );
399  $node->expects($this->any())->method('exists')->will($this->returnValue(false));
400  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
401  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
402  $uniqueReturn = $this->getUniqueId();
403  $node->expects($this->once())->method('createFile')->will($this->returnValue($uniqueReturn));
404  $actualReturn = $node->_call('fixSelf');
405  $actualReturn = $actualReturn[0];
406  $this->assertSame($uniqueReturn, $actualReturn);
407  }
408 
412  public function fixSelfCallsSetsContentIfFileCreationWasSuccessfulAndTargetContentIsNotNullAndReturnsResult()
413  {
415  $node = $this->getAccessibleMock(
416  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
417  ['exists', 'createFile', 'setContent', 'getAbsolutePath', 'isFile', 'isPermissionCorrect'],
418  [],
419  '',
420  false
421  );
422  $node->expects($this->any())->method('exists')->will($this->returnValue(false));
423  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
424  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
425  $uniqueReturn = $this->getUniqueId();
426  $createFileStatus = $this->getMock(\TYPO3\CMS\Install\Status\OkStatus::class, [], [], '', false);
427  $node->expects($this->any())->method('createFile')->will($this->returnValue($createFileStatus));
428  $node->_set('targetContent', 'foo');
429  $node->expects($this->once())->method('setContent')->will($this->returnValue($uniqueReturn));
430  $actualReturn = $node->_call('fixSelf');
431  $actualReturn = $actualReturn[1];
432  $this->assertSame($uniqueReturn, $actualReturn);
433  }
434 
438  public function fixSelfDoesNotCallSetContentIfFileCreationFailed()
439  {
441  $node = $this->getAccessibleMock(
442  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
443  ['exists', 'createFile', 'setContent', 'getAbsolutePath', 'isFile', 'isPermissionCorrect'],
444  [],
445  '',
446  false
447  );
448  $node->expects($this->any())->method('exists')->will($this->returnValue(false));
449  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
450  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
451  $createFileStatus = $this->getMock(\TYPO3\CMS\Install\Status\ErrorStatus::class, [], [], '', false);
452  $node->expects($this->any())->method('createFile')->will($this->returnValue($createFileStatus));
453  $node->_set('targetContent', 'foo');
454  $node->expects($this->never())->method('setContent');
455  $node->_call('fixSelf');
456  }
457 
461  public function fixSelfDoesNotCallSetContentIfFileTargetContentIsNull()
462  {
464  $node = $this->getAccessibleMock(
465  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
466  ['exists', 'createFile', 'setContent', 'getAbsolutePath', 'isFile', 'isPermissionCorrect'],
467  [],
468  '',
469  false
470  );
471  $node->expects($this->any())->method('exists')->will($this->returnValue(false));
472  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
473  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
474  $createFileStatus = $this->getMock(\TYPO3\CMS\Install\Status\OkStatus::class, [], [], '', false);
475  $node->expects($this->any())->method('createFile')->will($this->returnValue($createFileStatus));
476  $node->_set('targetContent', null);
477  $node->expects($this->never())->method('setContent');
478  $node->_call('fixSelf');
479  }
480 
484  public function fixSelfReturnsErrorStatusIfNodeExistsButIsNotAFileAndReturnsResult()
485  {
487  $node = $this->getAccessibleMock(
488  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
489  ['exists', 'createFile', 'getAbsolutePath', 'isFile', 'isPermissionCorrect', 'fixPermission'],
490  [],
491  '',
492  false
493  );
494  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
495  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
496  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(false));
497  $uniqueReturn = $this->getUniqueId();
498  $node->expects($this->once())->method('fixPermission')->will($this->returnValue($uniqueReturn));
499  $this->assertSame([$uniqueReturn], $node->_call('fixSelf'));
500  }
501 
505  public function fixSelfCallsFixPermissionIfFileExistsButPermissionAreWrong()
506  {
508  $node = $this->getAccessibleMock(
509  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
510  ['exists', 'createFile', 'getAbsolutePath', 'isFile', 'isPermissionCorrect', 'getRelativePathBelowSiteRoot'],
511  [],
512  '',
513  false
514  );
515  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
516  $node->expects($this->once())->method('isFile')->will($this->returnValue(false));
517  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
518  $resultArray = $node->_call('fixSelf');
519  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\StatusInterface::class, $resultArray[0]);
520  }
521 
526  {
527  $node = $this->getAccessibleMock(
528  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
529  ['exists', 'isFile', 'isPermissionCorrect'],
530  [],
531  '',
532  false
533  );
534  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
535  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
536  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
537  $this->assertInternalType('array', $node->_call('fixSelf'));
538  }
539 
544  public function createFileThrowsExceptionIfNodeExists()
545  {
547  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['exists', 'getAbsolutePath'], [], '', false);
548  $node->expects($this->once())->method('getAbsolutePath')->will($this->returnValue(''));
549  $node->expects($this->once())->method('exists')->will($this->returnValue(true));
550  $node->_call('createFile');
551  }
552 
556  public function createFileReturnsOkStatusIfFileWasCreated()
557  {
559  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['exists', 'getAbsolutePath', 'getRelativePathBelowSiteRoot'], [], '', false);
560  $path = $this->getVirtualTestFilePath('file_');
561  $node->expects($this->once())->method('exists')->will($this->returnValue(false));
562  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
563  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
564  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\StatusInterface::class, $node->_call('createFile'));
565  }
566 
570  public function createFileCreatesFile()
571  {
573  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['exists', 'getAbsolutePath', 'getRelativePathBelowSiteRoot'], [], '', false);
574  $path = $this->getVirtualTestFilePath('file_');
575  $node->expects($this->once())->method('exists')->will($this->returnValue(false));
576  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
577  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
578  $node->_call('createFile');
579  $this->assertTrue(is_file($path));
580  }
581 
585  public function createFileReturnsErrorStatusIfFileWasNotCreated()
586  {
587  if (TYPO3_OS === 'WIN') {
588  $this->markTestSkipped('Test not available on Windows OS.');
589  }
591  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['exists', 'getAbsolutePath', 'getRelativePathBelowSiteRoot'], [], '', false);
592  $path = $this->getVirtualTestDir();
593  chmod($path, 02550);
594  $subPath = $path . '/' . $this->getUniqueId('file_');
595  $node->expects($this->once())->method('exists')->will($this->returnValue(false));
596  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath));
597  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($subPath));
598  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\StatusInterface::class, $node->_call('createFile'));
599  }
600 
605  public function isContentCorrectThrowsExceptionIfTargetIsNotAFile()
606  {
608  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath'], [], '', false);
609  $path = $this->getVirtualTestDir('dir_');
610  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
611  $node->_call('isContentCorrect');
612  }
613 
617  public function isContentCorrectReturnsTrueIfTargetContentPropertyIsNull()
618  {
620  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath'], [], '', false);
621  $path = $this->getVirtualTestFilePath('file_');
622  touch($path);
623  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
624  $node->_set('targetContent', null);
625  $this->assertTrue($node->_call('isContentCorrect'));
626  }
627 
631  public function isContentCorrectReturnsTrueIfTargetContentEqualsCurrentContent()
632  {
634  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath'], [], '', false);
635  $path = $this->getVirtualTestFilePath('file_');
636  $content = $this->getUniqueId('content_');
637  file_put_contents($path, $content);
638  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
639  $node->_set('targetContent', $content);
640  $this->assertTrue($node->_call('isContentCorrect'));
641  }
642 
646  public function isContentCorrectReturnsFalseIfTargetContentNotEqualsCurrentContent()
647  {
649  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath'], [], '', false);
650  $path = $this->getVirtualTestFilePath('file_');
651  $content = $this->getUniqueId('content1_');
652  $targetContent = $this->getUniqueId('content2_');
653  file_put_contents($path, $content);
654  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
655  $node->_set('targetContent', $targetContent);
656  $this->assertFalse($node->_call('isContentCorrect'));
657  }
658 
662  public function isPermissionCorrectReturnsTrueIfTargetPermissionAndCurrentPermissionAreIdentical()
663  {
664  $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, [], [], '', false);
666  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getCurrentPermission', 'isWindowsOs'], [], '', false);
667  $node->expects($this->any())->method('isWindowsOs')->will($this->returnValue(false));
668  $node->expects($this->any())->method('getCurrentPermission')->will($this->returnValue('0664'));
669  $targetPermission = '0664';
670  $structure = [
671  'name' => 'foo',
672  'targetPermission' => $targetPermission,
673  ];
674  $node->__construct($structure, $parent);
675  $this->assertTrue($node->_call('isPermissionCorrect'));
676  }
677 
682  public function setContentThrowsExceptionIfTargetIsNotAFile()
683  {
685  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath'], [], '', false);
686  $path = $this->getVirtualTestDir('dir_');
687  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
688  $node->_set('targetContent', 'foo');
689  $node->_call('setContent');
690  }
691 
696  public function setContentThrowsExceptionIfTargetContentIsNull()
697  {
699  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath'], [], '', false);
700  $path = $this->getVirtualTestFilePath('file_');
701  touch($path);
702  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
703  $node->_set('targetContent', null);
704  $node->_call('setContent');
705  }
706 
710  public function setContentSetsContentToFile()
711  {
713  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath', 'getRelativePathBelowSiteRoot'], [], '', false);
714  $path = $this->getVirtualTestFilePath('file_');
715  touch($path);
716  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
717  $targetContent = $this->getUniqueId('content_');
718  $node->_set('targetContent', $targetContent);
719  $node->_call('setContent');
720  $resultContent = file_get_contents($path);
721  $this->assertSame($targetContent, $resultContent);
722  }
723 
727  public function setContentReturnsOkStatusIfContentWasSuccessfullySet()
728  {
730  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath', 'getRelativePathBelowSiteRoot'], [], '', false);
731  $path = $this->getVirtualTestFilePath('file_');
732  touch($path);
733  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
734  $targetContent = $this->getUniqueId('content_');
735  $node->_set('targetContent', $targetContent);
736  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\OkStatus::class, $node->_call('setContent'));
737  }
738 
742  public function setContentReturnsErrorStatusIfContentCanNotBeSetSet()
743  {
744  if (TYPO3_OS === 'WIN') {
745  $this->markTestSkipped('Test not available on Windows OS.');
746  }
747  if (function_exists('posix_getegid') && posix_getegid() === 0) {
748  $this->markTestSkipped('Test skipped if run on linux as root');
749  }
751  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath', 'getRelativePathBelowSiteRoot'], [], '', false);
752  $dir = $this->getVirtualTestDir('dir_');
753  $file = $dir . '/' . $this->getUniqueId('file_');
754  touch($file);
755  chmod($file, 0440);
756  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($file));
757  $targetContent = $this->getUniqueId('content_');
758  $node->_set('targetContent', $targetContent);
759  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus::class, $node->_call('setContent'));
760  }
761 
765  public function isFileReturnsTrueIfNameIsFile()
766  {
768  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath', 'getRelativePathBelowSiteRoot'], [], '', false);
769  $path = $this->getVirtualTestFilePath('file_');
770  touch($path);
771  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
772  $this->assertTrue($node->_call('isFile'));
773  }
774 
779  public function isFileReturnsFalseIfNameIsALinkFile()
780  {
781  if (TYPO3_OS === 'WIN') {
782  $this->markTestSkipped('Test not available on Windows OS.');
783  }
785  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath'], [], '', false);
786  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('root_');
788  $this->testFilesToDelete[] = $path;
789  $link = $this->getUniqueId('link_');
790  $file = $this->getUniqueId('file_');
791  touch($path . '/' . $file);
792  symlink($path . '/' . $file, $path . '/' . $link);
793  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path . '/' . $link));
794  $this->assertFalse($node->_call('isFile'));
795  }
796 }
static mkdir_deep($directory, $deepDirectory='')
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)