TYPO3 CMS  TYPO3_6-2
BaseTestCase.php
Go to the documentation of this file.
1 <?php
3 
17 use \org\bovigo\vfs\vfsStream;
18 
25 
29  protected $basedir = 'basedir';
30 
31  protected $mountDir;
32 
33  protected $vfsContents = array();
34 
35  public function setUp() {
36  $this->mountDir = $this->getUniqueId('mount-');
37  $this->basedir = $this->getUniqueId('base-');
38  vfsStream::setup($this->basedir);
39  // Add an entry for the mount directory to the VFS contents
40  $this->vfsContents = array($this->mountDir => array());
41  }
42 
43  protected function getMountRootUrl() {
44  return $this->getUrlInMount('');
45  }
46 
47  protected function mergeToVfsContents($contents) {
49  }
50 
51  protected function initializeVfs() {
52  if (is_callable('org\\bovigo\\vfs\\vfsStream::create') === FALSE) {
53  $this->markTestSkipped('vfsStream::create() does not exist');
54  }
55  vfsStream::create($this->vfsContents);
56  }
57 
64  protected function addToMount(array $dirStructure) {
65  $this->mergeToVfsContents(array($this->mountDir => $dirStructure));
66  }
67 
74  protected function getUrlInMount($path) {
75  return vfsStream::url($this->basedir . '/' . $this->mountDir . '/' . ltrim($path, '/'));
76  }
77 
84  protected function addToVfs(array $dirStructure) {
85  $this->mergeToVfsContents($dirStructure);
86  }
87 
94  protected function getUrl($path) {
95  return vfsStream::url($this->basedir . '/' . ltrim($path, '/'));
96  }
97 
106  protected function _createFileFolderMock($type, $identifier, $mockedMethods) {
107  if (!empty($mockedMethods)) {
108  if (!in_array('getIdentifier', $mockedMethods)) {
109  $mockedMethods[] = 'getIdentifier';
110  }
111  if (!in_array('getName', $mockedMethods)) {
112  $mockedMethods[] = 'getName';
113  }
114  }
115  $mock = $this->getMock($type, $mockedMethods, array(), '', FALSE);
116  $mock->expects($this->any())->method('getIdentifier')->will($this->returnValue($identifier));
117  $mock->expects($this->any())->method('getName')->will($this->returnValue(basename($identifier)));
118  return $mock;
119  }
120 
128  protected function getSimpleFileMock($identifier, $mockedMethods = array()) {
129  return $this->_createFileFolderMock('TYPO3\\CMS\\Core\\Resource\\File', $identifier, $mockedMethods);
130  }
131 
139  protected function getSimpleFolderMock($identifier, $mockedMethods = array()) {
140  return $this->_createFileFolderMock('TYPO3\\CMS\\Core\\Resource\\Folder', $identifier, $mockedMethods);
141  }
142 
152  protected function getFolderMock($identifier, $mockedMethods = array(), $subfolders = array(), $files = array()) {
153  $folder = $this->_createFileFolderMock('TYPO3\\CMS\\Core\\Resource\\Folder', $identifier, array_merge($mockedMethods, array('getFiles', 'getSubfolders')));
154  $folder->expects($this->any())->method('getSubfolders')->will($this->returnValue($subfolders));
155  $folder->expects($this->any())->method('getFiles')->will($this->returnValue($files));
156  return $folder;
157  }
158 
159 }
getSimpleFolderMock($identifier, $mockedMethods=array())
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=TRUE, $includeEmptyValues=TRUE, $enableUnsetFeature=TRUE)
getSimpleFileMock($identifier, $mockedMethods=array())
getFolderMock($identifier, $mockedMethods=array(), $subfolders=array(), $files=array())
_createFileFolderMock($type, $identifier, $mockedMethods)