From b0998e60800045f0d46150c3fd2290ce99092d4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Wed, 5 Dec 2018 11:19:40 +0100 Subject: [PATCH 01/10] manage articles on backend --- config/packages/grids/backend/article.yml | 29 ++++++++ config/packages/sylius_fixtures.yaml | 3 + config/packages/sylius_grid.yaml | 1 + config/packages/sylius_resource.yaml | 3 + config/routes/backend.yml | 3 + config/routes/backend/article.yml | 15 ++++ config/services/fixtures.yml | 8 ++ config/services/fixtures_factories.yml | 6 ++ spec/App/Entity/ArticleSpec.php | 25 +++++++ src/Entity/Article.php | 56 ++++++++++++++ src/Fixture/ArticleFixture.php | 38 ++++++++++ src/Fixture/Factory/ArticleExampleFactory.php | 73 +++++++++++++++++++ src/Menu/AdminMenuBuilder.php | 20 +++++ src/Migrations/Version20181205095848.php | 28 +++++++ translations/messages.fr.yml | 4 + 15 files changed, 312 insertions(+) create mode 100644 config/packages/grids/backend/article.yml create mode 100644 config/routes/backend/article.yml create mode 100644 spec/App/Entity/ArticleSpec.php create mode 100644 src/Entity/Article.php create mode 100644 src/Fixture/ArticleFixture.php create mode 100644 src/Fixture/Factory/ArticleExampleFactory.php create mode 100644 src/Migrations/Version20181205095848.php diff --git a/config/packages/grids/backend/article.yml b/config/packages/grids/backend/article.yml new file mode 100644 index 0000000..1b492ce --- /dev/null +++ b/config/packages/grids/backend/article.yml @@ -0,0 +1,29 @@ +sylius_grid: + grids: + app_backend_article: + driver: + name: doctrine/orm + options: + class: "%app.model.article.class%" + sorting: + title: asc + fields: + title: + type: string + label: sylius.ui.title + sortable: ~ + filters: + search: + type: string + label: sylius.ui.search + options: + fields: [title] + actions: + main: + create: + type: create + item: + update: + type: update + delete: + type: delete diff --git a/config/packages/sylius_fixtures.yaml b/config/packages/sylius_fixtures.yaml index 5d65441..176b208 100644 --- a/config/packages/sylius_fixtures.yaml +++ b/config/packages/sylius_fixtures.yaml @@ -36,3 +36,6 @@ sylius_fixtures: client: random_id: 5rbhrb0iiukokcwk8gow0w4ocgww0oco8g8gsgokwc0wcssg4w secret: 2rlxzhijcx448ow4c0gksw4wo8oo4k8kkwwg0osskk8g0k8kw8 + article: + options: + random: 20 diff --git a/config/packages/sylius_grid.yaml b/config/packages/sylius_grid.yaml index 56ebef4..1c36ae2 100644 --- a/config/packages/sylius_grid.yaml +++ b/config/packages/sylius_grid.yaml @@ -1,4 +1,5 @@ imports: + - { resource: 'grids/backend/article.yml' } - { resource: 'grids/backend/admin_user.yml' } - { resource: 'grids/backend/customer.yml' } diff --git a/config/packages/sylius_resource.yaml b/config/packages/sylius_resource.yaml index 488aacb..9755c48 100644 --- a/config/packages/sylius_resource.yaml +++ b/config/packages/sylius_resource.yaml @@ -1,5 +1,8 @@ sylius_resource: resources: + app.article: + classes: + model: App\Entity\Article app.oauth_client: classes: model: App\Entity\OAuth\Client diff --git a/config/routes/backend.yml b/config/routes/backend.yml index 8e97980..f649c6a 100644 --- a/config/routes/backend.yml +++ b/config/routes/backend.yml @@ -7,6 +7,9 @@ app_backend_dashboard: sylius_backend_admin_user: resource: "backend/admin_user.yml" +app_backend_article: + resource: "backend/article.yml" + sylius_backend_customer: resource: "backend/customer.yml" diff --git a/config/routes/backend/article.yml b/config/routes/backend/article.yml new file mode 100644 index 0000000..3a583b2 --- /dev/null +++ b/config/routes/backend/article.yml @@ -0,0 +1,15 @@ +app_backend_article: + resource: | + alias: app.article + section: backend + except: ['show'] + redirect: update + grid: app_backend_article + vars: + all: + subheader: app.ui.manage_articles + index: + icon: newspaper + templates: backend/crud + type: sylius.resource + diff --git a/config/services/fixtures.yml b/config/services/fixtures.yml index a1e2c83..927df48 100644 --- a/config/services/fixtures.yml +++ b/config/services/fixtures.yml @@ -15,6 +15,14 @@ services: tags: - { name: sylius_fixtures.fixture } + app.fixture.article: + class: App\Fixture\ArticleFixture + arguments: + - "@app.manager.article" + - "@app.fixture.example_factory.article" + tags: + - { name: sylius_fixtures.fixture } + app.fixture.oauth_client: class: App\Fixture\OAuthClientFixture arguments: diff --git a/config/services/fixtures_factories.yml b/config/services/fixtures_factories.yml index 737678b..19f0752 100644 --- a/config/services/fixtures_factories.yml +++ b/config/services/fixtures_factories.yml @@ -12,6 +12,12 @@ services: - "@sylius.factory.customer" public: true + app.fixture.example_factory.article: + class: App\Fixture\Factory\ArticleExampleFactory + arguments: + - "@app.factory.article" + public: true + app.fixture.example_factory.oauth_client: class: App\Fixture\Factory\OAuthClientExampleFactory arguments: diff --git a/spec/App/Entity/ArticleSpec.php b/spec/App/Entity/ArticleSpec.php new file mode 100644 index 0000000..24f429a --- /dev/null +++ b/spec/App/Entity/ArticleSpec.php @@ -0,0 +1,25 @@ +shouldImplement(ResourceInterface::class); + } + + function it_has_no_title_by_default() + { + $this->getTitle()->shouldReturn(null); + } + + function its_title_is_mutable() + { + $this->setTitle('Awesome title'); + $this->getTitle()->shouldReturn('Awesome title'); + } +} diff --git a/src/Entity/Article.php b/src/Entity/Article.php new file mode 100644 index 0000000..7a74bba --- /dev/null +++ b/src/Entity/Article.php @@ -0,0 +1,56 @@ +title; + } + + /** + * @param string|null $title + */ + public function setTitle(?string $title): void + { + $this->title = $title; + } +} diff --git a/src/Fixture/ArticleFixture.php b/src/Fixture/ArticleFixture.php new file mode 100644 index 0000000..57f2004 --- /dev/null +++ b/src/Fixture/ArticleFixture.php @@ -0,0 +1,38 @@ +children() + ->scalarNode('street')->cannotBeEmpty()->end() + ->scalarNode('city')->cannotBeEmpty()->end() + ->scalarNode('postcode')->cannotBeEmpty()->end() + ; + } +} diff --git a/src/Fixture/Factory/ArticleExampleFactory.php b/src/Fixture/Factory/ArticleExampleFactory.php new file mode 100644 index 0000000..91d3d57 --- /dev/null +++ b/src/Fixture/Factory/ArticleExampleFactory.php @@ -0,0 +1,73 @@ +addressFactory = $addressFactory; + + $this->faker = \Faker\Factory::create(); + $this->optionsResolver = new OptionsResolver(); + + $this->configureOptions($this->optionsResolver); + } + + /** + * {@inheritdoc} + */ + protected function configureOptions(OptionsResolver $resolver) + { + $resolver + ->setDefault('title', function (Options $options) { + return ucfirst($this->faker->words(3, true)); + }); + } + + /** + * {@inheritdoc} + */ + public function create(array $options = []) + { + $options = $this->optionsResolver->resolve($options); + + /** @var Article $article */ + $article = $this->addressFactory->createNew(); + $article->setTitle($options['title']); + + return $article; + } +} diff --git a/src/Menu/AdminMenuBuilder.php b/src/Menu/AdminMenuBuilder.php index d9f3fdb..b089d0f 100644 --- a/src/Menu/AdminMenuBuilder.php +++ b/src/Menu/AdminMenuBuilder.php @@ -39,12 +39,32 @@ public function createMenu(RequestStack $requestStack) { $menu = $this->factory->createItem('root'); + $this->addContentSubMenu($menu); $this->addCustomerSubMenu($menu); $this->addConfigurationSubMenu($menu); return $menu; } + /** + * @param ItemInterface $menu + * + * @return ItemInterface + */ + private function addContentSubMenu(ItemInterface $menu) + { + $customer = $menu + ->addChild('content') + ->setLabel('sylius.ui.content') + ; + + $customer->addChild('backend_article', ['route' => 'app_backend_article_index']) + ->setLabel('app.ui.articles') + ->setLabelAttribute('icon', 'newspaper'); + + return $customer; + } + /** * @param ItemInterface $menu * diff --git a/src/Migrations/Version20181205095848.php b/src/Migrations/Version20181205095848.php new file mode 100644 index 0000000..98581d4 --- /dev/null +++ b/src/Migrations/Version20181205095848.php @@ -0,0 +1,28 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('CREATE TABLE app_article (id INT AUTO_INCREMENT NOT NULL, title VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE UTF8_unicode_ci ENGINE = InnoDB'); + } + + public function down(Schema $schema) : void + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('DROP TABLE app_article'); + } +} diff --git a/translations/messages.fr.yml b/translations/messages.fr.yml index 83ddd37..df8a3f4 100644 --- a/translations/messages.fr.yml +++ b/translations/messages.fr.yml @@ -1,12 +1,16 @@ app: ui: addresses: Adresses + articles: Articles create_user: Créer un utilisateur edit_address: Modifier l'adresse + edit_article: Modifier l'article forgotten_password: Mot de passe oublié legal_notices: Mentions légales manage_addresses: Gérer les adresses + manage_articles: Gérer les articles new_address: Nouvelle adresse + new_article: Nouvel article overview_of_your_website: Aperçu de votre site web validate: Valider text: From 8c612b7983246f90ea9763ae5fcd30bbfc8b0b91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Wed, 5 Dec 2018 14:59:21 +0100 Subject: [PATCH 02/10] [Behat] browsing articles --- .../browsing_articles.feature | 19 +++++ src/Behat/Context/Setup/ArticleContext.php | 70 +++++++++++++++++++ .../Ui/Backend/ManagingArticlesContext.php | 61 ++++++++++++++++ src/Behat/Page/Backend/Article/IndexPage.php | 20 ++++++ .../config/services/contexts/setup.yml | 9 +++ .../Resources/config/services/contexts/ui.yml | 7 ++ .../config/services/pages/backend.yml | 1 + .../config/services/pages/backend/article.yml | 15 ++++ src/Behat/Resources/config/suites.yml | 1 + .../suites/ui/article/managing_articles.yml | 17 +++++ 10 files changed, 220 insertions(+) create mode 100644 features/article/managing_articles/browsing_articles.feature create mode 100644 src/Behat/Context/Setup/ArticleContext.php create mode 100644 src/Behat/Context/Ui/Backend/ManagingArticlesContext.php create mode 100644 src/Behat/Page/Backend/Article/IndexPage.php create mode 100644 src/Behat/Resources/config/services/pages/backend/article.yml create mode 100644 src/Behat/Resources/config/suites/ui/article/managing_articles.yml diff --git a/features/article/managing_articles/browsing_articles.feature b/features/article/managing_articles/browsing_articles.feature new file mode 100644 index 0000000..29e3987 --- /dev/null +++ b/features/article/managing_articles/browsing_articles.feature @@ -0,0 +1,19 @@ +@managing_articles +Feature: Browsing articles + In order to manage articles in the website + As an Administrator + I want to browse articles + + Background: + Given there is an article titled "Star Wars" + And there is also an article titled "Game Of Thrones" + And there is also an article titled "Back To The Future" + And I am logged in as an administrator + + @ui + Scenario: Browsing articles in the website + When I want to browse articles + Then there should be 3 articles in the list + And I should see the article "Star Wars" in the list + And I should see the article "Game Of Thrones" in the list + And I should see the article "Back To The Future" in the list diff --git a/src/Behat/Context/Setup/ArticleContext.php b/src/Behat/Context/Setup/ArticleContext.php new file mode 100644 index 0000000..5761602 --- /dev/null +++ b/src/Behat/Context/Setup/ArticleContext.php @@ -0,0 +1,70 @@ +sharedStorage = $sharedStorage; + $this->articleFactory = $articleFactory; + $this->articleRepository = $articleRepository; + } + + /** + * @Given there is (also )an article titled :title + */ + public function thereIsAnAdministratorIdentifiedBy(string $title): void + { + $this->createArticle(['title' => $title]); + } + + /** + * @param array $options + */ + private function createArticle(array $options): void + { + /** @var Article $article */ + $article = $this->articleFactory->create($options); + $this->articleRepository->add($article); + $this->sharedStorage->set('article', $article); + } +} diff --git a/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php b/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php new file mode 100644 index 0000000..46a39a0 --- /dev/null +++ b/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php @@ -0,0 +1,61 @@ +indexPage = $indexPage; + } + + /** + * @When I want to browse articles + */ + public function iWantToBrowseArticles() + { + $this->indexPage->open(); + } + + /** + * @Then /^there should be (\d+) articles in the list$/ + */ + public function iShouldSeeArticlesInTheList(int $number = 1): void + { + Assert::same($this->indexPage->countItems(), (int) $number); + } + + /** + * @Then I should (also )see the article :title in the list + */ + public function theArticleShouldAppearInTheWebsite($title) + { + $this->indexPage->open(); + + Assert::true($this->indexPage->isSingleResourceOnPage(['title' => $title])); + } +} diff --git a/src/Behat/Page/Backend/Article/IndexPage.php b/src/Behat/Page/Backend/Article/IndexPage.php new file mode 100644 index 0000000..d1ca724 --- /dev/null +++ b/src/Behat/Page/Backend/Article/IndexPage.php @@ -0,0 +1,20 @@ + Date: Wed, 5 Dec 2018 15:26:12 +0100 Subject: [PATCH 03/10] adding a new article --- config/packages/sylius_resource.yaml | 1 + .../managing_articles/adding_article.feature | 16 ++++++++ .../Ui/Backend/ManagingArticlesContext.php | 38 +++++++++++++++++- src/Behat/Page/Backend/Article/CreatePage.php | 37 +++++++++++++++++ src/Behat/Page/Backend/Article/IndexPage.php | 4 +- .../Resources/config/services/contexts/ui.yml | 1 + .../config/services/pages/backend/article.yml | 16 +++++--- .../suites/ui/article/managing_articles.yml | 2 +- src/Form/Type/ArticleType.php | 40 +++++++++++++++++++ 9 files changed, 146 insertions(+), 9 deletions(-) create mode 100644 features/article/managing_articles/adding_article.feature create mode 100644 src/Behat/Page/Backend/Article/CreatePage.php create mode 100644 src/Form/Type/ArticleType.php diff --git a/config/packages/sylius_resource.yaml b/config/packages/sylius_resource.yaml index 9755c48..45d2a0b 100644 --- a/config/packages/sylius_resource.yaml +++ b/config/packages/sylius_resource.yaml @@ -3,6 +3,7 @@ sylius_resource: app.article: classes: model: App\Entity\Article + form: App\Form\Type\ArticleType app.oauth_client: classes: model: App\Entity\OAuth\Client diff --git a/features/article/managing_articles/adding_article.feature b/features/article/managing_articles/adding_article.feature new file mode 100644 index 0000000..d2b3b3e --- /dev/null +++ b/features/article/managing_articles/adding_article.feature @@ -0,0 +1,16 @@ +@managing_articles +Feature: Adding a new article + In order to extend articles database + As an Administrator + I want to add a new article + + Background: + Given I am logged in as an administrator + + @ui + Scenario: Adding a new article + Given I want to create a new article + When I specify its title as "Star Wars" + And I add it + Then I should be notified that it has been successfully created + And the article "Star Wars" should appear in the website diff --git a/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php b/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php index 46a39a0..157ad20 100644 --- a/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php +++ b/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php @@ -14,25 +14,42 @@ namespace App\Behat\Context\Ui\Backend; use App\Behat\Page\Backend\Article\IndexPage; +use App\Behat\Page\Backend\Article\CreatePage; use Behat\Behat\Context\Context; use Webmozart\Assert\Assert; final class ManagingArticlesContext implements Context { + /** + * @var CreatePage + */ + private $createPage; + /** * @var IndexPage */ private $indexPage; /** - * @param IndexPage $indexPage + * @param CreatePage $createPage + * @param IndexPage $indexPage */ public function __construct( + CreatePage $createPage, IndexPage $indexPage ) { + $this->createPage = $createPage; $this->indexPage = $indexPage; } + /** + * @Given I want to create a new article + */ + public function iWantToCreateANewArticle() + { + $this->createPage->open(); + } + /** * @When I want to browse articles */ @@ -41,6 +58,24 @@ public function iWantToBrowseArticles() $this->indexPage->open(); } + /** + * @When I specify its title as :title + * @When I do not specify its title + */ + public function iSpecifyItsEmailAs($title = null) + { + $this->createPage->specifyTitle($title); + } + + /** + * @When I add it + * @When I try to add it + */ + public function iAddIt() + { + $this->createPage->create(); + } + /** * @Then /^there should be (\d+) articles in the list$/ */ @@ -51,6 +86,7 @@ public function iShouldSeeArticlesInTheList(int $number = 1): void /** * @Then I should (also )see the article :title in the list + * @Then the article :title should appear in the website */ public function theArticleShouldAppearInTheWebsite($title) { diff --git a/src/Behat/Page/Backend/Article/CreatePage.php b/src/Behat/Page/Backend/Article/CreatePage.php new file mode 100644 index 0000000..f4f5753 --- /dev/null +++ b/src/Behat/Page/Backend/Article/CreatePage.php @@ -0,0 +1,37 @@ +getElement('title')->setValue($title); + } + + /** + * {@inheritdoc} + */ + protected function getDefinedElements() + { + return array_merge(parent::getDefinedElements(), [ + 'title' => '#app_article_title', + ]); + } +} diff --git a/src/Behat/Page/Backend/Article/IndexPage.php b/src/Behat/Page/Backend/Article/IndexPage.php index d1ca724..0270827 100644 --- a/src/Behat/Page/Backend/Article/IndexPage.php +++ b/src/Behat/Page/Backend/Article/IndexPage.php @@ -1,7 +1,5 @@ add('title', TextType::class, [ + 'label' => 'sylius.ui.title', + ]); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() + { + return 'app_article'; + } +} From 24f6f6bce43479d3c2db214f703060f6960fee01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Wed, 5 Dec 2018 16:49:48 +0100 Subject: [PATCH 04/10] [Behat] Deleting an article --- .../managing_articles/deleting_articles.feature | 16 ++++++++++++++++ .../Ui/Backend/ManagingArticlesContext.php | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 features/article/managing_articles/deleting_articles.feature diff --git a/features/article/managing_articles/deleting_articles.feature b/features/article/managing_articles/deleting_articles.feature new file mode 100644 index 0000000..7f054c3 --- /dev/null +++ b/features/article/managing_articles/deleting_articles.feature @@ -0,0 +1,16 @@ +@managing_articles +Feature: Deleting an article + In order to get rid of deprecated articles + As an Administrator + I want to be able to delete articles + + Background: + Given there is an article titled "Star Wars" + And I am logged in as an administrator + + @ui + Scenario: Deleting an article + Given I want to browse articles + When I delete article with title "Star Wars" + Then I should be notified that it has been successfully deleted + And there should not be "Star Wars" article anymore diff --git a/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php b/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php index 157ad20..e7adfa4 100644 --- a/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php +++ b/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php @@ -76,6 +76,14 @@ public function iAddIt() $this->createPage->create(); } + /** + * @When I delete article with title :title + */ + public function iDeleteAdministratorWithEmail($title) + { + $this->indexPage->deleteResourceOnPage(['title' => $title]); + } + /** * @Then /^there should be (\d+) articles in the list$/ */ @@ -94,4 +102,12 @@ public function theArticleShouldAppearInTheWebsite($title) Assert::true($this->indexPage->isSingleResourceOnPage(['title' => $title])); } + + /** + * @Then there should not be :title article anymore + */ + public function thereShouldBeNoAnymore($title) + { + Assert::false($this->indexPage->isSingleResourceOnPage(['title' => $title])); + } } From 42f22f53ff9c0bcd59fe58289dbd4170bd5a6fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Wed, 5 Dec 2018 16:51:04 +0100 Subject: [PATCH 05/10] rename a method on managing articles context --- src/Behat/Context/Ui/Backend/ManagingArticlesContext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php b/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php index e7adfa4..9ba4004 100644 --- a/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php +++ b/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php @@ -79,7 +79,7 @@ public function iAddIt() /** * @When I delete article with title :title */ - public function iDeleteAdministratorWithEmail($title) + public function iDeleteArticleWithTitle($title) { $this->indexPage->deleteResourceOnPage(['title' => $title]); } From 5bff12e1516f0c561dc8c6cae354ec61f9437f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Fri, 14 Dec 2018 11:30:41 +0100 Subject: [PATCH 06/10] fix behat article create page --- src/Behat/Page/Backend/Article/CreatePage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Behat/Page/Backend/Article/CreatePage.php b/src/Behat/Page/Backend/Article/CreatePage.php index f4f5753..57a991e 100644 --- a/src/Behat/Page/Backend/Article/CreatePage.php +++ b/src/Behat/Page/Backend/Article/CreatePage.php @@ -28,7 +28,7 @@ public function specifyTitle(?string $title) /** * {@inheritdoc} */ - protected function getDefinedElements() + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ 'title' => '#app_article_title', From 0c3b9e73cf838dd28cdb299cf013337d31e778dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Mon, 17 Dec 2018 17:14:48 +0100 Subject: [PATCH 07/10] renaming an article --- .../managing_articles/editing_article.feature | 18 ++++++ .../Context/Transform/ArticleContext.php | 58 +++++++++++++++++++ .../Ui/Backend/ManagingArticlesContext.php | 36 +++++++++++- src/Behat/Page/Backend/Article/UpdatePage.php | 40 +++++++++++++ .../config/services/contexts/transform.yml | 47 ++++++++------- .../Resources/config/services/contexts/ui.yml | 1 + .../config/services/pages/backend/article.yml | 6 ++ .../suites/ui/article/managing_articles.yml | 1 + 8 files changed, 186 insertions(+), 21 deletions(-) create mode 100644 features/article/managing_articles/editing_article.feature create mode 100644 src/Behat/Context/Transform/ArticleContext.php create mode 100644 src/Behat/Page/Backend/Article/UpdatePage.php diff --git a/features/article/managing_articles/editing_article.feature b/features/article/managing_articles/editing_article.feature new file mode 100644 index 0000000..fe98c00 --- /dev/null +++ b/features/article/managing_articles/editing_article.feature @@ -0,0 +1,18 @@ +@managing_articles +Feature: Editing article + In order to change article details + As an Administrator + I want to be able to edit an article + + Background: + Given there is an article titled "Star Wars" + And I am logged in as an administrator + + @ui + Scenario: Renaming the article + Given I want to modify the "Star Wars" article + When I rename it to "Game Of Thrones" + And I save my changes + Then I should be notified that it has been successfully edited + And I should see the article "Game Of Thrones" in the list + But there should not be "Star Wars" article anymore diff --git a/src/Behat/Context/Transform/ArticleContext.php b/src/Behat/Context/Transform/ArticleContext.php new file mode 100644 index 0000000..b8d2943 --- /dev/null +++ b/src/Behat/Context/Transform/ArticleContext.php @@ -0,0 +1,58 @@ +articleRepository = $articleRepository; + } + + /** + * @Transform /^article "([^"]+)"$/ + * @Transform :article + * + * @param string $title + * + * @return Article + */ + public function getArticleTitle($title) + { + /** @var Article $article */ + $article = $this->articleRepository->findOneBy(['title' => $title]); + + Assert::notNull( + $article, + sprintf('Article with title "%s" does not exist', $title) + ); + + return $article; + } +} diff --git a/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php b/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php index 9ba4004..e2ac221 100644 --- a/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php +++ b/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php @@ -15,6 +15,8 @@ use App\Behat\Page\Backend\Article\IndexPage; use App\Behat\Page\Backend\Article\CreatePage; +use App\Behat\Page\Backend\Article\UpdatePage; +use App\Entity\Article; use Behat\Behat\Context\Context; use Webmozart\Assert\Assert; @@ -30,16 +32,24 @@ final class ManagingArticlesContext implements Context */ private $indexPage; + /** + * @var UpdatePage + */ + private $updatePage; + /** * @param CreatePage $createPage * @param IndexPage $indexPage + * @pram UpdatePage $updatePage */ public function __construct( CreatePage $createPage, - IndexPage $indexPage + IndexPage $indexPage, + UpdatePage $updatePage ) { $this->createPage = $createPage; $this->indexPage = $indexPage; + $this->updatePage = $updatePage; } /** @@ -58,6 +68,14 @@ public function iWantToBrowseArticles() $this->indexPage->open(); } + /** + * @Given I want to modify the :article article + */ + public function iWantToModifyAnArticle(Article $article) + { + $this->updatePage->open(['id' => $article->getId()]); + } + /** * @When I specify its title as :title * @When I do not specify its title @@ -67,6 +85,14 @@ public function iSpecifyItsEmailAs($title = null) $this->createPage->specifyTitle($title); } + /** + * @When I rename it to :title + */ + public function iChangeItsTitleAs($title = null) + { + $this->updatePage->changeTitle($title); + } + /** * @When I add it * @When I try to add it @@ -76,6 +102,14 @@ public function iAddIt() $this->createPage->create(); } + /** + * @When I save my changes + */ + public function iSaveMyChanges() + { + $this->updatePage->saveChanges(); + } + /** * @When I delete article with title :title */ diff --git a/src/Behat/Page/Backend/Article/UpdatePage.php b/src/Behat/Page/Backend/Article/UpdatePage.php new file mode 100644 index 0000000..3bbe96d --- /dev/null +++ b/src/Behat/Page/Backend/Article/UpdatePage.php @@ -0,0 +1,40 @@ +getElement('title')->setValue($title); + } + + /** + * {@inheritdoc} + */ + protected function getDefinedElements(): array + { + return array_merge(parent::getDefinedElements(), [ + 'title' => '#app_article_title', + ]); + } +} diff --git a/src/Behat/Resources/config/services/contexts/transform.yml b/src/Behat/Resources/config/services/contexts/transform.yml index 044ef88..433bbd1 100644 --- a/src/Behat/Resources/config/services/contexts/transform.yml +++ b/src/Behat/Resources/config/services/contexts/transform.yml @@ -8,25 +8,32 @@ services: # class: App\Directory\ClassName # arguments: ["@another_service_name", "plain_value", "%parameter_name%"] - app.behat.context.transform.customer: - class: App\Behat\Context\Transform\CustomerContext - arguments: - - "@__symfony__.sylius.repository.customer" - - "@__symfony__.sylius.factory.customer" - - "@app.behat.shared_storage" - tags: - - { name: fob.context_service } + app.behat.context.transform.article: + class: App\Behat\Context\Transform\ArticleContext + arguments: + - "@__symfony__.app.repository.article" + tags: + - { name: fob.context_service } - app.behat.context.transform.shared_storage: - class: App\Behat\Context\Transform\SharedStorageContext - arguments: - - "@app.behat.shared_storage" - tags: - - { name: fob.context_service } + app.behat.context.transform.customer: + class: App\Behat\Context\Transform\CustomerContext + arguments: + - "@__symfony__.sylius.repository.customer" + - "@__symfony__.sylius.factory.customer" + - "@app.behat.shared_storage" + tags: + - { name: fob.context_service } - app.behat.context.transform.user: - class: App\Behat\Context\Transform\UserContext - arguments: - - "@app.behat.shared_storage" - tags: - - { name: fob.context_service } + app.behat.context.transform.shared_storage: + class: App\Behat\Context\Transform\SharedStorageContext + arguments: + - "@app.behat.shared_storage" + tags: + - { name: fob.context_service } + + app.behat.context.transform.user: + class: App\Behat\Context\Transform\UserContext + arguments: + - "@app.behat.shared_storage" + tags: + - { name: fob.context_service } diff --git a/src/Behat/Resources/config/services/contexts/ui.yml b/src/Behat/Resources/config/services/contexts/ui.yml index f0ddc87..87fd04b 100644 --- a/src/Behat/Resources/config/services/contexts/ui.yml +++ b/src/Behat/Resources/config/services/contexts/ui.yml @@ -23,6 +23,7 @@ services: arguments: - "@app.behat.page.backend.article.create" - "@app.behat.page.backend.article.index" + - "@app.behat.page.backend.article.update" tags: - { name: fob.context_service } diff --git a/src/Behat/Resources/config/services/pages/backend/article.yml b/src/Behat/Resources/config/services/pages/backend/article.yml index 4df5c8c..01d8a05 100644 --- a/src/Behat/Resources/config/services/pages/backend/article.yml +++ b/src/Behat/Resources/config/services/pages/backend/article.yml @@ -19,3 +19,9 @@ services: parent: app.behat.page.backend.crud.index public: false arguments: ["app_backend_article_index"] + + app.behat.page.backend.article.update: + class: App\Behat\Page\Backend\Article\UpdatePage + parent: app.behat.page.backend.crud.update + public: false + arguments: ["app_backend_article_update"] diff --git a/src/Behat/Resources/config/suites/ui/article/managing_articles.yml b/src/Behat/Resources/config/suites/ui/article/managing_articles.yml index 1a52de8..78a72a5 100644 --- a/src/Behat/Resources/config/suites/ui/article/managing_articles.yml +++ b/src/Behat/Resources/config/suites/ui/article/managing_articles.yml @@ -8,6 +8,7 @@ default: - app.behat.context.setup.customer - app.behat.context.setup.admin_security + - app.behat.context.transform.article - app.behat.context.transform.customer - app.behat.context.transform.shared_storage From 8edf626c38ef718af7ed253033e323e4ad05a356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Mon, 17 Dec 2018 17:24:39 +0100 Subject: [PATCH 08/10] Trying to add a new article without title --- .../article_validation.feature | 16 ++++++++++++++++ .../Ui/Backend/ManagingArticlesContext.php | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 features/article/managing_articles/article_validation.feature diff --git a/features/article/managing_articles/article_validation.feature b/features/article/managing_articles/article_validation.feature new file mode 100644 index 0000000..0a3aeff --- /dev/null +++ b/features/article/managing_articles/article_validation.feature @@ -0,0 +1,16 @@ +@managing_articles +Feature: Articles validation + In order to avoid making mistakes when managing articles + As an Administrator + I want to be prevented from adding it without specifying required fields + + Background: + Given I am logged in as an administrator + + @ui + Scenario: Trying to add a new article without title + Given I want to create a new article + When I do not specify its title + And I try to add it + Then I should be notified that the title is required + And this article should not be added diff --git a/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php b/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php index e2ac221..adb156f 100644 --- a/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php +++ b/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php @@ -144,4 +144,22 @@ public function thereShouldBeNoAnymore($title) { Assert::false($this->indexPage->isSingleResourceOnPage(['title' => $title])); } + + /** + * @Then I should be notified that the title is required + */ + public function iShouldBeNotifiedThatTitleIsRequired() + { + Assert::same($this->createPage->getValidationMessage('title'), 'This value should not be blank.'); + } + + /** + * @Then this article should not be added + */ + public function thisArticleShouldNotBeAdded() + { + $this->indexPage->open(); + + Assert::same($this->indexPage->countItems(), 0); + } } From 7477a795de77eb6614aad2d4bc603aac38865bc3 Mon Sep 17 00:00:00 2001 From: Loic Fremont Date: Sat, 5 Jan 2019 17:14:21 +0100 Subject: [PATCH 09/10] Remove multiple articles at once --- config/packages/grids/backend/article.yml | 3 +++ .../deleting_multiple_articles.feature | 21 +++++++++++++++++++ .../Ui/Backend/ManagingArticlesContext.php | 18 ++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 features/article/managing_articles/deleting_multiple_articles.feature diff --git a/config/packages/grids/backend/article.yml b/config/packages/grids/backend/article.yml index 1b492ce..a1cf789 100644 --- a/config/packages/grids/backend/article.yml +++ b/config/packages/grids/backend/article.yml @@ -27,3 +27,6 @@ sylius_grid: type: update delete: type: delete + bulk: + delete: + type: delete diff --git a/features/article/managing_articles/deleting_multiple_articles.feature b/features/article/managing_articles/deleting_multiple_articles.feature new file mode 100644 index 0000000..e30670b --- /dev/null +++ b/features/article/managing_articles/deleting_multiple_articles.feature @@ -0,0 +1,21 @@ +@managing_articles +Feature: Deleting multiple articles + In order to get rid of spam articles in an efficient way + As an Administrator + I want to be able to delete multiple articles at once + + Background: + Given there is an article titled "Star Wars" + And there is also an article titled "Game Of Thrones" + And there is also an article titled "Back To The Future" + And I am logged in as an administrator + + @ui @javascript + Scenario: Deleting multiple articles at once + Given I browse articles + And I check the "Star Wars" article + And I also check the "Game Of Thrones" article + And I delete them + Then I should be notified that they have been successfully deleted + And I should see a single article in the list + And I should see the article "Back To The Future" in the list diff --git a/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php b/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php index adb156f..bf34516 100644 --- a/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php +++ b/src/Behat/Context/Ui/Backend/ManagingArticlesContext.php @@ -61,6 +61,7 @@ public function iWantToCreateANewArticle() } /** + * @When I browse articles * @When I want to browse articles */ public function iWantToBrowseArticles() @@ -119,6 +120,23 @@ public function iDeleteArticleWithTitle($title) } /** + * @When I (also) check the :title article + */ + public function iCheckTheArticle(string $title): void + { + $this->indexPage->checkResourceOnPage(['title' => $title]); + } + + /** + * @When I delete them + */ + public function iDeleteThem(): void + { + $this->indexPage->bulkDelete(); + } + + /** + * @Then I should see a single article in the list * @Then /^there should be (\d+) articles in the list$/ */ public function iShouldSeeArticlesInTheList(int $number = 1): void From 6664e81db21a48b1a2969475bf994a5d339ea682 Mon Sep 17 00:00:00 2001 From: Loic Fremont Date: Tue, 29 Jan 2019 15:47:58 +0100 Subject: [PATCH 10/10] fix managing articles suite --- .../Resources/config/suites/ui/article/managing_articles.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Behat/Resources/config/suites/ui/article/managing_articles.yml b/src/Behat/Resources/config/suites/ui/article/managing_articles.yml index 78a72a5..aefba8d 100644 --- a/src/Behat/Resources/config/suites/ui/article/managing_articles.yml +++ b/src/Behat/Resources/config/suites/ui/article/managing_articles.yml @@ -1,7 +1,7 @@ default: suites: ui_managing_articles: - contexts_services: + contexts: - app.behat.context.hook.doctrine_orm - app.behat.context.setup.article