‪TYPO3CMS  9.5
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 
23 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
24 
29 {
34  {
35  $this->expectException(InvalidArgumentException::class);
36  $this->expectExceptionCode(1366927513);
38  $node = $this->getAccessibleMock(FileNode::class, ['dummy'], [], '', false);
39  $node->__construct([], null);
40  }
41 
46  {
47  $this->expectException(InvalidArgumentException::class);
48  $this->expectExceptionCode(1366222207);
49  $parent = $this->createMock(\‪TYPO3\CMS\Install\FolderStructure\NodeInterface::class);
51  $node = $this->getAccessibleMock(FileNode::class, ['dummy'], [], '', false);
52  $structure = [
53  'name' => 'foo/bar',
54  ];
55  $node->__construct($structure, $parent);
56  }
57 
61  public function ‪constructorSetsParent()
62  {
63  $parent = $this->createMock(\‪TYPO3\CMS\Install\FolderStructure\NodeInterface::class);
65  $node = $this->getAccessibleMock(FileNode::class, ['dummy'], [], '', false);
66  $structure = [
67  'name' => 'foo',
68  ];
69  $node->__construct($structure, $parent);
70  $this->assertSame($parent, $node->_call('getParent'));
71  }
72 
77  {
78  $parent = $this->createMock(\‪TYPO3\CMS\Install\FolderStructure\NodeInterface::class);
80  $node = $this->getAccessibleMock(FileNode::class, ['dummy'], [], '', false);
81  $targetPermission = '0660';
82  $structure = [
83  'name' => 'foo',
84  'targetPermission' => $targetPermission,
85  ];
86  $node->__construct($structure, $parent);
87  $this->assertSame($targetPermission, $node->_call('getTargetPermission'));
88  }
89 
93  public function ‪constructorSetsName()
94  {
96  $node = $this->getAccessibleMock(FileNode::class, ['dummy'], [], '', false);
97  $parent = $this->createMock(\‪TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
98  $name = $this->getUniqueId('test_');
99  $node->__construct(['name' => $name], $parent);
100  $this->assertSame($name, $node->getName());
101  }
102 
107  {
108  $this->expectException(InvalidArgumentException::class);
109  $this->expectExceptionCode(1380364361);
111  $node = $this->getAccessibleMock(FileNode::class, ['dummy'], [], '', false);
112  $parent = $this->createMock(\‪TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
113  $structure = [
114  'name' => 'foo',
115  'targetContent' => 'foo',
116  'targetContentFile' => 'aPath',
117  ];
118  $node->__construct($structure, $parent);
119  }
120 
125  {
127  $node = $this->getAccessibleMock(FileNode::class, ['dummy'], [], '', false);
128  $parent = $this->createMock(\‪TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
129  $targetContent = $this->getUniqueId('content_');
130  $structure = [
131  'name' => 'foo',
132  'targetContent' => $targetContent,
133  ];
134  $node->__construct($structure, $parent);
135  $this->assertSame($targetContent, $node->_get('targetContent'));
136  }
137 
142  {
144  $node = $this->getAccessibleMock(FileNode::class, ['dummy'], [], '', false);
145  $parent = $this->createMock(\‪TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
146  $targetFile = $this->‪getVirtualTestFilePath('test_');
147  $targetContent = $this->getUniqueId('content_');
148  file_put_contents($targetFile, $targetContent);
149  $structure = [
150  'name' => 'foo',
151  'targetContentFile' => $targetFile,
152  ];
153  $node->__construct($structure, $parent);
154  $this->assertSame($targetContent, $node->_get('targetContent'));
155  }
156 
161  {
162  $this->expectException(InvalidArgumentException::class);
163  $this->expectExceptionCode(1380364362);
165  $node = $this->getAccessibleMock(FileNode::class, ['dummy'], [], '', false);
166  $parent = $this->createMock(\‪TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
167  $targetFile = $this->‪getVirtualTestFilePath('test_');
168  $structure = [
169  'name' => 'foo',
170  'targetContentFile' => $targetFile,
171  ];
172  $node->__construct($structure, $parent);
173  }
174 
179  {
181  $node = $this->getAccessibleMock(FileNode::class, ['dummy'], [], '', false);
182  $parent = $this->createMock(\‪TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class);
183  $structure = [
184  'name' => 'foo',
185  ];
186  $node->__construct($structure, $parent);
187  $this->assertNull($node->_get('targetContent'));
188  }
189 
193  public function ‪getStatusReturnsArray()
194  {
196  $node = $this->getAccessibleMock(
197  FileNode::class,
198  ['getAbsolutePath', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
199  [],
200  '',
201  false
202  );
203  $path = ‪Environment::getVarPath() . '/tests/' . $this->getUniqueId('dir_');
204  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
205  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
206  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
207  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
208  $node->expects($this->any())->method('isWritable')->will($this->returnValue(true));
209  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(true));
210  $this->assertInternalType('array', $node->getStatus());
211  }
212 
217  {
219  $node = $this->getAccessibleMock(
220  FileNode::class,
221  ['getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
222  [],
223  '',
224  false
225  );
226  $path = $this->‪getVirtualTestDir('dir_');
227  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
228  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
229  $node->expects($this->any())->method('exists')->will($this->returnValue(false));
230  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
231  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
232  $node->expects($this->any())->method('isWritable')->will($this->returnValue(true));
233  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(true));
234  $statusArray = $node->getStatus();
235  $this->assertSame(‪FlashMessage::WARNING, $statusArray[0]->getSeverity());
236  }
237 
242  {
244  $node = $this->getAccessibleMock(
245  FileNode::class,
246  ['getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
247  [],
248  '',
249  false
250  );
251  $path = $this->‪getVirtualTestFilePath('dir_');
252  touch($path);
253  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
254  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
255  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
256  $node->expects($this->any())->method('isFile')->will($this->returnValue(false));
257  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
258  $node->expects($this->any())->method('isWritable')->will($this->returnValue(true));
259  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(true));
260  $statusArray = $node->getStatus();
261  $this->assertSame(‪FlashMessage::ERROR, $statusArray[0]->getSeverity());
262  }
263 
268  {
270  $node = $this->getAccessibleMock(
271  FileNode::class,
272  ['getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
273  [],
274  '',
275  false
276  );
277  $path = $this->‪getVirtualTestFilePath('dir_');
278  touch($path);
279  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
280  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
281  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
282  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
283  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
284  $node->expects($this->any())->method('isWritable')->will($this->returnValue(false));
285  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(true));
286  $statusArray = $node->getStatus();
287  $this->assertSame(‪FlashMessage::NOTICE, $statusArray[0]->getSeverity());
288  }
289 
294  {
296  $node = $this->getAccessibleMock(
297  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();
313  $this->assertSame(‪FlashMessage::NOTICE, $statusArray[0]->getSeverity());
314  }
315 
320  {
322  $node = $this->getAccessibleMock(
323  FileNode::class,
324  ['getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
325  [],
326  '',
327  false
328  );
329  $path = $this->‪getVirtualTestFilePath('dir_');
330  touch($path);
331  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
332  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
333  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
334  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
335  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
336  $node->expects($this->any())->method('isWritable')->will($this->returnValue(true));
337  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(false));
338  $statusArray = $node->getStatus();
339  $this->assertSame(‪FlashMessage::NOTICE, $statusArray[0]->getSeverity());
340  }
341 
346  {
348  $node = $this->getAccessibleMock(
349  FileNode::class,
350  ['getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isFile', 'isWritable', 'isPermissionCorrect', 'isContentCorrect'],
351  [],
352  '',
353  false
354  );
355  $path = $this->‪getVirtualTestFilePath('dir_');
356  touch($path);
357  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
358  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
359  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
360  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
361  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
362  $node->expects($this->any())->method('isWritable')->will($this->returnValue(true));
363  $node->expects($this->any())->method('isContentCorrect')->will($this->returnValue(true));
364  $statusArray = $node->getStatus();
365  $this->assertSame(‪FlashMessage::OK, $statusArray[0]->getSeverity());
366  }
367 
372  {
374  $node = $this->getAccessibleMock(
375  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 
390  {
392  $node = $this->getAccessibleMock(
393  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  $message = new ‪FlashMessage('foo');
403  $node->expects($this->once())->method('createFile')->will($this->returnValue($message));
404  $actualReturn = $node->_call('fixSelf');
405  $actualReturn = $actualReturn[0];
406  $this->assertSame($message, $actualReturn);
407  }
408 
413  {
415  $node = $this->getAccessibleMock(
416  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  $message1 = new ‪FlashMessage('foo');
426  $node->expects($this->any())->method('createFile')->will($this->returnValue($message1));
427  $node->_set('targetContent', 'foo');
428  $message2 = new ‪FlashMessage('foo');
429  $node->expects($this->once())->method('setContent')->will($this->returnValue($message2));
430  $actualReturn = $node->_call('fixSelf');
431  $actualReturn = $actualReturn[1];
432  $this->assertSame($message2, $actualReturn);
433  }
434 
439  {
441  $node = $this->getAccessibleMock(
442  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  $message = new ‪FlashMessage('foo', '', ‪FlashMessage::ERROR);
452  $node->expects($this->any())->method('createFile')->will($this->returnValue($message));
453  $node->_set('targetContent', 'foo');
454  $node->expects($this->never())->method('setContent');
455  $node->_call('fixSelf');
456  }
457 
462  {
464  $node = $this->getAccessibleMock(
465  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  $message = new ‪FlashMessage('foo');
475  $node->expects($this->any())->method('createFile')->will($this->returnValue($message));
476  $node->_set('targetContent', null);
477  $node->expects($this->never())->method('setContent');
478  $node->_call('fixSelf');
479  }
480 
485  {
487  $node = $this->getAccessibleMock(
488  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  $message = new ‪FlashMessage('foo');
498  $node->expects($this->once())->method('fixPermission')->will($this->returnValue($message));
499  $this->assertSame([$message], $node->_call('fixSelf'));
500  }
501 
506  {
508  $node = $this->getAccessibleMock(
509  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  }
520 
525  {
526  $node = $this->getAccessibleMock(
527  FileNode::class,
528  ['exists', 'isFile', 'isPermissionCorrect'],
529  [],
530  '',
531  false
532  );
533  $node->expects($this->any())->method('exists')->will($this->returnValue(true));
534  $node->expects($this->any())->method('isFile')->will($this->returnValue(true));
535  $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
536  $this->assertInternalType('array', $node->_call('fixSelf'));
537  }
538 
543  {
544  $this->expectException(Exception::class);
545  $this->expectExceptionCode(1366398198);
547  $node = $this->getAccessibleMock(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 
557  {
559  $node = $this->getAccessibleMock(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->assertSame(‪FlashMessage::OK, $node->_call('createFile')->getSeverity());
565  }
566 
570  public function ‪createFileCreatesFile()
571  {
573  $node = $this->getAccessibleMock(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 
586  {
588  $node = $this->getAccessibleMock(FileNode::class, ['exists', 'getAbsolutePath', 'getRelativePathBelowSiteRoot'], [], '', false);
589  $path = $this->‪getVirtualTestDir();
590  chmod($path, 02550);
591  $subPath = $path . '/' . $this->getUniqueId('file_');
592  $node->expects($this->once())->method('exists')->will($this->returnValue(false));
593  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath));
594  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($subPath));
595  $this->assertSame(‪FlashMessage::ERROR, $node->_call('createFile')->getSeverity());
596  }
597 
602  {
603  $this->expectException(Exception::class);
604  $this->expectExceptionCode(1367056363);
606  $node = $this->getAccessibleMock(FileNode::class, ['getAbsolutePath'], [], '', false);
607  $path = $this->‪getVirtualTestDir('dir_');
608  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
609  $node->_call('isContentCorrect');
610  }
611 
616  {
618  $node = $this->getAccessibleMock(FileNode::class, ['getAbsolutePath'], [], '', false);
619  $path = $this->‪getVirtualTestFilePath('file_');
620  touch($path);
621  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
622  $node->_set('targetContent', null);
623  $this->assertTrue($node->_call('isContentCorrect'));
624  }
625 
630  {
632  $node = $this->getAccessibleMock(FileNode::class, ['getAbsolutePath'], [], '', false);
633  $path = $this->‪getVirtualTestFilePath('file_');
634  $content = $this->getUniqueId('content_');
635  file_put_contents($path, $content);
636  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
637  $node->_set('targetContent', $content);
638  $this->assertTrue($node->_call('isContentCorrect'));
639  }
640 
645  {
647  $node = $this->getAccessibleMock(FileNode::class, ['getAbsolutePath'], [], '', false);
648  $path = $this->‪getVirtualTestFilePath('file_');
649  $content = $this->getUniqueId('content1_');
650  $targetContent = $this->getUniqueId('content2_');
651  file_put_contents($path, $content);
652  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
653  $node->_set('targetContent', $targetContent);
654  $this->assertFalse($node->_call('isContentCorrect'));
655  }
656 
661  {
662  $parent = $this->createMock(\‪TYPO3\CMS\Install\FolderStructure\NodeInterface::class);
664  $node = $this->getAccessibleMock(FileNode::class, ['getCurrentPermission', 'isWindowsOs'], [], '', false);
665  $node->expects($this->any())->method('isWindowsOs')->will($this->returnValue(false));
666  $node->expects($this->any())->method('getCurrentPermission')->will($this->returnValue('0664'));
667  $targetPermission = '0664';
668  $structure = [
669  'name' => 'foo',
670  'targetPermission' => $targetPermission,
671  ];
672  $node->__construct($structure, $parent);
673  $this->assertTrue($node->_call('isPermissionCorrect'));
674  }
675 
680  {
681  $this->expectException(Exception::class);
682  $this->expectExceptionCode(1367060201);
684  $node = $this->getAccessibleMock(FileNode::class, ['getAbsolutePath'], [], '', false);
685  $path = $this->‪getVirtualTestDir('dir_');
686  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
687  $node->_set('targetContent', 'foo');
688  $node->_call('setContent');
689  }
690 
695  {
696  $this->expectException(Exception::class);
697  $this->expectExceptionCode(1367060202);
699  $node = $this->getAccessibleMock(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 
711  {
713  $node = $this->getAccessibleMock(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 
728  {
730  $node = $this->getAccessibleMock(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->assertSame(‪FlashMessage::OK, $node->_call('setContent')->getSeverity());
737  }
738 
743  {
744  if (function_exists('posix_getegid') && posix_getegid() === 0) {
745  $this->markTestSkipped('Test skipped if run on linux as root');
746  }
748  $node = $this->getAccessibleMock(FileNode::class, ['getAbsolutePath', 'getRelativePathBelowSiteRoot'], [], '', false);
749  ‪$dir = $this->‪getVirtualTestDir('dir_');
750  $file = ‪$dir . '/' . $this->getUniqueId('file_');
751  touch($file);
752  chmod($file, 0440);
753  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($file));
754  $targetContent = $this->getUniqueId('content_');
755  $node->_set('targetContent', $targetContent);
756  $this->assertSame(‪FlashMessage::ERROR, $node->_call('setContent')->getSeverity());
757  }
758 
763  {
765  $node = $this->getAccessibleMock(FileNode::class, ['getAbsolutePath', 'getRelativePathBelowSiteRoot'], [], '', false);
766  $path = $this->‪getVirtualTestFilePath('file_');
767  touch($path);
768  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
769  $this->assertTrue($node->_call('isFile'));
770  }
771 
777  {
779  $node = $this->getAccessibleMock(FileNode::class, ['getAbsolutePath'], [], '', false);
780  $path = ‪Environment::getVarPath() . '/tests/' . $this->getUniqueId('root_');
781  \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
782  $this->testFilesToDelete[] = $path;
783  $link = $this->getUniqueId('link_');
784  $file = $this->getUniqueId('file_');
785  touch($path . '/' . $file);
786  symlink($path . '/' . $file, $path . '/' . $link);
787  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path . '/' . $link));
788  $this->assertFalse($node->_call('isFile'));
789  }
790 }
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\getStatusReturnsArrayWithNoticeStatusIfFileExistsButContentIsNotCorrect
‪getStatusReturnsArrayWithNoticeStatusIfFileExistsButContentIsNotCorrect()
Definition: FileNodeTest.php:319
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest
Definition: FileNodeTest.php:29
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\createFileReturnsOkStatusIfFileWasCreated
‪createFileReturnsOkStatusIfFileWasCreated()
Definition: FileNodeTest.php:556
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\fixSelfDoesNotCallSetContentIfFileTargetContentIsNull
‪fixSelfDoesNotCallSetContentIfFileTargetContentIsNull()
Definition: FileNodeTest.php:461
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\createFileReturnsErrorStatusIfFileWasNotCreated
‪createFileReturnsErrorStatusIfFileWasNotCreated()
Definition: FileNodeTest.php:585
‪TYPO3\CMS\Install\Tests\Unit\FolderStructureTestCase\getVirtualTestDir
‪string getVirtualTestDir($prefix='root_')
Definition: FolderStructureTestCase.php:31
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\createFileCreatesFile
‪createFileCreatesFile()
Definition: FileNodeTest.php:570
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\getStatusReturnsArrayNoticeStatusIfFileExistsButIsNotWritable
‪getStatusReturnsArrayNoticeStatusIfFileExistsButIsNotWritable()
Definition: FileNodeTest.php:267
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\setContentReturnsOkStatusIfContentWasSuccessfullySet
‪setContentReturnsOkStatusIfContentWasSuccessfullySet()
Definition: FileNodeTest.php:727
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\setContentSetsContentToFile
‪setContentSetsContentToFile()
Definition: FileNodeTest.php:710
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\setContentThrowsExceptionIfTargetIsNotAFile
‪setContentThrowsExceptionIfTargetIsNotAFile()
Definition: FileNodeTest.php:679
‪TYPO3
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\fixSelfReturnsArrayOfStatusMessages
‪fixSelfReturnsArrayOfStatusMessages()
Definition: FileNodeTest.php:524
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\isContentCorrectReturnsTrueIfTargetContentEqualsCurrentContent
‪isContentCorrectReturnsTrueIfTargetContentEqualsCurrentContent()
Definition: FileNodeTest.php:629
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\getStatusReturnsArrayWithWarningStatusIFileNotExists
‪getStatusReturnsArrayWithWarningStatusIFileNotExists()
Definition: FileNodeTest.php:216
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\getStatusReturnsArrayWithOkStatusIfFileExistsAndPermissionAreCorrect
‪getStatusReturnsArrayWithOkStatusIfFileExistsAndPermissionAreCorrect()
Definition: FileNodeTest.php:345
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\createFileThrowsExceptionIfNodeExists
‪createFileThrowsExceptionIfNodeExists()
Definition: FileNodeTest.php:542
‪$dir
‪$dir
Definition: validateRstFiles.php:213
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\getStatusReturnsArray
‪getStatusReturnsArray()
Definition: FileNodeTest.php:193
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\getStatusReturnsArrayWithNoticeStatusIfFileExistsButPermissionAreNotCorrect
‪getStatusReturnsArrayWithNoticeStatusIfFileExistsButPermissionAreNotCorrect()
Definition: FileNodeTest.php:293
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\constructorSetsParent
‪constructorSetsParent()
Definition: FileNodeTest.php:61
‪TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
Definition: InvalidArgumentException.php:21
‪TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING
‪const WARNING
Definition: AbstractMessage.php:28
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\constructorThrowsExceptionIfNameContainsForwardSlash
‪constructorThrowsExceptionIfNameContainsForwardSlash()
Definition: FileNodeTest.php:45
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\setContentReturnsErrorStatusIfContentCanNotBeSetSet
‪setContentReturnsErrorStatusIfContentCanNotBeSetSet()
Definition: FileNodeTest.php:742
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure
Definition: AbstractNodeTest.php:2
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\fixSelfCallsCreateFileIfFileDoesNotExistAndReturnsResult
‪fixSelfCallsCreateFileIfFileDoesNotExistAndReturnsResult()
Definition: FileNodeTest.php:389
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\constructorSetsTargetPermission
‪constructorSetsTargetPermission()
Definition: FileNodeTest.php:76
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\isPermissionCorrectReturnsTrueIfTargetPermissionAndCurrentPermissionAreIdentical
‪isPermissionCorrectReturnsTrueIfTargetPermissionAndCurrentPermissionAreIdentical()
Definition: FileNodeTest.php:660
‪TYPO3\CMS\Install\FolderStructure\FileNode
Definition: FileNode.php:24
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\isFileReturnsTrueIfNameIsFile
‪isFileReturnsTrueIfNameIsFile()
Definition: FileNodeTest.php:762
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\fixSelfDoesNotCallSetContentIfFileCreationFailed
‪fixSelfDoesNotCallSetContentIfFileCreationFailed()
Definition: FileNodeTest.php:438
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\isContentCorrectThrowsExceptionIfTargetIsNotAFile
‪isContentCorrectThrowsExceptionIfTargetIsNotAFile()
Definition: FileNodeTest.php:601
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\getStatusReturnsArrayWithErrorStatusIfNodeIsNotAFile
‪getStatusReturnsArrayWithErrorStatusIfNodeIsNotAFile()
Definition: FileNodeTest.php:241
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\isContentCorrectReturnsTrueIfTargetContentPropertyIsNull
‪isContentCorrectReturnsTrueIfTargetContentPropertyIsNull()
Definition: FileNodeTest.php:615
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\fixSelfCallsFixPermissionIfFileExistsButPermissionAreWrong
‪fixSelfCallsFixPermissionIfFileExistsButPermissionAreWrong()
Definition: FileNodeTest.php:505
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\targetContentIsNullIfNotGiven
‪targetContentIsNullIfNotGiven()
Definition: FileNodeTest.php:178
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\fixSelfReturnsErrorStatusIfNodeExistsButIsNotAFileAndReturnsResult
‪fixSelfReturnsErrorStatusIfNodeExistsButIsNotAFileAndReturnsResult()
Definition: FileNodeTest.php:484
‪TYPO3\CMS\Core\Messaging\AbstractMessage\OK
‪const OK
Definition: AbstractMessage.php:27
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\isContentCorrectReturnsFalseIfTargetContentNotEqualsCurrentContent
‪isContentCorrectReturnsFalseIfTargetContentNotEqualsCurrentContent()
Definition: FileNodeTest.php:644
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\isFileReturnsFalseIfNameIsALinkFile
‪isFileReturnsFalseIfNameIsALinkFile()
Definition: FileNodeTest.php:776
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:22
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\constructorThrowsExceptionIfBothTargetContentAndTargetContentFileAreSet
‪constructorThrowsExceptionIfBothTargetContentAndTargetContentFileAreSet()
Definition: FileNodeTest.php:106
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\constructorThrowsExceptionIfParentIsNull
‪constructorThrowsExceptionIfParentIsNull()
Definition: FileNodeTest.php:33
‪TYPO3\CMS\Core\Messaging\AbstractMessage\NOTICE
‪const NOTICE
Definition: AbstractMessage.php:25
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\constructorSetsTargetContentToContentOfTargetContentFile
‪constructorSetsTargetContentToContentOfTargetContentFile()
Definition: FileNodeTest.php:141
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\constructorSetsName
‪constructorSetsName()
Definition: FileNodeTest.php:93
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\constructorThrowsExceptionIfTargetContentFileDoesNotExist
‪constructorThrowsExceptionIfTargetContentFileDoesNotExist()
Definition: FileNodeTest.php:160
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\fixSelfCallsSetsContentIfFileCreationWasSuccessfulAndTargetContentIsNotNullAndReturnsResult
‪fixSelfCallsSetsContentIfFileCreationWasSuccessfulAndTargetContentIsNotNullAndReturnsResult()
Definition: FileNodeTest.php:412
‪TYPO3\CMS\Install\Tests\Unit\FolderStructureTestCase
Definition: FolderStructureTestCase.php:24
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\constructorSetsTargetContent
‪constructorSetsTargetContent()
Definition: FileNodeTest.php:124
‪TYPO3\CMS\Install\FolderStructure\Exception
Definition: InvalidArgumentException.php:2
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:29
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\fixCallsFixSelfAndReturnsItsResult
‪fixCallsFixSelfAndReturnsItsResult()
Definition: FileNodeTest.php:371
‪TYPO3\CMS\Install\Tests\Unit\FolderStructure\FileNodeTest\setContentThrowsExceptionIfTargetContentIsNull
‪setContentThrowsExceptionIfTargetContentIsNull()
Definition: FileNodeTest.php:694
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static string getVarPath()
Definition: Environment.php:165
‪TYPO3\CMS\Install\Tests\Unit\FolderStructureTestCase\getVirtualTestFilePath
‪string getVirtualTestFilePath($prefix='file_')
Definition: FolderStructureTestCase.php:45