diff --git a/Build/phpunit/FunctionalTestsBootstrap.php b/Build/phpunit/FunctionalTestsBootstrap.php index 443197d..29a4cbb 100644 --- a/Build/phpunit/FunctionalTestsBootstrap.php +++ b/Build/phpunit/FunctionalTestsBootstrap.php @@ -1,4 +1,5 @@ assetRenderer = $assetRenderer; + $this->assetCollector = $assetCollector; } public function __invoke(AfterCacheableContentIsGeneratedEvent $event) { $frontendController = $event->getController(); $this->assetRenderer->collectInlineAssets([], $frontendController); + $event->getController()->content = str_ireplace( + '', + $this->assetCollector->buildInlineXmlTag() . '', + $event->getController()->content + ); + $event->enableCaching(); } } diff --git a/Classes/Middleware/InlineSvgInjector.php b/Classes/Middleware/InlineSvgInjector.php index dffa05a..80077e0 100644 --- a/Classes/Middleware/InlineSvgInjector.php +++ b/Classes/Middleware/InlineSvgInjector.php @@ -19,6 +19,7 @@ use Psr\Http\Server\RequestHandlerInterface; use TYPO3\CMS\Core\Http\NullResponse; use TYPO3\CMS\Core\Http\Stream; +use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; @@ -30,6 +31,9 @@ class InlineSvgInjector implements MiddlewareInterface public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $response = $handler->handle($request); + if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() > 11) { + return $response; + } if ($this->isOutputting($response)) { $svgAsset = $this->getInlineSvgAsset(); if ($svgAsset !== '') { diff --git a/Tests/Functional/Frontend/SvgViewHelperCachedTest.php b/Tests/Functional/Frontend/SvgViewHelperCachedTest.php new file mode 100644 index 0000000..a551375 --- /dev/null +++ b/Tests/Functional/Frontend/SvgViewHelperCachedTest.php @@ -0,0 +1,51 @@ + 'typo3conf/sites']; + + protected array $configurationToUseInTestInstance = [ + 'SYS' => [ + 'caching' => [ + 'cacheConfigurations' => [ + 'pages' => [ + 'backend' => \TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class, + ], + ], + ], + ], + ]; + + /** + * @test + */ + public function scriptTagForInlineCssIsRendered(): void + { + $this->importCSVDataSet(__DIR__ . '/Fixtures/SvgViewHelper.csv'); + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/')); + $expected = 'getBody(); + self::assertStringContainsString($expected, $bodyUncached); + self::assertStringNotContainsString($notExected, $bodyUncached); + // cached + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/')); + $bodyCached = (string)$response->getBody(); + self::assertSame($bodyUncached, $bodyCached); + } +}