Skip to content

Commit 5141493

Browse files
authored
Merge pull request #25 from b13/bugfix/issue-24
[BUGFIX] cached inline xml
2 parents 972072c + ef20cdf commit 5141493

File tree

5 files changed

+67
-1
lines changed

5 files changed

+67
-1
lines changed

Build/phpunit/FunctionalTestsBootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/*
34
* This file is part of the TYPO3 CMS project.
45
*

Build/phpunit/UnitTestsBootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/*
34
* This file is part of the TYPO3 CMS project.
45
*

Classes/Listener/AfterCacheableContentIsGenerated.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,30 @@
1212
* of the License, or any later version.
1313
*/
1414

15+
use B13\Assetcollector\AssetCollector;
1516
use B13\Assetcollector\Hooks\AssetRenderer;
1617
use TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent;
1718

1819
class AfterCacheableContentIsGenerated
1920
{
2021
protected AssetRenderer $assetRenderer;
22+
protected AssetCollector $assetCollector;
2123

22-
public function __construct(AssetRenderer $assetRenderer)
24+
public function __construct(AssetRenderer $assetRenderer, AssetCollector $assetCollector)
2325
{
2426
$this->assetRenderer = $assetRenderer;
27+
$this->assetCollector = $assetCollector;
2528
}
2629

2730
public function __invoke(AfterCacheableContentIsGeneratedEvent $event)
2831
{
2932
$frontendController = $event->getController();
3033
$this->assetRenderer->collectInlineAssets([], $frontendController);
34+
$event->getController()->content = str_ireplace(
35+
'</body>',
36+
$this->assetCollector->buildInlineXmlTag() . '</body>',
37+
$event->getController()->content
38+
);
39+
$event->enableCaching();
3140
}
3241
}

Classes/Middleware/InlineSvgInjector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Psr\Http\Server\RequestHandlerInterface;
2020
use TYPO3\CMS\Core\Http\NullResponse;
2121
use TYPO3\CMS\Core\Http\Stream;
22+
use TYPO3\CMS\Core\Information\Typo3Version;
2223
use TYPO3\CMS\Core\Utility\GeneralUtility;
2324
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
2425

@@ -30,6 +31,9 @@ class InlineSvgInjector implements MiddlewareInterface
3031
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
3132
{
3233
$response = $handler->handle($request);
34+
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() > 11) {
35+
return $response;
36+
}
3337
if ($this->isOutputting($response)) {
3438
$svgAsset = $this->getInlineSvgAsset();
3539
if ($svgAsset !== '') {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace B13\Assetcollector\Tests\Functional\Functional;
4+
5+
/*
6+
* This file is part of TYPO3 CMS-based extension "assetcollector" by b13.
7+
*
8+
* It is free software; you can redistribute it and/or modify it under
9+
* the terms of the GNU General Public License, either version 2
10+
* of the License, or any later version.
11+
*/
12+
13+
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
14+
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
15+
16+
class SvgViewHelperCachedTest extends FunctionalTestCase
17+
{
18+
protected array $testExtensionsToLoad = ['typo3conf/ext/assetcollector'];
19+
protected array $coreExtensionsToLoad = ['core', 'frontend'];
20+
protected array $pathsToLinkInTestInstance = ['typo3conf/ext/assetcollector/Build/sites' => 'typo3conf/sites'];
21+
22+
protected array $configurationToUseInTestInstance = [
23+
'SYS' => [
24+
'caching' => [
25+
'cacheConfigurations' => [
26+
'pages' => [
27+
'backend' => \TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class,
28+
],
29+
],
30+
],
31+
],
32+
];
33+
34+
/**
35+
* @test
36+
*/
37+
public function scriptTagForInlineCssIsRendered(): void
38+
{
39+
$this->importCSVDataSet(__DIR__ . '/Fixtures/SvgViewHelper.csv');
40+
$response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/'));
41+
$expected = '<svg class="tx_assetcollector"';
42+
$notExected = '</svg><svg class="tx_assetcollector"';
43+
$bodyUncached = (string)$response->getBody();
44+
self::assertStringContainsString($expected, $bodyUncached);
45+
self::assertStringNotContainsString($notExected, $bodyUncached);
46+
// cached
47+
$response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/'));
48+
$bodyCached = (string)$response->getBody();
49+
self::assertSame($bodyUncached, $bodyCached);
50+
}
51+
}

0 commit comments

Comments
 (0)