Skip to content

Commit

Permalink
OP-543: Fixtures fix and ECS
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Sep 13, 2024
1 parent 1b21440 commit 0475fdc
Show file tree
Hide file tree
Showing 10 changed files with 352 additions and 330 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Sylius\CmsPlugin\Entity\ContentConfigurationInterface;
use Sylius\CmsPlugin\Form\Type\ContentElements\PagesCollectionContentElementType;
use Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement;
use Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface;
use Sylius\CmsPlugin\Renderer\ContentElement\PagesCollectionContentElementRenderer;
use Sylius\CmsPlugin\Repository\CollectionRepositoryInterface;
use Twig\Environment;
Expand Down
8 changes: 4 additions & 4 deletions spec/Renderer/ContentElementRendererStrategySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class ContentElementRendererStrategySpec extends ObjectBehavior
public function let(
ContentParserInterface $contentParser,
LocaleContextInterface $localeContext,
ContentElementRendererInterface $renderer
ContentElementRendererInterface $renderer,
): void {
$this->beConstructedWith($contentParser, $localeContext, [$renderer]);
}
Expand All @@ -34,7 +34,7 @@ public function it_renders_a_page_content_element_correctly(
ContentConfigurationInterface $contentElement,
LocaleContextInterface $localeContext,
ContentElementRendererInterface $renderer,
ContentParserInterface $contentParser
ContentParserInterface $contentParser,
): void {
$page->getContentElements()->willReturn(new ArrayCollection([$contentElement->getWrappedObject()]));
$localeContext->getLocaleCode()->willReturn('en_US');
Expand All @@ -52,7 +52,7 @@ public function it_skips_content_element_with_non_matching_locale(
BlockInterface $block,
ContentConfigurationInterface $contentElement,
LocaleContextInterface $localeContext,
ContentParserInterface $contentParser
ContentParserInterface $contentParser,
): void {
$block->getContentElements()->willReturn(new ArrayCollection([$contentElement]));
$localeContext->getLocaleCode()->willReturn('en_US');
Expand All @@ -69,7 +69,7 @@ public function it_renders_only_supported_content_elements(
ContentConfigurationInterface $unsupportedElement,
LocaleContextInterface $localeContext,
ContentElementRendererInterface $renderer,
ContentParserInterface $contentParser
ContentParserInterface $contentParser,
): void {
$block->getContentElements()->willReturn(new ArrayCollection([$supportedElement->getWrappedObject(), $unsupportedElement->getWrappedObject()]));
$localeContext->getLocaleCode()->willReturn('en_US');
Expand Down
10 changes: 5 additions & 5 deletions spec/Twig/Runtime/TranslationFormReduceRuntimeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public function it_reduces_form_to_specified_fields(
FormView $form,
FormView $localeForm,
FormView $slugForm,
FormView $titleForm
FormView $titleForm,
): void {
$form->children = [
'en_US' => $localeForm
'en_US' => $localeForm,
];

$localeForm->children = [
Expand Down Expand Up @@ -56,7 +56,7 @@ public function it_handles_multiple_locales(
FormView $enLocale,
FormView $deLocale,
FormView $slugForm,
FormView $titleForm
FormView $titleForm,
): void {
$form->children = [
'en_US' => $enLocale,
Expand Down Expand Up @@ -85,7 +85,7 @@ public function it_throws_exception_if_field_is_not_present_in_multiple_locales(
FormView $form,
FormView $enLocale,
FormView $deLocale,
FormView $slugForm
FormView $slugForm,
): void {
$form->children = [
'en_US' => $enLocale,
Expand All @@ -108,7 +108,7 @@ public function it_handles_empty_field_array(
FormView $form,
FormView $localeForm,
FormView $slugForm,
FormView $titleForm
FormView $titleForm,
): void {
$form->children = [
'en_US' => $localeForm,
Expand Down
5 changes: 3 additions & 2 deletions src/Fixture/BlockFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
->arrayNode('taxons')->scalarPrototype()->end()->end()
->arrayNode('products_in_taxons')->scalarPrototype()->end()->end()
->arrayNode('content_elements')
->useAttributeAsKey('key')
->useAttributeAsKey('locale')
->arrayPrototype()
->useAttributeAsKey('key')
->arrayPrototype()
->children()
->scalarNode('type')->end()
Expand All @@ -54,7 +56,6 @@ protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
->scalarNode('products_carousel_by_taxon')->end()
->scalarNode('products_grid_by_taxon')->end()
->scalarNode('pages_collection')->end()
->scalarNode('pages_collection')->end()
->scalarNode('spacer')->end()
->arrayNode('multiple_media')->scalarPrototype()->end()->end()
->arrayNode('products_grid')
Expand Down
21 changes: 12 additions & 9 deletions src/Fixture/Factory/BlockFixtureFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,19 @@ private function createBlock(string $code, array $blockData): void
$this->taxonsAssigner->assign($block, $blockData['taxons']);
$this->productsInTaxonsAssigner->assign($block, $blockData['products_in_taxons']);

foreach ($blockData['content_elements'] as $data) {
$data['data'] = array_filter($data['data'], static function ($value) {
return !empty($value);
});
foreach ($blockData['content_elements'] as $locale => $data) {
foreach ($data as $contentElementData) {
$contentElementData['data'] = array_filter($contentElementData['data'], static function ($value) {
return !empty($value);
});

$contentConfiguration = new ContentConfiguration();
$contentConfiguration->setType($data['type']);
$contentConfiguration->setConfiguration($data['data']);
$contentConfiguration->setBlock($block);
$block->addContentElement($contentConfiguration);
$contentConfiguration = new ContentConfiguration();
$contentConfiguration->setType($contentElementData['type']);
$contentConfiguration->setConfiguration($contentElementData['data']);
$contentConfiguration->setLocale($locale);
$contentConfiguration->setBlock($block);
$block->addContentElement($contentConfiguration);
}
}

$this->blockRepository->add($block);
Expand Down
23 changes: 13 additions & 10 deletions src/Fixture/Factory/PageFixtureFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,19 @@ private function createPage(
$page->addTranslation($pageTranslation);
}

foreach ($pageData['content_elements'] as $data) {
$data['data'] = array_filter($data['data'], static function ($value) {
return !empty($value);
});

$contentConfiguration = new ContentConfiguration();
$contentConfiguration->setType($data['type']);
$contentConfiguration->setConfiguration($data['data']);
$contentConfiguration->setPage($page);
$page->addContentElement($contentConfiguration);
foreach ($pageData['content_elements'] as $locale => $data) {
foreach ($data as $contentElementData) {
$contentElementData['data'] = array_filter($contentElementData['data'], static function ($value) {
return !empty($value);
});

$contentConfiguration = new ContentConfiguration();
$contentConfiguration->setType($contentElementData['type']);
$contentConfiguration->setConfiguration($contentElementData['data']);
$contentConfiguration->setLocale($locale);
$contentConfiguration->setPage($page);
$page->addContentElement($contentConfiguration);
}
}

$this->pageRepository->add($page);
Expand Down
4 changes: 3 additions & 1 deletion src/Fixture/PageFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
->end()
->end()
->arrayNode('content_elements')
->useAttributeAsKey('key')
->useAttributeAsKey('locale')
->arrayPrototype()
->useAttributeAsKey('key')
->arrayPrototype()
->children()
->scalarNode('type')->end()
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Type/BlockType.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'label' => 'sylius.ui.locale',
'attr' => [
'class' => 'locale-selector',
]
],
])
;

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Type/PageType.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'label' => 'sylius.ui.locale',
'attr' => [
'class' => 'locale-selector',
]
],
])
;

Expand Down
Loading

0 comments on commit 0475fdc

Please sign in to comment.