TYPO3 CMS  TYPO3_8-7
FileStreamWrapperTest.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  */
19 
23 class FileStreamWrapperTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
24 {
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  ],
51  ],
52  ];
53  $this->assertEquals($expectedFileSystem, vfsStream::inspect(new vfsStreamStructureVisitor())->getStructure());
54  FileStreamWrapper::destroy();
55  }
56 
60  public function windowsPathsCanBeProcessed()
61  {
62  $cRoot = 'C:\\Windows\\Root\\Path\\';
63  vfsStream::setup('root');
64  FileStreamWrapper::init($cRoot);
65  FileStreamWrapper::registerOverlayPath('fileadmin', 'vfs://root/fileadmin');
66 
67  touch($cRoot . 'fileadmin\\someFile.txt');
68  $expectedFileStructure = [
69  'root' => [
70  'fileadmin' => ['someFile.txt' => null],
71  ],
72  ];
73 
74  $this->assertEquals($expectedFileStructure, vfsStream::inspect(new vfsStreamStructureVisitor())->getStructure());
75  FileStreamWrapper::destroy();
76  }
77 
81  public function symlinksCanBeCreated()
82  {
83  $this->markTestSkipped('symlink() is not routed through the stream wrapper as of PHP 5.5, therefore we cannot test it');
84  /*
85  * symlink() is not routed through the stream wrapper as of PHP 5.5,
86  * therefore we cannot test it.
87  */
88  vfsStream::setup('root');
89  FileStreamWrapper::init(PATH_site);
90  FileStreamWrapper::registerOverlayPath('fileadmin', 'vfs://root/fileadmin');
91 
92  $path = PATH_site . 'fileadmin/';
93  touch($path . 'file1.txt');
94  symlink($path . 'file1.txt', $path . 'file2.txt');
95 
96  $this->assertTrue(is_link($path . 'file2.txt'));
97  FileStreamWrapper::destroy();
98  }
99 }