From f75b21a874c4fa09ec501678fcebcc63e22d2a66 Mon Sep 17 00:00:00 2001 From: Ferdinand Kuhl Date: Thu, 30 May 2024 15:08:53 +0200 Subject: [PATCH] changing the format of the expression detections to avoid accidently being identified as objectaccessor and adding a test, where that happend with the previous expression --- Classes/CurrentControllerExpressionNode.php | 2 +- .../Functional/Fixtures/Test/InArrays.html | 6 +++++ .../Tests/Functional/Fixtures/Test/Index.html | 12 +++++----- .../Functional/Fixtures/Test/WithLayout.html | 12 +++++----- .../CurrentControllerExpressionNodeTest.php | 24 +++++++++++++++++++ .../Fixtures/Controller/TestController.php | 4 ++++ 6 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 Resources/Private/Templates/Tests/Functional/Fixtures/Test/InArrays.html diff --git a/Classes/CurrentControllerExpressionNode.php b/Classes/CurrentControllerExpressionNode.php index 66778c2..03289e1 100644 --- a/Classes/CurrentControllerExpressionNode.php +++ b/Classes/CurrentControllerExpressionNode.php @@ -16,7 +16,7 @@ class CurrentControllerExpressionNode extends AbstractExpressionNode implements * note: this could be readonly in PHP8 * @var string */ - public static string $detectionExpression = '/{currentController:([a-z0-9]+)}/i'; + public static string $detectionExpression = '/\{#currentController\.([a-z0-9]+)\}/'; public static function evaluateExpression(RenderingContextInterface $renderingContext, $expression, array $matches) { diff --git a/Resources/Private/Templates/Tests/Functional/Fixtures/Test/InArrays.html b/Resources/Private/Templates/Tests/Functional/Fixtures/Test/InArrays.html new file mode 100644 index 0000000..0cac6aa --- /dev/null +++ b/Resources/Private/Templates/Tests/Functional/Fixtures/Test/InArrays.html @@ -0,0 +1,6 @@ +{controllername} +{#currentController.actionName} +{#currentController.packageKey} +{#currentController.subpackageKey} +{#currentController.objectName} +{#currentController.format} diff --git a/Resources/Private/Templates/Tests/Functional/Fixtures/Test/Index.html b/Resources/Private/Templates/Tests/Functional/Fixtures/Test/Index.html index 48b6549..cb5df1f 100644 --- a/Resources/Private/Templates/Tests/Functional/Fixtures/Test/Index.html +++ b/Resources/Private/Templates/Tests/Functional/Fixtures/Test/Index.html @@ -1,6 +1,6 @@ -{currentController:name} -{currentController:actionName} -{currentController:packageKey} -{currentController:subpackageKey} -{currentController:objectName} -{currentController:format} +{#currentController.name} +{#currentController.actionName} +{#currentController.packageKey} +{#currentController.subpackageKey} +{#currentController.objectName} +{#currentController.format} diff --git a/Resources/Private/Templates/Tests/Functional/Fixtures/Test/WithLayout.html b/Resources/Private/Templates/Tests/Functional/Fixtures/Test/WithLayout.html index a20d817..2b71b43 100644 --- a/Resources/Private/Templates/Tests/Functional/Fixtures/Test/WithLayout.html +++ b/Resources/Private/Templates/Tests/Functional/Fixtures/Test/WithLayout.html @@ -1,7 +1,7 @@ -{currentController:name} -{currentController:actionName} -{currentController:packageKey} -{currentController:subpackageKey} -{currentController:objectName} -{currentController:format} +{#currentController.name} +{#currentController.actionName} +{#currentController.packageKey} +{#currentController.subpackageKey} +{#currentController.objectName} +{#currentController.format} diff --git a/Tests/Functional/CurrentControllerExpressionNodeTest.php b/Tests/Functional/CurrentControllerExpressionNodeTest.php index 0f73e9c..5602a61 100644 --- a/Tests/Functional/CurrentControllerExpressionNodeTest.php +++ b/Tests/Functional/CurrentControllerExpressionNodeTest.php @@ -49,7 +49,13 @@ html ', (string)$response->getBody() ); + } + /** + * @test + */ + public function itReturnsCurrentControllerInformationsUsedInLayouts(): void + { $response = $this->browser->request('http://localhost/test/currentcontrollerexpressions/test/withlayout'); static::assertEquals( 'Test @@ -58,6 +64,24 @@ DigiComp.FluidCurrentControllerExpression Tests\Functional\Fixtures DigiComp\FluidCurrentControllerExpression\Tests\Functional\Fixtures\Controller\TestController html +', + (string)$response->getBody() + ); + } + + /** + * @test + */ + public function itReturnsCurrentControllerInformationsUsedInArrays(): void + { + $response = $this->browser->request('http://localhost/test/currentcontrollerexpressions/test/inArrays'); + static::assertEquals( + 'Test +inArrays +DigiComp.FluidCurrentControllerExpression +Tests\Functional\Fixtures +DigiComp\FluidCurrentControllerExpression\Tests\Functional\Fixtures\Controller\TestController +html ', (string)$response->getBody() ); diff --git a/Tests/Functional/Fixtures/Controller/TestController.php b/Tests/Functional/Fixtures/Controller/TestController.php index 19911f3..341c8a2 100644 --- a/Tests/Functional/Fixtures/Controller/TestController.php +++ b/Tests/Functional/Fixtures/Controller/TestController.php @@ -15,4 +15,8 @@ class TestController extends ActionController public function withLayoutAction() { } + + public function inArraysAction() + { + } }