Skip to content

Commit

Permalink
OP-327: Code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Jul 12, 2024
1 parent 0fd2d10 commit e9185e7
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 92 deletions.
6 changes: 0 additions & 6 deletions src/Form/DataTransformer/MultipleMediaToCodesTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public function __construct(private MediaRepositoryInterface $mediaRepository)
{
}

/**
* @throws \InvalidArgumentException
*/
public function transform($value): Collection
{
Assert::nullOrIsArray($value);
Expand All @@ -37,9 +34,6 @@ public function transform($value): Collection
return new ArrayCollection($this->mediaRepository->findBy(['code' => $value]));
}

/**
* @throws \InvalidArgumentException
*/
public function reverseTransform($value): array
{
Assert::isInstanceOf($value, Collection::class);
Expand Down
15 changes: 10 additions & 5 deletions src/Form/Type/ContentConfigurationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,16 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
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()],
[
'field' => $builder->create(
'configuration',
$this->actionConfigurationTypes[$type],
[
'label' => false,
'csrf_protection' => false,
],
)->getForm()->createView(),
],
),
];
},
Expand Down
14 changes: 7 additions & 7 deletions src/Resources/config/services/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,40 +74,40 @@
<tag name="form.type" />
</service>

<service id="BitBag\SyliusCmsPlugin\Form\Type\ContentElements\TextareaContentElementType">
<service id="bitbag_sylius_cms_plugin.form.type.content_element.textarea" class="BitBag\SyliusCmsPlugin\Form\Type\ContentElements\TextareaContentElementType">
<tag name="bitbag_sylius_cms_plugin.content_elements.type" key="%bitbag_sylius_cms_plugin.content_elements.type.textarea%" />
<tag name="form.type" />
</service>

<service id="BitBag\SyliusCmsPlugin\Form\Type\ContentElements\SingleMediaContentElementType">
<service id="bitbag_sylius_cms_plugin.form.type.content_element.single_media" class="BitBag\SyliusCmsPlugin\Form\Type\ContentElements\SingleMediaContentElementType">
<argument type="service" id="bitbag_sylius_cms_plugin.repository.media" />
<tag name="bitbag_sylius_cms_plugin.content_elements.type" key="%bitbag_sylius_cms_plugin.content_elements.type.single_media%" />
<tag name="form.type" />
</service>

<service id="BitBag\SyliusCmsPlugin\Form\Type\ContentElements\MultipleMediaContentElementType">
<service id="bitbag_sylius_cms_plugin.form.type.content_element.multiple_media" class="BitBag\SyliusCmsPlugin\Form\Type\ContentElements\MultipleMediaContentElementType">
<argument type="service" id="bitbag_sylius_cms_plugin.form.type.data_transformer.multiple_media_to_codes" />
<tag name="bitbag_sylius_cms_plugin.content_elements.type" key="%bitbag_sylius_cms_plugin.content_elements.type.multiple_media%" />
<tag name="form.type" />
</service>

<service id="BitBag\SyliusCmsPlugin\Form\Type\ContentElements\HeadingContentElementType">
<service id="bitbag_sylius_cms_plugin.form.type.content_element.heading" class="BitBag\SyliusCmsPlugin\Form\Type\ContentElements\HeadingContentElementType">
<tag name="bitbag_sylius_cms_plugin.content_elements.type" key="%bitbag_sylius_cms_plugin.content_elements.type.heading%" />
<tag name="form.type" />
</service>

<service id="BitBag\SyliusCmsPlugin\Form\Type\ContentElements\ProductsCarouselContentElementType">
<service id="bitbag_sylius_cms_plugin.form.type.content_element.products_carousel" class="BitBag\SyliusCmsPlugin\Form\Type\ContentElements\ProductsCarouselContentElementType">
<tag name="bitbag_sylius_cms_plugin.content_elements.type" key="%bitbag_sylius_cms_plugin.content_elements.type.products_carousel%" />
<tag name="form.type" />
</service>

<service id="BitBag\SyliusCmsPlugin\Form\Type\ContentElements\ProductsCarouselByTaxonContentElementType">
<service id="bitbag_sylius_cms_plugin.form.type.content_element.products_carousel_by_taxon" class="BitBag\SyliusCmsPlugin\Form\Type\ContentElements\ProductsCarouselByTaxonContentElementType">
<argument type="service" id="sylius.repository.taxon" />
<tag name="bitbag_sylius_cms_plugin.content_elements.type" key="%bitbag_sylius_cms_plugin.content_elements.type.products_carousel_by_taxon%" />
<tag name="form.type" />
</service>

