From b3430789ec11c0645b2c7c472b5a3f1112647079 Mon Sep 17 00:00:00 2001 From: Ferdinand Kuhl Date: Thu, 30 May 2024 14:01:25 +0200 Subject: [PATCH 1/7] first version passing tests in Flow 8.3 --- .woodpecker/code-style.yml | 10 +++ .woodpecker/functional-tests.yml | 34 ++++++++++ Classes/CurrentControllerExpressionNode.php | 41 ++++++++++++ Configuration/Objects.yaml | 9 +++ Configuration/Testing/Views.yaml | 7 ++ Resources/Private/Layouts/Test.html | 1 + .../Tests/Functional/Fixtures/Test/Index.html | 6 ++ .../Functional/Fixtures/Test/WithLayout.html | 7 ++ .../CurrentControllerExpressionNodeTest.php | 65 +++++++++++++++++++ .../Fixtures/Controller/TestController.php | 18 +++++ composer.json | 20 ++++++ 11 files changed, 218 insertions(+) create mode 100644 .woodpecker/code-style.yml create mode 100644 .woodpecker/functional-tests.yml create mode 100644 Classes/CurrentControllerExpressionNode.php create mode 100644 Configuration/Objects.yaml create mode 100644 Configuration/Testing/Views.yaml create mode 100644 Resources/Private/Layouts/Test.html create mode 100644 Resources/Private/Templates/Tests/Functional/Fixtures/Test/Index.html create mode 100644 Resources/Private/Templates/Tests/Functional/Fixtures/Test/WithLayout.html create mode 100644 Tests/Functional/CurrentControllerExpressionNodeTest.php create mode 100644 Tests/Functional/Fixtures/Controller/TestController.php create mode 100644 composer.json diff --git a/.woodpecker/code-style.yml b/.woodpecker/code-style.yml new file mode 100644 index 0000000..6f13ed1 --- /dev/null +++ b/.woodpecker/code-style.yml @@ -0,0 +1,10 @@ +steps: + code-style: + image: composer + commands: + - composer global config repositories.repo-name vcs https://git.digital-competence.de/Packages/php-codesniffer + - composer global config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true + - composer global require digicomp/php-codesniffer:@dev + - composer global exec -- phpcs --runtime-set ignore_warnings_on_exit 1 --standard=DigiComp Classes/ Tests/ + when: + - event: [push, pull_request, manual] diff --git a/.woodpecker/functional-tests.yml b/.woodpecker/functional-tests.yml new file mode 100644 index 0000000..ecfbb6b --- /dev/null +++ b/.woodpecker/functional-tests.yml @@ -0,0 +1,34 @@ +workspace: + base: /woodpecker + path: package + +matrix: + include: + - FLOW_VERSION: 6.3 + PHP_VERSION: 7.4 + - FLOW_VERSION: 7.3 + PHP_VERSION: 7.4 + - FLOW_VERSION: 7.3 + PHP_VERSION: 8.2 + - FLOW_VERSION: 8.2 + PHP_VERSION: 8.2 + +steps: + functional-tests: + image: "thecodingmachine/php:${PHP_VERSION}-v4-cli" + environment: + # Enable the PDO_SQLITE extension + - "PHP_EXTENSION_PDO_SQLITE=1" + - "FLOW_VERSION=${FLOW_VERSION}" + - "NEOS_BUILD_DIR=/woodpecker/Build-${FLOW_VERSION}" + commands: + - "sudo mkdir $NEOS_BUILD_DIR" + - "sudo chown -R docker:docker $NEOS_BUILD_DIR" + - "cd $NEOS_BUILD_DIR" + - "composer create-project --no-install neos/flow-base-distribution:^$FLOW_VERSION ." + - "composer config repositories.repo-name path /woodpecker/package" + - "composer remove --dev --no-update neos/behat || composer remove --no-update neos/behat" + - "composer require digicomp/fluid-currentcontroller-expression:@dev" + - "bin/phpunit --configuration Build/BuildEssentials/PhpUnit/FunctionalTests.xml Packages/Application/DigiComp.FluidCurrentControllerExpression/Tests/Functional" + when: + - event: [ push, pull_request, manual ] diff --git a/Classes/CurrentControllerExpressionNode.php b/Classes/CurrentControllerExpressionNode.php new file mode 100644 index 0000000..66778c2 --- /dev/null +++ b/Classes/CurrentControllerExpressionNode.php @@ -0,0 +1,41 @@ +getControllerContext()->getRequest(), + $propertyToReturn + ); + } + return ''; + } +} diff --git a/Configuration/Objects.yaml b/Configuration/Objects.yaml new file mode 100644 index 0000000..7fadaa7 --- /dev/null +++ b/Configuration/Objects.yaml @@ -0,0 +1,9 @@ +Neos\FluidAdaptor\Core\Rendering\RenderingContext: + properties: + expressionNodeTypes: + value: + - Neos\FluidAdaptor\Core\Parser\SyntaxTree\Expression\LegacyNamespaceExpressionNode + - TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\CastingExpressionNode + - TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\MathExpressionNode + - TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\TernaryExpressionNode + - DigiComp\FluidCurrentControllerExpression\CurrentControllerExpressionNode diff --git a/Configuration/Testing/Views.yaml b/Configuration/Testing/Views.yaml new file mode 100644 index 0000000..6da4506 --- /dev/null +++ b/Configuration/Testing/Views.yaml @@ -0,0 +1,7 @@ +- + requestFilter: 'isFormat("html") && isPackage("DigiComp.FluidCurrentControllerExpression")' + options: + layoutRootPaths: + - "resource://DigiComp.FluidCurrentControllerExpression/Private/Layouts" + partialRootPaths: + - "resource://DigiComp.FluidCurrentControllerExpression/Private/Partials" diff --git a/Resources/Private/Layouts/Test.html b/Resources/Private/Layouts/Test.html new file mode 100644 index 0000000..24f730c --- /dev/null +++ b/Resources/Private/Layouts/Test.html @@ -0,0 +1 @@ + diff --git a/Resources/Private/Templates/Tests/Functional/Fixtures/Test/Index.html b/Resources/Private/Templates/Tests/Functional/Fixtures/Test/Index.html new file mode 100644 index 0000000..48b6549 --- /dev/null +++ b/Resources/Private/Templates/Tests/Functional/Fixtures/Test/Index.html @@ -0,0 +1,6 @@ +{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 new file mode 100644 index 0000000..a20d817 --- /dev/null +++ b/Resources/Private/Templates/Tests/Functional/Fixtures/Test/WithLayout.html @@ -0,0 +1,7 @@ + +{currentController:name} +{currentController:actionName} +{currentController:packageKey} +{currentController:subpackageKey} +{currentController:objectName} +{currentController:format} diff --git a/Tests/Functional/CurrentControllerExpressionNodeTest.php b/Tests/Functional/CurrentControllerExpressionNodeTest.php new file mode 100644 index 0000000..0f73e9c --- /dev/null +++ b/Tests/Functional/CurrentControllerExpressionNodeTest.php @@ -0,0 +1,65 @@ +setUriPattern('test/currentcontrollerexpressions/test(/{@action})'); + $route->setDefaults([ + '@package' => 'DigiComp.FluidCurrentControllerExpression', + '@subpackage' => 'Tests\Functional\Fixtures', + '@controller' => 'Test', + '@action' => 'index', + ]); + $route->setAppendExceedingArguments(true); + $this->router->addRoute($route); + } + + /** + * @test + */ + public function itReturnsCurrentControllerInformations(): void + { + $response = $this->browser->request('http://localhost/test/currentcontrollerexpressions/test'); + static::assertEquals( + 'Test +index +DigiComp.FluidCurrentControllerExpression +Tests\Functional\Fixtures +DigiComp\FluidCurrentControllerExpression\Tests\Functional\Fixtures\Controller\TestController +html +', + (string)$response->getBody() + ); + + $response = $this->browser->request('http://localhost/test/currentcontrollerexpressions/test/withlayout'); + static::assertEquals( + 'Test +withLayout +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 new file mode 100644 index 0000000..19911f3 --- /dev/null +++ b/Tests/Functional/Fixtures/Controller/TestController.php @@ -0,0 +1,18 @@ + Date: Thu, 30 May 2024 15:08:53 +0200 Subject: [PATCH 2/7] 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() + { + } } From 193d9b925a591626fd8d53fff40189f90d8a2c35 Mon Sep 17 00:00:00 2001 From: Ferdinand Kuhl Date: Thu, 30 May 2024 15:12:49 +0200 Subject: [PATCH 3/7] fixing an accidently error introduced by removing case insensitivity - and allowing path expressions for action request retrieval --- Classes/CurrentControllerExpressionNode.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/CurrentControllerExpressionNode.php b/Classes/CurrentControllerExpressionNode.php index 03289e1..390af09 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]+)\}/'; + public static string $detectionExpression = '/\{#currentController\.([a-zA-Z0-9\.]+)\}/'; public static function evaluateExpression(RenderingContextInterface $renderingContext, $expression, array $matches) { @@ -31,7 +31,7 @@ class CurrentControllerExpressionNode extends AbstractExpressionNode implements ) { $propertyToReturn = 'controller' . \ucfirst($propertyToReturn); } - return ObjectAccess::getProperty( + return ObjectAccess::getPropertyPath( $renderingContext->getControllerContext()->getRequest(), $propertyToReturn ); From e303f86640fbefb4d89129533f033f3c1a610498 Mon Sep 17 00:00:00 2001 From: Ferdinand Kuhl Date: Thu, 30 May 2024 15:23:04 +0200 Subject: [PATCH 4/7] adding minimal documentation and package meta information --- README.md | 13 +++++++++++++ composer.json | 17 ++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..bd99672 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# DigiComp.FluidCurrentControllerExpression + +This extends the fluid language with an expression to allow you to access values of the current action request. + +```html + + Welcome to {#currentController.name} {#currentController.actionName} + +``` + +The pattern is `{#currentController.PROPERTY_OF_ACTIONREQUEST}` - all properties are possible. To avoid duplicated "controller" in the expression you are allowed to omit them (even if it works, if you do not). + +It is really helpful if you try to generalize partials - being an expression, it is not depending on any aliased namespace, which might change in deeper structures. diff --git a/composer.json b/composer.json index 10cda9a..5c6a1b5 100644 --- a/composer.json +++ b/composer.json @@ -16,5 +16,20 @@ "psr-4": { "DigiComp\\FluidCurrentControllerExpression\\": "Classes/" } - } + }, + "authors": [ + { + "name": "Ferdinand Kuhl", + "email": "f.kuhl@digital-competence.de", + "homepage": "https://www.digital-competence.de", + "role": "Developer" + } + ], + "license": "MIT", + "homepage": "https://git.digital-competence.de/Packages/DigiComp.FluidCurrentControllerExpression", + "keywords": [ + "Neos", + "Flow", + "fluid" + ] } From 8695ecc9fe0e092210cbe0caed309c145a3c6f79 Mon Sep 17 00:00:00 2001 From: Ferdinand Kuhl Date: Thu, 30 May 2024 15:31:46 +0200 Subject: [PATCH 5/7] adding license --- License.txt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 License.txt diff --git a/License.txt b/License.txt new file mode 100644 index 0000000..7c439ae --- /dev/null +++ b/License.txt @@ -0,0 +1,19 @@ +Copyright (c) 2024 Ferdinand Kuhl + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. From b8931bd0489c425da4d6501783e5e506d7650413 Mon Sep 17 00:00:00 2001 From: Ferdinand Kuhl Date: Thu, 30 May 2024 16:10:51 +0200 Subject: [PATCH 6/7] adding description --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5c6a1b5..33499a5 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "digicomp/fluid-currentcontroller-expression", "type": "neos-package", - "description": "", + "description": "Extends fluid with expressions to retrieve current's ActionRequest values", "require": { "php": "^7.4 | ^8.1", "neos/flow": "^6.3 | ^7.3 | ^8.2", From f1227b963f182e0a6224387844d5d01ddaa3a46b Mon Sep 17 00:00:00 2001 From: Ferdinand Kuhl Date: Sun, 2 Jun 2024 03:59:34 +0200 Subject: [PATCH 7/7] removing senseless property override --- Tests/Functional/CurrentControllerExpressionNodeTest.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Tests/Functional/CurrentControllerExpressionNodeTest.php b/Tests/Functional/CurrentControllerExpressionNodeTest.php index 5602a61..fddbd4d 100644 --- a/Tests/Functional/CurrentControllerExpressionNodeTest.php +++ b/Tests/Functional/CurrentControllerExpressionNodeTest.php @@ -9,11 +9,6 @@ use Neos\Flow\Tests\FunctionalTestCase; class CurrentControllerExpressionNodeTest extends FunctionalTestCase { - /** - * @var \Neos\Flow\Http\Client\Browser - */ - protected $browser; - /** * Initializer */