From e14bdb8e7feadb527837cdd8389d27632472dd93 Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Fri, 29 Nov 2024 14:30:17 +0100 Subject: [PATCH 1/2] [BUGFIX] cached inline xml Fixes: #24 --- .../AfterCacheableContentIsGenerated.php | 11 +++- Classes/Middleware/InlineSvgInjector.php | 4 ++ .../Frontend/SvgViewHelperCachedTest.php | 51 +++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 Tests/Functional/Frontend/SvgViewHelperCachedTest.php diff --git a/Classes/Listener/AfterCacheableContentIsGenerated.php b/Classes/Listener/AfterCacheableContentIsGenerated.php index 3524af4..bf01526 100644 --- a/Classes/Listener/AfterCacheableContentIsGenerated.php +++ b/Classes/Listener/AfterCacheableContentIsGenerated.php @@ -12,21 +12,30 @@ * of the License, or any later version. */ +use B13\Assetcollector\AssetCollector; use B13\Assetcollector\Hooks\AssetRenderer; use TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent; class AfterCacheableContentIsGenerated { protected AssetRenderer $assetRenderer; + protected AssetCollector $assetCollector; - public function __construct(AssetRenderer $assetRenderer) + public function __construct(AssetRenderer $assetRenderer, AssetCollector $assetCollector) { $this->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); + } +} From ef20cdffc3ee5b4150427e0f18a56133003d29ff Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Fri, 29 Nov 2024 14:41:51 +0100 Subject: [PATCH 2/2] [TASK] make ci happy --- Build/phpunit/FunctionalTestsBootstrap.php | 1 + Build/phpunit/UnitTestsBootstrap.php | 1 + 2 files changed, 2 insertions(+) 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 @@