‪TYPO3CMS  9.5
InstallUtilityTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪InstallUtilityTest extends UnitTestCase
30 {
34  protected ‪$extensionKey;
35 
39  protected ‪$extensionData = [];
40 
44  protected ‪$fakedExtensions = [];
45 
49  protected ‪$installMock;
50 
53  protected function ‪setUp()
54  {
55  $this->extensionKey = 'dummy';
56  $this->extensionData = [
57  'key' => ‪$this->extensionKey,
58  'siteRelPath' => '',
59  ];
60  $this->installMock = $this->getAccessibleMock(
61  InstallUtility::class,
62  [
63  'isLoaded',
64  'loadExtension',
65  'unloadExtension',
66  'updateDatabase',
67  'importStaticSqlFile',
68  'importT3DFile',
69  'reloadCaches',
70  'processCachingFrameworkUpdates',
71  'saveDefaultConfiguration',
72  'getExtensionArray',
73  'enrichExtensionWithDetails',
74  'ensureConfiguredDirectoriesExist',
75  'importInitialFiles',
76  'emitAfterExtensionInstallSignal',
77  ],
78  [],
79  '',
80  false
81  );
82  $dependencyUtility = $this->getMockBuilder(DependencyUtility::class)->getMock();
83  $this->installMock->_set('dependencyUtility', $dependencyUtility);
84  $this->installMock->expects($this->any())
85  ->method('getExtensionArray')
86  ->with($this->extensionKey)
87  ->will($this->returnCallback([$this, 'getExtensionData']));
88  $this->installMock->expects($this->any())
89  ->method('enrichExtensionWithDetails')
90  ->with($this->extensionKey)
91  ->will($this->returnCallback([$this, 'getExtensionData']));
92  }
93 
97  public function ‪getExtensionData(): array
98  {
100  }
101 
104  protected function ‪tearDown()
105  {
106  foreach ($this->fakedExtensions as $fakeExtkey => $fakeExtension) {
107  $this->testFilesToDelete[] = ‪Environment::getVarPath() . '/tests/' . $fakeExtkey;
108  }
109  parent::tearDown();
110  }
111 
118  protected function ‪createFakeExtension(): string
119  {
120  $extKey = strtolower($this->getUniqueId('testing'));
121  $absExtPath = ‪Environment::getVarPath() . '/tests/' . $extKey;
122  $relPath = 'typo3temp/var/tests/' . $extKey . '/';
123  GeneralUtility::mkdir($absExtPath);
124  $this->fakedExtensions[$extKey] = [
125  'siteRelPath' => $relPath
126  ];
127  return $extKey;
128  }
129 
133  public function ‪installCallsUpdateDatabase()
134  {
135  $this->installMock->expects($this->once())
136  ->method('updateDatabase')
137  ->with([$this->extensionKey]);
138 
139  $cacheManagerMock = $this->getMockBuilder(CacheManager::class)->getMock();
140  $cacheManagerMock->expects($this->once())->method('flushCachesInGroup');
141  $this->installMock->_set('cacheManager', $cacheManagerMock);
142  $this->installMock->install($this->extensionKey);
143  }
144 
148  public function ‪installCallsLoadExtension()
149  {
150  $cacheManagerMock = $this->getMockBuilder(CacheManager::class)->getMock();
151  $cacheManagerMock->expects($this->once())->method('flushCachesInGroup');
152  $this->installMock->_set('cacheManager', $cacheManagerMock);
153  $this->installMock->expects($this->once())->method('loadExtension');
154  $this->installMock->install($this->extensionKey);
155  }
156 
161  {
162  $this->extensionData['clearcacheonload'] = true;
163  $cacheManagerMock = $this->getMockBuilder(CacheManager::class)->getMock();
164  $cacheManagerMock->expects($this->once())->method('flushCaches');
165  $this->installMock->_set('cacheManager', $cacheManagerMock);
166  $this->installMock->install($this->extensionKey);
167  }
168 
173  {
174  $this->extensionData['clearCacheOnLoad'] = true;
175  $cacheManagerMock = $this->getMockBuilder(CacheManager::class)->getMock();
176  $cacheManagerMock->expects($this->once())->method('flushCaches');
177  $this->installMock->_set('cacheManager', $cacheManagerMock);
178  $this->installMock->install($this->extensionKey);
179  }
180 
185  {
186  $cacheManagerMock = $this->getMockBuilder(CacheManager::class)->getMock();
187  $cacheManagerMock->expects($this->once())->method('flushCachesInGroup');
188  $this->installMock->_set('cacheManager', $cacheManagerMock);
189  $this->installMock->expects($this->once())->method('ensureConfiguredDirectoriesExist');
190  $this->installMock->install($this->extensionKey);
191  }
192 
196  public function ‪installCallsReloadCaches()
197  {
198  $cacheManagerMock = $this->getMockBuilder(CacheManager::class)->getMock();
199  $cacheManagerMock->expects($this->once())->method('flushCachesInGroup');
200  $this->installMock->_set('cacheManager', $cacheManagerMock);
201  $this->installMock->expects($this->once())->method('reloadCaches');
202  $this->installMock->install($this->extensionKey);
203  }
204 
209  {
210  $cacheManagerMock = $this->getMockBuilder(CacheManager::class)->getMock();
211  $cacheManagerMock->expects($this->once())->method('flushCachesInGroup');
212  $this->installMock->_set('cacheManager', $cacheManagerMock);
213  $this->installMock->expects($this->once())->method('saveDefaultConfiguration')->with($this->extensionKey);
214  $this->installMock->install($this->extensionKey);
215  }
216 
220  public function ‪uninstallCallsUnloadExtension()
221  {
222  $this->installMock->expects($this->once())->method('unloadExtension');
223  $this->installMock->uninstall($this->extensionKey);
224  }
225 
230  {
231  return [
232  'Import T3D file when T3D was imported before extension to XML' => [
233  'data.t3d',
234  'dataImported',
235  'data.t3d',
236  ],
237  'Import T3D file when a file was imported after extension to XML' => [
238  'data.t3d',
239  'data.t3d',
240  'dataImported'
241  ],
242  'Import XML file when T3D was imported before extension to XML' => [
243  'data.xml',
244  'dataImported',
245  'data.t3d'
246  ],
247  'Import XML file when a file was imported after extension to XML' => [
248  'data.xml',
249  'data.t3d',
250  'dataImported'
251  ]
252  ];
253  }
254 
262  public function ‪importT3DFileDoesNotImportFileIfAlreadyImported($fileName, $registryNameReturnsFalse, $registryNameReturnsTrue)
263  {
264  $extKey = $this->‪createFakeExtension();
265  $absPath = ‪Environment::getPublicPath() . '/' . $this->fakedExtensions[$extKey]['siteRelPath'];
266  GeneralUtility::mkdir($absPath . 'Initialisation');
267  file_put_contents($absPath . 'Initialisation/' . $fileName, 'DUMMY');
268  $registryMock = $this->getMockBuilder(Registry::class)
269  ->setMethods(['get', 'set'])
270  ->getMock();
271  $registryMock
272  ->expects($this->any())
273  ->method('get')
274  ->will($this->returnValueMap(
275  [
276  ['extensionDataImport', $this->fakedExtensions[$extKey]['siteRelPath'] . 'Initialisation/' . $registryNameReturnsFalse, null, false],
277  ['extensionDataImport', $this->fakedExtensions[$extKey]['siteRelPath'] . 'Initialisation/' . $registryNameReturnsTrue, null, true],
278  ]
279  ));
280  ‪$installMock = $this->getAccessibleMock(
281  InstallUtility::class,
282  ['getRegistry', 'getImportExportUtility'],
283  [],
284  '',
285  false
286  );
287  $dependencyUtility = $this->getMockBuilder(DependencyUtility::class)->getMock();
288  ‪$installMock->_set('dependencyUtility', $dependencyUtility);
289  ‪$installMock->_set('registry', $registryMock);
290  ‪$installMock->expects($this->never())->method('getImportExportUtility');
291  ‪$installMock->_call('importT3DFile', $this->fakedExtensions[$extKey]['siteRelPath']);
292  }
293 }
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\InstallUtilityTest\installCallsReloadCaches
‪installCallsReloadCaches()
Definition: InstallUtilityTest.php:192
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\InstallUtilityTest\installCallsFlushCachesIfClearCacheOnLoadCamelCasedIsSet
‪installCallsFlushCachesIfClearCacheOnLoadCamelCasedIsSet()
Definition: InstallUtilityTest.php:168
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\InstallUtilityTest
Definition: InstallUtilityTest.php:30
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:153
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility
Definition: DependencyUtilityTest.php:2
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:32
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\InstallUtilityTest\installCallsSaveDefaultConfigurationWithExtensionKey
‪installCallsSaveDefaultConfigurationWithExtensionKey()
Definition: InstallUtilityTest.php:204
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\InstallUtilityTest\$extensionKey
‪string $extensionKey
Definition: InstallUtilityTest.php:33
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\InstallUtilityTest\importT3DFileDoesNotImportFileIfAlreadyImported
‪importT3DFileDoesNotImportFileIfAlreadyImported($fileName, $registryNameReturnsFalse, $registryNameReturnsTrue)
Definition: InstallUtilityTest.php:258
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\InstallUtilityTest\uninstallCallsUnloadExtension
‪uninstallCallsUnloadExtension()
Definition: InstallUtilityTest.php:216
‪TYPO3\CMS\Extensionmanager\Utility\InstallUtility
Definition: InstallUtility.php:32
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\InstallUtilityTest\installCallsLoadExtension
‪installCallsLoadExtension()
Definition: InstallUtilityTest.php:144
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\InstallUtilityTest\importT3DFileDoesNotImportFileIfAlreadyImportedDataProvider
‪array importT3DFileDoesNotImportFileIfAlreadyImportedDataProvider()
Definition: InstallUtilityTest.php:225
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\InstallUtilityTest\tearDown
‪tearDown()
Definition: InstallUtilityTest.php:100
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\InstallUtilityTest\createFakeExtension
‪string createFakeExtension()
Definition: InstallUtilityTest.php:114
‪TYPO3\CMS\Extensionmanager\Utility\DependencyUtility
Definition: DependencyUtility.php:28
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\InstallUtilityTest\$extensionData
‪array $extensionData
Definition: InstallUtilityTest.php:37
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\InstallUtilityTest\installCallsUpdateDatabase
‪installCallsUpdateDatabase()
Definition: InstallUtilityTest.php:129
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\InstallUtilityTest\installCallsFlushCachesIfClearCacheOnLoadIsSet
‪installCallsFlushCachesIfClearCacheOnLoadIsSet()
Definition: InstallUtilityTest.php:156
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\InstallUtilityTest\installationOfAnExtensionWillCallEnsureThatDirectoriesExist
‪installationOfAnExtensionWillCallEnsureThatDirectoriesExist()
Definition: InstallUtilityTest.php:180
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\InstallUtilityTest\setUp
‪setUp()
Definition: InstallUtilityTest.php:49
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\InstallUtilityTest\$installMock
‪PHPUnit_Framework_MockObject_MockObject InstallUtility TYPO3 TestingFramework Core AccessibleObjectInterface $installMock
Definition: InstallUtilityTest.php:45
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\InstallUtilityTest\getExtensionData
‪array getExtensionData()
Definition: InstallUtilityTest.php:93
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\InstallUtilityTest\$fakedExtensions
‪array $fakedExtensions
Definition: InstallUtilityTest.php:41
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static string getVarPath()
Definition: Environment.php:165