Skip to content

Commit

Permalink
[BUGFIX] cached inline xml
Browse files Browse the repository at this point in the history
Fixes: #24
  • Loading branch information
achimfritz committed Nov 29, 2024
1 parent 972072c commit ec73f0e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Classes/Listener/AfterCacheableContentIsGenerated.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'</body>',
$this->assetCollector->buildInlineXmlTag() . '</body>',
$event->getController()->content
);
$event->enableCaching();
}
}
50 changes: 50 additions & 0 deletions Tests/Functional/Frontend/SvgViewHelperCachedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace B13\Assetcollector\Tests\Functional\Functional;

/*
* This file is part of TYPO3 CMS-based extension "assetcollector" by b13.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*/

use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

class SvgViewHelperCachedTest extends FunctionalTestCase
{
protected array $testExtensionsToLoad = ['typo3conf/ext/assetcollector'];
protected array $coreExtensionsToLoad = ['core', 'frontend'];
protected array $pathsToLinkInTestInstance = ['typo3conf/ext/assetcollector/Build/sites' => '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 = '<svg class="tx_assetcollector"';
$body = (string)$response->getBody();
#var_dump($body);
self::assertStringContainsString($expected, $body);
// cached
$response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/'));
$body = (string)$response->getBody();
self::assertStringContainsString($expected, $body);
}
}

0 comments on commit ec73f0e

Please sign in to comment.