TYPO3 CMS  TYPO3_7-6
BaseTestCase.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  */
16 
18 
23 {
27  protected $basedir = 'basedir';
28 
29  protected $mountDir;
30 
31  protected $vfsContents = [];
32 
33  protected function setUp()
34  {
35  $this->mountDir = $this->getUniqueId('mount-');
36  $this->basedir = $this->getUniqueId('base-');
37  vfsStream::setup($this->basedir);
38  // Add an entry for the mount directory to the VFS contents
39  $this->vfsContents = [$this->mountDir => []];
40  }
41 
42  protected function getMountRootUrl()
43  {
44  return $this->getUrlInMount('');
45  }
46 
47  protected function mergeToVfsContents($contents)
48  {
50  }
51 
52  protected function initializeVfs()
53  {
54  if (is_callable('org\\bovigo\\vfs\\vfsStream::create') === false) {
55  $this->markTestSkipped('vfsStream::create() does not exist');
56  }
57  vfsStream::create($this->vfsContents);
58  }
59 
66  protected function addToMount(array $dirStructure)
67  {
68  $this->mergeToVfsContents([$this->mountDir => $dirStructure]);
69  }
70 
77  protected function getUrlInMount($path)
78  {
79  return vfsStream::url($this->basedir . '/' . $this->mountDir . '/' . ltrim($path, '/'));
80  }
81 
88  protected function addToVfs(array $dirStructure)
89  {
90  $this->mergeToVfsContents($dirStructure);
91  }
92 
99  protected function getUrl($path)
100  {
101  return vfsStream::url($this->basedir . '/' . ltrim($path, '/'));
102  }
103 
112  protected function _createFileFolderMock($type, $identifier, $mockedMethods)
113  {
114  if (!empty($mockedMethods)) {
115  if (!in_array('getIdentifier', $mockedMethods)) {
116  $mockedMethods[] = 'getIdentifier';
117  }
118  if (!in_array('getName', $mockedMethods)) {
119  $mockedMethods[] = 'getName';
120  }
121  }
122  $mock = $this->getMock($type, $mockedMethods, [], '', false);
123  $mock->expects($this->any())->method('getIdentifier')->will($this->returnValue($identifier));
124  $mock->expects($this->any())->method('getName')->will($this->returnValue(basename($identifier)));
125  return $mock;
126  }
127 
135  protected function getSimpleFileMock($identifier, $mockedMethods = [])
136  {
137  return $this->_createFileFolderMock(\TYPO3\CMS\Core\Resource\File::class, $identifier, $mockedMethods);
138  }
139 
147  protected function getSimpleFolderMock($identifier, $mockedMethods = [])
148  {
149  return $this->_createFileFolderMock(\TYPO3\CMS\Core\Resource\Folder::class, $identifier, $mockedMethods);
150  }
151 
161  protected function getFolderMock($identifier, $mockedMethods = [], $subfolders = [], $files = [])
162  {
163  $folder = $this->_createFileFolderMock(\TYPO3\CMS\Core\Resource\Folder::class, $identifier, array_merge($mockedMethods, ['getFiles', 'getSubfolders']));
164  $folder->expects($this->any())->method('getSubfolders')->will($this->returnValue($subfolders));
165  $folder->expects($this->any())->method('getFiles')->will($this->returnValue($files));
166  return $folder;
167  }
168 }
getSimpleFileMock($identifier, $mockedMethods=[])
getFolderMock($identifier, $mockedMethods=[], $subfolders=[], $files=[])
_createFileFolderMock($type, $identifier, $mockedMethods)
getSimpleFolderMock($identifier, $mockedMethods=[])
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)