diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bcd3efca1..7bb751d6c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -115,6 +115,8 @@ jobs: name: Run lint container without twig/twig package run: | composer remove symfony/twig-bundle --no-scripts + composer remove sylius/grid-bundle --no-scripts --dev (cd src/Bundle/test && bin/console cache:clear --env=test_without_twig) (cd src/Bundle/test && bin/console lint:container --env=test_without_twig) composer require symfony/twig-bundle --no-scripts + composer require "sylius/grid-bundle: ^1.7 || v1.12.0-ALPHA.1" --no-scripts --dev diff --git a/composer.json b/composer.json index 3112cbe97..c5e893776 100644 --- a/composer.json +++ b/composer.json @@ -70,7 +70,7 @@ "phpstan/phpstan-webmozart-assert": "^1.2", "phpunit/phpunit": "^9.5", "sylius-labs/coding-standard": "^4.0", - "sylius/grid-bundle": "^1.7 || dev-symfony-6", + "sylius/grid-bundle": "^1.7 || v1.12.0-ALPHA.1", "symfony/dependency-injection": "^5.4 || ^6.0", "symfony/dotenv": "^5.4 || ^6.0", "symfony/workflow": "^5.4 || ^6.0", diff --git a/src/Bundle/test/config/bundles.php b/src/Bundle/test/config/bundles.php index ff60bdfc4..e800a48fc 100644 --- a/src/Bundle/test/config/bundles.php +++ b/src/Bundle/test/config/bundles.php @@ -18,6 +18,7 @@ use FOS\RestBundle\FOSRestBundle; use JMS\SerializerBundle\JMSSerializerBundle; use Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle; +use Sylius\Bundle\GridBundle\SyliusGridBundle; use Sylius\Bundle\ResourceBundle\SyliusResourceBundle; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; use Symfony\Bundle\TwigBundle\TwigBundle; @@ -35,4 +36,5 @@ FidryAliceDataFixturesBundle::class => ['all' => true], NelmioAliceBundle::class => ['all' => true], winzouStateMachineBundle::class => ['all' => true, 'test_without_state_machine' => false], + SyliusGridBundle::class => ['all' => true, 'test_without_twig' => false], ]; diff --git a/src/Bundle/test/config/packages/test/grids.yaml b/src/Bundle/test/config/packages/test/grids.yaml new file mode 100644 index 000000000..62b000f28 --- /dev/null +++ b/src/Bundle/test/config/packages/test/grids.yaml @@ -0,0 +1,23 @@ +sylius_grid: + grids: + science_book_grid: + driver: + options: + class: '%app.model.science_book.class%' + sorting: + title: asc + fields: + title: + type: string + sortable: ~ + authorFirstName: + type: string + sortable: author.firstName + authorLastName: + type: string + sortable: author.firstName + filters: + search: + type: string + options: + fields: [title, author.firstName, author.lastName] diff --git a/src/Bundle/test/config/routes.yaml b/src/Bundle/test/config/routes.yaml index 39c984138..b864c8740 100644 --- a/src/Bundle/test/config/routes.yaml +++ b/src/Bundle/test/config/routes.yaml @@ -92,4 +92,5 @@ app_science_book: resource: | alias: app.science_book templates: 'ScienceBook' + grid: science_book_grid type: sylius.resource diff --git a/src/Bundle/test/src/Tests/Controller/ScienceBookUiTest.php b/src/Bundle/test/src/Tests/Controller/ScienceBookUiTest.php index 6334eae70..497a6de83 100644 --- a/src/Bundle/test/src/Tests/Controller/ScienceBookUiTest.php +++ b/src/Bundle/test/src/Tests/Controller/ScienceBookUiTest.php @@ -111,6 +111,27 @@ public function it_allows_updating_a_book(): void $this->assertSame($newBookAuthorLastName, $book->getAuthorLastName()); } + /** @test */ + public function it_allows_filtering_books(): void + { + $scienceBooks = $this->loadFixturesFromFile('science_books.yml'); + + $this->client->request('GET', '/science-books/?criteria[search][value]=history of time'); + $response = $this->client->getResponse(); + + $this->assertResponseCode($response, Response::HTTP_OK); + $content = $response->getContent(); + $this->assertStringContainsString('

Books

', $content); + $this->assertStringContainsString( + sprintf('%dA Brief History of TimeStephen Hawking', $scienceBooks['science-book1']->getId()), + $content, + ); + $this->assertStringNotContainsString( + sprintf('%dThe Future of HumanityMichio Kaku', $scienceBooks['science-book2']->getId()), + $content, + ); + } + protected function buildMatcher(): Matcher { return $this->matcherFactory->createMatcher(new VoidBacktrace()); diff --git a/src/Bundle/test/templates/ScienceBook/index.html.twig b/src/Bundle/test/templates/ScienceBook/index.html.twig index 9135ecaa7..4cf6a0014 100644 --- a/src/Bundle/test/templates/ScienceBook/index.html.twig +++ b/src/Bundle/test/templates/ScienceBook/index.html.twig @@ -8,7 +8,7 @@ - {% for book in resources %} + {% for book in resources.data %} {{ book.id }}{{ book.title }}{{ book.authorFirstName }} {{ book.authorLastName }} {% endfor %}