From a56b751d51513cd739890a0a920170197da74556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BCrk?= Date: Thu, 19 Dec 2024 15:48:15 +0100 Subject: [PATCH] [TASK] Mitigate deprecated fluid TemplateView in favour of ViewFactoryInterface Since TYPO3 v13 directly instantiating a concrete view has been replaced with a more generic `ViewFactoryInterface` along with default fluid template based variant. To keep functional tests hard as possible we need to work around the deprecation with TYPO3 v13 by using a version check in the ViewHelper related functional tests to use either the factory or the old way for dual TYPO3 version compatibility. [1] https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.3/Feature-104773-GenericViewFactory.html --- .../ExtensionActiveViewHelperTest.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php b/Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php index 53d05c9f..da78cbad 100644 --- a/Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php +++ b/Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php @@ -8,6 +8,9 @@ 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; @@ -87,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()); } }