[FEATURE] Introduce new @import syntax for TS includes
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / FileStreamWrapperTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit;
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 use org\bovigo\vfs\vfsStream;
17 use org\bovigo\vfs\visitor\vfsStreamStructureVisitor;
18 use TYPO3\TestingFramework\Core\FileStreamWrapper;
19
20 /**
21 * Test case for \TYPO3\CMS\Core\Tests\Unit\FileStreamWrapper
22 */
23 class FileStreamWrapperTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
24 {
25 /**
26 * @test
27 */
28 public function pathsAreOverlaidAndFinalDirectoryStructureCanBeQueried()
29 {
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);
37
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);
44
45 $expectedFileSystem = [
46 'root' => [
47 'fileadmin' => [
48 'ext_typoscript_setup.txt' => 'test.Core.TypoScript = 1',
49 'test' => ['Foo.bar' => 'Baz'],
50 'setup.typoscript' => 'test.TYPO3Forever.TypoScript = 1
51 ',
52 'recursive_includes_setup.typoscript' => '@import \'EXT:core/Tests/Unit/TypoScript/Fixtures/setup.typoscript\'
53 ',
54 'badfilename.php' => 'good.bad = ugly
55 '
56 ],
57 ],
58 ];
59 $this->assertEquals($expectedFileSystem, vfsStream::inspect(new vfsStreamStructureVisitor())->getStructure());
60 FileStreamWrapper::destroy();
61 }
62
63 /**
64 * @test
65 */
66 public function windowsPathsCanBeProcessed()
67 {
68 $cRoot = 'C:\\Windows\\Root\\Path\\';
69 vfsStream::setup('root');
70 FileStreamWrapper::init($cRoot);
71 FileStreamWrapper::registerOverlayPath('fileadmin', 'vfs://root/fileadmin');
72
73 touch($cRoot . 'fileadmin\\someFile.txt');
74 $expectedFileStructure = [
75 'root' => [
76 'fileadmin' => ['someFile.txt' => null],
77 ],
78 ];
79
80 $this->assertEquals($expectedFileStructure, vfsStream::inspect(new vfsStreamStructureVisitor())->getStructure());
81 FileStreamWrapper::destroy();
82 }
83
84 /**
85 * @test
86 */
87 public function symlinksCanBeCreated()
88 {
89 $this->markTestSkipped('symlink() is not routed through the stream wrapper as of PHP 5.5, therefore we cannot test it');
90 /*
91 * symlink() is not routed through the stream wrapper as of PHP 5.5,
92 * therefore we cannot test it.
93 */
94 vfsStream::setup('root');
95 FileStreamWrapper::init(PATH_site);
96 FileStreamWrapper::registerOverlayPath('fileadmin', 'vfs://root/fileadmin');
97
98 $path = PATH_site . 'fileadmin/';
99 touch($path . 'file1.txt');
100 symlink($path . 'file1.txt', $path . 'file2.txt');
101
102 $this->assertTrue(is_link($path . 'file2.txt'));
103 FileStreamWrapper::destroy();
104 }
105 }