From 042f5603b201a5f3bdc7bcd95b056f022a431ffb Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Wed, 24 Apr 2024 22:15:28 +0200 Subject: [PATCH 1/2] Feature: Allow to enable Fusion caching for Behat tests --- .../Features/Bootstrap/FusionTrait.php | 12 ++++ .../Features/Fusion/ContentCache.feature | 66 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 Neos.Neos/Tests/Behavior/Features/Fusion/ContentCache.feature diff --git a/Neos.Neos/Tests/Behavior/Features/Bootstrap/FusionTrait.php b/Neos.Neos/Tests/Behavior/Features/Bootstrap/FusionTrait.php index 21b8f5ba725..8326cf17dcb 100644 --- a/Neos.Neos/Tests/Behavior/Features/Bootstrap/FusionTrait.php +++ b/Neos.Neos/Tests/Behavior/Features/Bootstrap/FusionTrait.php @@ -47,6 +47,8 @@ trait FusionTrait private ?\Throwable $lastRenderingException = null; + private $contentCacheEnabled = false; + /** * @template T of object * @param class-string $className @@ -63,6 +65,7 @@ public function setupFusionContext(): void $this->fusionGlobalContext = []; $this->fusionContext = []; $this->fusionCode = null; + $this->contentCacheEnabled = false; $this->renderingResult = null; } @@ -114,6 +117,14 @@ public function iHaveTheFollowingFusionSetup(PyStringNode $fusionCode): void $this->fusionCode = $fusionCode->getRaw(); } + /** + * @When I have Fusion content cache enabled + */ + public function iHaveFusionContentCacheEnabled(): void + { + $this->contentCacheEnabled = true; + } + /** * @When I execute the following Fusion code: * @When I execute the following Fusion code on path :path: @@ -131,6 +142,7 @@ public function iExecuteTheFollowingFusionCode(PyStringNode $fusionCode, string $fusionGlobals = FusionGlobals::fromArray($this->fusionGlobalContext); $fusionRuntime = (new RuntimeFactory())->createFromConfiguration($fusionAst, $fusionGlobals); + $fusionRuntime->setEnableContentCache($this->contentCacheEnabled); $fusionRuntime->overrideExceptionHandler($this->getObject(ThrowingHandler::class)); $fusionRuntime->pushContextArray($this->fusionContext); try { diff --git a/Neos.Neos/Tests/Behavior/Features/Fusion/ContentCache.feature b/Neos.Neos/Tests/Behavior/Features/Fusion/ContentCache.feature new file mode 100644 index 00000000000..b0e19d8f385 --- /dev/null +++ b/Neos.Neos/Tests/Behavior/Features/Fusion/ContentCache.feature @@ -0,0 +1,66 @@ +@flowEntities @contentrepository +Feature: Tests for Fusion ContentCache + Background: + Given I have Fusion content cache enabled + And I have the following Fusion setup: + """fusion + include: resource://Neos.Fusion/Private/Fusion/Root.fusion + include: resource://Neos.Neos/Private/Fusion/Root.fusion + + prototype(Neos.Neos:Test.ContentCache) < prototype(Neos.Fusion:Component) { + foo = '' + renderer = ${props.foo} + @cache { + mode = 'cached' + entryIdentifier { + test = 'test' + } + } + } + +""" + + Scenario: + When I execute the following Fusion code: + """fusion + test = Neos.Neos:Test.ContentCache { + foo = 'test1' + } + """ + Then I expect the following Fusion rendering result: + """ + test1 + """ + When I execute the following Fusion code: + """fusion + test = Neos.Neos:Test.ContentCache { + foo = 'test2' + } + """ + Then I expect the following Fusion rendering result: + """ + test1 + """ + + + Scenario: + When I execute the following Fusion code: + """fusion + test = Neos.Neos:Test.ContentCache { + foo = 'test2' + } + """ + Then I expect the following Fusion rendering result: + """ + test2 + """ + When I execute the following Fusion code: + """fusion + test = Neos.Neos:Test.ContentCache { + foo = 'test1' + } + """ + Then I expect the following Fusion rendering result: + """ + test2 + """ \ No newline at end of file From 23ebd0c54474d3c72b166c24d50c6c534ff09515 Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Thu, 25 Apr 2024 21:17:08 +0200 Subject: [PATCH 2/2] Feature: Allow to enable Fusion caching for Behat tests --- .../Features/Bootstrap/FusionTrait.php | 9 +++++++++ .../Features/Fusion/ContentCache.feature | 20 +++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Neos.Neos/Tests/Behavior/Features/Bootstrap/FusionTrait.php b/Neos.Neos/Tests/Behavior/Features/Bootstrap/FusionTrait.php index 8326cf17dcb..b1ebbbd35a5 100644 --- a/Neos.Neos/Tests/Behavior/Features/Bootstrap/FusionTrait.php +++ b/Neos.Neos/Tests/Behavior/Features/Bootstrap/FusionTrait.php @@ -28,6 +28,7 @@ use Neos\Neos\Domain\Service\RenderingModeService; use PHPUnit\Framework\Assert; use Psr\Http\Message\ServerRequestFactoryInterface; +use Neos\Fusion\Core\Cache\ContentCache; /** * @internal only for behat tests within the Neos.Neos package @@ -204,4 +205,12 @@ public function throwExceptionIfLastRenderingLedToAnError(): void } } + /** + * @BeforeScenario + */ + public function clearFusionCaches() + { + $this->getObject(ContentCache::class)->flush(); + } + } diff --git a/Neos.Neos/Tests/Behavior/Features/Fusion/ContentCache.feature b/Neos.Neos/Tests/Behavior/Features/Fusion/ContentCache.feature index b0e19d8f385..bc0c4c68455 100644 --- a/Neos.Neos/Tests/Behavior/Features/Fusion/ContentCache.feature +++ b/Neos.Neos/Tests/Behavior/Features/Fusion/ContentCache.feature @@ -20,47 +20,47 @@ Feature: Tests for Fusion ContentCache """ - Scenario: + Scenario: Render a cached prototype and check if rerendering doesn't happen on second try When I execute the following Fusion code: """fusion test = Neos.Neos:Test.ContentCache { - foo = 'test1' + foo = 'some-cached-string' } """ Then I expect the following Fusion rendering result: """ - test1 + some-cached-string """ When I execute the following Fusion code: """fusion test = Neos.Neos:Test.ContentCache { - foo = 'test2' + foo = 'some-other-string' } """ Then I expect the following Fusion rendering result: """ - test1 + some-cached-string """ - Scenario: + Scenario: Check if cached got flushed before running a new scenario and no leftover of last test is there When I execute the following Fusion code: """fusion test = Neos.Neos:Test.ContentCache { - foo = 'test2' + foo = 'some-new-string' } """ Then I expect the following Fusion rendering result: """ - test2 + some-new-string """ When I execute the following Fusion code: """fusion test = Neos.Neos:Test.ContentCache { - foo = 'test1' + foo = 'totally-different-string' } """ Then I expect the following Fusion rendering result: """ - test2 + some-new-string """ \ No newline at end of file