From ec73f0e83478b4fd568a8a71f13718ae96426127 Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Fri, 29 Nov 2024 14:30:17 +0100 Subject: [PATCH] [BUGFIX] cached inline xml Fixes: #24 --- .../AfterCacheableContentIsGenerated.php | 11 +++- .../Frontend/SvgViewHelperCachedTest.php | 50 +++++++++++++++++++ 2 files changed, 60 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..f8e0b80 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/Tests/Functional/Frontend/SvgViewHelperCachedTest.php b/Tests/Functional/Frontend/SvgViewHelperCachedTest.php new file mode 100644 index 0000000..52fc644 --- /dev/null +++ b/Tests/Functional/Frontend/SvgViewHelperCachedTest.php @@ -0,0 +1,50 @@ + '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(); + #var_dump($body); + self::assertStringContainsString($expected, $body); + // cached + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/')); + $body = (string)$response->getBody(); + self::assertStringContainsString($expected, $body); + } +}