Commit 3523a860 authored by Benjamin Franzke's avatar Benjamin Franzke Committed by Benni Mack
Browse files

[TASK] Deprecate $GLOBALS['TYPO3_LOADED_EXT']

$GLOBALS['TYPO3_LOADED_EXT'] is defined as the "old" way
since the introduction of the PackageManager in 2013:
https://review.typo3.org/19605
(The class description of LoadExtensionArrayElement states:
Class to simulate the "old" extension information array element)

This old way should finally be removed to reduce site effects
(pollution of the global scope) of the PackageManager class.
It's marked as deprecated now, to be removed in v10.

All existing usaged are rewritten to use the PackageManager API.

Releases: master
Resolves: #86404
Change-Id: Ic53f5155828ef2ea711a1961e08f8e020e3f836a
Reviewed-on: https://review.typo3.org/58408


Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog's avatarSusanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog's avatarSusanne Moog <susanne.moog@typo3.org>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent ab535bcf
......@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Core\Database\Schema;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
......@@ -27,17 +28,24 @@ use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
class SqlReader
{
/**
* @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
* @var Dispatcher
*/
protected $signalSlotDispatcher;
/**
* @var PackageManager
*/
protected $packageManager;
/**
* @param Dispatcher $signalSlotDispatcher
* @param PackageManager $packageManager
* @throws \InvalidArgumentException
*/
public function __construct(Dispatcher $signalSlotDispatcher = null)
public function __construct(Dispatcher $signalSlotDispatcher = null, PackageManager $packageManager = null)
{
$this->signalSlotDispatcher = $signalSlotDispatcher ?: GeneralUtility::makeInstance(Dispatcher::class);
$this->packageManager = $packageManager ?? GeneralUtility::makeInstance(PackageManager::class);
}
/**
......@@ -54,15 +62,13 @@ class SqlReader
$sqlString = [];
// Find all ext_tables.sql of loaded extensions
foreach ((array)$GLOBALS['TYPO3_LOADED_EXT'] as $extensionConfiguration) {
if (!is_array($extensionConfiguration) && !$extensionConfiguration instanceof \ArrayAccess) {
continue;
}
if ($extensionConfiguration['ext_tables.sql']) {
$sqlString[] = file_get_contents($extensionConfiguration['ext_tables.sql']);
foreach ($this->packageManager->getActivePackages() as $package) {
$packagePath = $package->getPackagePath();
if (@file_exists($packagePath . 'ext_tables.sql')) {
$sqlString[] = file_get_contents($packagePath . 'ext_tables.sql');
}
if ($withStatic && $extensionConfiguration['ext_tables_static+adt.sql']) {
$sqlString[] = file_get_contents($extensionConfiguration['ext_tables_static+adt.sql']);
if ($withStatic && @file_exists($packagePath . 'ext_tables_static+adt.sql')) {
$sqlString[] = file_get_contents($packagePath . 'ext_tables_static+adt.sql');
}
}
......
......@@ -143,6 +143,7 @@ class PackageManager implements SingletonInterface
} catch (Exception\PackageManagerCacheUnavailableException $exception) {
$this->loadPackageStates();
$this->initializePackageObjects();
// @deprecated will be removed in v10
$this->initializeCompatibilityLoadedExtArray();
$this->saveToPackageCache();
}
......@@ -184,6 +185,7 @@ class PackageManager implements SingletonInterface
$packageCache = [
'packageStatesConfiguration' => $this->packageStatesConfiguration,
'packageAliasMap' => $this->packageAliasMap,
// @deprecated will be removed in v10
'loadedExtArray' => $GLOBALS['TYPO3_LOADED_EXT'],
'composerNameToPackageKeyMap' => $this->composerNameToPackageKeyMap,
'packageObjects' => serialize($this->packages),
......@@ -220,6 +222,7 @@ class PackageManager implements SingletonInterface
\stdClass::class,
]
]);
// @deprecated will be removed in v10
$GLOBALS['TYPO3_LOADED_EXT'] = $packageCache['loadedExtArray'];
}
......@@ -299,6 +302,7 @@ class PackageManager implements SingletonInterface
*/
protected function initializeCompatibilityLoadedExtArray()
{
// @deprecated will be removed in v10
$loadedExtObj = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($this);
$GLOBALS['TYPO3_LOADED_EXT'] = $loadedExtObj->toArray();
}
......@@ -608,6 +612,7 @@ class PackageManager implements SingletonInterface
{
$package = $this->registerPackageDuringRuntime($packageKey);
$this->runtimeActivatedPackages[$package->getPackageKey()] = $package;
// @deprecated will be removed in v10
if (!isset($GLOBALS['TYPO3_LOADED_EXT'][$package->getPackageKey()])) {
$loadedExtArrayElement = new LoadedExtensionArrayElement($package);
$GLOBALS['TYPO3_LOADED_EXT'][$package->getPackageKey()] = $loadedExtArrayElement->toArray();
......@@ -790,6 +795,7 @@ class PackageManager implements SingletonInterface
$packageStatesCode = "<?php\n$fileDescription\nreturn " . ArrayUtility::arrayExport($this->packageStatesConfiguration) . ";\n";
GeneralUtility::writeFile($this->packageStatesPathAndFilename, $packageStatesCode, true);
// @deprecated will be removed in v10
$this->initializeCompatibilityLoadedExtArray();
GeneralUtility::makeInstance(OpcodeCacheService::class)->clearAllActive($this->packageStatesPathAndFilename);
......
......@@ -25,6 +25,7 @@ use TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer;
use TYPO3\CMS\Core\Database\Query\Restriction\DefaultRestrictionContainer;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException;
use TYPO3\CMS\Core\Resource\Exception\InvalidFileException;
use TYPO3\CMS\Core\Resource\Exception\InvalidFileNameException;
......@@ -368,12 +369,19 @@ class TemplateService
*/
protected $context;
/**
* @var PackageManager
*/
protected $packageManager;
/**
* @param Context|null $context
* @param PackageManager|null $packageManager
*/
public function __construct(Context $context = null)
public function __construct(Context $context = null, PackageManager $packageManager = null)
{
$this->context = $context ?? GeneralUtility::makeInstance(Context::class);
$this->packageManager = $packageManager ?? GeneralUtility::makeInstance(PackageManager::class);
$this->initializeDatabaseQueryRestrictions();
if ($this->context->getPropertyFromAspect('visibility', 'includeHiddenContent', false) || $GLOBALS['SIM_ACCESS_TIME'] !== $GLOBALS['ACCESS_TIME']) {
// Set the simulation flag, if simulation is detected!
......@@ -1009,16 +1017,28 @@ class TemplateService
{
$this->extensionStaticsProcessed = true;
// @todo Change to use new API
foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $extKey => $files) {
if ((is_array($files) || $files instanceof \ArrayAccess)
&& (
!empty($files['ext_typoscript_constants.txt'])
|| !empty($files['ext_typoscript_constants.typoscript'])
|| !empty($files['ext_typoscript_setup.txt'])
|| !empty($files['ext_typoscript_setup.typoscript'])
)
) {
foreach ($this->packageManager->getActivePackages() as $package) {
$extKey = $package->getPackageKey();
$packagePath = $package->getPackagePath();
$filesToCheck = [
'ext_typoscript_constants.txt',
'ext_typoscript_constants.typoscript',
'ext_typoscript_setup.txt',
'ext_typoscript_setup.typoscript',
];
$files = [];
$hasExtensionStatics = false;
foreach ($filesToCheck as $file) {
$path = $packagePath . $file;
if (@file_exists($path)) {
$files[$file] = $path;
$hasExtensionStatics = true;
} else {
$files[$file] = null;
}
}
if ($hasExtensionStatics) {
$mExtKey = str_replace('_', '', $extKey);
$constants = '';
$config = '';
......@@ -1046,7 +1066,7 @@ class TemplateService
$pid,
'ext_' . $mExtKey,
$templateID,
ExtensionManagementUtility::extPath($extKey)
$packagePath
);
}
}
......
......@@ -1236,10 +1236,9 @@ class ExtensionManagementUtility
1404068038
);
}
if ((!isset($itemArray[2]) || !$itemArray[2])
&& isset($GLOBALS['TYPO3_LOADED_EXT'][$extensionKey]['ext_icon'])
) {
$itemArray[2] = 'EXT:' . $extensionKey . '/' . $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey]['ext_icon'];
if (!isset($itemArray[2]) || !$itemArray[2]) {
// @todo do we really set $itemArray[2], even if we cannot find an icon? (as that means it's set to 'EXT:foobar/')
$itemArray[2] = 'EXT:' . $extensionKey . '/' . static::getExtensionIcon(static::$packageManager->getPackage($extensionKey)->getPackagePath());
}
if (is_array($GLOBALS['TCA']['tt_content']['columns']) && is_array($GLOBALS['TCA']['tt_content']['columns'][$type]['config']['items'])) {
foreach ($GLOBALS['TCA']['tt_content']['columns'][$type]['config']['items'] as $k => $v) {
......@@ -1558,12 +1557,14 @@ tt_content.' . $key . $suffix . ' {
// scope but to use $GLOBALS['TYPO3_CONF_VARS'] instead.
// Nevertheless we define it here as global for backwards compatibility.
global $TYPO3_CONF_VARS;
foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $_EXTKEY => $extensionInformation) {
if ((is_array($extensionInformation) || $extensionInformation instanceof \ArrayAccess) && isset($extensionInformation['ext_localconf.php'])) {
foreach (static::$packageManager->getActivePackages() as $package) {
$extLocalconfPath = $package->getPackagePath() . 'ext_localconf.php';
if (@file_exists($extLocalconfPath)) {
// $_EXTKEY and $_EXTCONF are available in ext_localconf.php
// and are explicitly set in cached file as well
$_EXTKEY = $package->getPackageKey();
$_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY] ?? null;
require $extensionInformation['ext_localconf.php'];
require $extLocalconfPath;
}
}
}
......@@ -1573,7 +1574,6 @@ tt_content.' . $key . $suffix . ' {
*/
protected static function createExtLocalconfCacheEntry()
{
$extensionInformation = $GLOBALS['TYPO3_LOADED_EXT'];
$phpCodeToCache = [];
// Set same globals as in loadSingleExtLocalconfFiles()
$phpCodeToCache[] = '/**';
......@@ -1583,12 +1583,14 @@ tt_content.' . $key . $suffix . ' {
$phpCodeToCache[] = 'global $TYPO3_CONF_VARS, $T3_SERVICES, $T3_VAR;';
$phpCodeToCache[] = '';
// Iterate through loaded extensions and add ext_localconf content
foreach ($extensionInformation as $extensionKey => $extensionDetails) {
if (isset($extensionDetails['ext_localconf.php']) && $extensionDetails['ext_localconf.php']) {
foreach (static::$packageManager->getActivePackages() as $package) {
$extensionKey = $package->getPackageKey();
$extLocalconfPath = $package->getPackagePath() . 'ext_localconf.php';
if (@file_exists($extLocalconfPath)) {
// Include a header per extension to make the cache file more readable
$phpCodeToCache[] = '/**';
$phpCodeToCache[] = ' * Extension: ' . $extensionKey;
$phpCodeToCache[] = ' * File: ' . $extensionDetails['ext_localconf.php'];
$phpCodeToCache[] = ' * File: ' . $extLocalconfPath;
$phpCodeToCache[] = ' */';
$phpCodeToCache[] = '';
// Set $_EXTKEY and $_EXTCONF for this extension
......@@ -1596,7 +1598,7 @@ tt_content.' . $key . $suffix . ' {
$phpCodeToCache[] = '$_EXTCONF = $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXT\'][\'extConf\'][$_EXTKEY] ?? null;';
$phpCodeToCache[] = '';
// Add ext_localconf.php content of extension
$phpCodeToCache[] = trim(file_get_contents($extensionDetails['ext_localconf.php']));
$phpCodeToCache[] = trim(file_get_contents($extLocalconfPath));
$phpCodeToCache[] = '';
$phpCodeToCache[] = '';
}
......@@ -1804,12 +1806,14 @@ tt_content.' . $key . $suffix . ' {
global $PAGES_TYPES, $TBE_STYLES;
global $_EXTKEY;
// Load each ext_tables.php file of loaded extensions
foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $_EXTKEY => $extensionInformation) {
if ((is_array($extensionInformation) || $extensionInformation instanceof \ArrayAccess) && !empty($extensionInformation['ext_tables.php'])) {
foreach (static::$packageManager->getActivePackages() as $package) {
$extTablesPath = $package->getPackagePath() . 'ext_tables.php';
if (@file_exists($extTablesPath)) {
// $_EXTKEY and $_EXTCONF are available in ext_tables.php
// and are explicitly set in cached file as well
$_EXTKEY = $package->getPackageKey();
$_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY] ?? null;
require $extensionInformation['ext_tables.php'];
require $extTablesPath;
}
}
}
......@@ -1819,7 +1823,6 @@ tt_content.' . $key . $suffix . ' {
*/
protected static function createExtTablesCacheEntry()
{
$extensionInformation = $GLOBALS['TYPO3_LOADED_EXT'];
$phpCodeToCache = [];
// Set same globals as in loadSingleExtTablesFiles()
$phpCodeToCache[] = '/**';
......@@ -1832,12 +1835,14 @@ tt_content.' . $key . $suffix . ' {
$phpCodeToCache[] = 'global $_EXTKEY;';
$phpCodeToCache[] = '';
// Iterate through loaded extensions and add ext_tables content
foreach ($extensionInformation as $extensionKey => $extensionDetails) {
if (isset($extensionDetails['ext_tables.php']) && $extensionDetails['ext_tables.php']) {
foreach (static::$packageManager->getActivePackages() as $package) {
$extensionKey = $package->getPackageKey();
$extTablesPath = $package->getPackagePath() . 'ext_tables.php';
if (@file_exists($extTablesPath)) {
// Include a header per extension to make the cache file more readable
$phpCodeToCache[] = '/**';
$phpCodeToCache[] = ' * Extension: ' . $extensionKey;
$phpCodeToCache[] = ' * File: ' . $extensionDetails['ext_tables.php'];
$phpCodeToCache[] = ' * File: ' . $extTablesPath;
$phpCodeToCache[] = ' */';
$phpCodeToCache[] = '';
// Set $_EXTKEY and $_EXTCONF for this extension
......@@ -1845,7 +1850,7 @@ tt_content.' . $key . $suffix . ' {
$phpCodeToCache[] = '$_EXTCONF = $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXT\'][\'extConf\'][$_EXTKEY] ?? null;';
$phpCodeToCache[] = '';
// Add ext_tables.php content of extension
$phpCodeToCache[] = trim(file_get_contents($extensionDetails['ext_tables.php']));
$phpCodeToCache[] = trim(file_get_contents($extTablesPath));
$phpCodeToCache[] = '';
}
}
......
.. include:: ../../Includes.txt
============================================================
Deprecation: #86404 - Deprecate $GLOBALS['TYPO3_LOADED_EXT']
============================================================
See :issue:`86404`
Description
===========
The global :php:`$GLOBALS['TYPO3_LOADED_EXT']` has been deprecated in favor
of the :php:`PackageManager` API.
Impact
======
Accessing :php:`$GLOBALS['TYPO3_LOADED_EXT']` is discouraged.
Affected Installations
======================
Instances with extensions using :php:`$GLOBALS['TYPO3_LOADED_EXT']`.
Migration
=========
Use the :php:`getActivePackages()` method of
:php:`\TYPO3\CMS\Core\Package\PackageManager` to get a list of active
packages.
.. index:: PHP-API, FullyScanned
......@@ -24,6 +24,7 @@ use Doctrine\DBAL\Types\SmallIntType;
use Doctrine\DBAL\Types\TextType;
use TYPO3\CMS\Core\Database\Schema\Parser\Parser;
use TYPO3\CMS\Core\Database\Schema\SqlReader;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
/**
......@@ -48,7 +49,8 @@ class TableBuilderTest extends UnitTestCase
{
parent::setUp();
$sqlFile = file_get_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', 'Fixtures', 'tablebuilder.sql']));
$sqlReader = new SqlReader();
$packageManagerProphecy = $this->prophesize(PackageManager::class);
$sqlReader = new SqlReader(null, $packageManagerProphecy->reveal());
$statements = $sqlReader->getCreateTableStatementArray($sqlFile);
$parser = new Parser($statements[0]);
......
......@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Database\Schema;
*/
use TYPO3\CMS\Core\Database\Schema\SqlReader;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
/**
......@@ -34,7 +35,7 @@ class SqlReaderTest extends UnitTestCase
*/
public function getStatementArraySplitsStatements()
{
$subject = new SqlReader();
$subject = new SqlReader(null, $this->prophesize(PackageManager::class)->reveal());
$result = $subject->getStatementArray(
'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
LF .
......@@ -50,7 +51,7 @@ class SqlReaderTest extends UnitTestCase
*/
public function getStatementArrayFiltersStatements()
{
$subject = new SqlReader();
$subject = new SqlReader(null, $this->prophesize(PackageManager::class)->reveal());
$result = $subject->getStatementArray(
'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
LF .
......@@ -66,7 +67,7 @@ class SqlReaderTest extends UnitTestCase
*/
public function getInsertStatementArrayResult()
{
$subject = new SqlReader();
$subject = new SqlReader(null, $this->prophesize(PackageManager::class)->reveal());
$result = $subject->getInsertStatementArray(
'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
LF .
......@@ -82,7 +83,7 @@ class SqlReaderTest extends UnitTestCase
*/
public function getInsertStatementArrayResultWithNewline()
{
$subject = new SqlReader();
$subject = new SqlReader(null, $this->prophesize(PackageManager::class)->reveal());
$result = $subject->getInsertStatementArray(
'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
LF .
......@@ -100,7 +101,7 @@ class SqlReaderTest extends UnitTestCase
*/
public function getCreateTableStatementArrayResult()
{
$subject = new SqlReader();
$subject = new SqlReader(null, $this->prophesize(PackageManager::class)->reveal());
$result = $subject->getCreateTableStatementArray(
'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
LF .
......
......@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\TypoScript;
*/
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
......@@ -50,19 +51,24 @@ class TemplateServiceTest extends UnitTestCase
*/
protected $backupPackageManager;
/**
* @var PackageManager|ObjectProphecy
*/
protected $packageManagerProphecy;
/**
* Set up
*/
protected function setUp(): void
{
$GLOBALS['TYPO3_LOADED_EXT'] = [];
$GLOBALS['SIM_ACCESS_TIME'] = time();
$GLOBALS['ACCESS_TIME'] = time();
$this->templateService = new TemplateService(new Context());
$this->packageManagerProphecy = $this->prophesize(PackageManager::class);
$this->templateService = new TemplateService(new Context(), $this->packageManagerProphecy->reveal());
$this->templateServiceMock = $this->getAccessibleMock(
TemplateService::class,
['dummy'],
[new Context()]
[new Context(), $this->packageManagerProphecy->reveal()]
);
$this->backupPackageManager = ExtensionManagementUtilityAccessibleProxy::getPackageManager();
}
......@@ -100,14 +106,7 @@ class TemplateServiceTest extends UnitTestCase
GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
$identifier = $this->getUniqueId('test');
$GLOBALS['TYPO3_LOADED_EXT'] = [
$identifier => [
'ext_typoscript_setup.txt' => ExtensionManagementUtility::extPath(
'core',
'Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt'
),
],
];
$this->packageManagerProphecy->getActivePackages()->shouldNotBeCalled();
$this->templateService->runThroughTemplates([], 0);
$this->assertFalse(
......@@ -126,21 +125,13 @@ class TemplateServiceTest extends UnitTestCase
GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
$identifier = $this->getUniqueId('test');
$GLOBALS['TYPO3_LOADED_EXT'] = [
$identifier => [
'ext_typoscript_setup.txt' => ExtensionManagementUtility::extPath(
'core',
'Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt'
),
'ext_typoscript_constants.txt' => ''
],
];
$mockPackage = $this->getMockBuilder(Package::class)
->setMethods(['getPackagePath'])
->setMethods(['getPackagePath', 'getPackageKey'])
->disableOriginalConstructor()
->getMock();
$mockPackage->expects($this->any())->method('getPackagePath')->will($this->returnValue(''));
$mockPackage->expects($this->any())->method('getPackagePath')->will($this->returnValue(__DIR__ . '/Fixtures/'));
$mockPackage->expects($this->any())->method('getPackageKey')->will($this->returnValue('core'));
$mockPackageManager = $this->getMockBuilder(PackageManager::class)
->setMethods(['isPackageActive', 'getPackage'])
......@@ -149,6 +140,7 @@ class TemplateServiceTest extends UnitTestCase
$mockPackageManager->expects($this->any())->method('isPackageActive')->will($this->returnValue(true));
$mockPackageManager->expects($this->any())->method('getPackage')->will($this->returnValue($mockPackage));
ExtensionManagementUtility::setPackageManager($mockPackageManager);
$this->packageManagerProphecy->getActivePackages()->willReturn(['core' => $mockPackage]);
$this->templateService->setProcessExtensionStatics(true);
$this->templateService->runThroughTemplates([], 0);
......
......@@ -17,7 +17,6 @@ namespace TYPO3\CMS\Core\Tests\Unit\Utility;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\PhpFrontend;
use TYPO3\CMS\Core\Category\CategoryRegistry;
use TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Package\MetaData;
use TYPO3\CMS\Core\Package\Package;
......@@ -58,7 +57,6 @@ class ExtensionManagementUtilityTest extends UnitTestCase
ExtensionManagementUtility::clearExtensionKeyMap();
ExtensionManagementUtilityAccessibleProxy::setPackageManager($this->backUpPackageManager);
ExtensionManagementUtilityAccessibleProxy::setCacheManager(null);
$GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($this->backUpPackageManager);
parent::tearDown();
}
......@@ -1201,7 +1199,8 @@ class ExtensionManagementUtilityTest extends UnitTestCase
->getMock();
$mockCacheManager->expects($this->never())->method('getCache');
ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
$GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage($this->getUniqueId()));
$packageManager = $this->createMockPackageManagerWithMockPackage($this->getUniqueId());
ExtensionManagementUtility::setPackageManager($packageManager);
ExtensionManagementUtility::loadExtLocalconf(false);
}
......@@ -1241,7 +1240,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase
$packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
$extLocalconfLocation = $packageManager->getPackage($extensionName)->getPackagePath() . 'ext_localconf.php';
file_put_contents($extLocalconfLocation, "<?php\n\nthrow new RuntimeException('', 1340559079);\n\n?>");
$GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($packageManager);
ExtensionManagementUtility::setPackageManager($packageManager);
ExtensionManagementUtilityAccessibleProxy::loadSingleExtLocalconfFiles();
}
......@@ -1333,7 +1332,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase
$extLocalconfLocation = $packageManager->getPackage($extensionName)->getPackagePath() . 'ext_localconf.php';
$uniqueStringInLocalconf = $this->getUniqueId('foo');
file_put_contents($extLocalconfLocation, "<?php\n\n" . $uniqueStringInLocalconf . "\n\n?>");
$GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($packageManager);
ExtensionManagementUtility::setPackageManager($packageManager);
$mockCache = $this->getMockBuilder(PhpFrontend::class)
->setMethods(['getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'require'])
->disableOriginalConstructor()
......@@ -1356,7 +1355,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase
{
$extensionName = $this->getUniqueId('foo');
$packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
$GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($packageManager);
ExtensionManagementUtility::setPackageManager($packageManager);
$mockCache = $this->getMockBuilder(PhpFrontend::class)
->setMethods(['getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'require'])
->disableOriginalConstructor()
......@@ -1391,7 +1390,8 @@ class ExtensionManagementUtilityTest extends UnitTestCase
$mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
$mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo([]));
$GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage($this->getUniqueId()));
$packageManager = $this->createMockPackageManagerWithMockPackage($this->getUniqueId());
ExtensionManagementUtility::setPackageManager($packageManager);
ExtensionManagementUtilityAccessibleProxy::createExtLocalconfCacheEntry();
}
......@@ -1459,7 +1459,6 @@ class ExtensionManagementUtilityTest extends UnitTestCase
GeneralUtility::mkdir($packagePath);
GeneralUtility::mkdir($packagePath . 'Configuration/');
GeneralUtility::mkdir($packagePath . 'Configuration/TCA/');
$GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($packageManager);
ExtensionManagementUtility::setPackageManager($packageManager);
$uniqueTableName = $this->getUniqueId('table_name_');
$uniqueStringInTableConfiguration = $this->getUniqueId('table_configuration_');
......@@ -1532,7 +1531,8 @@ class ExtensionManagementUtilityTest extends UnitTestCase
->getMock();
$mockCacheManager->expects($this->never())->method('getCache');
ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
$GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage($this->getUniqueId()));
$packageManager = $this->createMockPackageManagerWithMockPackage($this->getUniqueId());
ExtensionManagementUtility::setPackageManager($packageManager);
ExtensionManagementUtility::loadExtLocalconf(false);
}
......@@ -1569,15 +1569,12 @@ class ExtensionManagementUtilityTest extends UnitTestCase
public function createExtTablesCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtTables()
{
$extensionName = $this->getUniqueId('foo');
$extTablesLocation = Environment::getVarPath() . '/tests/' . $this->getUniqueId('test_ext_tables') . '.php';
$this->testFilesToDelete[] = $extTablesLocation;
$packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
$extensionPath = $packageManager->getPackage($extensionName)->getPackagePath();
$extTablesLocation = $extensionPath . 'ext_tables.php';