‪TYPO3CMS  9.5
ExtensionManagementUtilityTest.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 
20 use TYPO3\CMS\Core\Package\PackageManager;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪ExtensionManagementUtilityTest extends UnitTestCase
30 {
34  protected ‪$backUpPackageManager;
35 
39  protected function ‪setUp()
40  {
42  }
43 
47  protected function ‪tearDown()
48  {
52  parent::tearDown();
53  }
54 
60  protected function ‪createMockPackageManagerWithMockPackage($packageKey, $packageMethods = ['getPackagePath', 'getPackageKey'])
61  {
62  $packagePath = ‪Environment::getVarPath() . '/tests/' . $packageKey . '/';
63  GeneralUtility::mkdir_deep($packagePath);
64  $this->testFilesToDelete[] = $packagePath;
65  $package = $this->getMockBuilder(Package::class)
66  ->disableOriginalConstructor()
67  ->setMethods($packageMethods)
68  ->getMock();
69  $packageManager = $this->getMockBuilder(PackageManager::class)
70  ->setMethods(['isPackageActive', 'getPackage', 'getActivePackages'])
71  ->getMock();
72  $package->expects($this->any())
73  ->method('getPackagePath')
74  ->will($this->returnValue($packagePath));
75  $package->expects($this->any())
76  ->method('getPackageKey')
77  ->will($this->returnValue($packageKey));
78  $packageManager->expects($this->any())
79  ->method('isPackageActive')
80  ->will($this->returnValueMap([
81  [null, false],
82  [$packageKey, true]
83  ]));
84  $packageManager->expects($this->any())
85  ->method('getPackage')
86  ->with($this->equalTo($packageKey))
87  ->will($this->returnValue($package));
88  $packageManager->expects($this->any())
89  ->method('getActivePackages')
90  ->will($this->returnValue([$packageKey => $package]));
91  return $packageManager;
92  }
93 
95  // Tests concerning isLoaded
97 
101  {
102  $this->assertFalse(‪ExtensionManagementUtility::isLoaded($this->getUniqueId('foobar'), false));
103  }
104 
106  // Tests concerning extPath
108 
112  {
113  $this->expectException(\BadFunctionCallException::class);
114  $this->expectExceptionCode(1365429656);
115 
116  $packageName = $this->getUniqueId('foo');
118  $packageManager = $this->getMockBuilder(PackageManager::class)
119  ->setMethods(['isPackageActive'])
120  ->getMock();
121  $packageManager->expects($this->once())
122  ->method('isPackageActive')
123  ->with($this->equalTo($packageName))
124  ->will($this->returnValue(false));
127  }
128 
132  public function ‪extPathAppendsScriptNameToPath()
133  {
134  $package = $this->getMockBuilder(Package::class)
135  ->disableOriginalConstructor()
136  ->setMethods(['getPackagePath'])
137  ->getMock();
139  $packageManager = $this->getMockBuilder(PackageManager::class)
140  ->setMethods(['isPackageActive', 'getPackage'])
141  ->getMock();
142  $package->expects($this->once())
143  ->method('getPackagePath')
144  ->will($this->returnValue(‪Environment::getPublicPath() . '/foo/'));
145  $packageManager->expects($this->once())
146  ->method('isPackageActive')
147  ->with($this->equalTo('foo'))
148  ->will($this->returnValue(true));
149  $packageManager->expects($this->once())
150  ->method('getPackage')
151  ->with('foo')
152  ->will($this->returnValue($package));
154  $this->assertSame(‪Environment::getPublicPath() . '/foo/bar.txt', ‪ExtensionManagementUtility::extPath('foo', 'bar.txt'));
155  }
156 
158  // Utility functions
160 
166  private function ‪generateTCAForTable($table)
167  {
168  ‪$tca = [];
169  ‪$tca[$table] = [];
170  ‪$tca[$table]['columns'] = [
171  'fieldA' => [],
172  'fieldC' => []
173  ];
174  ‪$tca[$table]['types'] = [
175  'typeA' => ['showitem' => 'fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1'],
176  'typeB' => ['showitem' => 'fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1'],
177  'typeC' => ['showitem' => 'fieldC;;paletteD']
178  ];
179  ‪$tca[$table]['palettes'] = [
180  'paletteA' => ['showitem' => 'fieldX, fieldX1, fieldY'],
181  'paletteB' => ['showitem' => 'fieldX, fieldX1, fieldY'],
182  'paletteC' => ['showitem' => 'fieldX, fieldX1, fieldY'],
183  'paletteD' => ['showitem' => 'fieldX, fieldX1, fieldY']
184  ];
185  return ‪$tca;
186  }
187 
189  // Tests concerning getExtensionKeyByPrefix
191 
196  {
198  $uniqueSuffix = $this->getUniqueId('test');
199  $extensionKey = 'tt_news' . $uniqueSuffix;
200  $extensionPrefix = 'tx_ttnews' . $uniqueSuffix;
201  $package = $this->getMockBuilder(Package::class)
202  ->disableOriginalConstructor()
203  ->setMethods(['getPackageKey'])
204  ->getMock();
205  $package->expects($this->exactly(2))
206  ->method('getPackageKey')
207  ->will($this->returnValue($extensionKey));
209  $packageManager = $this->getMockBuilder(PackageManager::class)
210  ->setMethods(['getActivePackages'])
211  ->getMock();
212  $packageManager->expects($this->once())
213  ->method('getActivePackages')
214  ->will($this->returnValue([$extensionKey => $package]));
216  $this->assertEquals($extensionKey, ‪ExtensionManagementUtility::getExtensionKeyByPrefix($extensionPrefix));
217  }
218 
224  {
226  $uniqueSuffix = $this->getUniqueId('test');
227  $extensionKey = 'kickstarter' . $uniqueSuffix;
228  $extensionPrefix = 'tx_kickstarter' . $uniqueSuffix;
229  $package = $this->getMockBuilder(Package::class)
230  ->disableOriginalConstructor()
231  ->setMethods(['getPackageKey'])
232  ->getMock();
233  $package->expects($this->exactly(2))
234  ->method('getPackageKey')
235  ->will($this->returnValue($extensionKey));
237  $packageManager = $this->getMockBuilder(PackageManager::class)
238  ->setMethods(['getActivePackages'])
239  ->getMock();
240  $packageManager->expects($this->once())
241  ->method('getActivePackages')
242  ->will($this->returnValue([$extensionKey => $package]));
244  $this->assertEquals($extensionKey, ‪ExtensionManagementUtility::getExtensionKeyByPrefix($extensionPrefix));
245  }
246 
252  {
254  $uniqueSuffix = $this->getUniqueId('test');
255  $extensionPrefix = 'tx_unloadedextension' . $uniqueSuffix;
256  $this->assertFalse(‪ExtensionManagementUtility::getExtensionKeyByPrefix($extensionPrefix));
257  }
258 
260  // Tests concerning removeCacheFiles
262 
266  {
268  $mockCacheManager = $this->getMockBuilder(CacheManager::class)
269  ->setMethods(['flushCachesInGroup'])
270  ->getMock();
271  $mockCacheManager->expects($this->once())->method('flushCachesInGroup')->with('system');
274  }
275 }
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\removeCacheFiles
‪static removeCacheFiles()
Definition: ExtensionManagementUtility.php:1898
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\ExtensionManagementUtilityTest\extPathAppendsScriptNameToPath
‪extPathAppendsScriptNameToPath()
Definition: ExtensionManagementUtilityTest.php:131
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:153
‪TYPO3\CMS\Core\Tests\Unit\Utility\AccessibleProxies\ExtensionManagementUtilityAccessibleProxy\setCacheManager
‪static setCacheManager(CacheManager $cacheManager=null)
Definition: ExtensionManagementUtilityAccessibleProxy.php:27
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\ExtensionManagementUtilityTest\getExtensionKeyByPrefixForNotLoadedExtensionReturnsFalse
‪getExtensionKeyByPrefixForNotLoadedExtensionReturnsFalse()
Definition: ExtensionManagementUtilityTest.php:250
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\ExtensionManagementUtilityTest\getExtensionKeyByPrefixForLoadedExtensionWithoutUnderscoresReturnsExtensionKey
‪getExtensionKeyByPrefixForLoadedExtensionWithoutUnderscoresReturnsExtensionKey()
Definition: ExtensionManagementUtilityTest.php:222
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\ExtensionManagementUtilityTest
Definition: ExtensionManagementUtilityTest.php:30
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\ExtensionManagementUtilityTest\isLoadedReturnsFalseIfExtensionIsNotLoadedAndExitIsDisabled
‪isLoadedReturnsFalseIfExtensionIsNotLoadedAndExitIsDisabled()
Definition: ExtensionManagementUtilityTest.php:99
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:36
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\ExtensionManagementUtilityTest\$backUpPackageManager
‪TYPO3 CMS Core Package PackageManager $backUpPackageManager
Definition: ExtensionManagementUtilityTest.php:33
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\ExtensionManagementUtilityTest\tearDown
‪tearDown()
Definition: ExtensionManagementUtilityTest.php:46
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\clearExtensionKeyMap
‪static clearExtensionKeyMap()
Definition: ExtensionManagementUtility.php:214
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\setPackageManager
‪static setPackageManager(PackageManager $packageManager)
Definition: ExtensionManagementUtility.php:63
‪TYPO3\CMS\Core\Package\Package
Definition: Package.php:21
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded
‪static bool isLoaded($key, $exitOnError=null)
Definition: ExtensionManagementUtility.php:115
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility
Definition: ClientUtilityTest.php:3
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\ExtensionManagementUtilityTest\getExtensionKeyByPrefixForLoadedExtensionWithUnderscoresReturnsExtensionKey
‪getExtensionKeyByPrefixForLoadedExtensionWithUnderscoresReturnsExtensionKey()
Definition: ExtensionManagementUtilityTest.php:194
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\ExtensionManagementUtilityTest\createMockPackageManagerWithMockPackage
‪PackageManager PHPUnit_Framework_MockObject_MockObject createMockPackageManagerWithMockPackage($packageKey, $packageMethods=['getPackagePath', 'getPackageKey'])
Definition: ExtensionManagementUtilityTest.php:59
‪TYPO3\CMS\Core\Tests\Unit\Utility\AccessibleProxies\ExtensionManagementUtilityAccessibleProxy\getPackageManager
‪static getPackageManager()
Definition: ExtensionManagementUtilityAccessibleProxy.php:37
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\ExtensionManagementUtilityTest\removeCacheFilesFlushesSystemCaches
‪removeCacheFilesFlushesSystemCaches()
Definition: ExtensionManagementUtilityTest.php:264
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\ExtensionManagementUtilityTest\extPathThrowsExceptionIfExtensionIsNotLoaded
‪extPathThrowsExceptionIfExtensionIsNotLoaded()
Definition: ExtensionManagementUtilityTest.php:110
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪$tca
‪$tca
Definition: sys_file_metadata.php:4
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\extPath
‪static string extPath($key, $script='')
Definition: ExtensionManagementUtility.php:149
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\ExtensionManagementUtilityTest\generateTCAForTable
‪array generateTCAForTable($table)
Definition: ExtensionManagementUtilityTest.php:165
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\getExtensionKeyByPrefix
‪static mixed getExtensionKeyByPrefix($prefix)
Definition: ExtensionManagementUtility.php:191
‪TYPO3\CMS\Core\Tests\Unit\Utility\AccessibleProxies\ExtensionManagementUtilityAccessibleProxy
Definition: ExtensionManagementUtilityAccessibleProxy.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\ExtensionManagementUtilityTest\setUp
‪setUp()
Definition: ExtensionManagementUtilityTest.php:38
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static string getVarPath()
Definition: Environment.php:165