29cc69389383cce24b93ec9c6b9ebf3d148ec97b
[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
17 use org\bovigo\vfs\vfsStream;
18 use org\bovigo\vfs\visitor\vfsStreamStructureVisitor;
19 use TYPO3\CMS\Core\Tests\FileStreamWrapper;
20
21 /**
22 * Test case for \TYPO3\CMS\Core\Tests\Unit\FileStreamWrapper
23 */
24 class FileStreamWrapperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
25
26 /**
27 * @test
28 */
29 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);
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 = array(
46 'root' => array(
47 'fileadmin' => array(
48 'ext_typoscript_setup.txt' => 'test.Core.TypoScript = 1',
49 'test' => array('Foo.bar' => 'Baz'),
50 ),
51 ),
52 );
53 $this->assertEquals($expectedFileSystem, vfsStream::inspect(new vfsStreamStructureVisitor())->getStructure());
54
55 FileStreamWrapper::destroy();
56 }
57
58 /**
59 * @test
60 */
61 public function windowsPathsCanBeProcessed() {
62 $cRoot = 'C:\\Windows\\Root\\Path\\';
63 $root = vfsStream::setup('root');
64 FileStreamWrapper::init($cRoot);
65 FileStreamWrapper::registerOverlayPath('fileadmin', 'vfs://root/fileadmin');
66
67 touch($cRoot . 'fileadmin\\someFile.txt');
68 $expectedFileStructure = array(
69 'root' => array(
70 'fileadmin' => array('someFile.txt' => NULL),
71 ),
72 );
73
74 $this->assertEquals($expectedFileStructure, vfsStream::inspect(new vfsStreamStructureVisitor())->getStructure());
75 FileStreamWrapper::destroy();
76 }
77
78 /**
79 * @test
80 */
81 public function symlinksCanBeCreated() {
82 $this->markTestSkipped('symlink() is not routed through the stream wrapper as of PHP 5.5, therefore we cannot test it');
83 /*
84 * symlink() is not routed through the stream wrapper as of PHP 5.5,
85 * therefore we cannot test it.
86 */
87 vfsStream::setup('root');
88 FileStreamWrapper::init(PATH_site);
89 FileStreamWrapper::registerOverlayPath('fileadmin', 'vfs://root/fileadmin');
90
91 $path = PATH_site . 'fileadmin/';
92 touch($path . 'file1.txt');
93 symlink($path . 'file1.txt', $path . 'file2.txt');
94
95 $this->assertTrue(is_link($path . 'file2.txt'));
96 }
97 }