diff --git a/features/admin/adding_page.feature b/features/admin/adding_page.feature index e43446cb..b6df542d 100644 --- a/features/admin/adding_page.feature +++ b/features/admin/adding_page.feature @@ -208,3 +208,18 @@ Feature: Adding new page Then I should be notified that the page has been created And I should see newly created "Single media" content element in Content elements section And I should see newly created "Multiple media" content element in Content elements section + + @ui @javascript + Scenario: Adding page with template + Given there is an existing template named "Homepage" with "Page" type that contains "Textarea, Single media" content elements + When I go to the create page page + And I fill the code with "my_page" + And I fill the slug with "my_page" + And I fill the name with "My page" + And I select "Homepage" template + And I click button to use this template + And I confirm that I want to use this template + And I add it + Then I should be notified that the page has been created + And I should see newly created "Textarea" content element in Content elements section + And I should see newly created "Single media" content element in Content elements section diff --git a/features/admin/adding_template.feature b/features/admin/adding_template.feature new file mode 100644 index 00000000..ef850a27 --- /dev/null +++ b/features/admin/adding_template.feature @@ -0,0 +1,59 @@ +@managing_templates +Feature: Adding cms templates + In order to create templates + As an Administrator + I want to be able to add new templates + + Background: + Given the store operates on a single channel in "United States" + And I am logged in as an administrator + + @ui + Scenario: Creating template + When I go to the create template page + And I fill the name with "Test template" + And I choose "Page" in Type field + And I add it + Then I should be notified that the template has been created + + @ui @javascript + Scenario: Creating template with content elements + When I go to the create template page + And I fill the name with "Test template" + And I choose "Page" in Type field + And I click on Add button in Content elements section + And I select "Textarea" content element + And I click on Add button in Content elements section + And I select "Single media" content element + And I add it + Then I should be notified that the template has been created + And I should see newly created "Textarea" content element in Content elements section + And I should see newly created "Single media" content element in Content elements section + + @ui + Scenario: Trying to add template with existing name + Given there is a template in the store with "New template" name + When I go to the create template page + And I fill the name with "New template" + And I try to add it + Then I should be notified that there is already existing template with provided name + + @ui + Scenario: Adding new template with blank data + When I go to the create template page + And I add it + And I should be notified that "Name" field cannot be blank + + @ui + Scenario: Trying to add a template with too short data + When I go to the create template page + And I fill the name with "X" + And I try to add it + Then I should be notified that "Name" field is too short + + @ui + Scenario: Trying to add a template with too long data + When I go to the create template page + And I fill "Name" field with 251 characters + And I try to add it + Then I should be notified that "Name" field is too long diff --git a/features/admin/managing_templates.feature b/features/admin/managing_templates.feature new file mode 100644 index 00000000..0dd95fd9 --- /dev/null +++ b/features/admin/managing_templates.feature @@ -0,0 +1,35 @@ +@managing_templates +Feature: Managing cms templates + In order to manage existing templates + As an Administrator + I want to be able to edit and remove existing templates + + Background: + Given the store operates on a single channel in "United States" + And I am logged in as an administrator + + @ui + Scenario: Deleting template + Given there is a template in the store with "Test template" name + When I go to the templates page + And I delete this template + Then I should be notified that the template has been deleted + And I should see empty list of templates + + @ui + Scenario: Updating template + Given there is a template in the store with "Test template" name + When I go to the update "Test template" template page + And I fill the name with "New template" + And I update it + Then I should be notified that the template has been successfully updated + + @ui @javascript + Scenario: Updating template with content elements + Given there is a template in the store with "Test template" name + And there are "Textarea" and "Single media" content elements in this template + When I go to the update "Test template" template page + And I delete "Textarea" content element + And I update it + Then I should be notified that the template has been successfully updated + And I should see only "Single media" content element in Content elements section diff --git a/tests/Behat/Context/Setup/TemplateContext.php b/tests/Behat/Context/Setup/TemplateContext.php new file mode 100644 index 00000000..f01d0547 --- /dev/null +++ b/tests/Behat/Context/Setup/TemplateContext.php @@ -0,0 +1,92 @@ +createTemplate($name, $type); + + $this->saveTemplate($template); + } + + /** + * @Given there are :firstContentElement and :secondContentElement content elements in this template + */ + public function thereAreContentElementsInThisTemplate(string $firstContentElement, string $secondContentElement): void + { + /** @var TemplateInterface $template */ + $template = $this->sharedStorage->get('template'); + $template->setContentElements([ + ['type' => ContentElementHelper::getContentElementValueByName($firstContentElement)], + ['type' => ContentElementHelper::getContentElementValueByName($secondContentElement)], + ]); + + $this->saveTemplate($template); + } + + /** + * @Given there is an existing template named :templateName with :type type that contains :contentElements content elements + */ + public function thereIsAnExistingTemplateThatContainsContentElements(string $templateName, string $type, string $contentElements): void + { + $template = $this->createTemplate($templateName, $type); + + $contentElements = explode(', ', $contentElements); + + $contentElementsArray = []; + foreach ($contentElements as $contentElement) { + $contentElementsArray[] = ['type' => ContentElementHelper::getContentElementValueByName($contentElement)]; + } + + $template->setContentElements($contentElementsArray); + + $this->saveTemplate($template); + } + + private function createTemplate(string $name, ?string $type = null): TemplateInterface + { + /** @var TemplateInterface $template */ + $template = $this->templateFactory->createNew(); + $template->setName($name); + + if (null !== $type) { + $template->setType($type); + } + + return $template; + } + + private function saveTemplate(TemplateInterface $template): void + { + $this->templateRepository->add($template); + $this->sharedStorage->set('template', $template); + } +} diff --git a/tests/Behat/Context/Ui/Admin/PageContext.php b/tests/Behat/Context/Ui/Admin/PageContext.php index fd1af330..fb0238ff 100755 --- a/tests/Behat/Context/Ui/Admin/PageContext.php +++ b/tests/Behat/Context/Ui/Admin/PageContext.php @@ -297,6 +297,30 @@ public function iShouldNotSeeContentElementInTheContentElementsSection(string $c Assert::false($this->resolveCurrentPage()->containsContentElement($contentElement)); } + /** + * @Then I select :templateName template + */ + public function iSelectTemplate(string $templateName): void + { + $this->resolveCurrentPage()->selectTemplate($templateName); + } + + /** + * @Then I click button to use this template + */ + public function iClickButtonToUseThisTemplate(): void + { + $this->resolveCurrentPage()->useTemplate(); + } + + /** + * @Then I confirm that I want to use this template + */ + public function iConfirmThatIWantToUseThisTemplate(): void + { + $this->resolveCurrentPage()->confirmUseTemplate(); + } + /** * @When I add it * @When I try to add it diff --git a/tests/Behat/Context/Ui/Admin/TemplateContext.php b/tests/Behat/Context/Ui/Admin/TemplateContext.php new file mode 100644 index 00000000..d9ee3499 --- /dev/null +++ b/tests/Behat/Context/Ui/Admin/TemplateContext.php @@ -0,0 +1,275 @@ +createPage->open(); + } + + /** + * @When I go to the templates page + */ + public function iGoToTheTemplatesPage() + { + $this->indexPage->open(); + } + + /** + * @When I fill the name with :name + */ + public function iFillTheNameWith(string $name): void + { + $this->resolveCurrentPage()->fillName($name); + } + + /** + * @When I delete :name content element + */ + public function iDeleteContentElement(string $name): void + { + $this->resolveCurrentPage()->deleteContentElement($name); + } + + /** + * @When I choose :type in Type field + */ + public function iChooseInTypeField(string $type): void + { + $this->resolveCurrentPage()->chooseType($type); + } + + /** + * @Then I should be notified that the template has been created + */ + public function iShouldBeNotifiedThatNewImageBlockHasBeenCreated(): void + { + $this->notificationChecker->checkNotification( + 'Template has been successfully created.', + NotificationType::success(), + ); + } + + /** + * @Then I should be notified that the template has been deleted + */ + public function iShouldBeNotifiedThatTheTemplateHasBeenDeleted(): void + { + $this->notificationChecker->checkNotification( + 'Template has been successfully deleted.', + NotificationType::success(), + ); + } + + /** + * @Then I should be notified that the template has been successfully updated + */ + public function iShouldBeNotifiedThatTheTemplateHasBeenSuccessfullyUpdated(): void + { + $this->notificationChecker->checkNotification( + 'Template has been successfully updated.', + NotificationType::success(), + ); + } + + /** + * @Then I should be notified that there is already existing template with provided name + */ + public function iShouldBeNotifiedThatThereIsAlreadyExistingTemplateWithName(): void + { + Assert::true($this->resolveCurrentPage()->containsErrorWithMessage( + 'There is an existing template with this name.', + false, + )); + } + + /** + * @Then I should be notified that :fields fields cannot be blank + * @Then I should be notified that :fields field cannot be blank + */ + public function iShouldBeNotifiedThatFieldsCannotBeBlank(string $fields): void + { + $fields = explode(',', $fields); + + foreach ($fields as $field) { + Assert::true($this->resolveCurrentPage()->containsErrorWithMessage(sprintf( + '%s cannot be blank.', + trim($field), + ))); + } + } + + /** + * @Then I should be notified that :fields fields are too short + * @Then I should be notified that :fields field is too short + */ + public function iShouldBeNotifiedThatFieldsAreTooShort(string $fields): void + { + $fields = explode(',', $fields); + + foreach ($fields as $field) { + Assert::true($this->resolveCurrentPage()->containsErrorWithMessage(sprintf( + '%s must be at least %d characters long.', + trim($field), + 2, + ))); + } + } + + /** + * @Then I should be notified that :fields fields are too long + * @Then I should be notified that :fields field is too long + */ + public function iShouldBeNotifiedThatFieldsAreTooLong(string $fields): void + { + $fields = explode(',', $fields); + + foreach ($fields as $field) { + Assert::true($this->resolveCurrentPage()->containsErrorWithMessage(sprintf( + '%s can not be longer than %d characters.', + trim($field), + 250, + ), false)); + } + } + + /** + * @When /^I fill "([^"]*)" fields with (\d+) (?:character|characters)$/ + * @When /^I fill "([^"]*)" field with (\d+) (?:character|characters)$/ + */ + public function iFillFieldsWithCharacters(string $fields, int $length): void + { + $fields = explode(',', $fields); + + foreach ($fields as $field) { + $this->resolveCurrentPage()->fillField(trim($field), $this->randomStringGenerator->generate($length)); + } + } + + /** + * @When I add it + * @When I try to add it + */ + public function iAddIt(): void + { + $this->createPage->create(); + } + + /** + * @When I click on Add button in Content elements section + */ + public function iClickOnAddButtonInContentElementsSection(): void + { + $this->resolveCurrentPage()->clickOnAddContentElementButton(); + } + + /** + * @When I select :option content element + */ + public function iSelectContentElement(string $option): void + { + $this->resolveCurrentPage()->selectContentElement($option); + } + + /** + * @Then I should see only :name content element in Content elements section + */ + public function iShouldSeeOnlyContentElementInContentElementsSection(string $name): void + { + Assert::true($this->resolveCurrentPage()->hasOnlyContentElement($name)); + } + + /** + * @Then I should see newly created :contentElement content element in Content elements section + */ + public function iShouldSeeNewlyCreatedContentElementInContentElementsSection(string $contentElement): void + { + Assert::true($this->resolveCurrentPage()->hasContentElement($contentElement)); + } + + /** + * @When I delete this template + */ + public function iDeleteThisTemplate() + { + $template = $this->sharedStorage->get('template'); + + $this->indexPage->deleteTemplate($template); + } + + /** + * @Then I should see empty list of templates + */ + public function iShouldSeeEmptyListOfTemplates(): void + { + $this->resolveCurrentPage()->isEmpty(); + } + + /** + * @When I go to the update :name template page + */ + public function iGoToTheUpdateTemplatePage(string $name) + { + $id = $this->templateRepository->findOneBy(['name' => $name])->getId(); + + $this->updatePage->open(['id' => $id]); + } + + /** + * @When I update it + */ + public function iUpdateIt(): void + { + $this->updatePage->saveChanges(); + } + + /** + * @return IndexPageInterface|CreatePageInterface|UpdatePageInterface|SymfonyPageInterface + */ + private function resolveCurrentPage(): SymfonyPageInterface + { + return $this->currentPageResolver->getCurrentPageWithForm([ + $this->indexPage, + $this->createPage, + $this->updatePage, + ]); + } +} diff --git a/tests/Behat/Helpers/ContentElementHelper.php b/tests/Behat/Helpers/ContentElementHelper.php index 3f0ca2ef..b224f611 100644 --- a/tests/Behat/Helpers/ContentElementHelper.php +++ b/tests/Behat/Helpers/ContentElementHelper.php @@ -58,4 +58,44 @@ public static function getExampleConfigurationByContentElement(string $contentEl default => throw new \InvalidArgumentException(sprintf('Content element with name "%s" does not exist.', $contentElement)), }; } + + public static function getDefinedContentElements(): array + { + return [ + 'content_elements_select_type' => '.bb-collection-item:last-child .field > label:contains("Type") ~ select', + 'content_elements_textarea' => '.field > label:contains("Textarea") ~ textarea', + 'content_elements_single_media_dropdown' => '.field > label:contains("Single media") ~ .bitbag-media-autocomplete', + 'content_elements_single_media_dropdown_item' => '.field > label:contains("Single media") ~ .bitbag-media-autocomplete > div.menu > div.item:contains("%item%")', + 'content_elements_multiple_media_dropdown' => '.field > label:contains("Multiple media") ~ .bitbag-media-autocomplete', + 'content_elements_multiple_media_dropdown_item' => '.field > label:contains("Multiple media") ~ .bitbag-media-autocomplete > div.menu > div.item:contains("%item%")', + 'content_elements_heading' => '.field > label:contains("Heading type") ~ select', + 'content_elements_heading_content' => '.field > label:contains("Heading") ~ input[type="text"]', + 'content_elements_products_carousel' => '.field > label:contains("Products") ~ .sylius-autocomplete', + 'content_elements_products_carousel_item' => '.field > label:contains("Products") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', + 'content_elements_products_carousel_by_taxon' => '.field > label:contains("Taxon") ~ .sylius-autocomplete', + 'content_elements_products_carousel_by_taxon_item' => '.field > label:contains("Taxon") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', + 'content_elements_products_grid' => '.field > label:contains("Products") ~ .sylius-autocomplete', + 'content_elements_products_grid_item' => '.field > label:contains("Products") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', + 'content_elements_products_grid_by_taxon' => '.field > label:contains("Taxon") ~ .sylius-autocomplete', + 'content_elements_products_grid_by_taxon_item' => '.field > label:contains("Taxon") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', + 'content_elements_taxons_list' => '.field > label:contains("Taxons") ~ .sylius-autocomplete', + 'content_elements_taxons_list_item' => '.field > label:contains("Taxons") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', + ]; + } + + public static function getContentElementValueByName(string $name): string + { + return match ($name) { + 'Textarea' => 'textarea', + 'Single media' => 'single_media', + 'Multiple media' => 'multiple_media', + 'Heading' => 'heading', + 'Products carousel' => 'products_carousel', + 'Products carousel by Taxon' => 'products_carousel_by_taxon', + 'Products grid' => 'products_grid', + 'Products grid by Taxon' => 'products_grid_by_taxon', + 'Taxons list' => 'taxons_list', + default => throw new \InvalidArgumentException(sprintf('Content element with name "%s" does not exist.', $name)), + }; + } } diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index 98a9031b..6e07b44b 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -257,28 +257,14 @@ public function addTaxonsListContentElementWithTaxons(array $taxons): void protected function getDefinedElements(): array { - return array_merge(parent::getDefinedElements(), [ - 'association_dropdown_collection' => '.field > label:contains("Collections") ~ .sylius-autocomplete', - 'association_dropdown_collection_item' => '.field > label:contains("Collections") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', - 'content_elements_add_button' => '#bitbag_sylius_cms_plugin_block_contentElements a[data-form-collection="add"]', - 'content_elements_select_type' => '.field > label:contains("Type") ~ select', - 'content_elements_textarea' => '.field > label:contains("Textarea") ~ textarea', - 'content_elements_single_media_dropdown' => '.field > label:contains("Single media") ~ .bitbag-media-autocomplete', - 'content_elements_single_media_dropdown_item' => '.field > label:contains("Single media") ~ .bitbag-media-autocomplete > div.menu > div.item:contains("%item%")', - 'content_elements_multiple_media_dropdown' => '.field > label:contains("Multiple media") ~ .bitbag-media-autocomplete', - 'content_elements_multiple_media_dropdown_item' => '.field > label:contains("Multiple media") ~ .bitbag-media-autocomplete > div.menu > div.item:contains("%item%")', - 'content_elements_heading' => '.field > label:contains("Heading type") ~ select', - 'content_elements_heading_content' => '.field > label:contains("Heading") ~ input[type="text"]', - 'content_elements_products_carousel' => '.field > label:contains("Products") ~ .sylius-autocomplete', - 'content_elements_products_carousel_item' => '.field > label:contains("Products") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', - 'content_elements_products_carousel_by_taxon' => '.field > label:contains("Taxon") ~ .sylius-autocomplete', - 'content_elements_products_carousel_by_taxon_item' => '.field > label:contains("Taxon") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', - 'content_elements_products_grid' => '.field > label:contains("Products") ~ .sylius-autocomplete', - 'content_elements_products_grid_item' => '.field > label:contains("Products") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', - 'content_elements_products_grid_by_taxon' => '.field > label:contains("Taxon") ~ .sylius-autocomplete', - 'content_elements_products_grid_by_taxon_item' => '.field > label:contains("Taxon") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', - 'content_elements_taxons_list' => '.field > label:contains("Taxons") ~ .sylius-autocomplete', - 'content_elements_taxons_list_item' => '.field > label:contains("Taxons") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', - ]); + return array_merge( + parent::getDefinedElements(), + ContentElementHelper::getDefinedContentElements(), + [ + 'association_dropdown_collection' => '.field > label:contains("Collections") ~ .sylius-autocomplete', + 'association_dropdown_collection_item' => '.field > label:contains("Collections") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', + 'content_elements_add_button' => '#bitbag_sylius_cms_plugin_block_contentElements a[data-form-collection="add"]', + ], + ); } } diff --git a/tests/Behat/Page/Admin/Page/CreatePage.php b/tests/Behat/Page/Admin/Page/CreatePage.php index 2e292220..4c027ff7 100755 --- a/tests/Behat/Page/Admin/Page/CreatePage.php +++ b/tests/Behat/Page/Admin/Page/CreatePage.php @@ -264,31 +264,50 @@ public function addTaxonsListContentElementWithTaxons(array $taxons): void } } - protected function getDefinedElements(): array + public function selectTemplate(string $templateName): void { - return array_merge(parent::getDefinedElements(), [ - 'slug' => '#bitbag_sylius_cms_plugin_page_translations_en_US_slug', - 'association_dropdown_collection' => '.field > label:contains("Collections") ~ .sylius-autocomplete', - 'association_dropdown_collection_item' => '.field > label:contains("Collections") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', - 'content_elements_add_button' => '#bitbag_sylius_cms_plugin_page_contentElements a[data-form-collection="add"]', - 'content_elements_select_type' => '.field > label:contains("Type") ~ select', - 'content_elements_textarea' => '.field > label:contains("Textarea") ~ textarea', - 'content_elements_single_media_dropdown' => '.field > label:contains("Single media") ~ .bitbag-media-autocomplete', - 'content_elements_single_media_dropdown_item' => '.field > label:contains("Single media") ~ .bitbag-media-autocomplete > div.menu > div.item:contains("%item%")', - 'content_elements_multiple_media_dropdown' => '.field > label:contains("Multiple media") ~ .bitbag-media-autocomplete', - 'content_elements_multiple_media_dropdown_item' => '.field > label:contains("Multiple media") ~ .bitbag-media-autocomplete > div.menu > div.item:contains("%item%")', - 'content_elements_heading' => '.field > label:contains("Heading type") ~ select', - 'content_elements_heading_content' => '.field > label:contains("Heading") ~ input[type="text"]', - 'content_elements_products_carousel' => '.field > label:contains("Products") ~ .sylius-autocomplete', - 'content_elements_products_carousel_item' => '.field > label:contains("Products") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', - 'content_elements_products_carousel_by_taxon' => '.field > label:contains("Taxon") ~ .sylius-autocomplete', - 'content_elements_products_carousel_by_taxon_item' => '.field > label:contains("Taxon") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', - 'content_elements_products_grid' => '.field > label:contains("Products") ~ .sylius-autocomplete', - 'content_elements_products_grid_item' => '.field > label:contains("Products") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', - 'content_elements_products_grid_by_taxon' => '.field > label:contains("Taxon") ~ .sylius-autocomplete', - 'content_elements_products_grid_by_taxon_item' => '.field > label:contains("Taxon") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', - 'content_elements_taxons_list' => '.field > label:contains("Taxons") ~ .sylius-autocomplete', - 'content_elements_taxons_list_item' => '.field > label:contains("Taxons") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', + $dropdown = $this->getElement('template_select_dropdown'); + $dropdown->click(); + + $dropdown->waitFor(5, function () use ($templateName): bool { + return $this->hasElement('template_select_dropdown_item', [ + '%item%' => $templateName, + ]); + }); + + $item = $this->getElement('template_select_dropdown_item', [ + '%item%' => $templateName, ]); + + $item->click(); + } + + public function useTemplate(): void + { + $this->getDocument()->findLink('Use this template')->click(); + } + + public function confirmUseTemplate(): void + { + $this->getDocument()->findById('load-template-confirmation-button')->click(); + $this->getDocument()->waitFor(2, function (): bool { + return '' !== $this->getDocument()->find('css', '[data-form-collection="list"]')->getHtml(); + }); + } + + protected function getDefinedElements(): array + { + return array_merge( + parent::getDefinedElements(), + ContentElementHelper::getDefinedContentElements(), + [ + 'slug' => '#bitbag_sylius_cms_plugin_page_translations_en_US_slug', + 'association_dropdown_collection' => '.field > label:contains("Collections") ~ .sylius-autocomplete', + 'association_dropdown_collection_item' => '.field > label:contains("Collections") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', + 'content_elements_add_button' => '#bitbag_sylius_cms_plugin_page_contentElements a[data-form-collection="add"]', + 'template_select_dropdown' => 'h5:contains("Use page template") ~ .column .field > .sylius-autocomplete', + 'template_select_dropdown_item' => 'h5:contains("Use page template") ~ .column .field > .sylius-autocomplete > div.menu > div.item:contains("%item%")', + ], + ); } } diff --git a/tests/Behat/Page/Admin/Page/CreatePageInterface.php b/tests/Behat/Page/Admin/Page/CreatePageInterface.php index cd67dc2b..adc032b6 100755 --- a/tests/Behat/Page/Admin/Page/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Page/CreatePageInterface.php @@ -56,4 +56,8 @@ public function addProductsGridContentElementWithProducts(array $productsNames): public function addProductsGridByTaxonContentElementWithTaxon(string $taxon): void; public function addTaxonsListContentElementWithTaxons(array $taxons): void; + + public function selectTemplate(string $templateName): void; + + public function useTemplate(): void; } diff --git a/tests/Behat/Page/Admin/Template/CreatePage.php b/tests/Behat/Page/Admin/Template/CreatePage.php new file mode 100755 index 00000000..352af26b --- /dev/null +++ b/tests/Behat/Page/Admin/Template/CreatePage.php @@ -0,0 +1,73 @@ +getDocument()->fillField($field, $value); + } + + public function fillName(string $name): void + { + $this->getDocument()->fillField('Name', $name); + } + + public function chooseType(string $name): void + { + $this->getDocument()->selectFieldOption('Type', $name); + } + + public function clickOnAddContentElementButton(): void + { + Assert::isInstanceOf($this->getDriver(), ChromeDriver::class); + + $addButton = $this->getElement('content_elements_add_button'); + $addButton->click(); + + $addButton->waitFor(1, function (): bool { + return $this->hasElement('content_elements_select_type'); + }); + } + + public function selectContentElement(string $contentElement): void + { + Assert::isInstanceOf($this->getDriver(), ChromeDriver::class); + + $select = $this->getElement('content_elements_select_type'); + $select->selectOption($contentElement); + $select->waitFor(1, function () use ($contentElement): bool { + return $this->hasElement( + ContentElementHelper::getDefinedElementThatShouldAppearAfterSelectContentElement($contentElement), + ); + }); + } + + protected function getDefinedElements(): array + { + return array_merge( + parent::getDefinedElements(), + ContentElementHelper::getDefinedContentElements(), + [ + 'content_elements_add_button' => '#bitbag_sylius_cms_plugin_template_contentElements a[data-form-collection="add"]', + ], + ); + } +} diff --git a/tests/Behat/Page/Admin/Template/CreatePageInterface.php b/tests/Behat/Page/Admin/Template/CreatePageInterface.php new file mode 100644 index 00000000..6c113838 --- /dev/null +++ b/tests/Behat/Page/Admin/Template/CreatePageInterface.php @@ -0,0 +1,24 @@ +deleteResourceOnPage(['name' => $template->getName()]); + } +} diff --git a/tests/Behat/Page/Admin/Template/IndexPageInterface.php b/tests/Behat/Page/Admin/Template/IndexPageInterface.php new file mode 100644 index 00000000..dff8ca75 --- /dev/null +++ b/tests/Behat/Page/Admin/Template/IndexPageInterface.php @@ -0,0 +1,18 @@ +getDocument()->findAll('css', 'select'); + foreach ($selects as $select) { + $selectedOptionElement = $select->find('css', 'option[selected]'); + if (null !== $selectedOptionElement && $selectedOptionElement->getText() === $contentElement) { + return true; + } + } + + return false; + } + + public function hasOnlyContentElement(string $contentElement): bool + { + $selects = $this->getDocument()->findAll('css', 'select'); + $contentElementsCount = 0; + foreach ($selects as $select) { + $selectedOptionElement = $select->find('css', 'option[selected]'); + if (null !== $selectedOptionElement && $selectedOptionElement->getText() === $contentElement) { + ++$contentElementsCount; + } + } + + return 1 === $contentElementsCount; + } + + public function fillName(string $name): void + { + $this->getDocument()->fillField('Name', $name); + } + + public function deleteContentElement(string $name): void + { + $contentElementSelect = $this->getDocument()->find('css', sprintf('option:contains("%s")', $name)); + $contentElementSelect + ->getParent() + ->getParent() + ->getParent() + ->getParent() + ->find('css', '.bb-collection-item-delete')->click(); + } +} diff --git a/tests/Behat/Page/Admin/Template/UpdatePageInterface.php b/tests/Behat/Page/Admin/Template/UpdatePageInterface.php new file mode 100644 index 00000000..7404eafd --- /dev/null +++ b/tests/Behat/Page/Admin/Template/UpdatePageInterface.php @@ -0,0 +1,22 @@ + + + + + + + diff --git a/tests/Behat/Resources/services/contexts/ui.xml b/tests/Behat/Resources/services/contexts/ui.xml index 805535d3..d40a9ae5 100644 --- a/tests/Behat/Resources/services/contexts/ui.xml +++ b/tests/Behat/Resources/services/contexts/ui.xml @@ -59,5 +59,16 @@ + + + + + + + + + + + diff --git a/tests/Behat/Resources/services/pages/admin.xml b/tests/Behat/Resources/services/pages/admin.xml index 38901241..09858426 100644 --- a/tests/Behat/Resources/services/pages/admin.xml +++ b/tests/Behat/Resources/services/pages/admin.xml @@ -6,5 +6,6 @@ + diff --git a/tests/Behat/Resources/services/pages/admin/template.xml b/tests/Behat/Resources/services/pages/admin/template.xml new file mode 100644 index 00000000..4de874d5 --- /dev/null +++ b/tests/Behat/Resources/services/pages/admin/template.xml @@ -0,0 +1,19 @@ + + + + + + + + bitbag_sylius_cms_plugin_admin_template_index + + + + bitbag_sylius_cms_plugin_admin_template_create + + + + bitbag_sylius_cms_plugin_admin_template_update + + + diff --git a/tests/Behat/Resources/suites.yml b/tests/Behat/Resources/suites.yml index 678cca93..8acb5a3f 100644 --- a/tests/Behat/Resources/suites.yml +++ b/tests/Behat/Resources/suites.yml @@ -3,6 +3,7 @@ imports: - suites/ui/managing_pages.yml - suites/ui/managing_collections.yml - suites/ui/managing_media.yml + - suites/ui/managing_templates.yml - suites/ui/shop_blocks.yml - suites/ui/shop_media.yml - suites/ui/shop_pages.yml diff --git a/tests/Behat/Resources/suites/ui/managing_pages.yml b/tests/Behat/Resources/suites/ui/managing_pages.yml index bdf309b0..44d58653 100755 --- a/tests/Behat/Resources/suites/ui/managing_pages.yml +++ b/tests/Behat/Resources/suites/ui/managing_pages.yml @@ -11,6 +11,7 @@ default: - bitbag_sylius_cms_plugin.behat.context.setup.media - bitbag_sylius_cms_plugin.behat.context.setup.page - bitbag_sylius_cms_plugin.behat.context.setup.collection + - bitbag_sylius_cms_plugin.behat.context.setup.template - bitbag_sylius_cms_plugin.behat.context.ui.admin.page filters: diff --git a/tests/Behat/Resources/suites/ui/managing_templates.yml b/tests/Behat/Resources/suites/ui/managing_templates.yml new file mode 100755 index 00000000..c2b479ab --- /dev/null +++ b/tests/Behat/Resources/suites/ui/managing_templates.yml @@ -0,0 +1,11 @@ +default: + suites: + ui_managing_templates: + contexts: + - sylius.behat.context.hook.doctrine_orm + - sylius.behat.context.setup.channel + - sylius.behat.context.setup.admin_security + - bitbag_sylius_cms_plugin.behat.context.setup.template + - bitbag_sylius_cms_plugin.behat.context.ui.admin.template + filters: + tags: "@managing_templates&&@ui"