From c50344d71b8b1d464c73793d3c1cb213951ec504 Mon Sep 17 00:00:00 2001 From: jkindly Date: Fri, 5 Jul 2024 12:41:42 +0200 Subject: [PATCH 01/36] OP-326: Single media content type + configuration --- .../SingleMediaToCodeTransformer.php | 47 +++++++++++ src/Form/Type/ContentConfigurationType.php | 14 ++++ .../SingleMediaContentElementType.php | 42 ++++++++++ src/Repository/MediaRepository.php | 10 +++ .../js/bitbag/bitbag-content-configuration.js | 70 ++++++++++++++++ src/Resources/assets/admin/js/bitbag/index.js | 1 + src/Resources/assets/admin/scss/_css.scss | 8 ++ src/Resources/config/routing/admin/media.yml | 7 +- src/Resources/config/services/form.xml | 28 +++++++ .../ContentConfiguration/_action.html.twig | 5 ++ src/Resources/views/Form/theme.html.twig | 79 ++++++++++++++++--- 11 files changed, 297 insertions(+), 14 deletions(-) create mode 100644 src/Form/DataTransformer/SingleMediaToCodeTransformer.php create mode 100644 src/Form/Type/ContentElements/SingleMediaContentElementType.php create mode 100644 src/Resources/assets/admin/js/bitbag/bitbag-content-configuration.js create mode 100644 src/Resources/views/ContentConfiguration/_action.html.twig diff --git a/src/Form/DataTransformer/SingleMediaToCodeTransformer.php b/src/Form/DataTransformer/SingleMediaToCodeTransformer.php new file mode 100644 index 000000000..9419cb1c9 --- /dev/null +++ b/src/Form/DataTransformer/SingleMediaToCodeTransformer.php @@ -0,0 +1,47 @@ +mediaRepository->findOneBy(['code' => $value]); + + return $media; + } + + /** + * @throws \InvalidArgumentException + * @param MediaInterface $value + */ + public function reverseTransform($value): ?string + { + Assert::isInstanceOf($value, MediaInterface::class); + + return $value->getCode(); + } +} diff --git a/src/Form/Type/ContentConfigurationType.php b/src/Form/Type/ContentConfigurationType.php index e3e6478b2..5ba705910 100644 --- a/src/Form/Type/ContentConfigurationType.php +++ b/src/Form/Type/ContentConfigurationType.php @@ -16,6 +16,7 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; +use Twig\Environment; final class ContentConfigurationType extends AbstractResourceType { @@ -27,6 +28,7 @@ public function __construct( string $dataClass, array $validationGroups, iterable $actionConfigurationTypes, + private Environment $twig, ) { parent::__construct($dataClass, $validationGroups); @@ -45,6 +47,18 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('type', ChoiceType::class, [ 'label' => 'sylius.ui.type', 'choices' => $this->actionTypes, + 'choice_attr' => function (?string $type) use ($builder): array { + return [ + 'data-configuration' => $this->twig->render( + '@BitBagSyliusCmsPlugin/ContentConfiguration/_action.html.twig', + ['field' => $builder->create( + 'configuration', + $this->actionConfigurationTypes[$type], + ['label' => false, 'csrf_protection' => false], + )->getForm()->createView()], + ), + ]; + }, ]) ->add('configuration', $defaultActionConfigurationType, [ 'label' => false, diff --git a/src/Form/Type/ContentElements/SingleMediaContentElementType.php b/src/Form/Type/ContentElements/SingleMediaContentElementType.php new file mode 100644 index 000000000..a4bac0ece --- /dev/null +++ b/src/Form/Type/ContentElements/SingleMediaContentElementType.php @@ -0,0 +1,42 @@ +add(self::TYPE, MediaAutocompleteChoiceType::class, [ + 'label' => 'bitbag_sylius_cms_plugin.ui.content_elements.type.'.self::TYPE, + ]) + ; + + $builder->get(self::TYPE)->addModelTransformer($this->singleMediaToCodeTransformer); + } + + public function getBlockPrefix(): string + { + return 'bitbag_sylius_cms_plugin_content_elements_'.self::TYPE; + } +} diff --git a/src/Repository/MediaRepository.php b/src/Repository/MediaRepository.php index e69ae6980..3aaacb24f 100755 --- a/src/Repository/MediaRepository.php +++ b/src/Repository/MediaRepository.php @@ -85,4 +85,14 @@ public function findByProductCode( ->getResult() ; } + + public function findByNamePart(string $phrase): array + { + return $this->createQueryBuilder('o') + ->andWhere('o.name LIKE :name') + ->setParameter('name', '%' . $phrase . '%') + ->getQuery() + ->getResult() + ; + } } diff --git a/src/Resources/assets/admin/js/bitbag/bitbag-content-configuration.js b/src/Resources/assets/admin/js/bitbag/bitbag-content-configuration.js new file mode 100644 index 000000000..e308a0322 --- /dev/null +++ b/src/Resources/assets/admin/js/bitbag/bitbag-content-configuration.js @@ -0,0 +1,70 @@ +/* + * This file was created by developers working at BitBag + * Do you need more information about us and what we do? Visit our https://bitbag.io website! + * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career +*/ + +$(document).ready(function() { + $(document).on('collection-form-add', () => { + $('.bitbag-media-autocomplete').each((index, element) => { + if ($._data($(element).get(0), 'events') === undefined) { + $(element).autoComplete(); + } + }); + + $('#bitbag_sylius_cms_plugin_page_contentElements [data-form-collection="item"]').each((index, element) => { + $(document).loadContentConfiguration(element); + }); + }); + + $.fn.extend({ + loadContentConfiguration(target) { + target.querySelector('#bitbag_sylius_cms_plugin_page_contentElements select[name*="type"]').onchange = function () { + const parent = this.parentElement; + const newConfig = document.createElement('div'); + const selectedOption = this.selectedOptions[0]; + newConfig.innerHTML = selectedOption.getAttribute('data-configuration'); + + const oldConfig = parent.nextElementSibling; + + parent.parentElement.replaceChild(newConfig, oldConfig); + + let oldConfigInput = oldConfig.querySelector('input'); + if (!oldConfigInput) { + oldConfigInput = oldConfig.querySelector('textarea'); + } + + const oldConfigInputName = oldConfigInput.getAttribute('name'); + + let newConfigInputs = newConfig.querySelectorAll('input'); + if (!newConfigInputs.length) { + newConfigInputs = newConfig.querySelectorAll('textarea'); + } + + newConfigInputs.forEach(element => { + let newConfigInputName = element.getAttribute('name'); + + newConfigInputName = oldConfigInputName.replace( + oldConfigInputName.substring(oldConfigInputName.indexOf('[configuration]') + 15), + newConfigInputName.substring(newConfigInputName.indexOf('configuration') + 13), + ); + + $(element).attr('name', newConfigInputName); + $(newConfig).find('.bitbag-media-autocomplete').autoComplete(); + }); + } + } + }); + + $('.bitbag-media-autocomplete').each((index, element) => { + $(element).autoComplete(); + }); + + $('#bitbag_sylius_cms_plugin_page_contentElements [data-form-collection="item"]').each((index, element) => { + $(document).loadContentConfiguration(element); + }); + + $(document).loadContentConfiguration( + document.querySelector('#bitbag_sylius_cms_plugin_page_contentElements [data-form-collection="item"]') + ); +}); diff --git a/src/Resources/assets/admin/js/bitbag/index.js b/src/Resources/assets/admin/js/bitbag/index.js index 5d48e0b92..258d6d922 100644 --- a/src/Resources/assets/admin/js/bitbag/index.js +++ b/src/Resources/assets/admin/js/bitbag/index.js @@ -1,3 +1,4 @@ +import './bitbag-content-configuration'; export {HandleCsvUpload} from './bitbag-upload-csv'; export {HandleSlugUpdate} from './bitbag-page-slug'; export {HandlePreview} from './bitbag-cms-preview'; diff --git a/src/Resources/assets/admin/scss/_css.scss b/src/Resources/assets/admin/scss/_css.scss index 2489ccbb6..334c3a1cb 100644 --- a/src/Resources/assets/admin/scss/_css.scss +++ b/src/Resources/assets/admin/scss/_css.scss @@ -103,3 +103,11 @@ .bitbag-media-autocomplete .search { cursor: pointer !important; } + +.bb-collection-item { + margin-bottom: 1em; + + &-delete { + margin-top: 5px !important; + } +} diff --git a/src/Resources/config/routing/admin/media.yml b/src/Resources/config/routing/admin/media.yml index cfd9e3a6a..3638f5c8f 100644 --- a/src/Resources/config/routing/admin/media.yml +++ b/src/Resources/config/routing/admin/media.yml @@ -24,9 +24,12 @@ bitbag_sylius_cms_plugin_admin_ajax_media_by_name_phrase: _format: json _controller: bitbag_sylius_cms_plugin.controller.media.overriden::indexAction _sylius: - serialization_groups: [Default, Autocomplete] + serialization_groups: [Autocomplete] permission: true - grid: bitbag_sylius_cms_plugin_admin_media + repository: + method: findByNamePart + arguments: + phrase: $phrase bitbag_sylius_cms_plugin_admin_ajax_media_by_code: path: /ajax/media/code diff --git a/src/Resources/config/services/form.xml b/src/Resources/config/services/form.xml index a4cf678fc..b6d453494 100644 --- a/src/Resources/config/services/form.xml +++ b/src/Resources/config/services/form.xml @@ -3,6 +3,9 @@ BitBag\SyliusCmsPlugin\Form\Type\ContentElements\TextareaContentElementType::TYPE + BitBag\SyliusCmsPlugin\Form\Type\ContentElements\SingleMediaContentElementType::TYPE + BitBag\SyliusCmsPlugin\Form\Type\ContentElements\MultipleMediaContentElementType::TYPE + BitBag\SyliusCmsPlugin\Form\Type\ContentElements\HeadingContentElementType::TYPE @@ -18,6 +21,7 @@ BitBag\SyliusCmsPlugin\Entity\ContentConfiguration %bitbag_sylius_cms_plugin.form.type.content_configuration.validation_groups% + @@ -84,6 +88,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Resources/views/ContentConfiguration/_action.html.twig b/src/Resources/views/ContentConfiguration/_action.html.twig new file mode 100644 index 000000000..b7f55e28c --- /dev/null +++ b/src/Resources/views/ContentConfiguration/_action.html.twig @@ -0,0 +1,5 @@ +{% form_theme field '@BitBagSyliusCmsPlugin/Form/theme.html.twig' %} + +{{ form_row(field) }} + +
diff --git a/src/Resources/views/Form/theme.html.twig b/src/Resources/views/Form/theme.html.twig index 6df30e724..841343b8f 100755 --- a/src/Resources/views/Form/theme.html.twig +++ b/src/Resources/views/Form/theme.html.twig @@ -20,23 +20,23 @@ {{- form_label(form) -}} {{- form_errors(form) -}} @@ -49,3 +49,58 @@ {% block sylius_taxon_autocomplete_choice_row %} {{ form_row(form, {'remote_url': path('bitbag_sylius_cms_plugin_admin_ajax_taxon_by_name_phrase'), 'load_edit_url': path('sylius_admin_ajax_taxon_by_code')}) }} {% endblock %} + +{% block collection_widget -%} + {% from '@SyliusResource/Macros/notification.html.twig' import error %} + {% import _self as self %} + {% set attr = attr|merge({'class': attr.class|default ~ ' controls collection-widget'}) %} + + {% apply spaceless %} +
+ {{ error(form.vars.errors) }} + + {% if prototypes|default is iterable %} + {% for key, subPrototype in prototypes %} + + {% endfor %} + {% endif %} + +
+ {% for child in form %} + {{ self.collection_item(child, allow_delete, button_delete_label, loop.index0) }} + {% endfor %} +
+ + {% if prototype is defined and allow_add %} + + + {{ button_add_label|trans }} + + {% endif %} +
+ {% endapply %} +{%- endblock collection_widget %} + +{% macro collection_item(form, allow_delete, button_delete_label, index) %} + {% apply spaceless %} +
+
+ {{ form_widget(form) }} + {% if allow_delete %} + + + {{ button_delete_label|trans }} + + {% endif %} +
+
+ {% endapply %} +{% endmacro %} From 2af6c8e7f737cd5ba7a4e552e470937081207ea7 Mon Sep 17 00:00:00 2001 From: jkindly Date: Fri, 5 Jul 2024 12:42:03 +0200 Subject: [PATCH 02/36] OP-326: Multiple media content type --- .../MultipleMediaToCodesTransformer.php | 56 +++++++++++++++++++ .../MultipleMediaContentElementType.php | 43 ++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 src/Form/DataTransformer/MultipleMediaToCodesTransformer.php create mode 100644 src/Form/Type/ContentElements/MultipleMediaContentElementType.php diff --git a/src/Form/DataTransformer/MultipleMediaToCodesTransformer.php b/src/Form/DataTransformer/MultipleMediaToCodesTransformer.php new file mode 100644 index 000000000..aea36cb65 --- /dev/null +++ b/src/Form/DataTransformer/MultipleMediaToCodesTransformer.php @@ -0,0 +1,56 @@ +mediaRepository->findBy(['code' => $value])); + } + + /** + * @throws \InvalidArgumentException + */ + public function reverseTransform($value): array + { + Assert::isInstanceOf($value, Collection::class); + + $mediaCodes = []; + + /** @var MediaInterface $media */ + foreach ($value as $media) { + $mediaCodes[] = $media->getCode(); + } + + return $mediaCodes; + } +} diff --git a/src/Form/Type/ContentElements/MultipleMediaContentElementType.php b/src/Form/Type/ContentElements/MultipleMediaContentElementType.php new file mode 100644 index 000000000..818f02259 --- /dev/null +++ b/src/Form/Type/ContentElements/MultipleMediaContentElementType.php @@ -0,0 +1,43 @@ +add(self::TYPE, MediaAutocompleteChoiceType::class, [ + 'label' => 'bitbag_sylius_cms_plugin.ui.content_elements.type.'.self::TYPE, + 'multiple' => true, + ]) + ; + + $builder->get(self::TYPE)->addModelTransformer($this->mediaToCodesTransformer); + } + + public function getBlockPrefix(): string + { + return 'bitbag_sylius_cms_plugin_content_elements_'.self::TYPE; + } +} From 4b077fab214f70d7fca7db66a533239cbee4b8b2 Mon Sep 17 00:00:00 2001 From: jkindly Date: Fri, 5 Jul 2024 12:42:10 +0200 Subject: [PATCH 03/36] OP-326: Heading content type --- .../HeadingContentElementType.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/Form/Type/ContentElements/HeadingContentElementType.php diff --git a/src/Form/Type/ContentElements/HeadingContentElementType.php b/src/Form/Type/ContentElements/HeadingContentElementType.php new file mode 100644 index 000000000..4ac545eba --- /dev/null +++ b/src/Form/Type/ContentElements/HeadingContentElementType.php @@ -0,0 +1,48 @@ +add('heading_type', ChoiceType::class, [ + 'label' => 'bitbag_sylius_cms_plugin.ui.content_elements.heading_type', + 'choices' => [ + 'bitbag_sylius_cms_plugin.ui.content_elements.heading_type.h1' => 'h1', + 'bitbag_sylius_cms_plugin.ui.content_elements.heading_type.h2' => 'h2', + 'bitbag_sylius_cms_plugin.ui.content_elements.heading_type.h3' => 'h3', + 'bitbag_sylius_cms_plugin.ui.content_elements.heading_type.h4' => 'h4', + 'bitbag_sylius_cms_plugin.ui.content_elements.heading_type.h5' => 'h5', + 'bitbag_sylius_cms_plugin.ui.content_elements.heading_type.h6' => 'h6', + ], + 'required' => true, + 'empty_data' => 'h1', + ]) + ->add(self::TYPE, TextType::class, [ + 'label' => 'bitbag_sylius_cms_plugin.ui.content_elements.type.'.self::TYPE, + ]) + ; + } + + public function getBlockPrefix(): string + { + return 'bitbag_sylius_cms_plugin_content_elements_'.self::TYPE; + } +} From 3d4673d63d2931f0c9f4050d36663e544b6f5df6 Mon Sep 17 00:00:00 2001 From: jkindly Date: Fri, 5 Jul 2024 12:42:28 +0200 Subject: [PATCH 04/36] OP-326: Textarea content type constant --- src/Form/Type/ContentElements/TextareaContentElementType.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Form/Type/ContentElements/TextareaContentElementType.php b/src/Form/Type/ContentElements/TextareaContentElementType.php index 8607b78a2..94a05d47f 100644 --- a/src/Form/Type/ContentElements/TextareaContentElementType.php +++ b/src/Form/Type/ContentElements/TextareaContentElementType.php @@ -22,13 +22,13 @@ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add(self::TYPE, WysiwygType::class, [ - 'label' => 'bitbag_sylius_cms_plugin.ui.content_elements.type.textarea', + 'label' => 'bitbag_sylius_cms_plugin.ui.content_elements.type.'.self::TYPE, ]) ; } public function getBlockPrefix(): string { - return 'bitbag_sylius_cms_plugin_content_elements_textarea'; + return 'bitbag_sylius_cms_plugin_content_elements_'.self::TYPE; } } From 6b6581ec9281a051f0cd2b8eef8ae89630bff629 Mon Sep 17 00:00:00 2001 From: jkindly Date: Fri, 5 Jul 2024 13:28:08 +0200 Subject: [PATCH 05/36] OP-326: Products Carousel content type --- .../HeadingContentElementType.php | 12 +++---- .../ProductsCarouselContentElementType.php | 34 +++++++++++++++++++ .../js/bitbag/bitbag-content-configuration.js | 8 +++-- src/Resources/config/services/form.xml | 6 ++++ 4 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 src/Form/Type/ContentElements/ProductsCarouselContentElementType.php diff --git a/src/Form/Type/ContentElements/HeadingContentElementType.php b/src/Form/Type/ContentElements/HeadingContentElementType.php index 4ac545eba..7ffb4687b 100644 --- a/src/Form/Type/ContentElements/HeadingContentElementType.php +++ b/src/Form/Type/ContentElements/HeadingContentElementType.php @@ -25,12 +25,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('heading_type', ChoiceType::class, [ 'label' => 'bitbag_sylius_cms_plugin.ui.content_elements.heading_type', 'choices' => [ - 'bitbag_sylius_cms_plugin.ui.content_elements.heading_type.h1' => 'h1', - 'bitbag_sylius_cms_plugin.ui.content_elements.heading_type.h2' => 'h2', - 'bitbag_sylius_cms_plugin.ui.content_elements.heading_type.h3' => 'h3', - 'bitbag_sylius_cms_plugin.ui.content_elements.heading_type.h4' => 'h4', - 'bitbag_sylius_cms_plugin.ui.content_elements.heading_type.h5' => 'h5', - 'bitbag_sylius_cms_plugin.ui.content_elements.heading_type.h6' => 'h6', + 'H1' => 'h1', + 'H2' => 'h2', + 'H3' => 'h3', + 'H4' => 'h4', + 'H5' => 'h5', + 'H6' => 'h6', ], 'required' => true, 'empty_data' => 'h1', diff --git a/src/Form/Type/ContentElements/ProductsCarouselContentElementType.php b/src/Form/Type/ContentElements/ProductsCarouselContentElementType.php new file mode 100644 index 000000000..46b236714 --- /dev/null +++ b/src/Form/Type/ContentElements/ProductsCarouselContentElementType.php @@ -0,0 +1,34 @@ +add(self::TYPE, ForProductsScopeConfigurationType::class, [ + 'label' => false, + ]) + ; + } + + public function getBlockPrefix(): string + { + return 'bitbag_sylius_cms_plugin_content_elements_'.self::TYPE; + } +} diff --git a/src/Resources/assets/admin/js/bitbag/bitbag-content-configuration.js b/src/Resources/assets/admin/js/bitbag/bitbag-content-configuration.js index e308a0322..66761c5b1 100644 --- a/src/Resources/assets/admin/js/bitbag/bitbag-content-configuration.js +++ b/src/Resources/assets/admin/js/bitbag/bitbag-content-configuration.js @@ -6,7 +6,7 @@ $(document).ready(function() { $(document).on('collection-form-add', () => { - $('.bitbag-media-autocomplete').each((index, element) => { + $('.bitbag-media-autocomplete, .sylius-autocomplete').each((index, element) => { if ($._data($(element).get(0), 'events') === undefined) { $(element).autoComplete(); } @@ -43,6 +43,9 @@ $(document).ready(function() { newConfigInputs.forEach(element => { let newConfigInputName = element.getAttribute('name'); + if (!newConfigInputName) { + return; + } newConfigInputName = oldConfigInputName.replace( oldConfigInputName.substring(oldConfigInputName.indexOf('[configuration]') + 15), @@ -51,12 +54,13 @@ $(document).ready(function() { $(element).attr('name', newConfigInputName); $(newConfig).find('.bitbag-media-autocomplete').autoComplete(); + $(newConfig).find('.sylius-autocomplete').autoComplete(); }); } } }); - $('.bitbag-media-autocomplete').each((index, element) => { + $('.bitbag-media-autocomplete, .sylius-autocomplete').each((index, element) => { $(element).autoComplete(); }); diff --git a/src/Resources/config/services/form.xml b/src/Resources/config/services/form.xml index b6d453494..1536cc5f2 100644 --- a/src/Resources/config/services/form.xml +++ b/src/Resources/config/services/form.xml @@ -6,6 +6,7 @@ BitBag\SyliusCmsPlugin\Form\Type\ContentElements\SingleMediaContentElementType::TYPE BitBag\SyliusCmsPlugin\Form\Type\ContentElements\MultipleMediaContentElementType::TYPE BitBag\SyliusCmsPlugin\Form\Type\ContentElements\HeadingContentElementType::TYPE + BitBag\SyliusCmsPlugin\Form\Type\ContentElements\ProductsCarouselContentElementType::TYPE @@ -105,6 +106,11 @@ + + + + + From dd06d73536c13e70301a109023d81ff4493d8410 Mon Sep 17 00:00:00 2001 From: jkindly Date: Fri, 5 Jul 2024 14:04:42 +0200 Subject: [PATCH 06/36] OP-326: Products Carousel By Taxon content type --- .../SingleMediaToCodeTransformer.php | 47 ------------------- ...ductsCarouselByTaxonContentElementType.php | 47 +++++++++++++++++++ .../SingleMediaContentElementType.php | 10 ++-- src/Resources/config/services/form.xml | 9 ++-- 4 files changed, 60 insertions(+), 53 deletions(-) delete mode 100644 src/Form/DataTransformer/SingleMediaToCodeTransformer.php create mode 100644 src/Form/Type/ContentElements/ProductsCarouselByTaxonContentElementType.php diff --git a/src/Form/DataTransformer/SingleMediaToCodeTransformer.php b/src/Form/DataTransformer/SingleMediaToCodeTransformer.php deleted file mode 100644 index 9419cb1c9..000000000 --- a/src/Form/DataTransformer/SingleMediaToCodeTransformer.php +++ /dev/null @@ -1,47 +0,0 @@ -mediaRepository->findOneBy(['code' => $value]); - - return $media; - } - - /** - * @throws \InvalidArgumentException - * @param MediaInterface $value - */ - public function reverseTransform($value): ?string - { - Assert::isInstanceOf($value, MediaInterface::class); - - return $value->getCode(); - } -} diff --git a/src/Form/Type/ContentElements/ProductsCarouselByTaxonContentElementType.php b/src/Form/Type/ContentElements/ProductsCarouselByTaxonContentElementType.php new file mode 100644 index 000000000..94f4c2339 --- /dev/null +++ b/src/Form/Type/ContentElements/ProductsCarouselByTaxonContentElementType.php @@ -0,0 +1,47 @@ +add(self::TYPE, TaxonAutocompleteChoiceType::class, [ + 'label' => 'bitbag_sylius_cms_plugin.ui.taxon', + 'choice_value' => 'code', + 'resource' => 'sylius.taxon', + ]) + ; + + $builder->get(self::TYPE)->addModelTransformer( + new ReversedTransformer(new ResourceToIdentifierTransformer($this->taxonRepository, 'code')), + ); + } + + public function getBlockPrefix(): string + { + return 'bitbag_sylius_cms_plugin_content_elements_'.self::TYPE; + } +} diff --git a/src/Form/Type/ContentElements/SingleMediaContentElementType.php b/src/Form/Type/ContentElements/SingleMediaContentElementType.php index a4bac0ece..3aed84a8a 100644 --- a/src/Form/Type/ContentElements/SingleMediaContentElementType.php +++ b/src/Form/Type/ContentElements/SingleMediaContentElementType.php @@ -12,15 +12,17 @@ namespace BitBag\SyliusCmsPlugin\Form\Type\ContentElements; use BitBag\SyliusCmsPlugin\Form\Type\MediaAutocompleteChoiceType; +use Sylius\Bundle\ResourceBundle\Form\DataTransformer\ResourceToIdentifierTransformer; +use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\DataTransformerInterface; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\ReversedTransformer; final class SingleMediaContentElementType extends AbstractType { public const TYPE = 'single_media'; - public function __construct(private DataTransformerInterface $singleMediaToCodeTransformer) + public function __construct(private RepositoryInterface $mediaRepository) { } @@ -32,7 +34,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ]) ; - $builder->get(self::TYPE)->addModelTransformer($this->singleMediaToCodeTransformer); + $builder->get(self::TYPE)->addModelTransformer( + new ReversedTransformer(new ResourceToIdentifierTransformer($this->mediaRepository, 'code')), + ); } public function getBlockPrefix(): string diff --git a/src/Resources/config/services/form.xml b/src/Resources/config/services/form.xml index 1536cc5f2..b1de3374c 100644 --- a/src/Resources/config/services/form.xml +++ b/src/Resources/config/services/form.xml @@ -7,6 +7,7 @@ BitBag\SyliusCmsPlugin\Form\Type\ContentElements\MultipleMediaContentElementType::TYPE BitBag\SyliusCmsPlugin\Form\Type\ContentElements\HeadingContentElementType::TYPE BitBag\SyliusCmsPlugin\Form\Type\ContentElements\ProductsCarouselContentElementType::TYPE + BitBag\SyliusCmsPlugin\Form\Type\ContentElements\ProductsCarouselByTaxonContentElementType::TYPE @@ -90,7 +91,7 @@ - + @@ -111,8 +112,10 @@ - - + + + + From 5f2c35e8cb7929f611bf13924004f4fc52deb0e9 Mon Sep 17 00:00:00 2001 From: jkindly Date: Mon, 8 Jul 2024 08:28:56 +0200 Subject: [PATCH 07/36] OP-326: Taxons list element type --- .../TaxonsListContentElementType.php | 34 +++++++++++++++++++ src/Resources/config/services/form.xml | 6 ++++ 2 files changed, 40 insertions(+) create mode 100644 src/Form/Type/ContentElements/TaxonsListContentElementType.php diff --git a/src/Form/Type/ContentElements/TaxonsListContentElementType.php b/src/Form/Type/ContentElements/TaxonsListContentElementType.php new file mode 100644 index 000000000..5038a1802 --- /dev/null +++ b/src/Form/Type/ContentElements/TaxonsListContentElementType.php @@ -0,0 +1,34 @@ +add(self::TYPE, ForTaxonsScopeConfigurationType::class, [ + 'label' => false, + ]) + ; + } + + public function getBlockPrefix(): string + { + return 'bitbag_sylius_cms_plugin_content_elements_'.self::TYPE; + } +} diff --git a/src/Resources/config/services/form.xml b/src/Resources/config/services/form.xml index b1de3374c..eb467dc4d 100644 --- a/src/Resources/config/services/form.xml +++ b/src/Resources/config/services/form.xml @@ -8,6 +8,7 @@ BitBag\SyliusCmsPlugin\Form\Type\ContentElements\HeadingContentElementType::TYPE BitBag\SyliusCmsPlugin\Form\Type\ContentElements\ProductsCarouselContentElementType::TYPE BitBag\SyliusCmsPlugin\Form\Type\ContentElements\ProductsCarouselByTaxonContentElementType::TYPE + BitBag\SyliusCmsPlugin\Form\Type\ContentElements\TaxonsListContentElementType::TYPE @@ -118,6 +119,11 @@ + + + + + From b794f8b802aeb425fc227cfb53ef898b5af1dcf6 Mon Sep 17 00:00:00 2001 From: jkindly Date: Mon, 8 Jul 2024 11:09:01 +0200 Subject: [PATCH 08/36] OP-326: PHPStan anc ECS fixes --- src/Form/Type/ContentElements/HeadingContentElementType.php | 4 ++-- .../Type/ContentElements/MultipleMediaContentElementType.php | 5 ++--- .../ProductsCarouselByTaxonContentElementType.php | 2 +- .../ContentElements/ProductsCarouselContentElementType.php | 2 +- .../Type/ContentElements/SingleMediaContentElementType.php | 5 ++--- .../Type/ContentElements/TaxonsListContentElementType.php | 2 +- src/Form/Type/ContentElements/TextareaContentElementType.php | 4 ++-- src/Repository/MediaRepository.php | 2 +- 8 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/Form/Type/ContentElements/HeadingContentElementType.php b/src/Form/Type/ContentElements/HeadingContentElementType.php index 7ffb4687b..49d2ef3f5 100644 --- a/src/Form/Type/ContentElements/HeadingContentElementType.php +++ b/src/Form/Type/ContentElements/HeadingContentElementType.php @@ -36,13 +36,13 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'empty_data' => 'h1', ]) ->add(self::TYPE, TextType::class, [ - 'label' => 'bitbag_sylius_cms_plugin.ui.content_elements.type.'.self::TYPE, + 'label' => 'bitbag_sylius_cms_plugin.ui.content_elements.type.' . self::TYPE, ]) ; } public function getBlockPrefix(): string { - return 'bitbag_sylius_cms_plugin_content_elements_'.self::TYPE; + return 'bitbag_sylius_cms_plugin_content_elements_' . self::TYPE; } } diff --git a/src/Form/Type/ContentElements/MultipleMediaContentElementType.php b/src/Form/Type/ContentElements/MultipleMediaContentElementType.php index 818f02259..4406258f6 100644 --- a/src/Form/Type/ContentElements/MultipleMediaContentElementType.php +++ b/src/Form/Type/ContentElements/MultipleMediaContentElementType.php @@ -6,7 +6,6 @@ * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career */ - declare(strict_types=1); namespace BitBag\SyliusCmsPlugin\Form\Type\ContentElements; @@ -28,7 +27,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add(self::TYPE, MediaAutocompleteChoiceType::class, [ - 'label' => 'bitbag_sylius_cms_plugin.ui.content_elements.type.'.self::TYPE, + 'label' => 'bitbag_sylius_cms_plugin.ui.content_elements.type.' . self::TYPE, 'multiple' => true, ]) ; @@ -38,6 +37,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function getBlockPrefix(): string { - return 'bitbag_sylius_cms_plugin_content_elements_'.self::TYPE; + return 'bitbag_sylius_cms_plugin_content_elements_' . self::TYPE; } } diff --git a/src/Form/Type/ContentElements/ProductsCarouselByTaxonContentElementType.php b/src/Form/Type/ContentElements/ProductsCarouselByTaxonContentElementType.php index 94f4c2339..aed6a44a4 100644 --- a/src/Form/Type/ContentElements/ProductsCarouselByTaxonContentElementType.php +++ b/src/Form/Type/ContentElements/ProductsCarouselByTaxonContentElementType.php @@ -42,6 +42,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function getBlockPrefix(): string { - return 'bitbag_sylius_cms_plugin_content_elements_'.self::TYPE; + return 'bitbag_sylius_cms_plugin_content_elements_' . self::TYPE; } } diff --git a/src/Form/Type/ContentElements/ProductsCarouselContentElementType.php b/src/Form/Type/ContentElements/ProductsCarouselContentElementType.php index 46b236714..990c54c95 100644 --- a/src/Form/Type/ContentElements/ProductsCarouselContentElementType.php +++ b/src/Form/Type/ContentElements/ProductsCarouselContentElementType.php @@ -29,6 +29,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function getBlockPrefix(): string { - return 'bitbag_sylius_cms_plugin_content_elements_'.self::TYPE; + return 'bitbag_sylius_cms_plugin_content_elements_' . self::TYPE; } } diff --git a/src/Form/Type/ContentElements/SingleMediaContentElementType.php b/src/Form/Type/ContentElements/SingleMediaContentElementType.php index 3aed84a8a..e761c4a7f 100644 --- a/src/Form/Type/ContentElements/SingleMediaContentElementType.php +++ b/src/Form/Type/ContentElements/SingleMediaContentElementType.php @@ -6,7 +6,6 @@ * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career */ - declare(strict_types=1); namespace BitBag\SyliusCmsPlugin\Form\Type\ContentElements; @@ -30,7 +29,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add(self::TYPE, MediaAutocompleteChoiceType::class, [ - 'label' => 'bitbag_sylius_cms_plugin.ui.content_elements.type.'.self::TYPE, + 'label' => 'bitbag_sylius_cms_plugin.ui.content_elements.type.' . self::TYPE, ]) ; @@ -41,6 +40,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function getBlockPrefix(): string { - return 'bitbag_sylius_cms_plugin_content_elements_'.self::TYPE; + return 'bitbag_sylius_cms_plugin_content_elements_' . self::TYPE; } } diff --git a/src/Form/Type/ContentElements/TaxonsListContentElementType.php b/src/Form/Type/ContentElements/TaxonsListContentElementType.php index 5038a1802..d3da4df7f 100644 --- a/src/Form/Type/ContentElements/TaxonsListContentElementType.php +++ b/src/Form/Type/ContentElements/TaxonsListContentElementType.php @@ -29,6 +29,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function getBlockPrefix(): string { - return 'bitbag_sylius_cms_plugin_content_elements_'.self::TYPE; + return 'bitbag_sylius_cms_plugin_content_elements_' . self::TYPE; } } diff --git a/src/Form/Type/ContentElements/TextareaContentElementType.php b/src/Form/Type/ContentElements/TextareaContentElementType.php index 94a05d47f..7191dcffb 100644 --- a/src/Form/Type/ContentElements/TextareaContentElementType.php +++ b/src/Form/Type/ContentElements/TextareaContentElementType.php @@ -22,13 +22,13 @@ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add(self::TYPE, WysiwygType::class, [ - 'label' => 'bitbag_sylius_cms_plugin.ui.content_elements.type.'.self::TYPE, + 'label' => 'bitbag_sylius_cms_plugin.ui.content_elements.type.' . self::TYPE, ]) ; } public function getBlockPrefix(): string { - return 'bitbag_sylius_cms_plugin_content_elements_'.self::TYPE; + return 'bitbag_sylius_cms_plugin_content_elements_' . self::TYPE; } } diff --git a/src/Repository/MediaRepository.php b/src/Repository/MediaRepository.php index 3aaacb24f..bb0223551 100755 --- a/src/Repository/MediaRepository.php +++ b/src/Repository/MediaRepository.php @@ -93,6 +93,6 @@ public function findByNamePart(string $phrase): array ->setParameter('name', '%' . $phrase . '%') ->getQuery() ->getResult() - ; + ; } } From 5b9850df277112eedad9c51ef9312aa6e4e16a49 Mon Sep 17 00:00:00 2001 From: jkindly Date: Mon, 8 Jul 2024 11:22:49 +0200 Subject: [PATCH 09/36] OP-326: Translations --- src/Resources/translations/messages.cs.yml | 8 ++++++++ src/Resources/translations/messages.cs_CZ.yml | 8 ++++++++ src/Resources/translations/messages.de.yml | 8 ++++++++ src/Resources/translations/messages.en.yml | 8 ++++++++ src/Resources/translations/messages.es.yml | 8 ++++++++ src/Resources/translations/messages.fr.yml | 10 +++++++++- src/Resources/translations/messages.hr.yml | 8 ++++++++ src/Resources/translations/messages.lt.yml | 8 ++++++++ src/Resources/translations/messages.nl.yml | 8 ++++++++ src/Resources/translations/messages.pl.yml | 8 ++++++++ src/Resources/translations/messages.ru.yml | 8 ++++++++ src/Resources/translations/messages.sk.yml | 8 ++++++++ src/Resources/translations/messages.uk.yml | 8 ++++++++ 13 files changed, 105 insertions(+), 1 deletion(-) diff --git a/src/Resources/translations/messages.cs.yml b/src/Resources/translations/messages.cs.yml index 322db45b3..a055354ba 100755 --- a/src/Resources/translations/messages.cs.yml +++ b/src/Resources/translations/messages.cs.yml @@ -10,6 +10,14 @@ bitbag_sylius_cms_plugin: title: Obsahové prvky type: textarea: Textarea + single_media: Jediné médium + multiple_media: Více médií + heading: Nadpis + products_carousel: Produkty v karuselu + products_carousel_by_taxon: Produkty v karuselu podle taxonu + taxons_list: Seznam taxonů + heading_type: Typ nadpisu + taxon: Taxon cms: content_management: Obsahový management cms: Obsahový management diff --git a/src/Resources/translations/messages.cs_CZ.yml b/src/Resources/translations/messages.cs_CZ.yml index 322db45b3..a055354ba 100755 --- a/src/Resources/translations/messages.cs_CZ.yml +++ b/src/Resources/translations/messages.cs_CZ.yml @@ -10,6 +10,14 @@ bitbag_sylius_cms_plugin: title: Obsahové prvky type: textarea: Textarea + single_media: Jediné médium + multiple_media: Více médií + heading: Nadpis + products_carousel: Produkty v karuselu + products_carousel_by_taxon: Produkty v karuselu podle taxonu + taxons_list: Seznam taxonů + heading_type: Typ nadpisu + taxon: Taxon cms: content_management: Obsahový management cms: Obsahový management diff --git a/src/Resources/translations/messages.de.yml b/src/Resources/translations/messages.de.yml index 0cc146f7d..70db241fb 100755 --- a/src/Resources/translations/messages.de.yml +++ b/src/Resources/translations/messages.de.yml @@ -62,3 +62,11 @@ bitbag_sylius_cms_plugin: title: Inhalts-Elemente type: textarea: Textarea + single_media: Einzelmedium + multiple_media: Mehrere Medien + heading: Überschrift + products_carousel: Produkte im Karussell + products_carousel_by_taxon: Produkte im Karussell nach Taxon + taxons_list: Taxon-Liste + heading_type: Überschrift-Typ + taxon: Taxon diff --git a/src/Resources/translations/messages.en.yml b/src/Resources/translations/messages.en.yml index 1b7a1b43e..d3c14379d 100755 --- a/src/Resources/translations/messages.en.yml +++ b/src/Resources/translations/messages.en.yml @@ -68,4 +68,12 @@ bitbag_sylius_cms_plugin: title: Content elements type: textarea: Textarea + single_media: Single media + multiple_media: Multiple media + heading: Heading + products_carousel: Products carousel + products_carousel_by_taxon: Products carousel by Taxon + taxons_list: Taxons list + heading_type: Heading type + taxon: Taxon seo: SEO diff --git a/src/Resources/translations/messages.es.yml b/src/Resources/translations/messages.es.yml index 023df298e..d1ae38829 100755 --- a/src/Resources/translations/messages.es.yml +++ b/src/Resources/translations/messages.es.yml @@ -43,3 +43,11 @@ bitbag_sylius_cms_plugin: title: Elementos de contenido type: textarea: Textarea + single_media: Medio único + multiple_media: Múltiples medios + heading: Encabezado + products_carousel: Productos en carrusel + products_carousel_by_taxon: Productos en carrusel por taxón + taxons_list: Lista de taxones + heading_type: Tipo de encabezado + taxon: Taxón diff --git a/src/Resources/translations/messages.fr.yml b/src/Resources/translations/messages.fr.yml index eb09db1df..35946e2fe 100755 --- a/src/Resources/translations/messages.fr.yml +++ b/src/Resources/translations/messages.fr.yml @@ -60,4 +60,12 @@ bitbag_sylius_cms_plugin: content_elements: title: Éléments de contenu type: - textarea: Textarea de + textarea: Textarea + single_media: Média unique + multiple_media: Médias multiples + heading: En-tête + products_carousel: Produits en carrousel + products_carousel_by_taxon: Produits en carrousel par taxon + taxons_list: Liste de taxons + heading_type: Type d'en-tête + taxon: Taxon diff --git a/src/Resources/translations/messages.hr.yml b/src/Resources/translations/messages.hr.yml index c54e36769..a2cf5ce51 100755 --- a/src/Resources/translations/messages.hr.yml +++ b/src/Resources/translations/messages.hr.yml @@ -43,3 +43,11 @@ bitbag_sylius_cms_plugin: title: Elementi sadržaja type: textarea: Textarea + single_media: Jedan medij + multiple_media: Više medija + heading: Naslov + products_carousel: Proizvodi u karijeslu + products_carousel_by_taxon: Proizvodi u karijeslu po taksonu + taxons_list: Lista taksona + heading_type: Tip naslova + taxon: Takson diff --git a/src/Resources/translations/messages.lt.yml b/src/Resources/translations/messages.lt.yml index 470f8be25..c40292d45 100644 --- a/src/Resources/translations/messages.lt.yml +++ b/src/Resources/translations/messages.lt.yml @@ -60,3 +60,11 @@ bitbag_sylius_cms_plugin: title: Turinio elementai type: textarea: Textarea + single_media: Vienas medijos elementas + multiple_media: Kelios medijos elementai + heading: Antraštė + products_carousel: Produktų karuselė + products_carousel_by_taxon: Produktų karuselė pagal taksoną + taxons_list: Taksonų sąrašas + heading_type: Antraštės tipas + taxon: Taksonas diff --git a/src/Resources/translations/messages.nl.yml b/src/Resources/translations/messages.nl.yml index 4ac2cd007..e04141552 100755 --- a/src/Resources/translations/messages.nl.yml +++ b/src/Resources/translations/messages.nl.yml @@ -42,3 +42,11 @@ bitbag_sylius_cms_plugin: title: Inhoudselementen type: textarea: Textarea + single_media: Enkel medium + multiple_media: Meerdere media + heading: Kop + products_carousel: Producten in carrousel + products_carousel_by_taxon: Producten in carrousel per taxon + taxons_list: Taxon lijst + heading_type: Kop type + taxon: Taxon diff --git a/src/Resources/translations/messages.pl.yml b/src/Resources/translations/messages.pl.yml index e021b71c9..c3354bdc1 100755 --- a/src/Resources/translations/messages.pl.yml +++ b/src/Resources/translations/messages.pl.yml @@ -47,3 +47,11 @@ bitbag_sylius_cms_plugin: title: Elementy treści type: textarea: Textarea + single_media: Pojedyncze media + multiple_media: Wiele mediów + heading: Nagłówek + products_carousel: Karuzela produktów + products_carousel_by_taxon: Karuzela produktów według taksonomii + taxons_list: Lista taksonomii + heading_type: Typ nagłówka + taxon: Taksonomia diff --git a/src/Resources/translations/messages.ru.yml b/src/Resources/translations/messages.ru.yml index 7a03cfd74..b299e7c40 100755 --- a/src/Resources/translations/messages.ru.yml +++ b/src/Resources/translations/messages.ru.yml @@ -60,3 +60,11 @@ bitbag_sylius_cms_plugin: title: Элементы контента type: textarea: Textarea + single_media: Одиночный медиа + multiple_media: Несколько медиа + heading: Заголовок + products_carousel: Продукты в карусели + products_carousel_by_taxon: Продукты в карусели по таксону + taxons_list: Список таксонов + heading_type: Тип заголовка + taxon: Таксон diff --git a/src/Resources/translations/messages.sk.yml b/src/Resources/translations/messages.sk.yml index a949b90ed..fa1b8fb6d 100644 --- a/src/Resources/translations/messages.sk.yml +++ b/src/Resources/translations/messages.sk.yml @@ -61,3 +61,11 @@ bitbag_sylius_cms_plugin: title: Obsahové prvky type: textarea: Textarea + single_media: Jedno médium + multiple_media: Viacero médií + heading: Nadpis + products_carousel: Produkty v karuseli + products_carousel_by_taxon: Produkty v karuseli podľa taxónu + taxons_list: Zoznam taxónov + heading_type: Typ nadpisu + taxon: Taxón diff --git a/src/Resources/translations/messages.uk.yml b/src/Resources/translations/messages.uk.yml index 1f6825c8d..626638422 100755 --- a/src/Resources/translations/messages.uk.yml +++ b/src/Resources/translations/messages.uk.yml @@ -60,3 +60,11 @@ bitbag_sylius_cms_plugin: title: Елементи контенту type: textarea: Textarea + single_media: Одиночне медіа + multiple_media: Кілька медіа + heading: Заголовок + products_carousel: Продукти в каруселі + products_carousel_by_taxon: Продукти в каруселі за таксоном + taxons_list: Список таксонів + heading_type: Тип заголовка + taxon: Таксон From f74e4e12f5388d45b368d001a7cd1043d1d91504 Mon Sep 17 00:00:00 2001 From: jkindly Date: Mon, 8 Jul 2024 12:17:58 +0200 Subject: [PATCH 10/36] OP-326: Behat single media --- features/admin/adding_block.feature | 2 +- features/admin/adding_page.feature | 13 +++++- tests/Behat/Context/Setup/MediaContext.php | 12 ++++++ tests/Behat/Context/Ui/Admin/PageContext.php | 8 ++++ tests/Behat/Page/Admin/Page/CreatePage.php | 40 +++++++++++++++++++ .../Page/Admin/Page/CreatePageInterface.php | 2 + 6 files changed, 75 insertions(+), 2 deletions(-) diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index 773dbc47a..c5fcead60 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -27,7 +27,7 @@ Feature: Adding blocks Then I should be notified that the block has been created @ui @javascript - Scenario: Adding block with content element + Scenario: Adding block with textarea content element When I go to the create block page And I fill the code with "intro" And I fill the name with "Intro" diff --git a/features/admin/adding_page.feature b/features/admin/adding_page.feature index 3624fc93c..c063b2af4 100644 --- a/features/admin/adding_page.feature +++ b/features/admin/adding_page.feature @@ -68,7 +68,7 @@ Feature: Adding new page Then I should be notified that the page has been created @ui @javascript - Scenario: Adding page with content element + Scenario: Adding page with textarea content element When I go to the create page page And I fill the code with "my_page" And I fill the slug with "my_page" @@ -76,3 +76,14 @@ Feature: Adding new page And I add a textarea content element with "Welcome to our store" content And I add it Then I should be notified that the page has been created + + @ui @javascript + Scenario: Adding page with single media content element + Given there is an existing media with "image_1" code and name "Image 1" + 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 add a single media content element with name "Image 1" + And I add it + Then I should be notified that the page has been created diff --git a/tests/Behat/Context/Setup/MediaContext.php b/tests/Behat/Context/Setup/MediaContext.php index 3de6ea4a5..c70b3356e 100755 --- a/tests/Behat/Context/Setup/MediaContext.php +++ b/tests/Behat/Context/Setup/MediaContext.php @@ -43,6 +43,18 @@ public function thereIsAnExistingMediaWithCode(string $code): void $this->saveMedia($media); } + /** + * @Given there is an existing media with :code code and name :name + */ + public function thereIsAnExistingMediaWithCodeAndName(string $code, string $name): void + { + $media = $this->createMedia($code, $name); + + $this->uploadFile($media, 'aston_martin_db_11.jpg'); + + $this->saveMedia($media); + } + /** * @Given there is an existing :type media with :code code */ diff --git a/tests/Behat/Context/Ui/Admin/PageContext.php b/tests/Behat/Context/Ui/Admin/PageContext.php index 3843acf46..46257dc8c 100755 --- a/tests/Behat/Context/Ui/Admin/PageContext.php +++ b/tests/Behat/Context/Ui/Admin/PageContext.php @@ -193,6 +193,14 @@ public function iAddATextareaContentElementWithContent(string $content): void $this->resolveCurrentPage()->addTextareaContentElementWithContent($content); } + /** + * @When I add a single media content element with name :name + */ + public function iAddASingleMediaContentElementWithName(string $name): void + { + $this->resolveCurrentPage()->addSingleMediaContentElementWithName($name); + } + /** * @When I add it * @When I try to add it diff --git a/tests/Behat/Page/Admin/Page/CreatePage.php b/tests/Behat/Page/Admin/Page/CreatePage.php index aca17768d..f19b340e1 100755 --- a/tests/Behat/Page/Admin/Page/CreatePage.php +++ b/tests/Behat/Page/Admin/Page/CreatePage.php @@ -106,6 +106,43 @@ public function addTextareaContentElementWithContent(string $content): void $textarea->setValue($content); } + /** + * @throws ElementNotFoundException + */ + public function addSingleMediaContentElementWithName(string $name): void + { + Assert::isInstanceOf($this->getDriver(), ChromeDriver::class); + + $addButton = $this->getElement('content_elements_add_button'); + $addButton->click(); + + $addButton->waitFor(3, function (): bool { + return $this->hasElement('content_elements_select_type'); + }); + + $select = $this->getElement('content_elements_select_type'); + $select->selectOption('Single media'); + + $select->waitFor(3, function (): bool { + return $this->hasElement('content_elements_single_media_dropdown'); + }); + + $dropdown = $this->getElement('content_elements_single_media_dropdown'); + $dropdown->click(); + + $dropdown->waitFor(10, function () use ($name): bool { + return $this->hasElement('content_elements_single_media_dropdown_item', [ + '%item%' => $name, + ]); + }); + + $item = $this->getElement('content_elements_single_media_dropdown_item', [ + '%item%' => $name, + ]); + + $item->click(); + } + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ @@ -113,7 +150,10 @@ protected function getDefinedElements(): array '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%")', ]); } } diff --git a/tests/Behat/Page/Admin/Page/CreatePageInterface.php b/tests/Behat/Page/Admin/Page/CreatePageInterface.php index 0750ba454..fae16c4c1 100755 --- a/tests/Behat/Page/Admin/Page/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Page/CreatePageInterface.php @@ -36,4 +36,6 @@ public function fillContent(string $content): void; public function associateCollections(array $collectionsNames): void; public function addTextareaContentElementWithContent(string $content): void; + + public function addSingleMediaContentElementWithName(string $name): void; } From 307977041fd3ce5d6af0160ac2d76327f3e29998 Mon Sep 17 00:00:00 2001 From: jkindly Date: Mon, 8 Jul 2024 13:11:31 +0200 Subject: [PATCH 11/36] OP-326: Behat single media --- features/admin/adding_block.feature | 14 +++++ features/admin/adding_page.feature | 4 ++ tests/Behat/Context/Ui/Admin/BlockContext.php | 40 +++++++++++--- tests/Behat/Context/Ui/Admin/PageContext.php | 16 ++++++ tests/Behat/Helpers/ContentElementHelper.php | 23 ++++++++ tests/Behat/Page/Admin/Block/CreatePage.php | 55 ++++++++++++++++++- .../Page/Admin/Block/CreatePageInterface.php | 6 ++ tests/Behat/Page/Admin/Page/CreatePage.php | 43 +++++++++------ .../Page/Admin/Page/CreatePageInterface.php | 4 ++ 9 files changed, 177 insertions(+), 28 deletions(-) create mode 100644 tests/Behat/Helpers/ContentElementHelper.php diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index c5fcead60..3f84c33db 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -31,10 +31,24 @@ Feature: Adding blocks When I go to the create block page And I fill the code with "intro" And I fill the name with "Intro" + And I click on Add button in Content elements section + And I select "Textarea" content element And I add a textarea content element with "Welcome to our store" content And I add it Then I should be notified that the block has been created + @ui @javascript + Scenario: Adding block with single media content element + Given there is an existing media with "image_1" code and name "Image 1" + When I go to the create block page + And I fill the code with "intro" + And I fill the name with "Intro" + And I click on Add button in Content elements section + And I select "Single media" content element + And I add a single media content element with name "Image 1" + And I add it + Then I should be notified that the block has been created + @ui Scenario: Trying to add block with existing code Given there is an existing block with "homepage_image" code diff --git a/features/admin/adding_page.feature b/features/admin/adding_page.feature index c063b2af4..9a9f2750f 100644 --- a/features/admin/adding_page.feature +++ b/features/admin/adding_page.feature @@ -73,6 +73,8 @@ Feature: Adding new 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 click on Add button in Content elements section + And I select "Textarea" content element And I add a textarea content element with "Welcome to our store" content And I add it Then I should be notified that the page has been created @@ -84,6 +86,8 @@ Feature: Adding new 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 click on Add button in Content elements section + And I select "Single media" content element And I add a single media content element with name "Image 1" And I add it Then I should be notified that the page has been created diff --git a/tests/Behat/Context/Ui/Admin/BlockContext.php b/tests/Behat/Context/Ui/Admin/BlockContext.php index 435d11b43..eac6658ff 100755 --- a/tests/Behat/Context/Ui/Admin/BlockContext.php +++ b/tests/Behat/Context/Ui/Admin/BlockContext.php @@ -131,6 +131,30 @@ public function iFillTheNameIfItIsEmpty(string $name): void $this->resolveCurrentPage()->fillNameIfItIsEmpty($name); } + /** + * @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); + } + + /** + * @When I add a textarea content element with :content content + */ + public function iAddATextareaContentElementWithContent(string $content): void + { + $this->resolveCurrentPage()->addTextareaContentElementWithContent($content); + } + /** * @When I change textarea content element value to :value */ @@ -139,6 +163,14 @@ public function iChangeTextareaContentElementValueTo(string $value): void $this->resolveCurrentPage()->changeTextareaContentElementValue($value); } + /** + * @When I add a single media content element with name :name + */ + public function iAddASingleMediaContentElementWithName(string $name): void + { + $this->resolveCurrentPage()->addSingleMediaContentElementWithName($name); + } + /** * @Then I should see :content in the textarea content element */ @@ -179,14 +211,6 @@ public function iAddAndCollectionsToIt(string ...$collectionsNames): void $this->resolveCurrentPage()->associateCollections($collectionsNames); } - /** - * @When I add a textarea content element with :content content - */ - public function iAddATextareaContentElementWithContent(string $content): void - { - $this->resolveCurrentPage()->addTextareaContentElementWithContent($content); - } - /** * @When I add it * @When I try to add it diff --git a/tests/Behat/Context/Ui/Admin/PageContext.php b/tests/Behat/Context/Ui/Admin/PageContext.php index 46257dc8c..a220a8372 100755 --- a/tests/Behat/Context/Ui/Admin/PageContext.php +++ b/tests/Behat/Context/Ui/Admin/PageContext.php @@ -185,6 +185,22 @@ public function iAddAndCollectionsToIt(string ...$collectionsNames): void $this->resolveCurrentPage()->associateCollections($collectionsNames); } + /** + * @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); + } + /** * @When I add a textarea content element with :content content */ diff --git a/tests/Behat/Helpers/ContentElementHelper.php b/tests/Behat/Helpers/ContentElementHelper.php new file mode 100644 index 000000000..a3381a90b --- /dev/null +++ b/tests/Behat/Helpers/ContentElementHelper.php @@ -0,0 +1,23 @@ + 'content_elements_textarea', + 'Single media' => 'content_elements_single_media_dropdown', + default => throw new \InvalidArgumentException(sprintf('Content element with name "%s" does not exist.', $contentElement)), + }; + } +} diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index aa101218f..e3fc2241b 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -14,6 +14,7 @@ use DMore\ChromeDriver\ChromeDriver; use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsErrorTrait; +use Tests\BitBag\SyliusCmsPlugin\Behat\Helpers\ContentElementHelper; use Webmozart\Assert\Assert; class CreatePage extends BaseCreatePage implements CreatePageInterface @@ -82,28 +83,76 @@ public function associateCollections(array $collectionsNames): void /** * @throws ElementNotFoundException */ - public function addTextareaContentElementWithContent(string $content): void + public function clickOnAddContentElementButton(): void { Assert::isInstanceOf($this->getDriver(), ChromeDriver::class); $addButton = $this->getElement('content_elements_add_button'); $addButton->click(); - $addButton->waitFor(3, function (): bool { - return $this->hasElement('content_elements_textarea'); + $addButton->waitFor(2, function (): bool { + return $this->hasElement('content_elements_select_type'); + }); + } + + /** + * @throws ElementNotFoundException + */ + public function selectContentElement(string $contentElement): void + { + Assert::isInstanceOf($this->getDriver(), ChromeDriver::class); + + $select = $this->getElement('content_elements_select_type'); + $select->selectOption($contentElement); + $select->waitFor(3, function () use ($contentElement): bool { + return $this->hasElement( + ContentElementHelper::getDefinedElementThatShouldAppearAfterSelectContentElement($contentElement) + ); }); + } + + /** + * @throws ElementNotFoundException + */ + public function addTextareaContentElementWithContent(string $content): void + { + Assert::isInstanceOf($this->getDriver(), ChromeDriver::class); $textarea = $this->getElement('content_elements_textarea'); $textarea->setValue($content); } + /** + * @throws ElementNotFoundException + */ + public function addSingleMediaContentElementWithName(string $name): void + { + $dropdown = $this->getElement('content_elements_single_media_dropdown'); + $dropdown->click(); + + $dropdown->waitFor(10, function () use ($name): bool { + return $this->hasElement('content_elements_single_media_dropdown_item', [ + '%item%' => $name, + ]); + }); + + $item = $this->getElement('content_elements_single_media_dropdown_item', [ + '%item%' => $name, + ]); + + $item->click(); + } + 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%")', ]); } } diff --git a/tests/Behat/Page/Admin/Block/CreatePageInterface.php b/tests/Behat/Page/Admin/Block/CreatePageInterface.php index b96ffe4c4..646988826 100755 --- a/tests/Behat/Page/Admin/Block/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Block/CreatePageInterface.php @@ -29,7 +29,13 @@ public function fillContent(string $content): void; public function associateCollections(array $collectionsNames): void; + public function clickOnAddContentElementButton(): void; + + public function selectContentElement(string $contentElement): void; + public function addTextareaContentElementWithContent(string $content): void; + public function addSingleMediaContentElementWithName(string $name): void; + public function disable(): void; } diff --git a/tests/Behat/Page/Admin/Page/CreatePage.php b/tests/Behat/Page/Admin/Page/CreatePage.php index f19b340e1..62004e527 100755 --- a/tests/Behat/Page/Admin/Page/CreatePage.php +++ b/tests/Behat/Page/Admin/Page/CreatePage.php @@ -15,6 +15,7 @@ use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; use Sylius\Behat\Service\SlugGenerationHelper; use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsErrorTrait; +use Tests\BitBag\SyliusCmsPlugin\Behat\Helpers\ContentElementHelper; use Tests\BitBag\SyliusCmsPlugin\Behat\Service\FormHelper; use Webmozart\Assert\Assert; @@ -91,42 +92,50 @@ public function associateCollections(array $collectionsNames): void /** * @throws ElementNotFoundException */ - public function addTextareaContentElementWithContent(string $content): void + public function clickOnAddContentElementButton(): void { Assert::isInstanceOf($this->getDriver(), ChromeDriver::class); $addButton = $this->getElement('content_elements_add_button'); $addButton->click(); - $addButton->waitFor(3, function (): bool { - return $this->hasElement('content_elements_textarea'); + $addButton->waitFor(2, function (): bool { + return $this->hasElement('content_elements_select_type'); }); - - $textarea = $this->getElement('content_elements_textarea'); - $textarea->setValue($content); } /** * @throws ElementNotFoundException */ - public function addSingleMediaContentElementWithName(string $name): void + public function selectContentElement(string $contentElement): void { Assert::isInstanceOf($this->getDriver(), ChromeDriver::class); - $addButton = $this->getElement('content_elements_add_button'); - $addButton->click(); - - $addButton->waitFor(3, function (): bool { - return $this->hasElement('content_elements_select_type'); + $select = $this->getElement('content_elements_select_type'); + $select->selectOption($contentElement); + $select->waitFor(3, function () use ($contentElement): bool { + return $this->hasElement( + ContentElementHelper::getDefinedElementThatShouldAppearAfterSelectContentElement($contentElement) + ); }); + } - $select = $this->getElement('content_elements_select_type'); - $select->selectOption('Single media'); + /** + * @throws ElementNotFoundException + */ + public function addTextareaContentElementWithContent(string $content): void + { + Assert::isInstanceOf($this->getDriver(), ChromeDriver::class); - $select->waitFor(3, function (): bool { - return $this->hasElement('content_elements_single_media_dropdown'); - }); + $textarea = $this->getElement('content_elements_textarea'); + $textarea->setValue($content); + } + /** + * @throws ElementNotFoundException + */ + public function addSingleMediaContentElementWithName(string $name): void + { $dropdown = $this->getElement('content_elements_single_media_dropdown'); $dropdown->click(); diff --git a/tests/Behat/Page/Admin/Page/CreatePageInterface.php b/tests/Behat/Page/Admin/Page/CreatePageInterface.php index fae16c4c1..684446a5d 100755 --- a/tests/Behat/Page/Admin/Page/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Page/CreatePageInterface.php @@ -35,6 +35,10 @@ public function fillContent(string $content): void; public function associateCollections(array $collectionsNames): void; + public function clickOnAddContentElementButton(): void; + + public function selectContentElement(string $contentElement): void; + public function addTextareaContentElementWithContent(string $content): void; public function addSingleMediaContentElementWithName(string $name): void; From 54f11e0a649127539c54f25306ac30c0ed3ce7ff Mon Sep 17 00:00:00 2001 From: jkindly Date: Mon, 8 Jul 2024 13:14:22 +0200 Subject: [PATCH 12/36] OP-326: ECS fixes --- tests/Behat/Page/Admin/Block/CreatePage.php | 2 +- tests/Behat/Page/Admin/Page/CreatePage.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index e3fc2241b..fca23fecb 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -106,7 +106,7 @@ public function selectContentElement(string $contentElement): void $select->selectOption($contentElement); $select->waitFor(3, function () use ($contentElement): bool { return $this->hasElement( - ContentElementHelper::getDefinedElementThatShouldAppearAfterSelectContentElement($contentElement) + ContentElementHelper::getDefinedElementThatShouldAppearAfterSelectContentElement($contentElement), ); }); } diff --git a/tests/Behat/Page/Admin/Page/CreatePage.php b/tests/Behat/Page/Admin/Page/CreatePage.php index 62004e527..1f7955612 100755 --- a/tests/Behat/Page/Admin/Page/CreatePage.php +++ b/tests/Behat/Page/Admin/Page/CreatePage.php @@ -115,7 +115,7 @@ public function selectContentElement(string $contentElement): void $select->selectOption($contentElement); $select->waitFor(3, function () use ($contentElement): bool { return $this->hasElement( - ContentElementHelper::getDefinedElementThatShouldAppearAfterSelectContentElement($contentElement) + ContentElementHelper::getDefinedElementThatShouldAppearAfterSelectContentElement($contentElement), ); }); } From 6e7fac47ebe5495e3b2de19eb5677bba1de332e7 Mon Sep 17 00:00:00 2001 From: jkindly Date: Mon, 8 Jul 2024 13:34:44 +0200 Subject: [PATCH 13/36] OP-326: setup media --- tests/Behat/Resources/suites/ui/managing_blocks.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Behat/Resources/suites/ui/managing_blocks.yml b/tests/Behat/Resources/suites/ui/managing_blocks.yml index 3a93e317d..00bc5ab75 100755 --- a/tests/Behat/Resources/suites/ui/managing_blocks.yml +++ b/tests/Behat/Resources/suites/ui/managing_blocks.yml @@ -8,6 +8,7 @@ default: - sylius.behat.context.setup.admin_security - bitbag_sylius_cms_plugin.behat.context.setup.block - bitbag_sylius_cms_plugin.behat.context.setup.collection + - bitbag_sylius_cms_plugin.behat.context.setup.media - bitbag_sylius_cms_plugin.behat.context.ui.admin.block filters: From eb610d5f49c6a25194059cc0fa9ad4c8fe5bf0c2 Mon Sep 17 00:00:00 2001 From: jkindly Date: Mon, 8 Jul 2024 13:59:10 +0200 Subject: [PATCH 14/36] OP-326: js fix for blocks --- .../js/bitbag/bitbag-content-configuration.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Resources/assets/admin/js/bitbag/bitbag-content-configuration.js b/src/Resources/assets/admin/js/bitbag/bitbag-content-configuration.js index 66761c5b1..ee45066fa 100644 --- a/src/Resources/assets/admin/js/bitbag/bitbag-content-configuration.js +++ b/src/Resources/assets/admin/js/bitbag/bitbag-content-configuration.js @@ -5,6 +5,15 @@ */ $(document).ready(function() { + let pageElements = '#bitbag_sylius_cms_plugin_page_contentElements'; + let blockElements = '#bitbag_sylius_cms_plugin_block_contentElements'; + + let collectionHolder = $(pageElements).length ? pageElements : blockElements; + + if (!$(collectionHolder).length) { + return; + } + $(document).on('collection-form-add', () => { $('.bitbag-media-autocomplete, .sylius-autocomplete').each((index, element) => { if ($._data($(element).get(0), 'events') === undefined) { @@ -12,14 +21,14 @@ $(document).ready(function() { } }); - $('#bitbag_sylius_cms_plugin_page_contentElements [data-form-collection="item"]').each((index, element) => { + $(`${collectionHolder} [data-form-collection="item"]`).each((index, element) => { $(document).loadContentConfiguration(element); }); }); $.fn.extend({ loadContentConfiguration(target) { - target.querySelector('#bitbag_sylius_cms_plugin_page_contentElements select[name*="type"]').onchange = function () { + target.querySelector(`${collectionHolder} select[name*="type"]`).onchange = function () { const parent = this.parentElement; const newConfig = document.createElement('div'); const selectedOption = this.selectedOptions[0]; @@ -64,11 +73,11 @@ $(document).ready(function() { $(element).autoComplete(); }); - $('#bitbag_sylius_cms_plugin_page_contentElements [data-form-collection="item"]').each((index, element) => { + $(`${collectionHolder} [data-form-collection="item"]`).each((index, element) => { $(document).loadContentConfiguration(element); }); $(document).loadContentConfiguration( - document.querySelector('#bitbag_sylius_cms_plugin_page_contentElements [data-form-collection="item"]') + document.querySelector(`${collectionHolder} [data-form-collection="item"]`) ); }); From 476deb93dd229de0c6a1314f8e311c9696575942 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 9 Jul 2024 09:23:55 +0200 Subject: [PATCH 15/36] OP-326: Behat for heading content element --- features/admin/adding_block.feature | 11 ++++++ features/admin/adding_page.feature | 25 ++++++++++++ tests/Behat/Context/Setup/MediaContext.php | 14 +++++++ tests/Behat/Context/Ui/Admin/BlockContext.php | 8 ++++ tests/Behat/Context/Ui/Admin/PageContext.php | 16 ++++++++ tests/Behat/Helpers/ContentElementHelper.php | 2 + tests/Behat/Page/Admin/Block/CreatePage.php | 14 +++++++ .../Page/Admin/Block/CreatePageInterface.php | 2 + tests/Behat/Page/Admin/Page/CreatePage.php | 39 +++++++++++++++++++ .../Page/Admin/Page/CreatePageInterface.php | 4 ++ 10 files changed, 135 insertions(+) diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index 3f84c33db..3b855635d 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -49,6 +49,17 @@ Feature: Adding blocks And I add it Then I should be notified that the block has been created + @ui @javascript + Scenario: Adding block with heading content element + When I go to the create block page + And I fill the code with "intro" + And I fill the name with "Intro" + And I click on Add button in Content elements section + And I select "Heading" content element + And I add a heading content element with type "H3" and "Welcome to our store" content + And I add it + Then I should be notified that the block has been created + @ui Scenario: Trying to add block with existing code Given there is an existing block with "homepage_image" code diff --git a/features/admin/adding_page.feature b/features/admin/adding_page.feature index 9a9f2750f..0c7e79d3e 100644 --- a/features/admin/adding_page.feature +++ b/features/admin/adding_page.feature @@ -91,3 +91,28 @@ Feature: Adding new page And I add a single media content element with name "Image 1" And I add it Then I should be notified that the page has been created + + @ui @javascript + Scenario: Adding page with multiple media content element + Given there is an existing media with names "Image 1" and "Image 2" + 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 click on Add button in Content elements section + And I select "Multiple media" content element + And I add a multiple media content element with names "Image 1" and "Image 2" + And I add it + Then I should be notified that the page has been created + + @ui @javascript + Scenario: Adding page with heading content element + 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 click on Add button in Content elements section + And I select "Heading" content element + And I add a heading content element with type "H3" and "Welcome to our store" content + And I add it + Then I should be notified that the page has been created diff --git a/tests/Behat/Context/Setup/MediaContext.php b/tests/Behat/Context/Setup/MediaContext.php index c70b3356e..c45e2f38d 100755 --- a/tests/Behat/Context/Setup/MediaContext.php +++ b/tests/Behat/Context/Setup/MediaContext.php @@ -67,6 +67,20 @@ public function thereIsAnExistingTypeMediaWithCode(string $type, string $code): $this->saveMedia($media); } + /** + * @Given there is an existing media with names :firstMediaName and :secondMediaName + */ + public function thereIsExistingMediaWithNames(string ...$mediaNames): void + { + foreach ($mediaNames as $mediaName) { + $media = $this->createMedia(null, $mediaName); + + $this->uploadFile($media, 'aston_martin_db_11.jpg'); + + $this->saveMedia($media); + } + } + private function createMedia( ?string $code = null, ?string $name = null, diff --git a/tests/Behat/Context/Ui/Admin/BlockContext.php b/tests/Behat/Context/Ui/Admin/BlockContext.php index eac6658ff..ef6308fb5 100755 --- a/tests/Behat/Context/Ui/Admin/BlockContext.php +++ b/tests/Behat/Context/Ui/Admin/BlockContext.php @@ -171,6 +171,14 @@ public function iAddASingleMediaContentElementWithName(string $name): void $this->resolveCurrentPage()->addSingleMediaContentElementWithName($name); } + /** + * @When I add a heading content element with type :type and :content content + */ + public function iAddAHeadingContentElementWithTypeAndContent(string $type, string $content): void + { + $this->resolveCurrentPage()->addHeadingContentElementWithTypeAndContent($type, $content); + } + /** * @Then I should see :content in the textarea content element */ diff --git a/tests/Behat/Context/Ui/Admin/PageContext.php b/tests/Behat/Context/Ui/Admin/PageContext.php index a220a8372..850b3c6a5 100755 --- a/tests/Behat/Context/Ui/Admin/PageContext.php +++ b/tests/Behat/Context/Ui/Admin/PageContext.php @@ -217,6 +217,22 @@ public function iAddASingleMediaContentElementWithName(string $name): void $this->resolveCurrentPage()->addSingleMediaContentElementWithName($name); } + /** + * @When I add a multiple media content element with names :firstMediaName and :secondMediaName + */ + public function iAddAMultipleMediaContentElementWithNames(string ...$mediaNames): void + { + $this->resolveCurrentPage()->addMultipleMediaContentElementWithNames($mediaNames); + } + + /** + * @When I add a heading content element with type :type and :content content + */ + public function iAddAHeadingContentElementWithTypeAndContent(string $type, string $content): void + { + $this->resolveCurrentPage()->addHeadingContentElementWithTypeAndContent($type, $content); + } + /** * @When I add it * @When I try to add it diff --git a/tests/Behat/Helpers/ContentElementHelper.php b/tests/Behat/Helpers/ContentElementHelper.php index a3381a90b..9872eca98 100644 --- a/tests/Behat/Helpers/ContentElementHelper.php +++ b/tests/Behat/Helpers/ContentElementHelper.php @@ -17,6 +17,8 @@ public static function getDefinedElementThatShouldAppearAfterSelectContentElemen return match ($contentElement) { 'Textarea' => 'content_elements_textarea', 'Single media' => 'content_elements_single_media_dropdown', + 'Multiple media' => 'content_elements_multiple_media_dropdown', + 'Heading' => 'content_elements_heading', default => throw new \InvalidArgumentException(sprintf('Content element with name "%s" does not exist.', $contentElement)), }; } diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index fca23fecb..3e8812c34 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -143,6 +143,18 @@ public function addSingleMediaContentElementWithName(string $name): void $item->click(); } + /** + * @throws ElementNotFoundException + */ + public function addHeadingContentElementWithTypeAndContent(string $type, string $content): void + { + $heading = $this->getElement('content_elements_heading'); + $heading->selectOption($type); + + $headingContent = $this->getElement('content_elements_heading_content'); + $headingContent->setValue($content); + } + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ @@ -153,6 +165,8 @@ protected function getDefinedElements(): array '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_heading' => '.field > label:contains("Heading type") ~ select', + 'content_elements_heading_content' => '.field > label:contains("Heading") ~ input[type="text"]', ]); } } diff --git a/tests/Behat/Page/Admin/Block/CreatePageInterface.php b/tests/Behat/Page/Admin/Block/CreatePageInterface.php index 646988826..406a707b2 100755 --- a/tests/Behat/Page/Admin/Block/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Block/CreatePageInterface.php @@ -37,5 +37,7 @@ public function addTextareaContentElementWithContent(string $content): void; public function addSingleMediaContentElementWithName(string $name): void; + public function addHeadingContentElementWithTypeAndContent(string $type, string $content): void; + public function disable(): void; } diff --git a/tests/Behat/Page/Admin/Page/CreatePage.php b/tests/Behat/Page/Admin/Page/CreatePage.php index 1f7955612..89db3fb4f 100755 --- a/tests/Behat/Page/Admin/Page/CreatePage.php +++ b/tests/Behat/Page/Admin/Page/CreatePage.php @@ -152,6 +152,41 @@ public function addSingleMediaContentElementWithName(string $name): void $item->click(); } + /** + * @throws ElementNotFoundException + */ + public function addMultipleMediaContentElementWithNames(array $mediaNames): void + { + $dropdown = $this->getElement('content_elements_multiple_media_dropdown'); + $dropdown->click(); + + foreach ($mediaNames as $mediaName) { + $dropdown->waitFor(10, function () use ($mediaName): bool { + return $this->hasElement('content_elements_multiple_media_dropdown_item', [ + '%item%' => $mediaName, + ]); + }); + + $item = $this->getElement('content_elements_multiple_media_dropdown_item', [ + '%item%' => $mediaName, + ]); + + $item->click(); + } + } + + /** + * @throws ElementNotFoundException + */ + public function addHeadingContentElementWithTypeAndContent(string $type, string $content): void + { + $heading = $this->getElement('content_elements_heading'); + $heading->selectOption($type); + + $headingContent = $this->getElement('content_elements_heading_content'); + $headingContent->setValue($content); + } + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ @@ -163,6 +198,10 @@ protected function getDefinedElements(): array '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"]', ]); } } diff --git a/tests/Behat/Page/Admin/Page/CreatePageInterface.php b/tests/Behat/Page/Admin/Page/CreatePageInterface.php index 684446a5d..bb002eb82 100755 --- a/tests/Behat/Page/Admin/Page/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Page/CreatePageInterface.php @@ -42,4 +42,8 @@ public function selectContentElement(string $contentElement): void; public function addTextareaContentElementWithContent(string $content): void; public function addSingleMediaContentElementWithName(string $name): void; + + public function addMultipleMediaContentElementWithNames(array $mediaNames): void; + + public function addHeadingContentElementWithTypeAndContent(string $type, string $content): void; } From 818c30c18dd9f7908891833ca0b68c80834c1418 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 9 Jul 2024 10:12:57 +0200 Subject: [PATCH 16/36] OP-326: Behat for products carousel content element --- features/admin/adding_block.feature | 12 +++++++++ features/admin/adding_page.feature | 13 ++++++++++ tests/Behat/Context/Ui/Admin/BlockContext.php | 8 ++++++ tests/Behat/Context/Ui/Admin/PageContext.php | 8 ++++++ tests/Behat/Helpers/ContentElementHelper.php | 1 + tests/Behat/Page/Admin/Block/CreatePage.php | 25 +++++++++++++++++++ .../Page/Admin/Block/CreatePageInterface.php | 2 ++ tests/Behat/Page/Admin/Page/CreatePage.php | 25 +++++++++++++++++++ .../Page/Admin/Page/CreatePageInterface.php | 2 ++ 9 files changed, 96 insertions(+) diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index 3b855635d..989a957fa 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -60,6 +60,18 @@ Feature: Adding blocks And I add it Then I should be notified that the block has been created + @ui @javascript + Scenario: Adding block with products carousel content element + Given the store has "iPhone 8" and "iPhone X" products + When I go to the create block page + And I fill the code with "intro" + And I fill the name with "Intro" + And I click on Add button in Content elements section + And I select "Products carousel" content element + And I add a products carousel content element with "iPhone 8" and "iPhone X" products + And I add it + Then I should be notified that the block has been created + @ui Scenario: Trying to add block with existing code Given there is an existing block with "homepage_image" code diff --git a/features/admin/adding_page.feature b/features/admin/adding_page.feature index 0c7e79d3e..125250333 100644 --- a/features/admin/adding_page.feature +++ b/features/admin/adding_page.feature @@ -116,3 +116,16 @@ Feature: Adding new page And I add a heading content element with type "H3" and "Welcome to our store" content And I add it Then I should be notified that the page has been created + + @ui @javascript + Scenario: Adding page with products carousel content element + Given the store has "iPhone 8" and "iPhone X" products + 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 click on Add button in Content elements section + And I select "Products carousel" content element + And I add a products carousel content element with "iPhone 8" and "iPhone X" products + And I add it + Then I should be notified that the page has been created diff --git a/tests/Behat/Context/Ui/Admin/BlockContext.php b/tests/Behat/Context/Ui/Admin/BlockContext.php index ef6308fb5..b83a32f45 100755 --- a/tests/Behat/Context/Ui/Admin/BlockContext.php +++ b/tests/Behat/Context/Ui/Admin/BlockContext.php @@ -179,6 +179,14 @@ public function iAddAHeadingContentElementWithTypeAndContent(string $type, strin $this->resolveCurrentPage()->addHeadingContentElementWithTypeAndContent($type, $content); } + /** + * @When I add a products carousel content element with :firstProductName and :secondProductName products + */ + public function iAddAProductsCarouselContentElementWithProducts(string ...$productsNames): void + { + $this->resolveCurrentPage()->addProductsCarouselContentElementWithProducts($productsNames); + } + /** * @Then I should see :content in the textarea content element */ diff --git a/tests/Behat/Context/Ui/Admin/PageContext.php b/tests/Behat/Context/Ui/Admin/PageContext.php index 850b3c6a5..0e443815e 100755 --- a/tests/Behat/Context/Ui/Admin/PageContext.php +++ b/tests/Behat/Context/Ui/Admin/PageContext.php @@ -233,6 +233,14 @@ public function iAddAHeadingContentElementWithTypeAndContent(string $type, strin $this->resolveCurrentPage()->addHeadingContentElementWithTypeAndContent($type, $content); } + /** + * @When I add a products carousel content element with :firstProductName and :secondProductName products + */ + public function iAddAProductsCarouselContentElementWithProducts(string ...$productsNames): void + { + $this->resolveCurrentPage()->addProductsCarouselContentElementWithProducts($productsNames); + } + /** * @When I add it * @When I try to add it diff --git a/tests/Behat/Helpers/ContentElementHelper.php b/tests/Behat/Helpers/ContentElementHelper.php index 9872eca98..46c0c6138 100644 --- a/tests/Behat/Helpers/ContentElementHelper.php +++ b/tests/Behat/Helpers/ContentElementHelper.php @@ -19,6 +19,7 @@ public static function getDefinedElementThatShouldAppearAfterSelectContentElemen 'Single media' => 'content_elements_single_media_dropdown', 'Multiple media' => 'content_elements_multiple_media_dropdown', 'Heading' => 'content_elements_heading', + 'Products carousel' => 'content_elements_products_carousel', default => throw new \InvalidArgumentException(sprintf('Content element with name "%s" does not exist.', $contentElement)), }; } diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index 3e8812c34..48e2a59df 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -155,6 +155,29 @@ public function addHeadingContentElementWithTypeAndContent(string $type, string $headingContent->setValue($content); } + /** + * @throws ElementNotFoundException + */ + public function addProductsCarouselContentElementWithProducts(array $productsNames): void + { + $dropdown = $this->getElement('content_elements_products_carousel'); + $dropdown->click(); + + foreach ($productsNames as $productName) { + $dropdown->waitFor(10, function () use ($productName): bool { + return $this->hasElement('content_elements_products_carousel_item', [ + '%item%' => $productName, + ]); + }); + + $item = $this->getElement('content_elements_products_carousel_item', [ + '%item%' => $productName, + ]); + + $item->click(); + } + } + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ @@ -167,6 +190,8 @@ protected function getDefinedElements(): array 'content_elements_single_media_dropdown_item' => '.field > label:contains("Single 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%")', ]); } } diff --git a/tests/Behat/Page/Admin/Block/CreatePageInterface.php b/tests/Behat/Page/Admin/Block/CreatePageInterface.php index 406a707b2..6ff3ec80f 100755 --- a/tests/Behat/Page/Admin/Block/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Block/CreatePageInterface.php @@ -39,5 +39,7 @@ public function addSingleMediaContentElementWithName(string $name): void; public function addHeadingContentElementWithTypeAndContent(string $type, string $content): void; + public function addProductsCarouselContentElementWithProducts(array $productsNames): void; + public function disable(): void; } diff --git a/tests/Behat/Page/Admin/Page/CreatePage.php b/tests/Behat/Page/Admin/Page/CreatePage.php index 89db3fb4f..e4e928f3b 100755 --- a/tests/Behat/Page/Admin/Page/CreatePage.php +++ b/tests/Behat/Page/Admin/Page/CreatePage.php @@ -187,6 +187,29 @@ public function addHeadingContentElementWithTypeAndContent(string $type, string $headingContent->setValue($content); } + /** + * @throws ElementNotFoundException + */ + public function addProductsCarouselContentElementWithProducts(array $productsNames): void + { + $dropdown = $this->getElement('content_elements_products_carousel'); + $dropdown->click(); + + foreach ($productsNames as $productName) { + $dropdown->waitFor(10, function () use ($productName): bool { + return $this->hasElement('content_elements_products_carousel_item', [ + '%item%' => $productName, + ]); + }); + + $item = $this->getElement('content_elements_products_carousel_item', [ + '%item%' => $productName, + ]); + + $item->click(); + } + } + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ @@ -202,6 +225,8 @@ protected function getDefinedElements(): array '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%")', ]); } } diff --git a/tests/Behat/Page/Admin/Page/CreatePageInterface.php b/tests/Behat/Page/Admin/Page/CreatePageInterface.php index bb002eb82..4da78ce9a 100755 --- a/tests/Behat/Page/Admin/Page/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Page/CreatePageInterface.php @@ -46,4 +46,6 @@ public function addSingleMediaContentElementWithName(string $name): void; public function addMultipleMediaContentElementWithNames(array $mediaNames): void; public function addHeadingContentElementWithTypeAndContent(string $type, string $content): void; + + public function addProductsCarouselContentElementWithProducts(array $productsNames): void; } From f98a9afb05f34d59840bc8de724936f7e8b1f226 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 9 Jul 2024 10:37:44 +0200 Subject: [PATCH 17/36] OP-326: Behat for products carousel by taxon content element --- features/admin/adding_block.feature | 12 ++++++++++ features/admin/adding_page.feature | 13 +++++++++++ tests/Behat/Context/Ui/Admin/BlockContext.php | 8 +++++++ tests/Behat/Context/Ui/Admin/PageContext.php | 8 +++++++ tests/Behat/Helpers/ContentElementHelper.php | 1 + tests/Behat/Page/Admin/Block/CreatePage.php | 23 +++++++++++++++++++ .../Page/Admin/Block/CreatePageInterface.php | 2 ++ tests/Behat/Page/Admin/Page/CreatePage.php | 23 +++++++++++++++++++ .../Page/Admin/Page/CreatePageInterface.php | 2 ++ .../Resources/suites/ui/managing_blocks.yml | 1 + 10 files changed, 93 insertions(+) diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index 989a957fa..7e06f702e 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -72,6 +72,18 @@ Feature: Adding blocks And I add it Then I should be notified that the block has been created + @ui @javascript + Scenario: Adding block with products carousel by taxon content element + Given the store has "Smartphones" taxonomy + When I go to the create block page + And I fill the code with "intro" + And I fill the name with "Intro" + And I click on Add button in Content elements section + And I select "Products carousel by Taxon" content element + And I add a products carousel by taxon content element with "Smartphones" taxonomy + And I add it + Then I should be notified that the block has been created + @ui Scenario: Trying to add block with existing code Given there is an existing block with "homepage_image" code diff --git a/features/admin/adding_page.feature b/features/admin/adding_page.feature index 125250333..7d3d9074b 100644 --- a/features/admin/adding_page.feature +++ b/features/admin/adding_page.feature @@ -129,3 +129,16 @@ Feature: Adding new page And I add a products carousel content element with "iPhone 8" and "iPhone X" products And I add it Then I should be notified that the page has been created + + @ui @javascript + Scenario: Adding page with products carousel by taxon content element + Given the store has "Smartphones" taxonomy + 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 click on Add button in Content elements section + And I select "Products carousel by Taxon" content element + And I add a products carousel by taxon content element with "Smartphones" taxonomy + And I add it + Then I should be notified that the page has been created diff --git a/tests/Behat/Context/Ui/Admin/BlockContext.php b/tests/Behat/Context/Ui/Admin/BlockContext.php index b83a32f45..69f8e1f35 100755 --- a/tests/Behat/Context/Ui/Admin/BlockContext.php +++ b/tests/Behat/Context/Ui/Admin/BlockContext.php @@ -187,6 +187,14 @@ public function iAddAProductsCarouselContentElementWithProducts(string ...$produ $this->resolveCurrentPage()->addProductsCarouselContentElementWithProducts($productsNames); } + /** + * @When I add a products carousel by taxon content element with :taxon taxonomy + */ + public function iAddAProductsCarouselByTaxonContentElementWithTaxon(string $taxon): void + { + $this->resolveCurrentPage()->addProductsCarouselByTaxonContentElementWithTaxon($taxon); + } + /** * @Then I should see :content in the textarea content element */ diff --git a/tests/Behat/Context/Ui/Admin/PageContext.php b/tests/Behat/Context/Ui/Admin/PageContext.php index 0e443815e..cd4773db0 100755 --- a/tests/Behat/Context/Ui/Admin/PageContext.php +++ b/tests/Behat/Context/Ui/Admin/PageContext.php @@ -241,6 +241,14 @@ public function iAddAProductsCarouselContentElementWithProducts(string ...$produ $this->resolveCurrentPage()->addProductsCarouselContentElementWithProducts($productsNames); } + /** + * @When I add a products carousel by taxon content element with :taxon taxonomy + */ + public function iAddAProductsCarouselByTaxonContentElementWithTaxon(string $taxon): void + { + $this->resolveCurrentPage()->addProductsCarouselByTaxonContentElementWithTaxon($taxon); + } + /** * @When I add it * @When I try to add it diff --git a/tests/Behat/Helpers/ContentElementHelper.php b/tests/Behat/Helpers/ContentElementHelper.php index 46c0c6138..2df9821d7 100644 --- a/tests/Behat/Helpers/ContentElementHelper.php +++ b/tests/Behat/Helpers/ContentElementHelper.php @@ -20,6 +20,7 @@ public static function getDefinedElementThatShouldAppearAfterSelectContentElemen 'Multiple media' => 'content_elements_multiple_media_dropdown', 'Heading' => 'content_elements_heading', 'Products carousel' => 'content_elements_products_carousel', + 'Products carousel by Taxon' => 'content_elements_products_carousel_by_taxon', default => throw new \InvalidArgumentException(sprintf('Content element with name "%s" does not exist.', $contentElement)), }; } diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index 48e2a59df..ceff0062b 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -178,6 +178,27 @@ public function addProductsCarouselContentElementWithProducts(array $productsNam } } + /** + * @throws ElementNotFoundException + */ + public function addProductsCarouselByTaxonContentElementWithTaxon(string $taxon): void + { + $dropdown = $this->getElement('content_elements_products_carousel_by_taxon'); + $dropdown->click(); + + $dropdown->waitFor(10, function () use ($taxon): bool { + return $this->hasElement('content_elements_products_carousel_by_taxon_item', [ + '%item%' => $taxon, + ]); + }); + + $item = $this->getElement('content_elements_products_carousel_by_taxon_item', [ + '%item%' => $taxon, + ]); + + $item->click(); + } + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ @@ -192,6 +213,8 @@ protected function getDefinedElements(): array '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%")', ]); } } diff --git a/tests/Behat/Page/Admin/Block/CreatePageInterface.php b/tests/Behat/Page/Admin/Block/CreatePageInterface.php index 6ff3ec80f..bd0346557 100755 --- a/tests/Behat/Page/Admin/Block/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Block/CreatePageInterface.php @@ -41,5 +41,7 @@ public function addHeadingContentElementWithTypeAndContent(string $type, string public function addProductsCarouselContentElementWithProducts(array $productsNames): void; + public function addProductsCarouselByTaxonContentElementWithTaxon(string $taxon): void; + public function disable(): void; } diff --git a/tests/Behat/Page/Admin/Page/CreatePage.php b/tests/Behat/Page/Admin/Page/CreatePage.php index e4e928f3b..47a129cce 100755 --- a/tests/Behat/Page/Admin/Page/CreatePage.php +++ b/tests/Behat/Page/Admin/Page/CreatePage.php @@ -210,6 +210,27 @@ public function addProductsCarouselContentElementWithProducts(array $productsNam } } + /** + * @throws ElementNotFoundException + */ + public function addProductsCarouselByTaxonContentElementWithTaxon(string $taxon): void + { + $dropdown = $this->getElement('content_elements_products_carousel_by_taxon'); + $dropdown->click(); + + $dropdown->waitFor(10, function () use ($taxon): bool { + return $this->hasElement('content_elements_products_carousel_by_taxon_item', [ + '%item%' => $taxon, + ]); + }); + + $item = $this->getElement('content_elements_products_carousel_by_taxon_item', [ + '%item%' => $taxon, + ]); + + $item->click(); + } + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ @@ -227,6 +248,8 @@ protected function getDefinedElements(): array '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%")', ]); } } diff --git a/tests/Behat/Page/Admin/Page/CreatePageInterface.php b/tests/Behat/Page/Admin/Page/CreatePageInterface.php index 4da78ce9a..ff8a6bdbf 100755 --- a/tests/Behat/Page/Admin/Page/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Page/CreatePageInterface.php @@ -48,4 +48,6 @@ public function addMultipleMediaContentElementWithNames(array $mediaNames): void public function addHeadingContentElementWithTypeAndContent(string $type, string $content): void; public function addProductsCarouselContentElementWithProducts(array $productsNames): void; + + public function addProductsCarouselByTaxonContentElementWithTaxon(string $taxon): void; } diff --git a/tests/Behat/Resources/suites/ui/managing_blocks.yml b/tests/Behat/Resources/suites/ui/managing_blocks.yml index 00bc5ab75..af0ddde1c 100755 --- a/tests/Behat/Resources/suites/ui/managing_blocks.yml +++ b/tests/Behat/Resources/suites/ui/managing_blocks.yml @@ -6,6 +6,7 @@ default: - sylius.behat.context.setup.channel - sylius.behat.context.setup.admin_security + - sylius.behat.context.setup.product - bitbag_sylius_cms_plugin.behat.context.setup.block - bitbag_sylius_cms_plugin.behat.context.setup.collection - bitbag_sylius_cms_plugin.behat.context.setup.media From ab9dc5a57a44adaea350c3c03251145e4ee50958 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 9 Jul 2024 10:51:12 +0200 Subject: [PATCH 18/36] OP-326: Missing suites --- tests/Behat/Resources/suites/ui/managing_blocks.yml | 1 + tests/Behat/Resources/suites/ui/managing_pages.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/Behat/Resources/suites/ui/managing_blocks.yml b/tests/Behat/Resources/suites/ui/managing_blocks.yml index af0ddde1c..1645aa513 100755 --- a/tests/Behat/Resources/suites/ui/managing_blocks.yml +++ b/tests/Behat/Resources/suites/ui/managing_blocks.yml @@ -7,6 +7,7 @@ default: - sylius.behat.context.setup.channel - sylius.behat.context.setup.admin_security - sylius.behat.context.setup.product + - sylius.behat.context.setup.taxonomy - bitbag_sylius_cms_plugin.behat.context.setup.block - bitbag_sylius_cms_plugin.behat.context.setup.collection - bitbag_sylius_cms_plugin.behat.context.setup.media diff --git a/tests/Behat/Resources/suites/ui/managing_pages.yml b/tests/Behat/Resources/suites/ui/managing_pages.yml index becd2c602..bdf309b0f 100755 --- a/tests/Behat/Resources/suites/ui/managing_pages.yml +++ b/tests/Behat/Resources/suites/ui/managing_pages.yml @@ -7,6 +7,7 @@ default: - sylius.behat.context.setup.channel - sylius.behat.context.setup.admin_security - sylius.behat.context.setup.product + - sylius.behat.context.setup.taxonomy - bitbag_sylius_cms_plugin.behat.context.setup.media - bitbag_sylius_cms_plugin.behat.context.setup.page - bitbag_sylius_cms_plugin.behat.context.setup.collection From 6622c3c7e8abc69bfba88ca14848082edab8fae4 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 9 Jul 2024 11:02:37 +0200 Subject: [PATCH 19/36] OP-326: Behat for taxons list content element --- features/admin/adding_block.feature | 12 ++++++++++ features/admin/adding_page.feature | 13 +++++++++++ tests/Behat/Context/Ui/Admin/BlockContext.php | 8 +++++++ tests/Behat/Context/Ui/Admin/PageContext.php | 8 +++++++ tests/Behat/Helpers/ContentElementHelper.php | 1 + tests/Behat/Page/Admin/Block/CreatePage.php | 22 +++++++++++++++++++ .../Page/Admin/Block/CreatePageInterface.php | 2 ++ tests/Behat/Page/Admin/Page/CreatePage.php | 22 +++++++++++++++++++ .../Page/Admin/Page/CreatePageInterface.php | 2 ++ 9 files changed, 90 insertions(+) diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index 7e06f702e..a5bdf66ac 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -84,6 +84,18 @@ Feature: Adding blocks And I add it Then I should be notified that the block has been created + @ui @javascript + Scenario: Adding block with taxons list content element + Given the store classifies its products as "Smartphones" and "Laptops" + When I go to the create block page + And I fill the code with "intro" + And I fill the name with "Intro" + And I click on Add button in Content elements section + And I select "Taxons list" content element + And I add a taxons list content element with "Smartphones" and "Laptops" taxonomy + And I add it + Then I should be notified that the block has been created + @ui Scenario: Trying to add block with existing code Given there is an existing block with "homepage_image" code diff --git a/features/admin/adding_page.feature b/features/admin/adding_page.feature index 7d3d9074b..67c78348f 100644 --- a/features/admin/adding_page.feature +++ b/features/admin/adding_page.feature @@ -142,3 +142,16 @@ Feature: Adding new page And I add a products carousel by taxon content element with "Smartphones" taxonomy And I add it Then I should be notified that the page has been created + + @ui @javascript + Scenario: Adding page with taxons list content element + Given the store classifies its products as "Smartphones" and "Laptops" + 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 click on Add button in Content elements section + And I select "Taxons list" content element + And I add a taxons list content element with "Smartphones" and "Laptops" taxonomy + And I add it + Then I should be notified that the page has been created diff --git a/tests/Behat/Context/Ui/Admin/BlockContext.php b/tests/Behat/Context/Ui/Admin/BlockContext.php index 69f8e1f35..815be0517 100755 --- a/tests/Behat/Context/Ui/Admin/BlockContext.php +++ b/tests/Behat/Context/Ui/Admin/BlockContext.php @@ -195,6 +195,14 @@ public function iAddAProductsCarouselByTaxonContentElementWithTaxon(string $taxo $this->resolveCurrentPage()->addProductsCarouselByTaxonContentElementWithTaxon($taxon); } + /** + * @When I add a taxons list content element with :firstTaxon and :secondTaxon taxonomy + */ + public function iAddATaxonsListContentElementWithTaxons(string ...$taxons): void + { + $this->resolveCurrentPage()->addTaxonsListContentElementWithTaxons($taxons); + } + /** * @Then I should see :content in the textarea content element */ diff --git a/tests/Behat/Context/Ui/Admin/PageContext.php b/tests/Behat/Context/Ui/Admin/PageContext.php index cd4773db0..cc1edccb7 100755 --- a/tests/Behat/Context/Ui/Admin/PageContext.php +++ b/tests/Behat/Context/Ui/Admin/PageContext.php @@ -249,6 +249,14 @@ public function iAddAProductsCarouselByTaxonContentElementWithTaxon(string $taxo $this->resolveCurrentPage()->addProductsCarouselByTaxonContentElementWithTaxon($taxon); } + /** + * @When I add a taxons list content element with :firstTaxon and :secondTaxon taxonomy + */ + public function iAddATaxonsListContentElementWithTaxons(string ...$taxons): void + { + $this->resolveCurrentPage()->addTaxonsListContentElementWithTaxons($taxons); + } + /** * @When I add it * @When I try to add it diff --git a/tests/Behat/Helpers/ContentElementHelper.php b/tests/Behat/Helpers/ContentElementHelper.php index 2df9821d7..9f9aa2d78 100644 --- a/tests/Behat/Helpers/ContentElementHelper.php +++ b/tests/Behat/Helpers/ContentElementHelper.php @@ -21,6 +21,7 @@ public static function getDefinedElementThatShouldAppearAfterSelectContentElemen 'Heading' => 'content_elements_heading', 'Products carousel' => 'content_elements_products_carousel', 'Products carousel by Taxon' => 'content_elements_products_carousel_by_taxon', + 'Taxons list' => 'content_elements_taxons_list', default => throw new \InvalidArgumentException(sprintf('Content element with name "%s" does not exist.', $contentElement)), }; } diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index ceff0062b..e5e7972b8 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -199,6 +199,26 @@ public function addProductsCarouselByTaxonContentElementWithTaxon(string $taxon) $item->click(); } + public function addTaxonsListContentElementWithTaxons(array $taxons): void + { + $dropdown = $this->getElement('content_elements_taxons_list'); + $dropdown->click(); + + foreach ($taxons as $taxon) { + $dropdown->waitFor(10, function () use ($taxon): bool { + return $this->hasElement('content_elements_taxons_list_item', [ + '%item%' => $taxon, + ]); + }); + + $item = $this->getElement('content_elements_taxons_list_item', [ + '%item%' => $taxon, + ]); + + $item->click(); + } + } + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ @@ -215,6 +235,8 @@ protected function getDefinedElements(): array '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_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%")', ]); } } diff --git a/tests/Behat/Page/Admin/Block/CreatePageInterface.php b/tests/Behat/Page/Admin/Block/CreatePageInterface.php index bd0346557..7d60c0a19 100755 --- a/tests/Behat/Page/Admin/Block/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Block/CreatePageInterface.php @@ -43,5 +43,7 @@ public function addProductsCarouselContentElementWithProducts(array $productsNam public function addProductsCarouselByTaxonContentElementWithTaxon(string $taxon): void; + public function addTaxonsListContentElementWithTaxons(array $taxons): void; + public function disable(): void; } diff --git a/tests/Behat/Page/Admin/Page/CreatePage.php b/tests/Behat/Page/Admin/Page/CreatePage.php index 47a129cce..12d605cb2 100755 --- a/tests/Behat/Page/Admin/Page/CreatePage.php +++ b/tests/Behat/Page/Admin/Page/CreatePage.php @@ -231,6 +231,26 @@ public function addProductsCarouselByTaxonContentElementWithTaxon(string $taxon) $item->click(); } + public function addTaxonsListContentElementWithTaxons(array $taxons): void + { + $dropdown = $this->getElement('content_elements_taxons_list'); + $dropdown->click(); + + foreach ($taxons as $taxon) { + $dropdown->waitFor(10, function () use ($taxon): bool { + return $this->hasElement('content_elements_taxons_list_item', [ + '%item%' => $taxon, + ]); + }); + + $item = $this->getElement('content_elements_taxons_list_item', [ + '%item%' => $taxon, + ]); + + $item->click(); + } + } + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ @@ -250,6 +270,8 @@ protected function getDefinedElements(): array '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_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%")', ]); } } diff --git a/tests/Behat/Page/Admin/Page/CreatePageInterface.php b/tests/Behat/Page/Admin/Page/CreatePageInterface.php index ff8a6bdbf..5b511a7c5 100755 --- a/tests/Behat/Page/Admin/Page/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Page/CreatePageInterface.php @@ -50,4 +50,6 @@ public function addHeadingContentElementWithTypeAndContent(string $type, string public function addProductsCarouselContentElementWithProducts(array $productsNames): void; public function addProductsCarouselByTaxonContentElementWithTaxon(string $taxon): void; + + public function addTaxonsListContentElementWithTaxons(array $taxons): void; } From e0ce8eb233f4919bc87fddcc33685713c466852c Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 9 Jul 2024 11:03:14 +0200 Subject: [PATCH 20/36] OP-326: Missing PHPDoc --- tests/Behat/Page/Admin/Block/CreatePage.php | 3 +++ tests/Behat/Page/Admin/Page/CreatePage.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index e5e7972b8..1199ad85e 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -199,6 +199,9 @@ public function addProductsCarouselByTaxonContentElementWithTaxon(string $taxon) $item->click(); } + /** + * @throws ElementNotFoundException + */ public function addTaxonsListContentElementWithTaxons(array $taxons): void { $dropdown = $this->getElement('content_elements_taxons_list'); diff --git a/tests/Behat/Page/Admin/Page/CreatePage.php b/tests/Behat/Page/Admin/Page/CreatePage.php index 12d605cb2..2771612a5 100755 --- a/tests/Behat/Page/Admin/Page/CreatePage.php +++ b/tests/Behat/Page/Admin/Page/CreatePage.php @@ -231,6 +231,9 @@ public function addProductsCarouselByTaxonContentElementWithTaxon(string $taxon) $item->click(); } + /** + * @throws ElementNotFoundException + */ public function addTaxonsListContentElementWithTaxons(array $taxons): void { $dropdown = $this->getElement('content_elements_taxons_list'); From 9dfa8d0677ba114802a92cfa5a2eea47e89d9b62 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 9 Jul 2024 11:45:11 +0200 Subject: [PATCH 21/36] OP-326: Behat - make sure content element exists after create page/block --- features/admin/adding_block.feature | 6 +++ features/admin/adding_page.feature | 7 ++++ .../ContainsContentElementInterface.php | 16 ++++++++ .../Behaviour/ContainsContentElementTrait.php | 37 +++++++++++++++++++ tests/Behat/Context/Ui/Admin/PageContext.php | 10 ++++- tests/Behat/Page/Admin/Page/CreatePage.php | 2 + .../Page/Admin/Page/CreatePageInterface.php | 6 ++- 7 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 tests/Behat/Behaviour/ContainsContentElementInterface.php create mode 100644 tests/Behat/Behaviour/ContainsContentElementTrait.php diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index a5bdf66ac..f3853c355 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -36,6 +36,7 @@ Feature: Adding blocks And I add a textarea content element with "Welcome to our store" content And I add it Then I should be notified that the block has been created + And I should see newly created "Textarea" content element in Content elements section @ui @javascript Scenario: Adding block with single media content element @@ -48,6 +49,7 @@ Feature: Adding blocks And I add a single media content element with name "Image 1" And I add it Then I should be notified that the block has been created + And I should see newly created "Single media" content element in Content elements section @ui @javascript Scenario: Adding block with heading content element @@ -59,6 +61,7 @@ Feature: Adding blocks And I add a heading content element with type "H3" and "Welcome to our store" content And I add it Then I should be notified that the block has been created + And I should see newly created "Heading" content element in Content elements section @ui @javascript Scenario: Adding block with products carousel content element @@ -71,6 +74,7 @@ Feature: Adding blocks And I add a products carousel content element with "iPhone 8" and "iPhone X" products And I add it Then I should be notified that the block has been created + And I should see newly created "Products carousel" content element in Content elements section @ui @javascript Scenario: Adding block with products carousel by taxon content element @@ -83,6 +87,7 @@ Feature: Adding blocks And I add a products carousel by taxon content element with "Smartphones" taxonomy And I add it Then I should be notified that the block has been created + And I should see newly created "Products carousel by Taxon" content element in Content elements section @ui @javascript Scenario: Adding block with taxons list content element @@ -95,6 +100,7 @@ Feature: Adding blocks And I add a taxons list content element with "Smartphones" and "Laptops" taxonomy And I add it Then I should be notified that the block has been created + And I should see newly created "Taxons list" content element in Content elements section @ui Scenario: Trying to add block with existing code diff --git a/features/admin/adding_page.feature b/features/admin/adding_page.feature index 67c78348f..df5e2e98e 100644 --- a/features/admin/adding_page.feature +++ b/features/admin/adding_page.feature @@ -78,6 +78,7 @@ Feature: Adding new page And I add a textarea content element with "Welcome to our store" content 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 @ui @javascript Scenario: Adding page with single media content element @@ -91,6 +92,7 @@ Feature: Adding new page And I add a single media content element with name "Image 1" And I add it 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 @ui @javascript Scenario: Adding page with multiple media content element @@ -104,6 +106,7 @@ Feature: Adding new page And I add a multiple media content element with names "Image 1" and "Image 2" And I add it Then I should be notified that the page has been created + And I should see newly created "Multiple media" content element in Content elements section @ui @javascript Scenario: Adding page with heading content element @@ -116,6 +119,7 @@ Feature: Adding new page And I add a heading content element with type "H3" and "Welcome to our store" content And I add it Then I should be notified that the page has been created + And I should see newly created "Heading" content element in Content elements section @ui @javascript Scenario: Adding page with products carousel content element @@ -129,6 +133,7 @@ Feature: Adding new page And I add a products carousel content element with "iPhone 8" and "iPhone X" products And I add it Then I should be notified that the page has been created + And I should see newly created "Products carousel" content element in Content elements section @ui @javascript Scenario: Adding page with products carousel by taxon content element @@ -142,6 +147,7 @@ Feature: Adding new page And I add a products carousel by taxon content element with "Smartphones" taxonomy And I add it Then I should be notified that the page has been created + And I should see newly created "Products carousel by Taxon" content element in Content elements section @ui @javascript Scenario: Adding page with taxons list content element @@ -155,3 +161,4 @@ Feature: Adding new page And I add a taxons list content element with "Smartphones" and "Laptops" taxonomy And I add it Then I should be notified that the page has been created + And I should see newly created "Taxons list" content element in Content elements section diff --git a/tests/Behat/Behaviour/ContainsContentElementInterface.php b/tests/Behat/Behaviour/ContainsContentElementInterface.php new file mode 100644 index 000000000..76bc9dd94 --- /dev/null +++ b/tests/Behat/Behaviour/ContainsContentElementInterface.php @@ -0,0 +1,16 @@ + 'Products', + 'Products carousel by taxon' => 'Taxon', + 'Taxons list' => 'Taxons', + default => $contentElement, + }; + + $contentElements = $this->getDocument()->findById('bitbag_sylius_cms_plugin_block_contentElements') + ?? $this->getDocument()->findById('bitbag_sylius_cms_plugin_page_contentElements'); + + if (null === $contentElements) { + throw new \InvalidArgumentException('Content elements container not found'); + } + + return $contentElements->hasField($fieldName); + } +} diff --git a/tests/Behat/Context/Ui/Admin/PageContext.php b/tests/Behat/Context/Ui/Admin/PageContext.php index cc1edccb7..b172780c3 100755 --- a/tests/Behat/Context/Ui/Admin/PageContext.php +++ b/tests/Behat/Context/Ui/Admin/PageContext.php @@ -150,7 +150,7 @@ public function iChangeTextareaContentElementValueTo(string $value): void */ public function iShouldSeeNewContentInTheTextareaContentElement(string $content): void { - $this->resolveCurrentPage()->containsTextareaContentElementWithValue($content); + Assert::true($this->resolveCurrentPage()->containsTextareaContentElementWithValue($content)); } /** @@ -257,6 +257,14 @@ public function iAddATaxonsListContentElementWithTaxons(string ...$taxons): void $this->resolveCurrentPage()->addTaxonsListContentElementWithTaxons($taxons); } + /** + * @Then I should see newly created :contentElement content element in Content elements section + */ + public function iShouldSeeNewlyCreatedContentElementInContentElementsSection(string $contentElement): void + { + Assert::true($this->resolveCurrentPage()->containsContentElement($contentElement)); + } + /** * @When I add it * @When I try to add it diff --git a/tests/Behat/Page/Admin/Page/CreatePage.php b/tests/Behat/Page/Admin/Page/CreatePage.php index 2771612a5..e8b344e54 100755 --- a/tests/Behat/Page/Admin/Page/CreatePage.php +++ b/tests/Behat/Page/Admin/Page/CreatePage.php @@ -14,6 +14,7 @@ use DMore\ChromeDriver\ChromeDriver; use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; use Sylius\Behat\Service\SlugGenerationHelper; +use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsContentElementTrait; use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsErrorTrait; use Tests\BitBag\SyliusCmsPlugin\Behat\Helpers\ContentElementHelper; use Tests\BitBag\SyliusCmsPlugin\Behat\Service\FormHelper; @@ -22,6 +23,7 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface { use ContainsErrorTrait; + use ContainsContentElementTrait; public function fillField(string $field, string $value): void { diff --git a/tests/Behat/Page/Admin/Page/CreatePageInterface.php b/tests/Behat/Page/Admin/Page/CreatePageInterface.php index 5b511a7c5..bd4ee90db 100755 --- a/tests/Behat/Page/Admin/Page/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Page/CreatePageInterface.php @@ -11,9 +11,13 @@ namespace Tests\BitBag\SyliusCmsPlugin\Behat\Page\Admin\Page; use Sylius\Behat\Page\Admin\Crud\CreatePageInterface as BaseCreatePageInterface; +use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsContentElementInterface; use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsErrorInterface; -interface CreatePageInterface extends BaseCreatePageInterface, ContainsErrorInterface +interface CreatePageInterface extends + BaseCreatePageInterface, + ContainsErrorInterface, + ContainsContentElementInterface { public const IMAGE_FORM_ID = 'bitbag_sylius_cms_plugin_page_translations_en_US_image'; From c7fcf23a17ae0f8e0003e9cd0467d5cd5387835a Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 9 Jul 2024 12:12:58 +0200 Subject: [PATCH 22/36] OP-326: Behat - error fixes --- tests/Behat/Context/Ui/Admin/BlockContext.php | 8 ++++++++ tests/Behat/Page/Admin/Block/CreatePage.php | 2 ++ tests/Behat/Page/Admin/Block/CreatePageInterface.php | 6 +++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/Behat/Context/Ui/Admin/BlockContext.php b/tests/Behat/Context/Ui/Admin/BlockContext.php index 815be0517..0bbafab1f 100755 --- a/tests/Behat/Context/Ui/Admin/BlockContext.php +++ b/tests/Behat/Context/Ui/Admin/BlockContext.php @@ -203,6 +203,14 @@ public function iAddATaxonsListContentElementWithTaxons(string ...$taxons): void $this->resolveCurrentPage()->addTaxonsListContentElementWithTaxons($taxons); } + /** + * @Then I should see newly created :contentElement content element in Content elements section + */ + public function iShouldSeeNewlyCreatedContentElementInContentElementsSection(string $contentElement): void + { + Assert::true($this->resolveCurrentPage()->containsContentElement($contentElement)); + } + /** * @Then I should see :content in the textarea content element */ diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index 1199ad85e..afb2bb3c1 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -13,6 +13,7 @@ use Behat\Mink\Exception\ElementNotFoundException; use DMore\ChromeDriver\ChromeDriver; use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; +use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsContentElementTrait; use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsErrorTrait; use Tests\BitBag\SyliusCmsPlugin\Behat\Helpers\ContentElementHelper; use Webmozart\Assert\Assert; @@ -20,6 +21,7 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface { use ContainsErrorTrait; + use ContainsContentElementTrait; public function fillField(string $field, string $value): void { diff --git a/tests/Behat/Page/Admin/Block/CreatePageInterface.php b/tests/Behat/Page/Admin/Block/CreatePageInterface.php index 7d60c0a19..2e07dd6e3 100755 --- a/tests/Behat/Page/Admin/Block/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Block/CreatePageInterface.php @@ -11,9 +11,13 @@ namespace Tests\BitBag\SyliusCmsPlugin\Behat\Page\Admin\Block; use Sylius\Behat\Page\Admin\Crud\CreatePageInterface as BaseCreatePageInterface; +use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsContentElementInterface; use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsErrorInterface; -interface CreatePageInterface extends BaseCreatePageInterface, ContainsErrorInterface +interface CreatePageInterface extends + BaseCreatePageInterface, + ContainsErrorInterface, + ContainsContentElementInterface { public function fillField(string $field, string $value): void; From fac6dfe3661405f5acd1d85bda399ca618278ec5 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 9 Jul 2024 13:23:13 +0200 Subject: [PATCH 23/36] OP-326: Behat - move behaviour trait to update section instead create --- tests/Behat/Page/Admin/Block/CreatePage.php | 2 -- tests/Behat/Page/Admin/Block/CreatePageInterface.php | 6 +----- tests/Behat/Page/Admin/Block/UpdatePage.php | 2 ++ tests/Behat/Page/Admin/Block/UpdatePageInterface.php | 6 +++++- tests/Behat/Page/Admin/Page/CreatePage.php | 2 -- tests/Behat/Page/Admin/Page/CreatePageInterface.php | 6 +----- tests/Behat/Page/Admin/Page/UpdatePage.php | 2 ++ tests/Behat/Page/Admin/Page/UpdatePageInterface.php | 6 +++++- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index afb2bb3c1..1199ad85e 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -13,7 +13,6 @@ use Behat\Mink\Exception\ElementNotFoundException; use DMore\ChromeDriver\ChromeDriver; use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; -use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsContentElementTrait; use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsErrorTrait; use Tests\BitBag\SyliusCmsPlugin\Behat\Helpers\ContentElementHelper; use Webmozart\Assert\Assert; @@ -21,7 +20,6 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface { use ContainsErrorTrait; - use ContainsContentElementTrait; public function fillField(string $field, string $value): void { diff --git a/tests/Behat/Page/Admin/Block/CreatePageInterface.php b/tests/Behat/Page/Admin/Block/CreatePageInterface.php index 2e07dd6e3..7d60c0a19 100755 --- a/tests/Behat/Page/Admin/Block/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Block/CreatePageInterface.php @@ -11,13 +11,9 @@ namespace Tests\BitBag\SyliusCmsPlugin\Behat\Page\Admin\Block; use Sylius\Behat\Page\Admin\Crud\CreatePageInterface as BaseCreatePageInterface; -use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsContentElementInterface; use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsErrorInterface; -interface CreatePageInterface extends - BaseCreatePageInterface, - ContainsErrorInterface, - ContainsContentElementInterface +interface CreatePageInterface extends BaseCreatePageInterface, ContainsErrorInterface { public function fillField(string $field, string $value): void; diff --git a/tests/Behat/Page/Admin/Block/UpdatePage.php b/tests/Behat/Page/Admin/Block/UpdatePage.php index 8e59ce73e..ffba781ba 100755 --- a/tests/Behat/Page/Admin/Block/UpdatePage.php +++ b/tests/Behat/Page/Admin/Block/UpdatePage.php @@ -12,10 +12,12 @@ use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage; use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ChecksCodeImmutabilityTrait; +use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsContentElementTrait; class UpdatePage extends BaseUpdatePage implements UpdatePageInterface { use ChecksCodeImmutabilityTrait; + use ContainsContentElementTrait; public function fillName(string $name): void { diff --git a/tests/Behat/Page/Admin/Block/UpdatePageInterface.php b/tests/Behat/Page/Admin/Block/UpdatePageInterface.php index 019357b34..6aa8e0e1c 100755 --- a/tests/Behat/Page/Admin/Block/UpdatePageInterface.php +++ b/tests/Behat/Page/Admin/Block/UpdatePageInterface.php @@ -12,8 +12,12 @@ use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface as BaseUpdatePageInterface; use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ChecksCodeImmutabilityInterface; +use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsContentElementInterface; -interface UpdatePageInterface extends BaseUpdatePageInterface, ChecksCodeImmutabilityInterface +interface UpdatePageInterface extends + BaseUpdatePageInterface, + ChecksCodeImmutabilityInterface, + ContainsContentElementInterface { public function fillName(string $name): void; diff --git a/tests/Behat/Page/Admin/Page/CreatePage.php b/tests/Behat/Page/Admin/Page/CreatePage.php index e8b344e54..2771612a5 100755 --- a/tests/Behat/Page/Admin/Page/CreatePage.php +++ b/tests/Behat/Page/Admin/Page/CreatePage.php @@ -14,7 +14,6 @@ use DMore\ChromeDriver\ChromeDriver; use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; use Sylius\Behat\Service\SlugGenerationHelper; -use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsContentElementTrait; use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsErrorTrait; use Tests\BitBag\SyliusCmsPlugin\Behat\Helpers\ContentElementHelper; use Tests\BitBag\SyliusCmsPlugin\Behat\Service\FormHelper; @@ -23,7 +22,6 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface { use ContainsErrorTrait; - use ContainsContentElementTrait; public function fillField(string $field, string $value): void { diff --git a/tests/Behat/Page/Admin/Page/CreatePageInterface.php b/tests/Behat/Page/Admin/Page/CreatePageInterface.php index bd4ee90db..5b511a7c5 100755 --- a/tests/Behat/Page/Admin/Page/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Page/CreatePageInterface.php @@ -11,13 +11,9 @@ namespace Tests\BitBag\SyliusCmsPlugin\Behat\Page\Admin\Page; use Sylius\Behat\Page\Admin\Crud\CreatePageInterface as BaseCreatePageInterface; -use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsContentElementInterface; use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsErrorInterface; -interface CreatePageInterface extends - BaseCreatePageInterface, - ContainsErrorInterface, - ContainsContentElementInterface +interface CreatePageInterface extends BaseCreatePageInterface, ContainsErrorInterface { public const IMAGE_FORM_ID = 'bitbag_sylius_cms_plugin_page_translations_en_US_image'; diff --git a/tests/Behat/Page/Admin/Page/UpdatePage.php b/tests/Behat/Page/Admin/Page/UpdatePage.php index 4271fa098..b5514b8be 100755 --- a/tests/Behat/Page/Admin/Page/UpdatePage.php +++ b/tests/Behat/Page/Admin/Page/UpdatePage.php @@ -12,11 +12,13 @@ use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage; use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ChecksCodeImmutabilityTrait; +use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsContentElementTrait; use Tests\BitBag\SyliusCmsPlugin\Behat\Service\FormHelper; class UpdatePage extends BaseUpdatePage implements UpdatePageInterface { use ChecksCodeImmutabilityTrait; + use ContainsContentElementTrait; public function fillField(string $field, string $value): void { diff --git a/tests/Behat/Page/Admin/Page/UpdatePageInterface.php b/tests/Behat/Page/Admin/Page/UpdatePageInterface.php index 383638842..2cd61f3b2 100755 --- a/tests/Behat/Page/Admin/Page/UpdatePageInterface.php +++ b/tests/Behat/Page/Admin/Page/UpdatePageInterface.php @@ -12,8 +12,12 @@ use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface as BaseUpdatePageInterface; use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ChecksCodeImmutabilityInterface; +use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsContentElementInterface; -interface UpdatePageInterface extends BaseUpdatePageInterface, ChecksCodeImmutabilityInterface +interface UpdatePageInterface extends + BaseUpdatePageInterface, + ChecksCodeImmutabilityInterface, + ContainsContentElementInterface { public const IMAGE_FORM_ID = 'bitbag_sylius_cms_plugin_page_translations_en_US_image'; From e3c457a3da43d3920256563f33d341f3de51614f Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 9 Jul 2024 14:41:12 +0200 Subject: [PATCH 24/36] OP-326: Behat - testing result of hasElement method --- tests/Behat/Page/Admin/Block/CreatePage.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index 1199ad85e..9c393ce1b 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -90,9 +90,11 @@ public function clickOnAddContentElementButton(): void $addButton = $this->getElement('content_elements_add_button'); $addButton->click(); - $addButton->waitFor(2, function (): bool { - return $this->hasElement('content_elements_select_type'); - }); + Assert::true( + $addButton->waitFor(3, function (): bool { + return $this->hasElement('content_elements_select_type'); + }) + ); } /** @@ -104,11 +106,14 @@ public function selectContentElement(string $contentElement): void $select = $this->getElement('content_elements_select_type'); $select->selectOption($contentElement); - $select->waitFor(3, function () use ($contentElement): bool { - return $this->hasElement( - ContentElementHelper::getDefinedElementThatShouldAppearAfterSelectContentElement($contentElement), - ); - }); + + Assert::true( + $select->waitFor(3, function () use ($contentElement): bool { + return $this->hasElement( + ContentElementHelper::getDefinedElementThatShouldAppearAfterSelectContentElement($contentElement), + ); + }) + ); } /** From 1dfd7a6aa5776200af46cb79cfc4bbe6d5fe1189 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 9 Jul 2024 14:57:19 +0200 Subject: [PATCH 25/36] OP-326: Behat - testing result of hasElement method --- .../Behat/Behaviour/ContainsContentElementTrait.php | 9 +-------- tests/Behat/Page/Admin/Block/CreatePage.php | 12 +++++++----- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/tests/Behat/Behaviour/ContainsContentElementTrait.php b/tests/Behat/Behaviour/ContainsContentElementTrait.php index 6659789f4..38e6f8ba2 100644 --- a/tests/Behat/Behaviour/ContainsContentElementTrait.php +++ b/tests/Behat/Behaviour/ContainsContentElementTrait.php @@ -25,13 +25,6 @@ public function containsContentElement(string $contentElement): bool default => $contentElement, }; - $contentElements = $this->getDocument()->findById('bitbag_sylius_cms_plugin_block_contentElements') - ?? $this->getDocument()->findById('bitbag_sylius_cms_plugin_page_contentElements'); - - if (null === $contentElements) { - throw new \InvalidArgumentException('Content elements container not found'); - } - - return $contentElements->hasField($fieldName); + return $this->getDocument()->hasField($fieldName); } } diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index 9c393ce1b..ae9ab1cc3 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -135,11 +135,13 @@ public function addSingleMediaContentElementWithName(string $name): void $dropdown = $this->getElement('content_elements_single_media_dropdown'); $dropdown->click(); - $dropdown->waitFor(10, function () use ($name): bool { - return $this->hasElement('content_elements_single_media_dropdown_item', [ - '%item%' => $name, - ]); - }); + Assert::true( + $dropdown->waitFor(10, function () use ($name): bool { + return $this->hasElement('content_elements_single_media_dropdown_item', [ + '%item%' => $name, + ]); + }), + ); $item = $this->getElement('content_elements_single_media_dropdown_item', [ '%item%' => $name, From b70602e3768bce32774559a5da8c7a49c096dd94 Mon Sep 17 00:00:00 2001 From: jkindly Date: Wed, 10 Jul 2024 09:19:59 +0200 Subject: [PATCH 26/36] OP-326: Behat - ContainsContentElementTrait.php adjustment --- .../Behaviour/ContainsContentElementTrait.php | 23 +++++++++---- tests/Behat/Page/Admin/Block/CreatePage.php | 33 ++++++++----------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/tests/Behat/Behaviour/ContainsContentElementTrait.php b/tests/Behat/Behaviour/ContainsContentElementTrait.php index 38e6f8ba2..eb85d11d2 100644 --- a/tests/Behat/Behaviour/ContainsContentElementTrait.php +++ b/tests/Behat/Behaviour/ContainsContentElementTrait.php @@ -18,13 +18,24 @@ trait ContainsContentElementTrait public function containsContentElement(string $contentElement): bool { - $fieldName = match ($contentElement) { - 'Products carousel' => 'Products', - 'Products carousel by taxon' => 'Taxon', - 'Taxons list' => 'Taxons', - default => $contentElement, + $isAutocompleteField = match ($contentElement) { + 'Single media', + 'Multiple media', + 'Products carousel', + 'Products carousel by taxon', + 'Taxons list' => true, + default => false, }; - return $this->getDocument()->hasField($fieldName); + $contentElements = $this->getDocument()->findById('bitbag_sylius_cms_plugin_block_contentElements') + ?? $this->getDocument()->findById('bitbag_sylius_cms_plugin_page_contentElements'); + + if (null === $contentElements) { + throw new \InvalidArgumentException('Content elements container not found'); + } + + return $isAutocompleteField + ? $contentElements->has('css', '[data-autocomplete]') + : $contentElements->hasField($contentElement); } } diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index ae9ab1cc3..0fedd8482 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -90,11 +90,9 @@ public function clickOnAddContentElementButton(): void $addButton = $this->getElement('content_elements_add_button'); $addButton->click(); - Assert::true( - $addButton->waitFor(3, function (): bool { - return $this->hasElement('content_elements_select_type'); - }) - ); + $addButton->waitFor(3, function (): bool { + return $this->hasElement('content_elements_select_type'); + }); } /** @@ -106,14 +104,11 @@ public function selectContentElement(string $contentElement): void $select = $this->getElement('content_elements_select_type'); $select->selectOption($contentElement); - - Assert::true( - $select->waitFor(3, function () use ($contentElement): bool { - return $this->hasElement( - ContentElementHelper::getDefinedElementThatShouldAppearAfterSelectContentElement($contentElement), - ); - }) - ); + $select->waitFor(3, function () use ($contentElement): bool { + return $this->hasElement( + ContentElementHelper::getDefinedElementThatShouldAppearAfterSelectContentElement($contentElement), + ); + }); } /** @@ -135,13 +130,11 @@ public function addSingleMediaContentElementWithName(string $name): void $dropdown = $this->getElement('content_elements_single_media_dropdown'); $dropdown->click(); - Assert::true( - $dropdown->waitFor(10, function () use ($name): bool { - return $this->hasElement('content_elements_single_media_dropdown_item', [ - '%item%' => $name, - ]); - }), - ); + $dropdown->waitFor(10, function () use ($name): bool { + return $this->hasElement('content_elements_single_media_dropdown_item', [ + '%item%' => $name, + ]); + }); $item = $this->getElement('content_elements_single_media_dropdown_item', [ '%item%' => $name, From fca3d72818d9be296b11f318b59b5c4f8f8842b5 Mon Sep 17 00:00:00 2001 From: jkindly Date: Wed, 10 Jul 2024 09:26:29 +0200 Subject: [PATCH 27/36] OP-326: Behat - ContainsContentElementTrait.php adjustment --- tests/Behat/Behaviour/ContainsContentElementTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Behat/Behaviour/ContainsContentElementTrait.php b/tests/Behat/Behaviour/ContainsContentElementTrait.php index eb85d11d2..65cd9297c 100644 --- a/tests/Behat/Behaviour/ContainsContentElementTrait.php +++ b/tests/Behat/Behaviour/ContainsContentElementTrait.php @@ -35,7 +35,7 @@ public function containsContentElement(string $contentElement): bool } return $isAutocompleteField - ? $contentElements->has('css', '[data-autocomplete]') + ? $contentElements->has('css', 'input.search') : $contentElements->hasField($contentElement); } } From 726c73dccede19721f558ad5bba8097a598ddbd2 Mon Sep 17 00:00:00 2001 From: jkindly Date: Wed, 10 Jul 2024 09:34:51 +0200 Subject: [PATCH 28/36] OP-326: Behat - ContainsContentElementTrait.php adjustment --- tests/Behat/Behaviour/ContainsContentElementTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Behat/Behaviour/ContainsContentElementTrait.php b/tests/Behat/Behaviour/ContainsContentElementTrait.php index 65cd9297c..19726f05d 100644 --- a/tests/Behat/Behaviour/ContainsContentElementTrait.php +++ b/tests/Behat/Behaviour/ContainsContentElementTrait.php @@ -22,7 +22,7 @@ public function containsContentElement(string $contentElement): bool 'Single media', 'Multiple media', 'Products carousel', - 'Products carousel by taxon', + 'Products carousel by Taxon', 'Taxons list' => true, default => false, }; From 1192bb8ed6c8ad0fff329d3f80a9c50cadfe5014 Mon Sep 17 00:00:00 2001 From: jkindly Date: Wed, 10 Jul 2024 10:40:09 +0200 Subject: [PATCH 29/36] OP-326: Behat - adding page with multiple content elements --- features/admin/adding_block.feature | 13 +++++++ features/admin/adding_page.feature | 39 +++++++++++++++++++ .../Behaviour/ContainsContentElementTrait.php | 4 +- tests/Behat/Context/Ui/Admin/BlockContext.php | 8 ++++ tests/Behat/Page/Admin/Block/CreatePage.php | 25 ++++++++++++ .../Page/Admin/Block/CreatePageInterface.php | 2 + 6 files changed, 90 insertions(+), 1 deletion(-) diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index f3853c355..1bb3cd92a 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -51,6 +51,19 @@ Feature: Adding blocks Then I should be notified that the block has been created And I should see newly created "Single media" content element in Content elements section + @ui @javascript + Scenario: Adding block with multiple media content element + Given there is an existing media with names "Image 1" and "Image 2" + When I go to the create block page + And I fill the code with "intro" + And I fill the name with "Intro" + And I click on Add button in Content elements section + And I select "Multiple media" content element + And I add a multiple media content element with names "Image 1" and "Image 2" + And I add it + Then I should be notified that the block has been created + And I should see newly created "Single media" content element in Content elements section + @ui @javascript Scenario: Adding block with heading content element When I go to the create block page diff --git a/features/admin/adding_page.feature b/features/admin/adding_page.feature index df5e2e98e..045460b3a 100644 --- a/features/admin/adding_page.feature +++ b/features/admin/adding_page.feature @@ -162,3 +162,42 @@ Feature: Adding new page And I add it Then I should be notified that the page has been created And I should see newly created "Taxons list" content element in Content elements section + + @ui @javascript + Scenario: Adding page with multiple content elements + Given there is an existing media with names "Image 1" and "Image 2" + And the store has "iPhone 8" and "iPhone X" products + And the store classifies its products as "Smartphones" and "Laptops" + 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 click on Add button in Content elements section + And I select "Textarea" content element + And I add a textarea content element with "Welcome to our store" content + And I click on Add button in Content elements section + And I select "Single media" content element + And I add a single media content element with name "Image 1" + And I click on Add button in Content elements section + And I select "Multiple media" content element + And I add a multiple media content element with names "Image 1" and "Image 2" + And I click on Add button in Content elements section + And I select "Heading" content element + And I add a heading content element with type "H2" and "Welcome to our store" content + And I click on Add button in Content elements section + And I select "Products carousel" content element + And I add a products carousel content element with "iPhone 8" and "iPhone X" products + And I click on Add button in Content elements section + And I select "Products carousel by Taxon" content element + And I add a products carousel by taxon content element with "Smartphones" taxonomy + And I click on Add button in Content elements section + And I select "Taxons list" content element + And I add a taxons list content element with "Smartphones" and "Laptops" taxonomy + 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 + And I should see newly created "Multiple media" content element in Content elements section + And I should see newly created "Heading" content element in Content elements section + And I should see newly created "Products carousel" content element in Content elements section + And I should see newly created "Products carousel by Taxon" content element in Content elements section diff --git a/tests/Behat/Behaviour/ContainsContentElementTrait.php b/tests/Behat/Behaviour/ContainsContentElementTrait.php index 19726f05d..3cc685472 100644 --- a/tests/Behat/Behaviour/ContainsContentElementTrait.php +++ b/tests/Behat/Behaviour/ContainsContentElementTrait.php @@ -31,9 +31,11 @@ public function containsContentElement(string $contentElement): bool ?? $this->getDocument()->findById('bitbag_sylius_cms_plugin_page_contentElements'); if (null === $contentElements) { - throw new \InvalidArgumentException('Content elements container not found'); + throw new \InvalidArgumentException('Content elements container not found.'); } + // Autocomplete fields doesn't have labels directly above input field, so we can't use hasField method, + // so we need to check if input field with search class exists instead. return $isAutocompleteField ? $contentElements->has('css', 'input.search') : $contentElements->hasField($contentElement); diff --git a/tests/Behat/Context/Ui/Admin/BlockContext.php b/tests/Behat/Context/Ui/Admin/BlockContext.php index 0bbafab1f..e2c7b338e 100755 --- a/tests/Behat/Context/Ui/Admin/BlockContext.php +++ b/tests/Behat/Context/Ui/Admin/BlockContext.php @@ -171,6 +171,14 @@ public function iAddASingleMediaContentElementWithName(string $name): void $this->resolveCurrentPage()->addSingleMediaContentElementWithName($name); } + /** + * @When I add a multiple media content element with names :firstMediaName and :secondMediaName + */ + public function iAddAMultipleMediaContentElementWithNames(string ...$mediaNames): void + { + $this->resolveCurrentPage()->addMultipleMediaContentElementWithNames($mediaNames); + } + /** * @When I add a heading content element with type :type and :content content */ diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index 0fedd8482..4a4a2f669 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -143,6 +143,29 @@ public function addSingleMediaContentElementWithName(string $name): void $item->click(); } + /** + * @throws ElementNotFoundException + */ + public function addMultipleMediaContentElementWithNames(array $mediaNames): void + { + $dropdown = $this->getElement('content_elements_multiple_media_dropdown'); + $dropdown->click(); + + foreach ($mediaNames as $mediaName) { + $dropdown->waitFor(10, function () use ($mediaName): bool { + return $this->hasElement('content_elements_multiple_media_dropdown_item', [ + '%item%' => $mediaName, + ]); + }); + + $item = $this->getElement('content_elements_multiple_media_dropdown_item', [ + '%item%' => $mediaName, + ]); + + $item->click(); + } + } + /** * @throws ElementNotFoundException */ @@ -232,6 +255,8 @@ protected function getDefinedElements(): array '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', diff --git a/tests/Behat/Page/Admin/Block/CreatePageInterface.php b/tests/Behat/Page/Admin/Block/CreatePageInterface.php index 7d60c0a19..95bbcfbbb 100755 --- a/tests/Behat/Page/Admin/Block/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Block/CreatePageInterface.php @@ -37,6 +37,8 @@ public function addTextareaContentElementWithContent(string $content): void; public function addSingleMediaContentElementWithName(string $name): void; + public function addMultipleMediaContentElementWithNames(array $mediaNames): void; + public function addHeadingContentElementWithTypeAndContent(string $type, string $content): void; public function addProductsCarouselContentElementWithProducts(array $productsNames): void; From bc81d10bdec43b5d2c7e742a035d215fc6f5aca2 Mon Sep 17 00:00:00 2001 From: jkindly Date: Wed, 10 Jul 2024 11:32:56 +0200 Subject: [PATCH 30/36] OP-326: Behat - adding block/page with two content elements --- features/admin/adding_block.feature | 18 ++++++++++++++++++ features/admin/adding_page.feature | 23 +---------------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index 1bb3cd92a..bfa957115 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -115,6 +115,24 @@ Feature: Adding blocks Then I should be notified that the block has been created And I should see newly created "Taxons list" content element in Content elements section + @ui @javascript + Scenario: Adding block with two content elements + Given there is an existing media with names "Image 1" and "Image 2" + And the store classifies its products as "Smartphones" and "Laptops" + When I go to the create block page + And I fill the code with "intro" + And I fill the name with "Intro" + And I click on Add button in Content elements section + And I select "Taxons list" content element + And I add a taxons list content element with "Smartphones" and "Laptops" taxonomy + And I click on Add button in Content elements section + And I select "Multiple media" content element + And I add a multiple media content element with names "Image 1" and "Image 2" + And I add it + Then I should be notified that the block has been created + And I should see newly created "Taxons list" content element in Content elements section + And I should see newly created "Multiple media" content element in Content elements section + @ui Scenario: Trying to add block with existing code Given there is an existing block with "homepage_image" code diff --git a/features/admin/adding_page.feature b/features/admin/adding_page.feature index 045460b3a..fc9bd1cc8 100644 --- a/features/admin/adding_page.feature +++ b/features/admin/adding_page.feature @@ -164,40 +164,19 @@ Feature: Adding new page And I should see newly created "Taxons list" content element in Content elements section @ui @javascript - Scenario: Adding page with multiple content elements + Scenario: Adding page with two content elements Given there is an existing media with names "Image 1" and "Image 2" - And the store has "iPhone 8" and "iPhone X" products - And the store classifies its products as "Smartphones" and "Laptops" 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 click on Add button in Content elements section - And I select "Textarea" content element - And I add a textarea content element with "Welcome to our store" content - And I click on Add button in Content elements section And I select "Single media" content element And I add a single media content element with name "Image 1" And I click on Add button in Content elements section And I select "Multiple media" content element And I add a multiple media content element with names "Image 1" and "Image 2" - And I click on Add button in Content elements section - And I select "Heading" content element - And I add a heading content element with type "H2" and "Welcome to our store" content - And I click on Add button in Content elements section - And I select "Products carousel" content element - And I add a products carousel content element with "iPhone 8" and "iPhone X" products - And I click on Add button in Content elements section - And I select "Products carousel by Taxon" content element - And I add a products carousel by taxon content element with "Smartphones" taxonomy - And I click on Add button in Content elements section - And I select "Taxons list" content element - And I add a taxons list content element with "Smartphones" and "Laptops" taxonomy 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 And I should see newly created "Multiple media" content element in Content elements section - And I should see newly created "Heading" content element in Content elements section - And I should see newly created "Products carousel" content element in Content elements section - And I should see newly created "Products carousel by Taxon" content element in Content elements section From 391330d2e6437392be3cfa411912b7ffd4aa698d Mon Sep 17 00:00:00 2001 From: jkindly Date: Wed, 10 Jul 2024 13:27:24 +0200 Subject: [PATCH 31/36] OP-326: Behat - deleting content element --- features/admin/managing_blocks.feature | 9 +++++++ features/admin/managing_pages.feature | 9 +++++++ tests/Behat/Context/Setup/BlockContext.php | 13 +++++----- tests/Behat/Context/Setup/PageContext.php | 13 +++++----- tests/Behat/Context/Ui/Admin/BlockContext.php | 16 +++++++++++++ tests/Behat/Context/Ui/Admin/PageContext.php | 16 +++++++++++++ tests/Behat/Helpers/ContentElementHelper.php | 24 +++++++++++++++++++ tests/Behat/Page/Admin/Block/UpdatePage.php | 5 ++++ .../Page/Admin/Block/UpdatePageInterface.php | 2 ++ tests/Behat/Page/Admin/Page/UpdatePage.php | 5 ++++ .../Page/Admin/Page/UpdatePageInterface.php | 2 ++ 11 files changed, 102 insertions(+), 12 deletions(-) diff --git a/features/admin/managing_blocks.feature b/features/admin/managing_blocks.feature index e9a6af46a..75ceb4b34 100644 --- a/features/admin/managing_blocks.feature +++ b/features/admin/managing_blocks.feature @@ -34,6 +34,15 @@ Feature: Managing cms blocks Then I should be notified that the block has been successfully updated And I should see "New content" in the textarea content element + @ui @javascript + Scenario: Deleting content element in block + Given there is a block with "store_phone_number" code and "Textarea" content element + When I go to the update "store_phone_number" block page + And I delete the content element + And I update it + Then I should be notified that the block has been successfully updated + And I should not see "Textarea" content element in the Content elements section + @ui Scenario: Disabling block Given there is an existing block with "bitbag_quote" code diff --git a/features/admin/managing_pages.feature b/features/admin/managing_pages.feature index 7e4c3f4cc..b4f4f1d91 100644 --- a/features/admin/managing_pages.feature +++ b/features/admin/managing_pages.feature @@ -39,3 +39,12 @@ Feature: Managing cms pages And I update it Then I should be notified that the page was updated And I should see "New content" in the textarea content element + + @ui @javascript + Scenario: Deleting content element in page + Given there is a page in the store with "Textarea" content element + When I want to edit this page + And I delete the content element + And I update it + Then I should be notified that the page was updated + And I should not see "Textarea" content element in the Content elements section diff --git a/tests/Behat/Context/Setup/BlockContext.php b/tests/Behat/Context/Setup/BlockContext.php index e17f04c20..0bea3fc39 100755 --- a/tests/Behat/Context/Setup/BlockContext.php +++ b/tests/Behat/Context/Setup/BlockContext.php @@ -17,6 +17,7 @@ use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Resource\Factory\FactoryInterface; +use Tests\BitBag\SyliusCmsPlugin\Behat\Helpers\ContentElementHelper; use Tests\BitBag\SyliusCmsPlugin\Behat\Service\RandomStringGeneratorInterface; final class BlockContext implements Context @@ -61,11 +62,11 @@ public function thereIsABlockWithCodeAndContent(string $code): void } /** - * @Given there is a block with :code code and textarea content element + * @Given there is a block with :code code and :contentElement content element */ - public function thereIsABlockWithCodeAndTextareaContentElement(string $code): void + public function thereIsABlockWithCodeAndContentElement(string $code, string $contentElement): void { - $block = $this->createBlockWithTextareaContentElement($code); + $block = $this->createBlockWithContentElement($code, $contentElement); $this->saveBlock($block); } @@ -91,13 +92,13 @@ private function createBlock( return $block; } - private function createBlockWithTextareaContentElement(string $code): BlockInterface + private function createBlockWithContentElement(string $code, string $contentElement): BlockInterface { $block = $this->createBlock($code); $contentConfiguration = new ContentConfiguration(); - $contentConfiguration->setType('textarea'); - $contentConfiguration->setConfiguration(['textarea' => 'Content']); + $contentConfiguration->setType($contentElement); + $contentConfiguration->setConfiguration(ContentElementHelper::getExampleConfigurationByContentElement($contentElement)); $contentConfiguration->setBlock($block); $block->addContentElement($contentConfiguration); diff --git a/tests/Behat/Context/Setup/PageContext.php b/tests/Behat/Context/Setup/PageContext.php index d91b1837d..15ff23e5c 100755 --- a/tests/Behat/Context/Setup/PageContext.php +++ b/tests/Behat/Context/Setup/PageContext.php @@ -26,6 +26,7 @@ use Sylius\Component\Core\Repository\ProductRepositoryInterface; use Sylius\Component\Resource\Factory\FactoryInterface; use Symfony\Component\HttpFoundation\File\UploadedFile; +use Tests\BitBag\SyliusCmsPlugin\Behat\Helpers\ContentElementHelper; use Tests\BitBag\SyliusCmsPlugin\Behat\Service\RandomStringGeneratorInterface; final class PageContext implements Context @@ -53,11 +54,11 @@ public function thereIsAPageInTheStore(): void } /** - * @Given there is a page in the store with textarea content element + * @Given there is a page in the store with :contentElement content element */ - public function thereIsAPageInTheStoreWithTextareaContentElement(): void + public function thereIsAPageInTheStoreWithTextareaContentElement(string $contentElement): void { - $page = $this->createPageWithTextareaContentElement(); + $page = $this->createPageWithContentElement($contentElement); $this->savePage($page); } @@ -203,14 +204,14 @@ private function createPage( return $page; } - private function createPageWithTextareaContentElement(): PageInterface + private function createPageWithContentElement(string $contentElement): PageInterface { $page = $this->createPage(); /** @var ContentConfigurationInterface $contentConfiguration */ $contentConfiguration = new ContentConfiguration(); - $contentConfiguration->setType('textarea'); - $contentConfiguration->setConfiguration(['textarea' => 'Content']); + $contentConfiguration->setType($contentElement); + $contentConfiguration->setConfiguration(ContentElementHelper::getExampleConfigurationByContentElement($contentElement)); $contentConfiguration->setPage($page); $page->addContentElement($contentConfiguration); diff --git a/tests/Behat/Context/Ui/Admin/BlockContext.php b/tests/Behat/Context/Ui/Admin/BlockContext.php index e2c7b338e..6d250cd31 100755 --- a/tests/Behat/Context/Ui/Admin/BlockContext.php +++ b/tests/Behat/Context/Ui/Admin/BlockContext.php @@ -227,6 +227,22 @@ public function iShouldSeeNewContentInTheTextareaContentElement(string $content) $this->resolveCurrentPage()->containsTextareaContentElementWithValue($content); } + /** + * @When I delete the content element + */ + public function iDeleteTheContentElement(): void + { + $this->resolveCurrentPage()->deleteContentElement(); + } + + /** + * @Then I should not see :contentElement content element in the Content elements section + */ + public function iShouldNotSeeContentElementInTheContentElementsSection(string $contentElement): void + { + Assert::false($this->resolveCurrentPage()->containsContentElement($contentElement)); + } + /** * @When I fill the link with :link */ diff --git a/tests/Behat/Context/Ui/Admin/PageContext.php b/tests/Behat/Context/Ui/Admin/PageContext.php index b172780c3..b5f3d4880 100755 --- a/tests/Behat/Context/Ui/Admin/PageContext.php +++ b/tests/Behat/Context/Ui/Admin/PageContext.php @@ -265,6 +265,22 @@ public function iShouldSeeNewlyCreatedContentElementInContentElementsSection(str Assert::true($this->resolveCurrentPage()->containsContentElement($contentElement)); } + /** + * @When I delete the content element + */ + public function iDeleteTheContentElement(): void + { + $this->resolveCurrentPage()->deleteContentElement(); + } + + /** + * @Then I should not see :contentElement content element in the Content elements section + */ + public function iShouldNotSeeContentElementInTheContentElementsSection(string $contentElement): void + { + Assert::false($this->resolveCurrentPage()->containsContentElement($contentElement)); + } + /** * @When I add it * @When I try to add it diff --git a/tests/Behat/Helpers/ContentElementHelper.php b/tests/Behat/Helpers/ContentElementHelper.php index 9f9aa2d78..32a5161a1 100644 --- a/tests/Behat/Helpers/ContentElementHelper.php +++ b/tests/Behat/Helpers/ContentElementHelper.php @@ -25,4 +25,28 @@ public static function getDefinedElementThatShouldAppearAfterSelectContentElemen default => throw new \InvalidArgumentException(sprintf('Content element with name "%s" does not exist.', $contentElement)), }; } + + public static function getExampleConfigurationByContentElement(string $contentElement): array + { + return match ($contentElement) { + 'Textarea' => ['textarea' => 'Content'], + 'Single media' => ['single_media' => 'homepage_header_image'], + 'Multiple media' => ['multiple_media' => ['homepage_header_image', 'homepage_pdf']], + 'Heading' => ['heading_type' => 'h1', 'heading' => 'Heading content'], + 'Products carousel' => ["products_carousel" => [ + "products" => [ + "Everyday_white_basic_T_Shirt", + "Loose_white_designer_T_Shirt" + ], + ]], + 'Products carousel by Taxon' => ['products_carousel_by_taxon' => 'MENU_CATEGORY'], + 'Taxons list' => ["taxons_list" => [ + "taxons" => [ + "MENU_CATEGORY", + "t_shirts" + ], + ]], + default => throw new \InvalidArgumentException(sprintf('Content element with name "%s" does not exist.', $contentElement)), + }; + } } diff --git a/tests/Behat/Page/Admin/Block/UpdatePage.php b/tests/Behat/Page/Admin/Block/UpdatePage.php index ffba781ba..cb80482aa 100755 --- a/tests/Behat/Page/Admin/Block/UpdatePage.php +++ b/tests/Behat/Page/Admin/Block/UpdatePage.php @@ -60,4 +60,9 @@ public function containsTextareaContentElementWithValue(string $value): bool { return $this->getDocument()->findField('Textarea')->getValue() === $value; } + + public function deleteContentElement(): void + { + $this->getDocument()->find('css', '.bb-collection-item-delete')->click(); + } } diff --git a/tests/Behat/Page/Admin/Block/UpdatePageInterface.php b/tests/Behat/Page/Admin/Block/UpdatePageInterface.php index 6aa8e0e1c..bc104bf32 100755 --- a/tests/Behat/Page/Admin/Block/UpdatePageInterface.php +++ b/tests/Behat/Page/Admin/Block/UpdatePageInterface.php @@ -34,4 +34,6 @@ public function isBlockDisabled(): bool; public function changeTextareaContentElementValue(string $value): void; public function containsTextareaContentElementWithValue(string $value): bool; + + public function deleteContentElement(): void; } diff --git a/tests/Behat/Page/Admin/Page/UpdatePage.php b/tests/Behat/Page/Admin/Page/UpdatePage.php index b5514b8be..39bed0ec3 100755 --- a/tests/Behat/Page/Admin/Page/UpdatePage.php +++ b/tests/Behat/Page/Admin/Page/UpdatePage.php @@ -39,4 +39,9 @@ public function containsTextareaContentElementWithValue(string $value): bool { return $this->getDocument()->findField('Textarea')->getValue() === $value; } + + public function deleteContentElement(): void + { + $this->getDocument()->find('css', '.bb-collection-item-delete')->click(); + } } diff --git a/tests/Behat/Page/Admin/Page/UpdatePageInterface.php b/tests/Behat/Page/Admin/Page/UpdatePageInterface.php index 2cd61f3b2..86faa678d 100755 --- a/tests/Behat/Page/Admin/Page/UpdatePageInterface.php +++ b/tests/Behat/Page/Admin/Page/UpdatePageInterface.php @@ -26,4 +26,6 @@ public function chooseImage(string $code): void; public function changeTextareaContentElementValue(string $value): void; public function containsTextareaContentElementWithValue(string $value): bool; + + public function deleteContentElement(): void; } From 394cb62e0e4a7f53a4fe8ba060ba3139dc0d890b Mon Sep 17 00:00:00 2001 From: jkindly Date: Wed, 10 Jul 2024 13:35:50 +0200 Subject: [PATCH 32/36] OP-326: Behat - deleting content element --- features/admin/managing_blocks.feature | 2 +- features/admin/managing_pages.feature | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/features/admin/managing_blocks.feature b/features/admin/managing_blocks.feature index 75ceb4b34..db8c7dc4c 100644 --- a/features/admin/managing_blocks.feature +++ b/features/admin/managing_blocks.feature @@ -26,7 +26,7 @@ Feature: Managing cms blocks @ui Scenario: Updating block textarea content element - Given there is a block with "store_phone_number" code and textarea content element + Given there is a block with "store_phone_number" code and "Textarea" content element When I go to the update "store_phone_number" block page And I fill the name with "Store phone number" if the name field is empty And I change textarea content element value to "New content" diff --git a/features/admin/managing_pages.feature b/features/admin/managing_pages.feature index b4f4f1d91..27c73d3dc 100644 --- a/features/admin/managing_pages.feature +++ b/features/admin/managing_pages.feature @@ -32,7 +32,7 @@ Feature: Managing cms pages @ui Scenario: Updating page with textarea content element - Given there is a page in the store with textarea content element + Given there is a page in the store with "Textarea" content element When I want to edit this page And I fill "Code, Name" fields And I change textarea content element value to "New content" From 00a9086ea0f57786b0c4f76cfe50a517f0305ee3 Mon Sep 17 00:00:00 2001 From: jkindly Date: Wed, 10 Jul 2024 13:36:31 +0200 Subject: [PATCH 33/36] OP-326: Behat - deleting content element --- tests/Behat/Helpers/ContentElementHelper.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/Behat/Helpers/ContentElementHelper.php b/tests/Behat/Helpers/ContentElementHelper.php index 32a5161a1..c2915b9d7 100644 --- a/tests/Behat/Helpers/ContentElementHelper.php +++ b/tests/Behat/Helpers/ContentElementHelper.php @@ -33,17 +33,17 @@ public static function getExampleConfigurationByContentElement(string $contentEl 'Single media' => ['single_media' => 'homepage_header_image'], 'Multiple media' => ['multiple_media' => ['homepage_header_image', 'homepage_pdf']], 'Heading' => ['heading_type' => 'h1', 'heading' => 'Heading content'], - 'Products carousel' => ["products_carousel" => [ - "products" => [ - "Everyday_white_basic_T_Shirt", - "Loose_white_designer_T_Shirt" + 'Products carousel' => ['products_carousel' => [ + 'products' => [ + 'Everyday_white_basic_T_Shirt', + 'Loose_white_designer_T_Shirt', ], ]], 'Products carousel by Taxon' => ['products_carousel_by_taxon' => 'MENU_CATEGORY'], - 'Taxons list' => ["taxons_list" => [ - "taxons" => [ - "MENU_CATEGORY", - "t_shirts" + 'Taxons list' => ['taxons_list' => [ + 'taxons' => [ + 'MENU_CATEGORY', + 't_shirts', ], ]], default => throw new \InvalidArgumentException(sprintf('Content element with name "%s" does not exist.', $contentElement)), From d5f795cc38aa23b41c7d59ad1caf42d2a049b486 Mon Sep 17 00:00:00 2001 From: jkindly Date: Wed, 10 Jul 2024 13:53:22 +0200 Subject: [PATCH 34/36] OP-326: Behat - deleting content element --- features/admin/managing_blocks.feature | 4 ++-- features/admin/managing_pages.feature | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/features/admin/managing_blocks.feature b/features/admin/managing_blocks.feature index db8c7dc4c..31da0f318 100644 --- a/features/admin/managing_blocks.feature +++ b/features/admin/managing_blocks.feature @@ -26,7 +26,7 @@ Feature: Managing cms blocks @ui Scenario: Updating block textarea content element - Given there is a block with "store_phone_number" code and "Textarea" content element + Given there is a block with "store_phone_number" code and "textarea" content element When I go to the update "store_phone_number" block page And I fill the name with "Store phone number" if the name field is empty And I change textarea content element value to "New content" @@ -36,7 +36,7 @@ Feature: Managing cms blocks @ui @javascript Scenario: Deleting content element in block - Given there is a block with "store_phone_number" code and "Textarea" content element + Given there is a block with "store_phone_number" code and "textarea" content element When I go to the update "store_phone_number" block page And I delete the content element And I update it diff --git a/features/admin/managing_pages.feature b/features/admin/managing_pages.feature index 27c73d3dc..69920c04b 100644 --- a/features/admin/managing_pages.feature +++ b/features/admin/managing_pages.feature @@ -32,7 +32,7 @@ Feature: Managing cms pages @ui Scenario: Updating page with textarea content element - Given there is a page in the store with "Textarea" content element + Given there is a page in the store with "textarea" content element When I want to edit this page And I fill "Code, Name" fields And I change textarea content element value to "New content" @@ -42,7 +42,7 @@ Feature: Managing cms pages @ui @javascript Scenario: Deleting content element in page - Given there is a page in the store with "Textarea" content element + Given there is a page in the store with "textarea" content element When I want to edit this page And I delete the content element And I update it From f14c55ac8a8a195d941506647281dcd2a75ec02c Mon Sep 17 00:00:00 2001 From: jkindly Date: Wed, 10 Jul 2024 14:20:33 +0200 Subject: [PATCH 35/36] OP-326: Behat - deleting content element --- features/admin/managing_blocks.feature | 4 ++-- features/admin/managing_pages.feature | 4 ++-- tests/Behat/Context/Setup/BlockContext.php | 2 +- tests/Behat/Context/Setup/PageContext.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/features/admin/managing_blocks.feature b/features/admin/managing_blocks.feature index 31da0f318..db8c7dc4c 100644 --- a/features/admin/managing_blocks.feature +++ b/features/admin/managing_blocks.feature @@ -26,7 +26,7 @@ Feature: Managing cms blocks @ui Scenario: Updating block textarea content element - Given there is a block with "store_phone_number" code and "textarea" content element + Given there is a block with "store_phone_number" code and "Textarea" content element When I go to the update "store_phone_number" block page And I fill the name with "Store phone number" if the name field is empty And I change textarea content element value to "New content" @@ -36,7 +36,7 @@ Feature: Managing cms blocks @ui @javascript Scenario: Deleting content element in block - Given there is a block with "store_phone_number" code and "textarea" content element + Given there is a block with "store_phone_number" code and "Textarea" content element When I go to the update "store_phone_number" block page And I delete the content element And I update it diff --git a/features/admin/managing_pages.feature b/features/admin/managing_pages.feature index 69920c04b..27c73d3dc 100644 --- a/features/admin/managing_pages.feature +++ b/features/admin/managing_pages.feature @@ -32,7 +32,7 @@ Feature: Managing cms pages @ui Scenario: Updating page with textarea content element - Given there is a page in the store with "textarea" content element + Given there is a page in the store with "Textarea" content element When I want to edit this page And I fill "Code, Name" fields And I change textarea content element value to "New content" @@ -42,7 +42,7 @@ Feature: Managing cms pages @ui @javascript Scenario: Deleting content element in page - Given there is a page in the store with "textarea" content element + Given there is a page in the store with "Textarea" content element When I want to edit this page And I delete the content element And I update it diff --git a/tests/Behat/Context/Setup/BlockContext.php b/tests/Behat/Context/Setup/BlockContext.php index 0bea3fc39..c7ab01deb 100755 --- a/tests/Behat/Context/Setup/BlockContext.php +++ b/tests/Behat/Context/Setup/BlockContext.php @@ -97,7 +97,7 @@ private function createBlockWithContentElement(string $code, string $contentElem $block = $this->createBlock($code); $contentConfiguration = new ContentConfiguration(); - $contentConfiguration->setType($contentElement); + $contentConfiguration->setType(mb_strtolower($contentElement)); $contentConfiguration->setConfiguration(ContentElementHelper::getExampleConfigurationByContentElement($contentElement)); $contentConfiguration->setBlock($block); diff --git a/tests/Behat/Context/Setup/PageContext.php b/tests/Behat/Context/Setup/PageContext.php index 15ff23e5c..2c842d9e6 100755 --- a/tests/Behat/Context/Setup/PageContext.php +++ b/tests/Behat/Context/Setup/PageContext.php @@ -210,7 +210,7 @@ private function createPageWithContentElement(string $contentElement): PageInter /** @var ContentConfigurationInterface $contentConfiguration */ $contentConfiguration = new ContentConfiguration(); - $contentConfiguration->setType($contentElement); + $contentConfiguration->setType(mb_strtolower($contentElement)); $contentConfiguration->setConfiguration(ContentElementHelper::getExampleConfigurationByContentElement($contentElement)); $contentConfiguration->setPage($page); From bfee78ab20c1781a7c32edcb617f9f90bd0bbac4 Mon Sep 17 00:00:00 2001 From: jkindly Date: Wed, 10 Jul 2024 14:29:28 +0200 Subject: [PATCH 36/36] OP-326: Behat - deleting content element --- features/admin/managing_blocks.feature | 1 + tests/Behat/Context/Setup/BlockContext.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/features/admin/managing_blocks.feature b/features/admin/managing_blocks.feature index db8c7dc4c..311e55aac 100644 --- a/features/admin/managing_blocks.feature +++ b/features/admin/managing_blocks.feature @@ -38,6 +38,7 @@ Feature: Managing cms blocks Scenario: Deleting content element in block Given there is a block with "store_phone_number" code and "Textarea" content element When I go to the update "store_phone_number" block page + And I fill the name with "Store phone number" if the name field is empty And I delete the content element And I update it Then I should be notified that the block has been successfully updated diff --git a/tests/Behat/Context/Setup/BlockContext.php b/tests/Behat/Context/Setup/BlockContext.php index c7ab01deb..4f3b06ecb 100755 --- a/tests/Behat/Context/Setup/BlockContext.php +++ b/tests/Behat/Context/Setup/BlockContext.php @@ -13,6 +13,7 @@ use Behat\Behat\Context\Context; use BitBag\SyliusCmsPlugin\Entity\BlockInterface; use BitBag\SyliusCmsPlugin\Entity\ContentConfiguration; +use BitBag\SyliusCmsPlugin\Entity\ContentConfigurationInterface; use BitBag\SyliusCmsPlugin\Repository\BlockRepositoryInterface; use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Component\Core\Model\ChannelInterface; @@ -96,6 +97,7 @@ private function createBlockWithContentElement(string $code, string $contentElem { $block = $this->createBlock($code); + /** @var ContentConfigurationInterface $contentConfiguration */ $contentConfiguration = new ContentConfiguration(); $contentConfiguration->setType(mb_strtolower($contentElement)); $contentConfiguration->setConfiguration(ContentElementHelper::getExampleConfigurationByContentElement($contentElement));