TYPO3 CMS  TYPO3_6-2
InstallUtilityTest.php
Go to the documentation of this file.
1 <?php
3 
21 
25  protected $extensionKey;
26 
30  protected $extensionData = array();
31 
35  protected $fakedExtensions = array();
36 
40  protected $installMock;
41 
45  public function setUp() {
46  $this->extensionKey = 'dummy';
47  $this->extensionData = array(
48  'key' => $this->extensionKey
49  );
50  $this->installMock = $this->getAccessibleMock(
51  'TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility',
52  array(
53  'isLoaded',
54  'loadExtension',
55  'unloadExtension',
56  'processDatabaseUpdates',
57  'processRuntimeDatabaseUpdates',
58  'reloadCaches',
59  'processCachingFrameworkUpdates',
60  'saveDefaultConfiguration',
61  'enrichExtensionWithDetails',
62  'ensureConfiguredDirectoriesExist',
63  'importInitialFiles'
64  ),
65  array(),
66  '',
67  FALSE
68  );
69  $dependencyUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility');
70  $this->installMock->_set('dependencyUtility', $dependencyUtility);
71  $this->installMock->expects($this->any())
72  ->method('enrichExtensionWithDetails')
73  ->with($this->extensionKey)
74  ->will($this->returnCallback(array($this, 'getExtensionData')));
75  }
76 
80  public function getExtensionData() {
81  return $this->extensionData;
82  }
83 
87  public function tearDown() {
88  foreach ($this->fakedExtensions as $extension => $dummy) {
89  \TYPO3\CMS\Core\Utility\GeneralUtility::rmdir(PATH_site . 'typo3temp/' . $extension, TRUE);
90  }
91  parent::tearDown();
92  }
93 
100  protected function createFakeExtension() {
101  $extKey = strtolower($this->getUniqueId('testing'));
102  $absExtPath = PATH_site . 'typo3temp/' . $extKey;
103  $relPath = 'typo3temp/' . $extKey . '/';
105  $this->fakedExtensions[$extKey] = array(
106  'siteRelPath' => $relPath
107  );
108  return $extKey;
109  }
110 
115  $this->installMock->expects($this->once())
116  ->method('processRuntimeDatabaseUpdates')
117  ->with($this->extensionKey);
118 
119  $cacheManagerMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager');
120  $cacheManagerMock->expects($this->once())->method('flushCachesInGroup');
121  $this->installMock->_set('cacheManager', $cacheManagerMock);
122  $this->installMock->install($this->extensionKey);
123  }
124 
128  public function installCallsLoadExtension() {
129  $cacheManagerMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager');
130  $cacheManagerMock->expects($this->once())->method('flushCachesInGroup');
131  $this->installMock->_set('cacheManager', $cacheManagerMock);
132  $this->installMock->expects($this->once())->method('loadExtension');
133  $this->installMock->install($this->extensionKey);
134  }
135 
140  $this->extensionData['clearcacheonload'] = TRUE;
141  $cacheManagerMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager');
142  $cacheManagerMock->expects($this->once())->method('flushCaches');
143  $this->installMock->_set('cacheManager', $cacheManagerMock);
144  $this->installMock->install($this->extensionKey);
145  }
146 
151  $this->extensionData['clearCacheOnLoad'] = TRUE;
152  $cacheManagerMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager');
153  $cacheManagerMock->expects($this->once())->method('flushCaches');
154  $this->installMock->_set('cacheManager', $cacheManagerMock);
155  $this->installMock->install($this->extensionKey);
156  }
157 
162  $cacheManagerMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager');
163  $cacheManagerMock->expects($this->once())->method('flushCachesInGroup');
164  $this->installMock->_set('cacheManager', $cacheManagerMock);
165  $this->installMock->expects($this->once())->method('ensureConfiguredDirectoriesExist');
166  $this->installMock->install($this->extensionKey);
167  }
168 
172  public function installCallsReloadCaches() {
173  $cacheManagerMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager');
174  $cacheManagerMock->expects($this->once())->method('flushCachesInGroup');
175  $this->installMock->_set('cacheManager', $cacheManagerMock);
176  $this->installMock->expects($this->once())->method('reloadCaches');
177  $this->installMock->install('dummy');
178  }
179 
184  $cacheManagerMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager');
185  $cacheManagerMock->expects($this->once())->method('flushCachesInGroup');
186  $this->installMock->_set('cacheManager', $cacheManagerMock);
187  $this->installMock->expects($this->once())->method('saveDefaultConfiguration')->with('dummy');
188  $this->installMock->install('dummy');
189  }
190 
194  public function uninstallCallsUnloadExtension() {
195  $this->installMock->expects($this->once())->method('unloadExtension');
196  $this->installMock->uninstall($this->extensionKey);
197  }
198 
203  $extKey = $this->createFakeExtension();
204  $extPath = PATH_site . 'typo3temp/' . $extKey . '/';
205  $extTablesFile = $extPath . 'ext_tables.sql';
206  $fileContent = 'DUMMY TEXT TO COMPARE';
207  file_put_contents($extTablesFile, $fileContent);
209  'TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility',
210  array('updateDbWithExtTablesSql', 'importStaticSqlFile', 'importT3DFile'),
211  array(),
212  '',
213  FALSE
214  );
215  $dependencyUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility');
216  $installMock->_set('dependencyUtility', $dependencyUtility);
217 
218  $installMock->expects($this->once())->method('updateDbWithExtTablesSql')->with($this->stringStartsWith($fileContent));
219  $installMock->processDatabaseUpdates($this->fakedExtensions[$extKey]);
220  }
221 
226  $extKey = $this->createFakeExtension();
227  $extRelPath = 'typo3temp/' . $extKey . '/';
229  'TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility',
230  array('importStaticSqlFile', 'updateDbWithExtTablesSql', 'importT3DFile'),
231  array(),
232  '',
233  FALSE
234  );
235  $dependencyUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility');
236  $installMock->_set('dependencyUtility', $dependencyUtility);
237  $installMock->expects($this->once())->method('importStaticSqlFile')->with($extRelPath);
238  $installMock->processDatabaseUpdates($this->fakedExtensions[$extKey]);
239  }
240 
245  return array(
246  'T3D file' => array(
247  'data.t3d'
248  ),
249  'XML file' => array(
250  'data.xml'
251  )
252  );
253  }
254 
260  public function processDatabaseUpdatesCallsImportFile($fileName) {
261  $extKey = $this->createFakeExtension();
262  $absPath = PATH_site . $this->fakedExtensions[$extKey]['siteRelPath'];
263  \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($absPath . '/Initialisation');
264  file_put_contents($absPath . '/Initialisation/' . $fileName, 'DUMMY');
266  'TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility',
267  array('updateDbWithExtTablesSql', 'importStaticSqlFile', 'importT3DFile'),
268  array(),
269  '',
270  FALSE
271  );
272  $dependencyUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility');
273  $installMock->_set('dependencyUtility', $dependencyUtility);
274  $installMock->expects($this->once())->method('importT3DFile')->with($this->fakedExtensions[$extKey]['siteRelPath']);
275  $installMock->processDatabaseUpdates($this->fakedExtensions[$extKey]);
276  }
277 
282  return array(
283  'Import T3D file when T3D was imported before extension to XML' => array(
284  'data.t3d',
285  'dataImported',
286  'data.t3d',
287  ),
288  'Import T3D file when a file was imported after extension to XML' => array(
289  'data.t3d',
290  'data.t3d',
291  'dataImported'
292  ),
293  'Import XML file when T3D was imported before extension to XML' => array(
294  'data.xml',
295  'dataImported',
296  'data.t3d'
297  ),
298  'Import XML file when a file was imported after extension to XML' => array(
299  'data.xml',
300  'data.t3d',
301  'dataImported'
302  )
303  );
304  }
305 
314  public function importT3DFileDoesNotImportFileIfAlreadyImported($fileName, $registryNameReturnsFalse, $registryNameReturnsTrue) {
315  $extKey = $this->createFakeExtension();
316  $absPath = PATH_site . $this->fakedExtensions[$extKey]['siteRelPath'];
317  \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($absPath . 'Initialisation');
318  file_put_contents($absPath . 'Initialisation/' . $fileName, 'DUMMY');
319  $registryMock = $this->getMock('\\TYPO3\\CMS\\Core\\Registry', array('get', 'set'));
320  $registryMock
321  ->expects($this->any())
322  ->method('get')
323  ->will($this->returnValueMap(
324  array(
325  array('extensionDataImport', $this->fakedExtensions[$extKey]['siteRelPath'] . 'Initialisation/' . $registryNameReturnsFalse, NULL, FALSE),
326  array('extensionDataImport', $this->fakedExtensions[$extKey]['siteRelPath'] . 'Initialisation/' . $registryNameReturnsTrue, NULL, TRUE),
327  )
328  ));
330  'TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility',
331  array('getRegistry', 'getImportExportUtility'),
332  array(),
333  '',
334  FALSE
335  );
336  $dependencyUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility');
337  $installMock->_set('dependencyUtility', $dependencyUtility);
338  $installMock->_set('registry', $registryMock);
339  $installMock->expects($this->never())->method('getImportExportUtility');
340  $installMock->_call('importT3DFile', $this->fakedExtensions[$extKey]['siteRelPath']);
341  }
342 }
static rmdir($path, $removeNonEmpty=FALSE)
importT3DFileDoesNotImportFileIfAlreadyImported($fileName, $registryNameReturnsFalse, $registryNameReturnsTrue)
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)