[BUGFIX] Missing stream_cast() in FileStreamWrapper
[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 FileStreamWrapper::destroy();
55 }
56
57 /**
58 * @test
59 */
60 public function windowsPathsCanBeProcessed() {
61 $cRoot = 'C:\\Windows\\Root\\Path\\';
62 $root = vfsStream::setup('root');
63 FileStreamWrapper::init($cRoot);
64 FileStreamWrapper::registerOverlayPath('fileadmin', 'vfs://root/fileadmin');
65
66 touch($cRoot . 'fileadmin\\someFile.txt');
67 $expectedFileStructure = array(
68 'root' => array(
69 'fileadmin' => array('someFile.txt' => NULL),
70 ),
71 );
72
73 $this->assertEquals($expectedFileStructure, vfsStream::inspect(new vfsStreamStructureVisitor())->getStructure());
74 FileStreamWrapper::destroy();
75 }
76
77 /**
78 * @test
79 */
80 public function symlinksCanBeCreated() {
81 $this->markTestSkipped('symlink() is not routed through the stream wrapper as of PHP 5.5, therefore we cannot test it');
82 /*
83 * symlink() is not routed through the stream wrapper as of PHP 5.5,
84 * therefore we cannot test it.
85 */
86 vfsStream::setup('root');
87 FileStreamWrapper::init(PATH_site);
88 FileStreamWrapper::registerOverlayPath('fileadmin', 'vfs://root/fileadmin');
89
90 $path = PATH_site . 'fileadmin/';
91 touch($path . 'file1.txt');
92 symlink($path . 'file1.txt', $path . 'file2.txt');
93
94 $this->assertTrue(is_link($path . 'file2.txt'));
95 FileStreamWrapper::destroy();
96 }
97 }