diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7bb751d6c..759cf16ca 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,8 +18,12 @@ jobs: fail-fast: false matrix: php: ["8.0", "8.1"] - symfony: ["^5.4", "^6.0"] + symfony: ["^5.4", "~6.0.0", "~6.1.0"] twig: ["^2.12", "^3.0"] + exclude: + - + php: "8.0" + symfony: "~6.1.0" steps: - diff --git a/src/Bundle/DependencyInjection/Compiler/CsrfTokenManagerPass.php b/src/Bundle/DependencyInjection/Compiler/CsrfTokenManagerPass.php new file mode 100644 index 000000000..e1bee4836 --- /dev/null +++ b/src/Bundle/DependencyInjection/Compiler/CsrfTokenManagerPass.php @@ -0,0 +1,33 @@ +hasDefinition('security.csrf.token_manager')) { + return; + } + + $csrdTokenManagerDefinition = $container->getDefinition('security.csrf.token_manager'); + $csrdTokenManagerDefinition->setPublic(true); + } +} diff --git a/src/Bundle/SyliusResourceBundle.php b/src/Bundle/SyliusResourceBundle.php index f5ee44478..55136b581 100644 --- a/src/Bundle/SyliusResourceBundle.php +++ b/src/Bundle/SyliusResourceBundle.php @@ -13,6 +13,7 @@ namespace Sylius\Bundle\ResourceBundle; +use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\CsrfTokenManagerPass; use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\DoctrineContainerRepositoryFactoryPass; use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\DoctrineTargetEntitiesResolverPass; use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\Helper\TargetEntitiesResolver; @@ -41,15 +42,16 @@ public function build(ContainerBuilder $container): void { parent::build($container); - $container->addCompilerPass(new WinzouStateMachinePass()); - $container->addCompilerPass(new RegisterStateMachinePass()); - $container->addCompilerPass(new RegisterResourcesPass()); - $container->addCompilerPass(new RegisterFqcnControllersPass()); - $container->addCompilerPass(new DoctrineTargetEntitiesResolverPass(new TargetEntitiesResolver()), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1); + $container->addCompilerPass(new CsrfTokenManagerPass()); $container->addCompilerPass(new DoctrineContainerRepositoryFactoryPass()); - $container->addCompilerPass(new RegisterResourceRepositoryPass()); + $container->addCompilerPass(new DoctrineTargetEntitiesResolverPass(new TargetEntitiesResolver()), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1); $container->addCompilerPass(new RegisterFormBuilderPass()); + $container->addCompilerPass(new RegisterFqcnControllersPass()); + $container->addCompilerPass(new RegisterResourceRepositoryPass()); + $container->addCompilerPass(new RegisterResourcesPass()); + $container->addCompilerPass(new RegisterStateMachinePass()); $container->addCompilerPass(new TwigPass()); + $container->addCompilerPass(new WinzouStateMachinePass()); $container->registerExtension(new PagerfantaExtension(true)); $container->addCompilerPass(new PagerfantaBridgePass(true), PassConfig::TYPE_BEFORE_OPTIMIZATION, -1); // Should run after all passes from BabDevPagerfantaBundle diff --git a/src/Bundle/test/src/Tests/Controller/ScienceBookUiTest.php b/src/Bundle/test/src/Tests/Controller/ScienceBookUiTest.php index 497a6de83..843510945 100644 --- a/src/Bundle/test/src/Tests/Controller/ScienceBookUiTest.php +++ b/src/Bundle/test/src/Tests/Controller/ScienceBookUiTest.php @@ -48,11 +48,11 @@ public function it_allows_indexing_books(): void $content = $response->getContent(); $this->assertStringContainsString('

Books

', $content); $this->assertStringContainsString( - sprintf('%dA Brief History of TimeStephen Hawking', $scienceBooks['science-book1']->getId()), + sprintf('%dA Brief History of TimeStephen Hawking', $scienceBooks['science-book1']->getId()), $content, ); $this->assertStringContainsString( - sprintf('%dThe Future of HumanityMichio Kaku', $scienceBooks['science-book2']->getId()), + sprintf('%dThe Future of HumanityMichio Kaku', $scienceBooks['science-book2']->getId()), $content, ); } @@ -111,6 +111,22 @@ public function it_allows_updating_a_book(): void $this->assertSame($newBookAuthorLastName, $book->getAuthorLastName()); } + /** @test */ + public function it_allows_deleting_a_book(): void + { + $this->loadFixturesFromFile('single_science_book.yml'); + + $this->client->request('GET', '/science-books/'); + $this->client->submitForm('Delete'); + + $this->assertResponseRedirects(null, expectedCode: Response::HTTP_FOUND); + + /** @var ScienceBook[] $books */ + $books = static::getContainer()->get('app.repository.science_book')->findAll(); + + $this->assertEmpty($books); + } + /** @test */ public function it_allows_filtering_books(): void { @@ -123,11 +139,11 @@ public function it_allows_filtering_books(): void $content = $response->getContent(); $this->assertStringContainsString('

Books

', $content); $this->assertStringContainsString( - sprintf('%dA Brief History of TimeStephen Hawking', $scienceBooks['science-book1']->getId()), + sprintf('%dA Brief History of TimeStephen Hawking', $scienceBooks['science-book1']->getId()), $content, ); $this->assertStringNotContainsString( - sprintf('%dThe Future of HumanityMichio Kaku', $scienceBooks['science-book2']->getId()), + sprintf('%dThe Future of HumanityMichio Kaku', $scienceBooks['science-book2']->getId()), $content, ); } diff --git a/src/Bundle/test/src/Tests/DataFixtures/ORM/single_science_book.yml b/src/Bundle/test/src/Tests/DataFixtures/ORM/single_science_book.yml new file mode 100644 index 000000000..7351dcc9f --- /dev/null +++ b/src/Bundle/test/src/Tests/DataFixtures/ORM/single_science_book.yml @@ -0,0 +1,9 @@ +App\Entity\ScienceBook: + science-book1: + title: "A Brief History of Time" + author: "@stephen-hawking" + +App\Entity\Author: + stephen-hawking: + firstName: "Stephen" + lastName: "Hawking" diff --git a/src/Bundle/test/templates/ScienceBook/index.html.twig b/src/Bundle/test/templates/ScienceBook/index.html.twig index 4cf6a0014..114bd80d5 100644 --- a/src/Bundle/test/templates/ScienceBook/index.html.twig +++ b/src/Bundle/test/templates/ScienceBook/index.html.twig @@ -5,11 +5,20 @@ ID Title Author + Actions {% for book in resources.data %} - {{ book.id }}{{ book.title }}{{ book.authorFirstName }} {{ book.authorLastName }} + {{ book.id }}{{ book.title }}{{ book.authorFirstName }} {{ book.authorLastName }} + +
+ + + +
+ + {% endfor %}