From 4da7a931bf4c065d7fe50cad931f6205111ccea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Tue, 24 Sep 2024 10:14:16 +0200 Subject: [PATCH] [BootstrapAdminUi] Add functional tests & fix requirements --- ...me.yaml => sylius_bootstrap_admin_ui.yaml} | 0 .../tests/Functional/.application/.env | 3 - src/BootstrapAdminUi/composer.json | 32 ++++++++-- .../tests/Functional/.application/.env | 4 ++ .../.application/config/bundles.php | 8 ++- .../config/packages/doctrine.yaml | 50 ++++++++++++++++ .../packages/sylius_bootstrap_admin_ui.yaml | 2 + .../config/packages/sylius_resource.yaml | 17 ++++++ .../config/routes/sylius_resource.yaml | 7 +++ .../.application/config/services.yaml | 1 + .../.application/src/Entity/.gitignore | 0 .../src/Form/BookResourceType.php | 36 +++++++++++ .../.application/src/Grid/BookGrid.php | 59 +++++++++++++++++++ .../src/Grid/Provider/BookGridProvider.php | 32 ++++++++++ .../src/Resource/BookResource.php | 47 +++++++++++++++ .../src/State/Provider/BookItemProvider.php | 27 +++++++++ .../tests/Functional/TemplatesTest.php | 36 +++++++++++ 17 files changed, 352 insertions(+), 9 deletions(-) rename config/packages/{sylius_admin_theme.yaml => sylius_bootstrap_admin_ui.yaml} (100%) create mode 100644 src/BootstrapAdminUi/tests/Functional/.application/config/packages/doctrine.yaml create mode 100644 src/BootstrapAdminUi/tests/Functional/.application/config/packages/sylius_bootstrap_admin_ui.yaml create mode 100644 src/BootstrapAdminUi/tests/Functional/.application/config/packages/sylius_resource.yaml create mode 100644 src/BootstrapAdminUi/tests/Functional/.application/config/routes/sylius_resource.yaml create mode 100644 src/BootstrapAdminUi/tests/Functional/.application/src/Entity/.gitignore create mode 100644 src/BootstrapAdminUi/tests/Functional/.application/src/Form/BookResourceType.php create mode 100644 src/BootstrapAdminUi/tests/Functional/.application/src/Grid/BookGrid.php create mode 100644 src/BootstrapAdminUi/tests/Functional/.application/src/Grid/Provider/BookGridProvider.php create mode 100644 src/BootstrapAdminUi/tests/Functional/.application/src/Resource/BookResource.php create mode 100644 src/BootstrapAdminUi/tests/Functional/.application/src/State/Provider/BookItemProvider.php create mode 100644 src/BootstrapAdminUi/tests/Functional/TemplatesTest.php diff --git a/config/packages/sylius_admin_theme.yaml b/config/packages/sylius_bootstrap_admin_ui.yaml similarity index 100% rename from config/packages/sylius_admin_theme.yaml rename to config/packages/sylius_bootstrap_admin_ui.yaml diff --git a/src/AdminUi/tests/Functional/.application/.env b/src/AdminUi/tests/Functional/.application/.env index d84e5bf0..4a5b1be7 100644 --- a/src/AdminUi/tests/Functional/.application/.env +++ b/src/AdminUi/tests/Functional/.application/.env @@ -19,6 +19,3 @@ APP_ENV=dev APP_SECRET=c9570eaa5cbfadf33ad1a93f95c2e42a ###< symfony/framework-bundle ### -###> doctrine/doctrine-bundle ### -DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" -###< doctrine/doctrine-bundle ### diff --git a/src/BootstrapAdminUi/composer.json b/src/BootstrapAdminUi/composer.json index 97b63351..6c58bacd 100644 --- a/src/BootstrapAdminUi/composer.json +++ b/src/BootstrapAdminUi/composer.json @@ -3,17 +3,27 @@ "type": "library", "require": { "php": "^8.1", + "pagerfanta/twig": "^4.6", + "sylius/admin-ui": "dev-main", + "sylius/grid-bundle": "^1.13@alpha", + "sylius/resource-bundle": "^1.11 || ^1.12@alpha", + "sylius/twig-extra": "dev-main", "sylius/twig-hooks": "^0.3", "symfony/asset": "^6.4 || ^7.0", "symfony/http-kernel": "^6.4 || ^7.0", "symfony/ux-live-component": "^2.17" }, "require-dev": { - "symfony/framework-bundle": "^6.4 || ^7.0", - "symfony/console": "^6.4 || ^7.0", - "symfony/yaml": "^6.4 || ^7.0", + "doctrine/doctrine-bundle": "^2.12", + "doctrine/orm": "^2.0", "phpunit/phpunit": "^9.6", - "symfony/dotenv": "^6.4 || ^7.0" + "symfony/browser-kit": "^6.4 || ^7.0", + "symfony/console": "^6.4 || ^7.0", + "symfony/css-selector": "^6.4 || ^7.0", + "symfony/dotenv": "^6.4 || ^7.0", + "symfony/framework-bundle": "^6.4 || ^7.0", + "symfony/runtime": "^6.4 || ^7.0", + "symfony/yaml": "^6.4 || ^7.0" }, "autoload": { "psr-4": { @@ -22,15 +32,27 @@ }, "autoload-dev": { "psr-4": { - "TestApplication\\Sylius\\BootstrapAdminUi\\": "tests/Functional/.application/src/" + "TestApplication\\Sylius\\BootstrapAdminUi\\": "tests/Functional/.application/src/", + "Tests\\Sylius\\BootstrapAdminUi\\": "tests/" } }, + "config": { + "allow-plugins": { + "symfony/runtime": true + }, + "sort-packages": true + }, "repositories": [ { "type": "path", "url": "../*/*" } ], + "extra": { + "symfony": { + "require": "7.1.*" + } + }, "minimum-stability": "dev", "prefer-stable": true } diff --git a/src/BootstrapAdminUi/tests/Functional/.application/.env b/src/BootstrapAdminUi/tests/Functional/.application/.env index 62608011..d84e5bf0 100644 --- a/src/BootstrapAdminUi/tests/Functional/.application/.env +++ b/src/BootstrapAdminUi/tests/Functional/.application/.env @@ -18,3 +18,7 @@ APP_ENV=dev APP_SECRET=c9570eaa5cbfadf33ad1a93f95c2e42a ###< symfony/framework-bundle ### + +###> doctrine/doctrine-bundle ### +DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" +###< doctrine/doctrine-bundle ### diff --git a/src/BootstrapAdminUi/tests/Functional/.application/config/bundles.php b/src/BootstrapAdminUi/tests/Functional/.application/config/bundles.php index aa3d22a1..01656a7a 100644 --- a/src/BootstrapAdminUi/tests/Functional/.application/config/bundles.php +++ b/src/BootstrapAdminUi/tests/Functional/.application/config/bundles.php @@ -12,10 +12,16 @@ declare(strict_types=1); return [ + Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], Symfony\UX\TwigComponent\TwigComponentBundle::class => ['all' => true], Sylius\TwigHooks\TwigHooksBundle::class => ['all' => true], - Sylius\AdminUi\Symfony\SyliusAdminUiBundle::class => ['all' => true], Sylius\BootstrapAdminUi\Symfony\SyliusBootstrapAdminUiBundle::class => ['all' => true], + Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], + Sylius\Bundle\ResourceBundle\SyliusResourceBundle::class => ['all' => true], + Sylius\TwigExtra\Symfony\SyliusTwigExtraBundle::class => ['all' => true], + Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true], + BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true], + Sylius\AdminUi\Symfony\SyliusAdminUiBundle::class => ['all' => true], ]; diff --git a/src/BootstrapAdminUi/tests/Functional/.application/config/packages/doctrine.yaml b/src/BootstrapAdminUi/tests/Functional/.application/config/packages/doctrine.yaml new file mode 100644 index 00000000..d42c52d6 --- /dev/null +++ b/src/BootstrapAdminUi/tests/Functional/.application/config/packages/doctrine.yaml @@ -0,0 +1,50 @@ +doctrine: + dbal: + url: '%env(resolve:DATABASE_URL)%' + + # IMPORTANT: You MUST configure your server version, + # either here or in the DATABASE_URL env var (see .env file) + #server_version: '16' + + profiling_collect_backtrace: '%kernel.debug%' + use_savepoints: true + orm: + auto_generate_proxy_classes: true + enable_lazy_ghost_objects: true + report_fields_where_declared: true + validate_xml_mapping: true + naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware + auto_mapping: true + mappings: + App: + type: attribute + is_bundle: false + dir: '%kernel.project_dir%/src/Entity' + prefix: 'App\Entity' + alias: App + +when@test: + doctrine: + dbal: + # "TEST_TOKEN" is typically set by ParaTest + dbname_suffix: '_test%env(default::TEST_TOKEN)%' + +when@prod: + doctrine: + orm: + auto_generate_proxy_classes: false + proxy_dir: '%kernel.build_dir%/doctrine/orm/Proxies' + query_cache_driver: + type: pool + pool: doctrine.system_cache_pool + result_cache_driver: + type: pool + pool: doctrine.result_cache_pool + + framework: + cache: + pools: + doctrine.result_cache_pool: + adapter: cache.app + doctrine.system_cache_pool: + adapter: cache.system diff --git a/src/BootstrapAdminUi/tests/Functional/.application/config/packages/sylius_bootstrap_admin_ui.yaml b/src/BootstrapAdminUi/tests/Functional/.application/config/packages/sylius_bootstrap_admin_ui.yaml new file mode 100644 index 00000000..870b2b91 --- /dev/null +++ b/src/BootstrapAdminUi/tests/Functional/.application/config/packages/sylius_bootstrap_admin_ui.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: '../../../../../config/app.php' } diff --git a/src/BootstrapAdminUi/tests/Functional/.application/config/packages/sylius_resource.yaml b/src/BootstrapAdminUi/tests/Functional/.application/config/packages/sylius_resource.yaml new file mode 100644 index 00000000..f8468814 --- /dev/null +++ b/src/BootstrapAdminUi/tests/Functional/.application/config/packages/sylius_resource.yaml @@ -0,0 +1,17 @@ +# @see https://github.com/Sylius/SyliusResourceBundle/blob/master/docs/index.md +sylius_resource: + drivers: [] + + # Override default settings + #settings: + + # Configure the mapping for your resources + mapping: + paths: + - '%kernel.project_dir%/src/Resource' + + # Configure your resources + resources: + #app.book: + #classes: + #model: App\Entity\Book diff --git a/src/BootstrapAdminUi/tests/Functional/.application/config/routes/sylius_resource.yaml b/src/BootstrapAdminUi/tests/Functional/.application/config/routes/sylius_resource.yaml new file mode 100644 index 00000000..0c8ade2c --- /dev/null +++ b/src/BootstrapAdminUi/tests/Functional/.application/config/routes/sylius_resource.yaml @@ -0,0 +1,7 @@ +sylius_crud_routes: + resource: 'sylius.routing.loader.crud_routes_attributes' + type: service + +sylius_routes: + resource: 'sylius.routing.loader.routes_attributes' + type: service diff --git a/src/BootstrapAdminUi/tests/Functional/.application/config/services.yaml b/src/BootstrapAdminUi/tests/Functional/.application/config/services.yaml index ca2b6832..18d10cda 100644 --- a/src/BootstrapAdminUi/tests/Functional/.application/config/services.yaml +++ b/src/BootstrapAdminUi/tests/Functional/.application/config/services.yaml @@ -4,6 +4,7 @@ # Put parameters here that don't need to change on each machine where the app is deployed # https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration parameters: + locale: en services: # default configuration for services in *this* file diff --git a/src/BootstrapAdminUi/tests/Functional/.application/src/Entity/.gitignore b/src/BootstrapAdminUi/tests/Functional/.application/src/Entity/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/src/BootstrapAdminUi/tests/Functional/.application/src/Form/BookResourceType.php b/src/BootstrapAdminUi/tests/Functional/.application/src/Form/BookResourceType.php new file mode 100644 index 00000000..f8c3664a --- /dev/null +++ b/src/BootstrapAdminUi/tests/Functional/.application/src/Form/BookResourceType.php @@ -0,0 +1,36 @@ +add('name') + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => BookResource::class, + ]); + } +} diff --git a/src/BootstrapAdminUi/tests/Functional/.application/src/Grid/BookGrid.php b/src/BootstrapAdminUi/tests/Functional/.application/src/Grid/BookGrid.php new file mode 100644 index 00000000..a03f7a02 --- /dev/null +++ b/src/BootstrapAdminUi/tests/Functional/.application/src/Grid/BookGrid.php @@ -0,0 +1,59 @@ +setProvider(BookGridProvider::class) + ->addField( + StringField::create('name') + ->setLabel('Name'), + ) + ->addActionGroup( + MainActionGroup::create( + CreateAction::create(), + ), + ) + ->addActionGroup( + ItemActionGroup::create( + UpdateAction::create(), + ), + ) + ; + } + + public function getResourceClass(): string + { + return BookResource::class; + } +} diff --git a/src/BootstrapAdminUi/tests/Functional/.application/src/Grid/Provider/BookGridProvider.php b/src/BootstrapAdminUi/tests/Functional/.application/src/Grid/Provider/BookGridProvider.php new file mode 100644 index 00000000..2306ffff --- /dev/null +++ b/src/BootstrapAdminUi/tests/Functional/.application/src/Grid/Provider/BookGridProvider.php @@ -0,0 +1,32 @@ +id; + } +} diff --git a/src/BootstrapAdminUi/tests/Functional/.application/src/State/Provider/BookItemProvider.php b/src/BootstrapAdminUi/tests/Functional/.application/src/State/Provider/BookItemProvider.php new file mode 100644 index 00000000..c5de8154 --- /dev/null +++ b/src/BootstrapAdminUi/tests/Functional/.application/src/State/Provider/BookItemProvider.php @@ -0,0 +1,27 @@ +client = self::createClient(); + } + + public function testIndexTemplate(): void + { + $this->client->request('GET', '/books'); + + self::assertResponseIsSuccessful(); + self::assertSelectorTextContains('tr.item:first-child[data-test-resource-id]', 'Shinning'); + self::assertSelectorTextContains('tr.item:last-child[data-test-resource-id]', 'Carrie'); + } +}