<service id="BitBag\SyliusCmsPlugin\Form\Type\ContentElements\TaxonsListContentElementType">
<service id="bitbag_sylius_cms_plugin.form.type.content_element.taxons_list" class="BitBag\SyliusCmsPlugin\Form\Type\ContentElements\TaxonsListContentElementType">
<tag name="bitbag_sylius_cms_plugin.content_elements.type" key="%bitbag_sylius_cms_plugin.content_elements.type.taxons_list%" />
<tag name="form.type" />
</service>
Expand Down
2 changes: 0 additions & 2 deletions tests/Behat/Behaviour/ContainsContentElementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public function containsContentElement(string $contentElement): bool
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);
Expand Down
44 changes: 8 additions & 36 deletions tests/Behat/Page/Admin/Block/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace Tests\BitBag\SyliusCmsPlugin\Behat\Page\Admin\Block;

use Behat\Mink\Exception\ElementNotFoundException;
use DMore\ChromeDriver\ChromeDriver;
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsErrorTrait;
Expand Down Expand Up @@ -66,7 +65,7 @@ public function associateCollections(array $collectionsNames): void
$dropdown->click();

foreach ($collectionsNames as $collectionName) {
$dropdown->waitFor(10, function () use ($collectionName): bool {
$dropdown->waitFor(5, function () use ($collectionName): bool {
return $this->hasElement('association_dropdown_collection_item', [
'%item%' => $collectionName,
]);
Expand All @@ -80,40 +79,31 @@ public function associateCollections(array $collectionsNames): void
}
}

/**
* @throws ElementNotFoundException
*/
public function clickOnAddContentElementButton(): void
{
Assert::isInstanceOf($this->getDriver(), ChromeDriver::class);

$addButton = $this->getElement('content_elements_add_button');
$addButton->click();

$addButton->waitFor(3, function (): bool {
$addButton->waitFor(1, 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 {
$select->waitFor(1, function () use ($contentElement): bool {
return $this->hasElement(
ContentElementHelper::getDefinedElementThatShouldAppearAfterSelectContentElement($contentElement),
);
});
}

/**
* @throws ElementNotFoundException
*/
public function addTextareaContentElementWithContent(string $content): void
{
Assert::isInstanceOf($this->getDriver(), ChromeDriver::class);
Expand All @@ -122,15 +112,12 @@ public function addTextareaContentElementWithContent(string $content): void
$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 {
$dropdown->waitFor(5, function () use ($name): bool {
return $this->hasElement('content_elements_single_media_dropdown_item', [
'%item%' => $name,
]);
Expand All @@ -143,16 +130,13 @@ 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 {
$dropdown->waitFor(5, function () use ($mediaName): bool {
return $this->hasElement('content_elements_multiple_media_dropdown_item', [
'%item%' => $mediaName,
]);
Expand All @@ -166,9 +150,6 @@ public function addMultipleMediaContentElementWithNames(array $mediaNames): void
}
}

/**
* @throws ElementNotFoundException
*/
public function addHeadingContentElementWithTypeAndContent(string $type, string $content): void
{
$heading = $this->getElement('content_elements_heading');
Expand All @@ -178,16 +159,13 @@ 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 {
$dropdown->waitFor(5, function () use ($productName): bool {
return $this->hasElement('content_elements_products_carousel_item', [
'%item%' => $productName,
]);
Expand All @@ -201,15 +179,12 @@ 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 {
$dropdown->waitFor(5, function () use ($taxon): bool {
return $this->hasElement('content_elements_products_carousel_by_taxon_item', [
'%item%' => $taxon,
]);
Expand All @@ -222,16 +197,13 @@ public function addProductsCarouselByTaxonContentElementWithTaxon(string $taxon)
$item->click();
}

/**
* @throws ElementNotFoundException
*/
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 {
$dropdown->waitFor(5, function () use ($taxon): bool {
return $this->hasElement('content_elements_taxons_list_item', [
'%item%' => $taxon,
]);
Expand Down
Loading

0 comments on commit e9185e7

Please sign in to comment.