From d5fca333108ac9c3c06ae072f6631a8b96a3c159 Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Mon, 28 Oct 2024 09:14:19 +0100 Subject: [PATCH] feat(areabrick-overview): display template location for all bricks (#34) --- .github/workflows/qa.yaml | 1 - .github/workflows/tests.yaml | 9 +++- composer.json | 4 ++ config/pimcore/config.yaml | 2 +- config/services.yaml | 2 +- phpunit.xml.dist | 1 - .../BrickTemplateLocationPopulator.php | 29 +++++++++++++ .../BrickTemplateLocationPopulatorTest.php | 42 +++++++++++++++++++ tests/app/config/.gitkeep | 0 tests/app/config/services.yaml | 8 ++++ .../src/Document/Areabrick/CustomTemplate.php | 24 +++++++++++ .../Areabrick/GlobalTemplateLocation.php | 24 +++++++++++ .../global-template-location/view.html.twig | 1 + .../custom-template-areabrick/index.html | 1 + 14 files changed, 142 insertions(+), 6 deletions(-) create mode 100644 src/Bricks/Populator/BrickTemplateLocationPopulator.php create mode 100644 tests/Integration/Bricks/Populator/BrickTemplateLocationPopulatorTest.php delete mode 100644 tests/app/config/.gitkeep create mode 100644 tests/app/config/services.yaml create mode 100644 tests/app/src/Document/Areabrick/CustomTemplate.php create mode 100644 tests/app/src/Document/Areabrick/GlobalTemplateLocation.php create mode 100644 tests/app/templates/areas/global-template-location/view.html.twig create mode 100644 tests/app/templates/custom-template-areabrick/index.html diff --git a/.github/workflows/qa.yaml b/.github/workflows/qa.yaml index 5ca161e..dad50b9 100644 --- a/.github/workflows/qa.yaml +++ b/.github/workflows/qa.yaml @@ -4,7 +4,6 @@ on: push: branches: [ "main" ] pull_request: - branches: [ "main" ] workflow_dispatch: permissions: diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index e750a47..a23ce84 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -4,7 +4,6 @@ on: push: branches: [ "main" ] pull_request: - branches: [ "main" ] workflow_dispatch: permissions: @@ -23,8 +22,10 @@ jobs: dependencies: "lowest" - php-version: "8.1" dependencies: "highest" + tests: --fail-on-risky - php-version: "8.2" dependencies: "highest" + tests: --fail-on-risky steps: - name: Git Checkout @@ -40,5 +41,9 @@ jobs: with: dependency-versions: ${{ matrix.dependencies }} + - name: Add Pimcore Admin UI + run: composer require --dev pimcore/admin-ui-classic-bundle --no-interaction + if: matrix.dependencies == 'highest' + - name: Execute tests - run: composer tests + run: composer tests -- ${{ matrix.tests }} diff --git a/composer.json b/composer.json index 9cb001b..4a1405b 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,7 @@ "require-dev": { "friendsofphp/php-cs-fixer": "^3.62", "jangregor/phpstan-prophecy": "^1.0.2", + "laminas/laminas-zendframework-bridge": "^1.8", "phpspec/prophecy-phpunit": "^2.2", "phpstan/phpstan": "^1.11.10", "phpstan/phpstan-phpunit": "^1.4", @@ -52,6 +53,9 @@ } }, "autoload-dev": { + "classmap": [ + "tests/app/TestKernel.php" + ], "psr-4": { "Neusta\\Pimcore\\AreabrickConfigBundle\\Tests\\": "tests/" } diff --git a/config/pimcore/config.yaml b/config/pimcore/config.yaml index 1fced03..3fd97de 100644 --- a/config/pimcore/config.yaml +++ b/config/pimcore/config.yaml @@ -7,13 +7,13 @@ neusta_converter: neusta_pimcore_areabrick_config.brick.converter: target: Neusta\Pimcore\AreabrickConfigBundle\Bricks\Model\Brick populators: + - Neusta\Pimcore\AreabrickConfigBundle\Bricks\Populator\BrickTemplateLocationPopulator - Neusta\Pimcore\AreabrickConfigBundle\Bricks\Populator\BrickPagePopulator properties: id: ~ name: ~ version: ~ description: ~ - template: ~ neusta_pimcore_areabrick_config.page.converter: target: Neusta\Pimcore\AreabrickConfigBundle\Bricks\Model\Page diff --git a/config/services.yaml b/config/services.yaml index b5fa311..d99dcfa 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -8,7 +8,7 @@ services: $brickConverter: '@neusta_pimcore_areabrick_config.brick.converter' tags: [ 'controller.service_arguments' ] - Neusta\Pimcore\AreabrickConfigBundle\Bricks\Populator\BrickPageEditModeUrlPopulator: ~ + Neusta\Pimcore\AreabrickConfigBundle\Bricks\Populator\BrickTemplateLocationPopulator: ~ Neusta\Pimcore\AreabrickConfigBundle\Bricks\Populator\BrickPagePopulator: arguments: diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 6d27b57..5eb7de4 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,6 @@ bootstrap="tests/bootstrap.php" cacheResultFile=".phpunit.cache/test-results" colors="true" - failOnRisky="true" failOnWarning="true" > diff --git a/src/Bricks/Populator/BrickTemplateLocationPopulator.php b/src/Bricks/Populator/BrickTemplateLocationPopulator.php new file mode 100644 index 0000000..9e4c6c0 --- /dev/null +++ b/src/Bricks/Populator/BrickTemplateLocationPopulator.php @@ -0,0 +1,29 @@ + + */ +final class BrickTemplateLocationPopulator implements Populator +{ + private readonly \Closure $resolveTemplate; + + public function __construct(EditableHandler $editableHandler) + { + $this->resolveTemplate = (new \ReflectionMethod($editableHandler, 'resolveBrickTemplate'))->getClosure($editableHandler); + } + + public function populate(object $target, object $source, ?object $ctx = null): void + { + // Todo: remove the second parameter when Pimcore 10 support is dropped + $target->template = ($this->resolveTemplate)($source, 'view'); + } +} diff --git a/tests/Integration/Bricks/Populator/BrickTemplateLocationPopulatorTest.php b/tests/Integration/Bricks/Populator/BrickTemplateLocationPopulatorTest.php new file mode 100644 index 0000000..c44e530 --- /dev/null +++ b/tests/Integration/Bricks/Populator/BrickTemplateLocationPopulatorTest.php @@ -0,0 +1,42 @@ +get(BrickTemplateLocationPopulator::class); + $source = $container->get(AreabrickManagerInterface::class)->getBrick('custom-template'); + $target = new Brick(); + + $populator->populate($target, $source); + + self::assertSame('custom-template-areabrick/index.html.twig', $target->template); + } + + /** + * @test + */ + public function itPopulatesDefaultTemplateLocations(): void + { + $container = self::getContainer(); + $populator = $container->get(BrickTemplateLocationPopulator::class); + $source = $container->get(AreabrickManagerInterface::class)->getBrick('global-template-location'); + $target = new Brick(); + + $populator->populate($target, $source); + + self::assertSame('areas/global-template-location/view.html.twig', $target->template); + } +} diff --git a/tests/app/config/.gitkeep b/tests/app/config/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tests/app/config/services.yaml b/tests/app/config/services.yaml new file mode 100644 index 0000000..d219fa7 --- /dev/null +++ b/tests/app/config/services.yaml @@ -0,0 +1,8 @@ +services: + Neusta\Pimcore\AreabrickConfigBundle\Tests\app\src\Document\Areabrick\CustomTemplate: + tags: + - { name: pimcore.area.brick, id: custom-template } + + Neusta\Pimcore\AreabrickConfigBundle\Tests\app\src\Document\Areabrick\GlobalTemplateLocation: + tags: + - { name: pimcore.area.brick, id: global-template-location } diff --git a/tests/app/src/Document/Areabrick/CustomTemplate.php b/tests/app/src/Document/Areabrick/CustomTemplate.php new file mode 100644 index 0000000..a65ed72 --- /dev/null +++ b/tests/app/src/Document/Areabrick/CustomTemplate.php @@ -0,0 +1,24 @@ +