Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into lolli-1
Browse files Browse the repository at this point in the history
  • Loading branch information
lolli42 committed Apr 4, 2023
2 parents 3367b5e + 54cc600 commit 0e95a19
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 67 deletions.
68 changes: 2 additions & 66 deletions Classes/Core/Functional/Framework/FrameworkState.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\RootlineUtility;

/**
* This is an ugly helper class to manage some TYPO3 framework state.
Expand Down Expand Up @@ -46,42 +45,19 @@ public static function push()
$state['globals-typo3-conf-vars'] = $GLOBALS['TYPO3_CONF_VARS'] ?: null;

// Backing up TCA *should* not be needed: TCA is (hopefully) never changed after bootstrap and identical in FE and BE.
// Some tests change TCA on the fly (eg. core DataHandling/Regular/Modify localizeContentWithEmptyTcaIntegrityColumns).
// Some tests change TCA on the fly (e.g. core DataHandling/Regular/Modify localizeContentWithEmptyTcaIntegrityColumns).
// A FE call then resets this TCA change since it initializes the global again. Then, after the FE call, the TCA is
// different. And code that runs after that within the test scope may fail (eg. the referenceIndex check in tearDown() that
// relies on TCA). So we backup TCA for now before executing frontend tests.
// relies on TCA). So we back up TCA for now before executing frontend tests.
$state['globals-tca'] = $GLOBALS['TCA'];

// Can be dropped when GeneralUtility::getIndpEnv() is abandoned
$generalUtilityReflection = new \ReflectionClass(GeneralUtility::class);
$generalUtilityIndpEnvCache = $generalUtilityReflection->getProperty('indpEnvCache');
$generalUtilityIndpEnvCache->setAccessible(true);
$state['generalUtilityIndpEnvCache'] = $generalUtilityIndpEnvCache->getValue();

$state['generalUtilitySingletonInstances'] = GeneralUtility::getSingletonInstances();

// @todo Remove this block with next major version of the testing-framework,
// or if TYPO3 v13 is the min supported version.
if (method_exists(RootlineUtility::class, 'purgeCaches')) {
// Infamous RootlineUtility carries various static state ...
$rootlineUtilityReflection = new \ReflectionClass(RootlineUtility::class);
$rootlineUtilityLocalCache = $rootlineUtilityReflection->getProperty('localCache');
$rootlineUtilityLocalCache->setAccessible(true);
$state['rootlineUtilityLocalCache'] = $rootlineUtilityLocalCache->getValue();

try {
$rootlineUtilityRootlineFields = $rootlineUtilityReflection->getProperty('rootlineFields');
$rootlineUtilityRootlineFields->setAccessible(true);
$state['rootlineUtilityRootlineFields'] = $rootlineUtilityRootlineFields->getValue();
} catch (\ReflectionException $e) {
// @todo: Remove full block when rootlineFields has been removed from core RootlineUtility
}

$rootlineUtilityPageRecordCache = $rootlineUtilityReflection->getProperty('pageRecordCache');
$rootlineUtilityPageRecordCache->setAccessible(true);
$state['rootlineUtilityPageRecordCache'] = $rootlineUtilityPageRecordCache->getValue();
}

self::$state[] = $state;
}

Expand All @@ -94,27 +70,9 @@ public static function reset()

$generalUtilityReflection = new \ReflectionClass(GeneralUtility::class);
$generalUtilityIndpEnvCache = $generalUtilityReflection->getProperty('indpEnvCache');
$generalUtilityIndpEnvCache->setAccessible(true);
$generalUtilityIndpEnvCache->setValue([]);

GeneralUtility::resetSingletonInstances([]);

// @todo Remove this block with next major version of the testing-framework,
// or if TYPO3 v13 is the min supported version.
if (method_exists(RootlineUtility::class, 'purgeCaches')) {
RootlineUtility::purgeCaches();
$rootlineUtilityReflection = new \ReflectionClass(RootlineUtility::class);
$rootlineFieldsDefault = $rootlineUtilityReflection->getDefaultProperties();

try {
$rootlineUtilityRootlineFields = $rootlineUtilityReflection->getProperty('rootlineFields');
$rootlineFieldsDefault = $rootlineFieldsDefault['rootlineFields'];
$rootlineUtilityRootlineFields->setAccessible(true);
$state['rootlineUtilityRootlineFields'] = $rootlineFieldsDefault;
} catch (\ReflectionException $e) {
// @todo: Remove full block when rootlineFields has been removed from core RootlineUtility
}
}
}

/**
Expand All @@ -136,30 +94,8 @@ public static function pop()

$generalUtilityReflection = new \ReflectionClass(GeneralUtility::class);
$generalUtilityIndpEnvCache = $generalUtilityReflection->getProperty('indpEnvCache');
$generalUtilityIndpEnvCache->setAccessible(true);
$generalUtilityIndpEnvCache->setValue($state['generalUtilityIndpEnvCache']);

GeneralUtility::resetSingletonInstances($state['generalUtilitySingletonInstances']);

// @todo Remove this block with next major version of the testing-framework,
// or if TYPO3 v13 is the min supported version.
if (method_exists(RootlineUtility::class, 'purgeCaches')) {
$rootlineUtilityReflection = new \ReflectionClass(RootlineUtility::class);
$rootlineUtilityLocalCache = $rootlineUtilityReflection->getProperty('localCache');
$rootlineUtilityLocalCache->setAccessible(true);
$rootlineUtilityLocalCache->setValue($state['rootlineUtilityLocalCache']);

try {
$rootlineUtilityRootlineFields = $rootlineUtilityReflection->getProperty('rootlineFields');
$rootlineUtilityRootlineFields->setAccessible(true);
$rootlineUtilityRootlineFields->setValue($state['rootlineUtilityRootlineFields']);
} catch (\ReflectionException $e) {
// @todo: Remove full block when rootlineFields has been removed from core RootlineUtility
}

$rootlineUtilityPageRecordCache = $rootlineUtilityReflection->getProperty('pageRecordCache');
$rootlineUtilityPageRecordCache->setAccessible(true);
$rootlineUtilityPageRecordCache->setValue($state['rootlineUtilityPageRecordCache']);
}
}
}
1 change: 0 additions & 1 deletion Classes/Core/Unit/UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ protected function tearDown(): void
// Verify LocalizationUtility class internal state has been reset properly if a test fiddled with it
$reflectionClass = new \ReflectionClass(LocalizationUtility::class);
$property = $reflectionClass->getProperty('configurationManager');
$property->setAccessible(true);
self::assertNull($property->getValue());

self::assertTrue($this->setUpMethodCallChainValid, 'tearDown() integrity check detected that setUp has a '
Expand Down

0 comments on commit 0e95a19

Please sign in to comment.