2 namespace TYPO3\CMS\Core\Tests\Unit
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
16 use org\bovigo\vfs\vfsStream
;
17 use org\bovigo\vfs\visitor\vfsStreamStructureVisitor
;
18 use TYPO3\TestingFramework\Core\FileStreamWrapper
;
21 * Test case for \TYPO3\CMS\Core\Tests\Unit\FileStreamWrapper
23 class FileStreamWrapperTest
extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
28 public function pathsAreOverlaidAndFinalDirectoryStructureCanBeQueried()
30 $root = vfsStream
::setup('root');
31 $subfolder = vfsStream
::newDirectory('fileadmin');
32 $root->addChild($subfolder);
33 // Load fixture files and folders from disk
34 vfsStream
::copyFromFileSystem(__DIR__
. '/TypoScript/Fixtures', $subfolder, 1024*1024);
35 FileStreamWrapper
::init(PATH_site
);
36 FileStreamWrapper
::registerOverlayPath('fileadmin', 'vfs://root/fileadmin', false);
38 // Use file functions as normal
39 mkdir(PATH_site
. 'fileadmin/test/');
40 $file = PATH_site
. 'fileadmin/test/Foo.bar';
41 file_put_contents($file, 'Baz');
42 $content = file_get_contents($file);
43 $this->assertSame('Baz', $content);
45 $expectedFileSystem = [
48 'ext_typoscript_setup.txt' => 'test.Core.TypoScript = 1',
49 'test' => ['Foo.bar' => 'Baz'],
50 'setup.typoscript' => 'test.TYPO3Forever.TypoScript = 1
52 'recursive_includes_setup.typoscript' => '@import \'EXT:core/Tests/Unit/TypoScript/Fixtures/setup.typoscript\'
54 'badfilename.php' => 'good.bad = ugly
59 $this->assertEquals($expectedFileSystem, vfsStream
::inspect(new vfsStreamStructureVisitor())->getStructure());
60 FileStreamWrapper
::destroy();
66 public function windowsPathsCanBeProcessed()
68 $cRoot = 'C:\\Windows\\Root\\Path\\';
69 vfsStream
::setup('root');
70 FileStreamWrapper
::init($cRoot);
71 FileStreamWrapper
::registerOverlayPath('fileadmin', 'vfs://root/fileadmin');
73 touch($cRoot . 'fileadmin\\someFile.txt');
74 $expectedFileStructure = [
76 'fileadmin' => ['someFile.txt' => null],
80 $this->assertEquals($expectedFileStructure, vfsStream
::inspect(new vfsStreamStructureVisitor())->getStructure());
81 FileStreamWrapper
::destroy();
87 public function symlinksCanBeCreated()
89 $this->markTestSkipped('symlink() is not routed through the stream wrapper as of PHP 5.5, therefore we cannot test it');
91 * symlink() is not routed through the stream wrapper as of PHP 5.5,
92 * therefore we cannot test it.
94 vfsStream
::setup('root');
95 FileStreamWrapper
::init(PATH_site
);
96 FileStreamWrapper
::registerOverlayPath('fileadmin', 'vfs://root/fileadmin');
98 $path = PATH_site
. 'fileadmin/';
99 touch($path . 'file1.txt');
100 symlink($path . 'file1.txt', $path . 'file2.txt');
102 $this->assertTrue(is_link($path . 'file2.txt'));
103 FileStreamWrapper
::destroy();