Skip to content

Commit

Permalink
[TASK] Mitigate deprecated fluid TemplateView in favour of ViewFactor…
Browse files Browse the repository at this point in the history
…yInterface

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
  • Loading branch information
sbuerk committed Dec 19, 2024
1 parent caa7b81 commit a56b751
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}

0 comments on commit a56b751

Please sign in to comment.