TYPO3 CMS  TYPO3_8-7
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  */
18 
23 {
27  public function constructorThrowsExceptionIfParentIsNull()
28  {
29  $this->expectException(InvalidArgumentException::class);
30  $this->expectExceptionCode(1366927513);
32  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['dummy'], [], '', false);
33  $node->__construct([], null);
34  }
35 
39  public function constructorThrowsExceptionIfNameContainsForwardSlash()
40  {
41  $this->expectException(InvalidArgumentException::class);
42  $this->expectExceptionCode(1366222207);
43  $parent = $this->createMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class);
45  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['dummy'], [], '', false);
46  $structure = [
47  'name' => 'foo/bar',
48  ];
49  $node->__construct($structure, $parent);
50  }
51 
55  public function constructorSetsParent()
56  {
57  $parent = $this->createMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class);
59  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['dummy'], [], '', false);
60  $structure = [
61  'name' => 'foo',
62  ];
63  $node->__construct($structure, $parent);
64  $this->assertSame($parent, $node->_call('getParent'));
65  }
66 
70  public function constructorSetsTargetPermission()
71  {
72  $parent = $this->createMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class);
74  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['dummy'], [], '', false);
75  $targetPermission = '0660';
76  $structure = [
77  'name' => 'foo',
78  'targetPermission' => $targetPermission,
79  ];
80  $node->__construct($structure, $parent);
81  $this->assertSame($targetPermission, $node->_call('getTargetPermission'));
82  }
83 
87  public function constructorSetsName()
88  {
90  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['dummy'], [], '', false);
91  $parent = $this->createMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
92  $name = $this->getUniqueId('test_');
93  $node->__construct(['name' => $name], $parent);
94  $this->assertSame($name, $node->getName());
95  }
96 
100  public function constructorThrowsExceptionIfBothTargetContentAndTargetContentFileAreSet()
101  {
102  $this->expectException(InvalidArgumentException::class);
103  $this->expectExceptionCode(1380364361);
105  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['dummy'], [], '', false);
106  $parent = $this->createMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
107  $structure = [
108  'name' => 'foo',
109  'targetContent' => 'foo',
110  'targetContentFile' => 'aPath',
111  ];
112  $node->__construct($structure, $parent);
113  }
114 
118  public function constructorSetsTargetContent()
119  {
121  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['dummy'], [], '', false);
122  $parent = $this->createMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
123  $targetContent = $this->getUniqueId('content_');
124  $structure = [
125  'name' => 'foo',
126  'targetContent' => $targetContent,
127  ];
128  $node->__construct($structure, $parent);
129  $this->assertSame($targetContent, $node->_get('targetContent'));
130  }
131 
135  public function constructorSetsTargetContentToContentOfTargetContentFile()
136  {
138  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['dummy'], [], '', false);
139  $parent = $this->createMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
140  $targetFile = $this->getVirtualTestFilePath('test_');
141  $targetContent = $this->getUniqueId('content_');
142  file_put_contents($targetFile, $targetContent);
143  $structure = [
144  'name' => 'foo',
145  'targetContentFile' => $targetFile,
146  ];
147  $node->__construct($structure, $parent);
148  $this->assertSame($targetContent, $node->_get('targetContent'));
149  }
150 
154  public function constructorThrowsExceptionIfTargetContentFileDoesNotExist()
155  {
156  $this->expectException(InvalidArgumentException::class);
157  $this->expectExceptionCode(1380364362);
159  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['dummy'], [], '', false);
160  $parent = $this->createMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
161  $targetFile = $this->getVirtualTestFilePath('test_');
162  $structure = [
163  'name' => 'foo',
164  'targetContentFile' => $targetFile,
165  ];
166  $node->__construct($structure, $parent);
167  }
168 
172  public function targetContentIsNullIfNotGiven()
173  {
175  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['dummy'], [], '', false);
176  $parent = $this->createMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
177  $structure = [
178  'name' => 'foo',
179  ];
180  $node->__construct($structure, $parent);
181  $this->assertNull($node->_get('targetContent'));
182  }
183 
187  public function getStatusReturnsArray()
188  {
190  $node = $this->getAccessibleMock(
191  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
192  ['getAbsolutePath', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
193  [],
194  '',
195  false
196  );
197  $path = PATH_site . 'typo3temp/var/tests/' . $this->getUniqueId('dir_');
198  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
199  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
200  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
201  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
202  $node->expects($this->any())->method('isWritable')->will($this->returnValue(true));
203  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(true));
204  $this->assertInternalType('array', $node->getStatus());
205  }
206 
210  public function getStatusReturnsArrayWithWarningStatusIFileNotExists()
211  {
213  $node = $this->getAccessibleMock(
214  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
215  ['getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
216  [],
217  '',
218  false
219  );
220  $path = $this->getVirtualTestDir('dir_');
221  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
222  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
223  $node->expects($this->any())->method('exists')->will($this->returnValue(false));
224  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
225  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
226  $node->expects($this->any())->method('isWritable')->will($this->returnValue(true));
227  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(true));
228  $statusArray = $node->getStatus();
230  $status = $statusArray[0];
231  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\WarningStatus::class, $status);
232  }
233 
237  public function getStatusReturnsArrayWithErrorStatusIfNodeIsNotAFile()
238  {
240  $node = $this->getAccessibleMock(
241  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
242  ['getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
243  [],
244  '',
245  false
246  );
247  $path = $this->getVirtualTestFilePath('dir_');
248  touch($path);
249  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
250  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
251  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
252  $node->expects($this->any())->method('isFile')->will($this->returnValue(false));
253  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
254  $node->expects($this->any())->method('isWritable')->will($this->returnValue(true));
255  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(true));
256  $statusArray = $node->getStatus();
258  $status = $statusArray[0];
259  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus::class, $status);
260  }
261 
265  public function getStatusReturnsArrayNoticeStatusIfFileExistsButIsNotWritable()
266  {
268  $node = $this->getAccessibleMock(
269  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
270  ['getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
271  [],
272  '',
273  false
274  );
275  $path = $this->getVirtualTestFilePath('dir_');
276  touch($path);
277  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
278  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
279  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
280  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
281  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
282  $node->expects($this->any())->method('isWritable')->will($this->returnValue(false));
283  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(true));
284  $statusArray = $node->getStatus();
286  $status = $statusArray[0];
287  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\NoticeStatus::class, $status);
288  }
289 
293  public function getStatusReturnsArrayWithNoticeStatusIfFileExistsButPermissionAreNotCorrect()
294  {
296  $node = $this->getAccessibleMock(
297  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
298  ['getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
299  [],
300  '',
301  false
302  );
303  $path = $this->getVirtualTestFilePath('dir_');
304  touch($path);
305  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
306  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
307  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
308  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
309  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(false));
310  $node->expects($this->any())->method('isWritable')->will($this->returnValue(true));
311  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(true));
312  $statusArray = $node->getStatus();
314  $status = $statusArray[0];
315  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\NoticeStatus::class, $status);
316  }
317 
321  public function getStatusReturnsArrayWithNoticeStatusIfFileExistsButContentIsNotCorrect()
322  {
324  $node = $this->getAccessibleMock(
325  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
326  ['getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
327  [],
328  '',
329  false
330  );
331  $path = $this->getVirtualTestFilePath('dir_');
332  touch($path);
333  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
334  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
335  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
336  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
337  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
338  $node->expects($this->any())->method('isWritable')->will($this->returnValue(true));
339  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(false));
340  $statusArray = $node->getStatus();
342  $status = $statusArray[0];
343  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\NoticeStatus::class, $status);
344  }
345 
349  public function getStatusReturnsArrayWithOkStatusIfFileExistsAndPermissionAreCorrect()
350  {
352  $node = $this->getAccessibleMock(
353  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
354  ['getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
355  [],
356  '',
357  false
358  );
359  $path = $this->getVirtualTestFilePath('dir_');
360  touch($path);
361  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
362  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
363  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
364  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
365  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
366  $node->expects($this->any())->method('isWritable')->will($this->returnValue(true));
367  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(true));
368  $statusArray = $node->getStatus();
370  $status = $statusArray[0];
371  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\OkStatus::class, $status);
372  }
373 
377  public function fixCallsFixSelfAndReturnsItsResult()
378  {
380  $node = $this->getAccessibleMock(
381  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
382  ['fixSelf'],
383  [],
384  '',
385  false
386  );
387  $uniqueReturn = [$this->getUniqueId('foo_')];
388  $node->expects($this->once())->method('fixSelf')->will($this->returnValue($uniqueReturn));
389  $this->assertSame($uniqueReturn, $node->fix());
390  }
391 
395  public function fixSelfCallsCreateFileIfFileDoesNotExistAndReturnsResult()
396  {
398  $node = $this->getAccessibleMock(
399  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
400  ['exists', 'createFile', 'setContent', 'getAbsolutePath', 'isFile', 'isPermissionCorrect'],
401  [],
402  '',
403  false
404  );
405  $node->expects($this->any())->method('exists')->will($this->returnValue(false));
406  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
407  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
408  $uniqueReturn = $this->getUniqueId();
409  $node->expects($this->once())->method('createFile')->will($this->returnValue($uniqueReturn));
410  $actualReturn = $node->_call('fixSelf');
411  $actualReturn = $actualReturn[0];
412  $this->assertSame($uniqueReturn, $actualReturn);
413  }
414 
418  public function fixSelfCallsSetsContentIfFileCreationWasSuccessfulAndTargetContentIsNotNullAndReturnsResult()
419  {
421  $node = $this->getAccessibleMock(
422  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
423  ['exists', 'createFile', 'setContent', 'getAbsolutePath', 'isFile', 'isPermissionCorrect'],
424  [],
425  '',
426  false
427  );
428  $node->expects($this->any())->method('exists')->will($this->returnValue(false));
429  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
430  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
431  $uniqueReturn = $this->getUniqueId();
432  $createFileStatus = $this->createMock(\TYPO3\CMS\Install\Status\OkStatus::class);
433  $node->expects($this->any())->method('createFile')->will($this->returnValue($createFileStatus));
434  $node->_set('targetContent', 'foo');
435  $node->expects($this->once())->method('setContent')->will($this->returnValue($uniqueReturn));
436  $actualReturn = $node->_call('fixSelf');
437  $actualReturn = $actualReturn[1];
438  $this->assertSame($uniqueReturn, $actualReturn);
439  }
440 
444  public function fixSelfDoesNotCallSetContentIfFileCreationFailed()
445  {
447  $node = $this->getAccessibleMock(
448  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
449  ['exists', 'createFile', 'setContent', 'getAbsolutePath', 'isFile', 'isPermissionCorrect'],
450  [],
451  '',
452  false
453  );
454  $node->expects($this->any())->method('exists')->will($this->returnValue(false));
455  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
456  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
457  $createFileStatus = $this->createMock(\TYPO3\CMS\Install\Status\ErrorStatus::class);
458  $node->expects($this->any())->method('createFile')->will($this->returnValue($createFileStatus));
459  $node->_set('targetContent', 'foo');
460  $node->expects($this->never())->method('setContent');
461  $node->_call('fixSelf');
462  }
463 
467  public function fixSelfDoesNotCallSetContentIfFileTargetContentIsNull()
468  {
470  $node = $this->getAccessibleMock(
471  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
472  ['exists', 'createFile', 'setContent', 'getAbsolutePath', 'isFile', 'isPermissionCorrect'],
473  [],
474  '',
475  false
476  );
477  $node->expects($this->any())->method('exists')->will($this->returnValue(false));
478  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
479  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
480  $createFileStatus = $this->createMock(\TYPO3\CMS\Install\Status\OkStatus::class);
481  $node->expects($this->any())->method('createFile')->will($this->returnValue($createFileStatus));
482  $node->_set('targetContent', null);
483  $node->expects($this->never())->method('setContent');
484  $node->_call('fixSelf');
485  }
486 
490  public function fixSelfReturnsErrorStatusIfNodeExistsButIsNotAFileAndReturnsResult()
491  {
493  $node = $this->getAccessibleMock(
494  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
495  ['exists', 'createFile', 'getAbsolutePath', 'isFile', 'isPermissionCorrect', 'fixPermission'],
496  [],
497  '',
498  false
499  );
500  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
501  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
502  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(false));
503  $uniqueReturn = $this->getUniqueId();
504  $node->expects($this->once())->method('fixPermission')->will($this->returnValue($uniqueReturn));
505  $this->assertSame([$uniqueReturn], $node->_call('fixSelf'));
506  }
507 
511  public function fixSelfCallsFixPermissionIfFileExistsButPermissionAreWrong()
512  {
514  $node = $this->getAccessibleMock(
515  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
516  ['exists', 'createFile', 'getAbsolutePath', 'isFile', 'isPermissionCorrect', 'getRelativePathBelowSiteRoot'],
517  [],
518  '',
519  false
520  );
521  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
522  $node->expects($this->once())->method('isFile')->will($this->returnValue(false));
523  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
524  $resultArray = $node->_call('fixSelf');
525  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\StatusInterface::class, $resultArray[0]);
526  }
527 
532  {
533  $node = $this->getAccessibleMock(
534  \TYPO3\CMS\Install\FolderStructure\FileNode::class,
535  ['exists', 'isFile', 'isPermissionCorrect'],
536  [],
537  '',
538  false
539  );
540  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
541  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
542  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
543  $this->assertInternalType('array', $node->_call('fixSelf'));
544  }
545 
549  public function createFileThrowsExceptionIfNodeExists()
550  {
551  $this->expectException(Exception::class);
552  $this->expectExceptionCode(1366398198);
554  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['exists', 'getAbsolutePath'], [], '', false);
555  $node->expects($this->once())->method('getAbsolutePath')->will($this->returnValue(''));
556  $node->expects($this->once())->method('exists')->will($this->returnValue(true));
557  $node->_call('createFile');
558  }
559 
563  public function createFileReturnsOkStatusIfFileWasCreated()
564  {
566  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['exists', 'getAbsolutePath', 'getRelativePathBelowSiteRoot'], [], '', false);
567  $path = $this->getVirtualTestFilePath('file_');
568  $node->expects($this->once())->method('exists')->will($this->returnValue(false));
569  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
570  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
571  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\StatusInterface::class, $node->_call('createFile'));
572  }
573 
577  public function createFileCreatesFile()
578  {
580  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['exists', 'getAbsolutePath', 'getRelativePathBelowSiteRoot'], [], '', false);
581  $path = $this->getVirtualTestFilePath('file_');
582  $node->expects($this->once())->method('exists')->will($this->returnValue(false));
583  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
584  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
585  $node->_call('createFile');
586  $this->assertTrue(is_file($path));
587  }
588 
592  public function createFileReturnsErrorStatusIfFileWasNotCreated()
593  {
595  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['exists', 'getAbsolutePath', 'getRelativePathBelowSiteRoot'], [], '', false);
596  $path = $this->getVirtualTestDir();
597  chmod($path, 02550);
598  $subPath = $path . '/' . $this->getUniqueId('file_');
599  $node->expects($this->once())->method('exists')->will($this->returnValue(false));
600  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath));
601  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($subPath));
602  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\StatusInterface::class, $node->_call('createFile'));
603  }
604 
608  public function isContentCorrectThrowsExceptionIfTargetIsNotAFile()
609  {
610  $this->expectException(Exception::class);
611  $this->expectExceptionCode(1367056363);
613  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath'], [], '', false);
614  $path = $this->getVirtualTestDir('dir_');
615  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
616  $node->_call('isContentCorrect');
617  }
618 
622  public function isContentCorrectReturnsTrueIfTargetContentPropertyIsNull()
623  {
625  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath'], [], '', false);
626  $path = $this->getVirtualTestFilePath('file_');
627  touch($path);
628  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
629  $node->_set('targetContent', null);
630  $this->assertTrue($node->_call('isContentCorrect'));
631  }
632 
636  public function isContentCorrectReturnsTrueIfTargetContentEqualsCurrentContent()
637  {
639  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath'], [], '', false);
640  $path = $this->getVirtualTestFilePath('file_');
641  $content = $this->getUniqueId('content_');
642  file_put_contents($path, $content);
643  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
644  $node->_set('targetContent', $content);
645  $this->assertTrue($node->_call('isContentCorrect'));
646  }
647 
651  public function isContentCorrectReturnsFalseIfTargetContentNotEqualsCurrentContent()
652  {
654  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath'], [], '', false);
655  $path = $this->getVirtualTestFilePath('file_');
656  $content = $this->getUniqueId('content1_');
657  $targetContent = $this->getUniqueId('content2_');
658  file_put_contents($path, $content);
659  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
660  $node->_set('targetContent', $targetContent);
661  $this->assertFalse($node->_call('isContentCorrect'));
662  }
663 
667  public function isPermissionCorrectReturnsTrueIfTargetPermissionAndCurrentPermissionAreIdentical()
668  {
669  $parent = $this->createMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class);
671  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getCurrentPermission', 'isWindowsOs'], [], '', false);
672  $node->expects($this->any())->method('isWindowsOs')->will($this->returnValue(false));
673  $node->expects($this->any())->method('getCurrentPermission')->will($this->returnValue('0664'));
674  $targetPermission = '0664';
675  $structure = [
676  'name' => 'foo',
677  'targetPermission' => $targetPermission,
678  ];
679  $node->__construct($structure, $parent);
680  $this->assertTrue($node->_call('isPermissionCorrect'));
681  }
682 
686  public function setContentThrowsExceptionIfTargetIsNotAFile()
687  {
688  $this->expectException(Exception::class);
689  $this->expectExceptionCode(1367060201);
691  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath'], [], '', false);
692  $path = $this->getVirtualTestDir('dir_');
693  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
694  $node->_set('targetContent', 'foo');
695  $node->_call('setContent');
696  }
697 
701  public function setContentThrowsExceptionIfTargetContentIsNull()
702  {
703  $this->expectException(Exception::class);
704  $this->expectExceptionCode(1367060202);
706  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath'], [], '', false);
707  $path = $this->getVirtualTestFilePath('file_');
708  touch($path);
709  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
710  $node->_set('targetContent', null);
711  $node->_call('setContent');
712  }
713 
717  public function setContentSetsContentToFile()
718  {
720  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath', 'getRelativePathBelowSiteRoot'], [], '', false);
721  $path = $this->getVirtualTestFilePath('file_');
722  touch($path);
723  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
724  $targetContent = $this->getUniqueId('content_');
725  $node->_set('targetContent', $targetContent);
726  $node->_call('setContent');
727  $resultContent = file_get_contents($path);
728  $this->assertSame($targetContent, $resultContent);
729  }
730 
734  public function setContentReturnsOkStatusIfContentWasSuccessfullySet()
735  {
737  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath', 'getRelativePathBelowSiteRoot'], [], '', false);
738  $path = $this->getVirtualTestFilePath('file_');
739  touch($path);
740  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
741  $targetContent = $this->getUniqueId('content_');
742  $node->_set('targetContent', $targetContent);
743  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\OkStatus::class, $node->_call('setContent'));
744  }
745 
749  public function setContentReturnsErrorStatusIfContentCanNotBeSetSet()
750  {
751  if (function_exists('posix_getegid') && posix_getegid() === 0) {
752  $this->markTestSkipped('Test skipped if run on linux as root');
753  }
755  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath', 'getRelativePathBelowSiteRoot'], [], '', false);
756  $dir = $this->getVirtualTestDir('dir_');
757  $file = $dir . '/' . $this->getUniqueId('file_');
758  touch($file);
759  chmod($file, 0440);
760  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($file));
761  $targetContent = $this->getUniqueId('content_');
762  $node->_set('targetContent', $targetContent);
763  $this->assertInstanceOf(\TYPO3\CMS\Install\Status\ErrorStatus::class, $node->_call('setContent'));
764  }
765 
769  public function isFileReturnsTrueIfNameIsFile()
770  {
772  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath', 'getRelativePathBelowSiteRoot'], [], '', false);
773  $path = $this->getVirtualTestFilePath('file_');
774  touch($path);
775  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
776  $this->assertTrue($node->_call('isFile'));
777  }
778 
783  public function isFileReturnsFalseIfNameIsALinkFile()
784  {
786  $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\FileNode::class, ['getAbsolutePath'], [], '', false);
787  $path = PATH_site . 'typo3temp/var/tests/' . $this->getUniqueId('root_');
789  $this->testFilesToDelete[] = $path;
790  $link = $this->getUniqueId('link_');
791  $file = $this->getUniqueId('file_');
792  touch($path . '/' . $file);
793  symlink($path . '/' . $file, $path . '/' . $link);
794  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path . '/' . $link));
795  $this->assertFalse($node->_call('isFile'));
796  }
797 }
static mkdir_deep($directory, $deepDirectory='')