diff --git a/Build/Scripts/composer-for-core-version.sh b/Build/Scripts/composer-for-core-version.sh index 1532abc5..60044e0d 100755 --- a/Build/Scripts/composer-for-core-version.sh +++ b/Build/Scripts/composer-for-core-version.sh @@ -6,6 +6,7 @@ composer_cleanup() { echo -e "💥 Cleanup folders" rm -Rf \ + .cache/phpstan/* \ .Build/vendor/* \ .Build/var/* \ .Build/bin/* \ diff --git a/Build/phpstan/Core12/phpstan-baseline.neon b/Build/phpstan/Core12/phpstan-baseline.neon index 3bb73956..4bc67bfb 100644 --- a/Build/phpstan/Core12/phpstan-baseline.neon +++ b/Build/phpstan/Core12/phpstan-baseline.neon @@ -40,6 +40,11 @@ parameters: count: 1 path: ../../../Classes/Service/LanguageService.php + - + message: "#^Call to method write\\(\\) on an unknown class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteWriter\\.$#" + count: 1 + path: ../../../Classes/Upgrades/FormalityUpgradeWizard.php + - message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Utility\\\\DeeplBackendUtility\\:\\:buildBackendRoute\\(\\) has parameter \\$parameters with no value type specified in iterable type array\\.$#" count: 1 @@ -105,6 +110,16 @@ parameters: count: 1 path: ../../../Tests/Functional/Fixtures/Frontend/PhpError.php + - + message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor invoked with 7 parameters, 2\\-3 required\\.$#" + count: 1 + path: ../../../Tests/Functional/Hooks/TranslateHookTest.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Site\\\\Set\\\\SetRegistry not found\\.$#" + count: 1 + path: ../../../Tests/Functional/Hooks/TranslateHookTest.php + - message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Hooks\\\\TranslateHookTest\\:\\:buildDefaultLanguageConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -155,6 +170,26 @@ parameters: count: 1 path: ../../../Tests/Functional/Hooks/TranslateHookTest.php + - + message: "#^Parameter \\#2 \\$eventDispatcher of class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor expects Psr\\\\EventDispatcher\\\\EventDispatcherInterface, TYPO3\\\\CMS\\\\Core\\\\Site\\\\SiteSettingsFactory given\\.$#" + count: 1 + path: ../../../Tests/Functional/Hooks/TranslateHookTest.php + + - + message: "#^Parameter \\#3 \\$coreCache of class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor expects TYPO3\\\\CMS\\\\Core\\\\Cache\\\\Frontend\\\\PhpFrontend\\|null, TYPO3\\\\CMS\\\\Core\\\\Site\\\\Set\\\\SetRegistry given\\.$#" + count: 1 + path: ../../../Tests/Functional/Hooks/TranslateHookTest.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor invoked with 7 parameters, 2\\-3 required\\.$#" + count: 1 + path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Site\\\\Set\\\\SetRegistry not found\\.$#" + count: 1 + path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php + - message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:buildDefaultLanguageConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -205,6 +240,26 @@ parameters: count: 1 path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php + - + message: "#^Parameter \\#2 \\$eventDispatcher of class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor expects Psr\\\\EventDispatcher\\\\EventDispatcherInterface, TYPO3\\\\CMS\\\\Core\\\\Site\\\\SiteSettingsFactory given\\.$#" + count: 1 + path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php + + - + message: "#^Parameter \\#3 \\$coreCache of class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor expects TYPO3\\\\CMS\\\\Core\\\\Cache\\\\Frontend\\\\PhpFrontend\\|null, TYPO3\\\\CMS\\\\Core\\\\Site\\\\Set\\\\SetRegistry given\\.$#" + count: 1 + path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor invoked with 7 parameters, 2\\-3 required\\.$#" + count: 1 + path: ../../../Tests/Functional/Regression/PreviewTranslationInformationTest.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Site\\\\Set\\\\SetRegistry not found\\.$#" + count: 1 + path: ../../../Tests/Functional/Regression/PreviewTranslationInformationTest.php + - message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Regression\\\\PreviewTranslationInformationTest\\:\\:buildDefaultLanguageConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -255,11 +310,31 @@ parameters: count: 1 path: ../../../Tests/Functional/Regression/PreviewTranslationInformationTest.php + - + message: "#^Parameter \\#2 \\$eventDispatcher of class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor expects Psr\\\\EventDispatcher\\\\EventDispatcherInterface, TYPO3\\\\CMS\\\\Core\\\\Site\\\\SiteSettingsFactory given\\.$#" + count: 1 + path: ../../../Tests/Functional/Regression/PreviewTranslationInformationTest.php + + - + message: "#^Parameter \\#3 \\$coreCache of class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor expects TYPO3\\\\CMS\\\\Core\\\\Cache\\\\Frontend\\\\PhpFrontend\\|null, TYPO3\\\\CMS\\\\Core\\\\Site\\\\Set\\\\SetRegistry given\\.$#" + count: 1 + path: ../../../Tests/Functional/Regression/PreviewTranslationInformationTest.php + - message: "#^Cannot access property \\$code on DeepL\\\\Language\\|null\\.$#" count: 7 path: ../../../Tests/Functional/Services/DeeplServiceTest.php + - + message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor invoked with 7 parameters, 2\\-3 required\\.$#" + count: 1 + path: ../../../Tests/Functional/Services/LanguageServiceTest.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Site\\\\Set\\\\SetRegistry not found\\.$#" + count: 1 + path: ../../../Tests/Functional/Services/LanguageServiceTest.php + - message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Services\\\\LanguageServiceTest\\:\\:buildDefaultLanguageConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -310,6 +385,26 @@ parameters: count: 1 path: ../../../Tests/Functional/Services/LanguageServiceTest.php + - + message: "#^Parameter \\#2 \\$eventDispatcher of class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor expects Psr\\\\EventDispatcher\\\\EventDispatcherInterface, TYPO3\\\\CMS\\\\Core\\\\Site\\\\SiteSettingsFactory given\\.$#" + count: 1 + path: ../../../Tests/Functional/Services/LanguageServiceTest.php + + - + message: "#^Parameter \\#3 \\$coreCache of class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor expects TYPO3\\\\CMS\\\\Core\\\\Cache\\\\Frontend\\\\PhpFrontend\\|null, TYPO3\\\\CMS\\\\Core\\\\Site\\\\Set\\\\SetRegistry given\\.$#" + count: 1 + path: ../../../Tests/Functional/Services/LanguageServiceTest.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor invoked with 7 parameters, 2\\-3 required\\.$#" + count: 1 + path: ../../../Tests/Functional/Updates/FormalityUpgradeWizardTest.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Site\\\\Set\\\\SetRegistry not found\\.$#" + count: 1 + path: ../../../Tests/Functional/Updates/FormalityUpgradeWizardTest.php + - message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Updates\\\\FormalityUpgradeWizardTest\\:\\:buildDefaultLanguageConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -359,3 +454,28 @@ parameters: message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Updates\\\\FormalityUpgradeWizardTest\\:\\:writeSiteConfiguration\\(\\) has parameter \\$site with no value type specified in iterable type array\\.$#" count: 1 path: ../../../Tests/Functional/Updates/FormalityUpgradeWizardTest.php + + - + message: "#^Parameter \\#2 \\$eventDispatcher of class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor expects Psr\\\\EventDispatcher\\\\EventDispatcherInterface, TYPO3\\\\CMS\\\\Core\\\\Site\\\\SiteSettingsFactory given\\.$#" + count: 1 + path: ../../../Tests/Functional/Updates/FormalityUpgradeWizardTest.php + + - + message: "#^Parameter \\#3 \\$coreCache of class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor expects TYPO3\\\\CMS\\\\Core\\\\Cache\\\\Frontend\\\\PhpFrontend\\|null, TYPO3\\\\CMS\\\\Core\\\\Site\\\\Set\\\\SetRegistry given\\.$#" + count: 1 + path: ../../../Tests/Functional/Updates/FormalityUpgradeWizardTest.php + + - + message: "#^Call to method create\\(\\) on an unknown class TYPO3\\\\CMS\\\\Core\\\\View\\\\ViewFactoryInterface\\.$#" + count: 1 + path: ../../../Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Core\\\\View\\\\ViewFactoryInterface not found\\.$#" + count: 1 + path: ../../../Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php + + - + message: "#^Instantiated class TYPO3\\\\CMS\\\\Core\\\\View\\\\ViewFactoryData not found\\.$#" + count: 1 + path: ../../../Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php diff --git a/Build/phpstan/Core13/phpstan-baseline.neon b/Build/phpstan/Core13/phpstan-baseline.neon index 3bb73956..af3f7fa5 100644 --- a/Build/phpstan/Core13/phpstan-baseline.neon +++ b/Build/phpstan/Core13/phpstan-baseline.neon @@ -1,5 +1,10 @@ parameters: ignoreErrors: + - + message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Frontend\\\\Controller\\\\TypoScriptFrontendController\\:\\:getContext\\(\\)\\.$#" + count: 1 + path: ../../../Classes/Event/Listener/RenderTranslatedFlagInFrontendPreviewMode.php + - message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Form\\\\Item\\\\SiteConfigSupportedLanguageItemsProcFunc\\:\\:getSupportedLanguageForField\\(\\) has parameter \\$configuration with no value type specified in iterable type array\\.$#" count: 1 @@ -105,6 +110,16 @@ parameters: count: 1 path: ../../../Tests/Functional/Fixtures/Frontend/PhpError.php + - + message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration\\:\\:write\\(\\)\\.$#" + count: 2 + path: ../../../Tests/Functional/Hooks/TranslateHookTest.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor invoked with 3 parameters, 7 required\\.$#" + count: 1 + path: ../../../Tests/Functional/Hooks/TranslateHookTest.php + - message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Hooks\\\\TranslateHookTest\\:\\:buildDefaultLanguageConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -155,6 +170,21 @@ parameters: count: 1 path: ../../../Tests/Functional/Hooks/TranslateHookTest.php + - + message: "#^Parameter \\#2 \\$siteSettingsFactory of class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor expects TYPO3\\\\CMS\\\\Core\\\\Site\\\\SiteSettingsFactory, Psr\\\\EventDispatcher\\\\EventDispatcherInterface given\\.$#" + count: 1 + path: ../../../Tests/Functional/Hooks/TranslateHookTest.php + + - + message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration\\:\\:write\\(\\)\\.$#" + count: 2 + path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor invoked with 3 parameters, 7 required\\.$#" + count: 1 + path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php + - message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:buildDefaultLanguageConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -205,6 +235,21 @@ parameters: count: 1 path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php + - + message: "#^Parameter \\#2 \\$siteSettingsFactory of class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor expects TYPO3\\\\CMS\\\\Core\\\\Site\\\\SiteSettingsFactory, Psr\\\\EventDispatcher\\\\EventDispatcherInterface given\\.$#" + count: 1 + path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php + + - + message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration\\:\\:write\\(\\)\\.$#" + count: 2 + path: ../../../Tests/Functional/Regression/PreviewTranslationInformationTest.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor invoked with 3 parameters, 7 required\\.$#" + count: 1 + path: ../../../Tests/Functional/Regression/PreviewTranslationInformationTest.php + - message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Regression\\\\PreviewTranslationInformationTest\\:\\:buildDefaultLanguageConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -255,11 +300,26 @@ parameters: count: 1 path: ../../../Tests/Functional/Regression/PreviewTranslationInformationTest.php + - + message: "#^Parameter \\#2 \\$siteSettingsFactory of class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor expects TYPO3\\\\CMS\\\\Core\\\\Site\\\\SiteSettingsFactory, Psr\\\\EventDispatcher\\\\EventDispatcherInterface given\\.$#" + count: 1 + path: ../../../Tests/Functional/Regression/PreviewTranslationInformationTest.php + - message: "#^Cannot access property \\$code on DeepL\\\\Language\\|null\\.$#" count: 7 path: ../../../Tests/Functional/Services/DeeplServiceTest.php + - + message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration\\:\\:write\\(\\)\\.$#" + count: 2 + path: ../../../Tests/Functional/Services/LanguageServiceTest.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor invoked with 3 parameters, 7 required\\.$#" + count: 1 + path: ../../../Tests/Functional/Services/LanguageServiceTest.php + - message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Services\\\\LanguageServiceTest\\:\\:buildDefaultLanguageConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -310,6 +370,21 @@ parameters: count: 1 path: ../../../Tests/Functional/Services/LanguageServiceTest.php + - + message: "#^Parameter \\#2 \\$siteSettingsFactory of class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor expects TYPO3\\\\CMS\\\\Core\\\\Site\\\\SiteSettingsFactory, Psr\\\\EventDispatcher\\\\EventDispatcherInterface given\\.$#" + count: 1 + path: ../../../Tests/Functional/Services/LanguageServiceTest.php + + - + message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration\\:\\:write\\(\\)\\.$#" + count: 2 + path: ../../../Tests/Functional/Updates/FormalityUpgradeWizardTest.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor invoked with 3 parameters, 7 required\\.$#" + count: 1 + path: ../../../Tests/Functional/Updates/FormalityUpgradeWizardTest.php + - message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Updates\\\\FormalityUpgradeWizardTest\\:\\:buildDefaultLanguageConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -359,3 +434,13 @@ parameters: message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Updates\\\\FormalityUpgradeWizardTest\\:\\:writeSiteConfiguration\\(\\) has parameter \\$site with no value type specified in iterable type array\\.$#" count: 1 path: ../../../Tests/Functional/Updates/FormalityUpgradeWizardTest.php + + - + message: "#^Parameter \\#2 \\$siteSettingsFactory of class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor expects TYPO3\\\\CMS\\\\Core\\\\Site\\\\SiteSettingsFactory, Psr\\\\EventDispatcher\\\\EventDispatcherInterface given\\.$#" + count: 1 + path: ../../../Tests/Functional/Updates/FormalityUpgradeWizardTest.php + + - + message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Core\\\\View\\\\ViewInterface\\:\\:getRenderingContext\\(\\)\\.$#" + count: 3 + path: ../../../Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php diff --git a/Classes/Event/Listener/RenderTranslatedFlagInFrontendPreviewMode.php b/Classes/Event/Listener/RenderTranslatedFlagInFrontendPreviewMode.php index d91f48c5..d81c118b 100644 --- a/Classes/Event/Listener/RenderTranslatedFlagInFrontendPreviewMode.php +++ b/Classes/Event/Listener/RenderTranslatedFlagInFrontendPreviewMode.php @@ -5,6 +5,8 @@ namespace WebVision\Deepltranslate\Core\Event\Listener; use TYPO3\CMS\Core\Context\Context; +use TYPO3\CMS\Core\Information\Typo3Version; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; use TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent; @@ -18,7 +20,9 @@ final class RenderTranslatedFlagInFrontendPreviewMode public function __invoke(AfterCacheableContentIsGeneratedEvent $event): void { $controller = $this->getTypoScriptFrontendController($event); - $context = $controller->getContext(); + $context = ((new Typo3Version())->getMajorVersion() >= 13) + ? GeneralUtility::makeInstance(Context::class) + : $controller->getContext(); if ( !$this->isInPreviewMode($context) || $this->processWorkspacePreview($context) diff --git a/Classes/Upgrades/FormalityUpgradeWizard.php b/Classes/Upgrades/FormalityUpgradeWizard.php index c6692171..ed737a13 100644 --- a/Classes/Upgrades/FormalityUpgradeWizard.php +++ b/Classes/Upgrades/FormalityUpgradeWizard.php @@ -8,6 +8,7 @@ use Symfony\Component\Finder\Finder; use Symfony\Component\Yaml\Yaml; use TYPO3\CMS\Core\Configuration\SiteConfiguration; +use TYPO3\CMS\Core\Configuration\SiteWriter; use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Install\Attribute\UpgradeWizard; @@ -48,7 +49,9 @@ public function updateNecessary(): bool public function executeUpdate(): bool { - $siteConfiguration = GeneralUtility::makeInstance(SiteConfiguration::class); + $siteConfiguration = (class_exists(SiteWriter::class)) + ? GeneralUtility::makeInstance(SiteWriter::class) + : GeneralUtility::makeInstance(SiteConfiguration::class); $deeplService = GeneralUtility::makeInstance(DeeplService::class); $globalFormality = 'default'; @@ -89,8 +92,11 @@ public function executeUpdate(): bool $explodedSiteConfigPath = explode(DIRECTORY_SEPARATOR, $file->getPath()); $siteIdentifier = array_pop($explodedSiteConfigPath); - - $siteConfiguration->write($siteIdentifier, $loadedSiteConfiguration); + if (method_exists($siteConfiguration, 'write')) { + $siteConfiguration->write($siteIdentifier, $loadedSiteConfiguration); + } else { + throw new \RuntimeException(__CLASS__ . ' does not implement write().', 1734624531); + } } return true; diff --git a/Tests/Functional/AbstractDeepLTestCase.php b/Tests/Functional/AbstractDeepLTestCase.php index 6c62713e..b11732d1 100644 --- a/Tests/Functional/AbstractDeepLTestCase.php +++ b/Tests/Functional/AbstractDeepLTestCase.php @@ -13,6 +13,7 @@ use Ramsey\Uuid\Uuid; use RuntimeException; use Symfony\Component\DependencyInjection\Container; +use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Utility\StringUtility; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; use WebVision\Deepltranslate\Core\Client; @@ -124,6 +125,9 @@ abstract class AbstractDeepLTestCase extends FunctionalTestCase protected function setUp(): void { + if ((new Typo3Version())->getMajorVersion() >= 13) { + $this->coreExtensionsToLoad[] = 'typo3/cms-install'; + } $this->EXAMPLE_LARGE_DOCUMENT_INPUT = str_repeat(AbstractDeepLTestCase::EXAMPLE_TEXT['en'] . PHP_EOL, 1000); $this->EXAMPLE_LARGE_DOCUMENT_OUTPUT = str_repeat(AbstractDeepLTestCase::EXAMPLE_TEXT['de'] . PHP_EOL, 1000); $this->serverUrl = getenv('DEEPL_SERVER_URL'); diff --git a/Tests/Functional/Fixtures/Traits/SiteBasedTestTrait.php b/Tests/Functional/Fixtures/Traits/SiteBasedTestTrait.php index 6f5ef39d..ea2ea055 100644 --- a/Tests/Functional/Fixtures/Traits/SiteBasedTestTrait.php +++ b/Tests/Functional/Fixtures/Traits/SiteBasedTestTrait.php @@ -5,8 +5,11 @@ use Exception; use LogicException; use Psr\EventDispatcher\EventDispatcherInterface; +use TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader; use TYPO3\CMS\Core\Configuration\SiteConfiguration; -use TYPO3\CMS\Core\Information\Typo3Version; +use TYPO3\CMS\Core\Configuration\SiteWriter; +use TYPO3\CMS\Core\Site\Set\SetRegistry; +use TYPO3\CMS\Core\Site\SiteSettingsFactory; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\Internal\ArrayValueInstruction; use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\Internal\InstructionInterface; @@ -54,14 +57,17 @@ protected function writeSiteConfiguration( if (!empty($errorHandling)) { $configuration['errorHandling'] = $errorHandling; } - $siteConfiguration = $this->createSiteConfiguration($this->instancePath . '/typo3conf/sites/'); try { // ensure no previous site configuration influences the test GeneralUtility::rmdir($this->instancePath . '/typo3conf/sites/' . $identifier, true); - $siteConfiguration->write($identifier, $configuration); + if (!class_exists(SiteWriter::class)) { + $this->createSiteConfiguration($this->instancePath . '/typo3conf/sites/')->write($identifier, $configuration); + } else { + $this->get(SiteWriter::class)->write($identifier, $configuration); + } } catch (Exception $exception) { - $this->markTestSkipped($exception->getMessage()); + self::fail($exception->getMessage()); } } @@ -73,9 +79,13 @@ protected function mergeSiteConfiguration( $configuration = $siteConfiguration->load($identifier); $configuration = array_merge($configuration, $overrides); try { - $siteConfiguration->write($identifier, $configuration); + if (!class_exists(SiteWriter::class)) { + $this->createSiteConfiguration($this->instancePath . '/typo3conf/sites/')->write($identifier, $configuration); + } else { + $this->get(SiteWriter::class)->write($identifier, $configuration); + } } catch (Exception $exception) { - $this->markTestSkipped($exception->getMessage()); + self::fail($exception->getMessage()); } } @@ -98,17 +108,22 @@ protected function buildSiteConfiguration( protected function createSiteConfiguration(string $path): SiteConfiguration { - if ((new Typo3Version())->getMajorVersion() < 12) { + if (!class_exists(SiteSettingsFactory::class)) { return new SiteConfiguration( $path, + $this->get(EventDispatcherInterface::class), $this->get('cache.core') ); } return new SiteConfiguration( $path, + $this->get(SiteSettingsFactory::class), + $this->get(SetRegistry::class), $this->get(EventDispatcherInterface::class), - $this->get('cache.core') + $this->get('cache.core'), + $this->get(YamlFileLoader::class), + $this->get('cache.runtime') ); } @@ -139,24 +154,6 @@ protected function buildLanguageConfiguration( 'flag' => $preset['flag'] ?? $preset['iso'] ?? '', 'fallbackType' => $fallbackType ?? (empty($fallbackIdentifiers) ? 'strict' : 'fallback'), ]; - if ((new Typo3Version())->getMajorVersion() < 12) { - // TYPO3 v12 changed locale api, and therefore removed some language configurations from the - // siteConfiguration. As we are using this trait for v12 AND v11 in parallel, we add the pre - // v12 values only for versions before v12 to be in line with core behaviour. - // See: https://review.typo3.org/c/Packages/TYPO3.CMS/+/77807 [TASK] Remove "hreflang" from site configuration - // https://review.typo3.org/c/Packages/TYPO3.CMS/+/77597 [TASK] Remove "ISO 639-1" option from site configuration - // https://review.typo3.org/c/Packages/TYPO3.CMS/+/77726 [TASK] Remove "typo3Language" configuration option - // https://review.typo3.org/c/Packages/TYPO3.CMS/+/77814 [TASK] Remove "direction" from site configuration - $configuration = array_replace( - $configuration, - [ - 'hreflang' => $preset['hrefLang'] ?? '', - 'typo3Language' => $preset['iso'] ?? '', - 'iso-639-1' => $preset['iso'] ?? '', - 'direction' => $preset['direction'] ?? '', - ] - ); - } if ($preset['custom']) { $configuration = array_replace( $configuration, diff --git a/Tests/Functional/Hooks/TranslateHookTest.php b/Tests/Functional/Hooks/TranslateHookTest.php index 8d0e88cb..10cce514 100644 --- a/Tests/Functional/Hooks/TranslateHookTest.php +++ b/Tests/Functional/Hooks/TranslateHookTest.php @@ -6,12 +6,12 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; -use TYPO3\CMS\Core\Core\Bootstrap; use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\DataHandling\DataHandler; use TYPO3\CMS\Core\Http\NormalizedParams; use TYPO3\CMS\Core\Http\ServerRequest; +use TYPO3\CMS\Core\Localization\LanguageServiceFactory; use TYPO3\CMS\Core\Site\SiteFinder; use TYPO3\CMS\Core\Utility\GeneralUtility; use WebVision\Deepltranslate\Core\Hooks\TranslateHook; @@ -153,7 +153,7 @@ public function translateContentElementsAndUpdatePagesProperties(): void { $this->importCSVDataSet(__DIR__ . '/Fixtures/BeUsersTranslateDeeplFlag.csv'); $this->setUpBackendUser(2); - Bootstrap::initializeLanguageObject(); + $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->createFromUserPreferences($GLOBALS['BE_USER']); $dataHandler = GeneralUtility::makeInstance(DataHandler::class); $cmdMap = [ diff --git a/Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php b/Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php index 6abbd770..da78cbad 100644 --- a/Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php +++ b/Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php @@ -7,6 +7,10 @@ use Generator; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; +use TYPO3\CMS\Core\Information\Typo3Version; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\View\ViewFactoryData; +use TYPO3\CMS\Core\View\ViewFactoryInterface; use TYPO3\CMS\Fluid\View\TemplateView; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; use TYPO3Fluid\Fluid\Core\Cache\FluidCacheInterface; @@ -45,6 +49,14 @@ public static function tearDownAfterClass(): void rmdir(self::$cachePath); } + protected function setUp(): void + { + if ((new Typo3Version())->getMajorVersion() >= 13) { + $this->coreExtensionsToLoad[] = 'typo3/cms-install'; + } + parent::setUp(); + } + public static function renderDataProvider(): Generator { yield 'extension name empty, await else' => [ @@ -78,11 +90,18 @@ public static function renderDataProvider(): Generator #[Test] public function render(string $template, array $variables, string $expected): void { - $view = new TemplateView(); + if ((new Typo3Version())->getMajorVersion() < 13) { + $view = new TemplateView(); + $view->getRenderingContext()->getViewHelperResolver()->addNamespace('deepl', 'WebVision\\Deepltranslate\\Core\\ViewHelpers'); + $view->getRenderingContext()->setCache(self::$cache); + $view->getRenderingContext()->getTemplatePaths()->setTemplateSource($template); + } else { + $view = GeneralUtility::makeInstance(ViewFactoryInterface::class)->create(new ViewFactoryData()); + $view->getRenderingContext()->getViewHelperResolver()->addNamespace('deepl', 'WebVision\\Deepltranslate\\Core\\ViewHelpers'); + $view->getRenderingContext()->setCache(self::$cache); + $view->getRenderingContext()->getTemplatePaths()->setTemplateSource($template); + } $view->assignMultiple($variables); - $view->getRenderingContext()->getViewHelperResolver()->addNamespace('deepl', 'WebVision\\Deepltranslate\\Core\\ViewHelpers'); - $view->getRenderingContext()->setCache(self::$cache); - $view->getRenderingContext()->getTemplatePaths()->setTemplateSource($template); static::assertSame($expected, $view->render()); } }