|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace spec\Omikron\FactFinder\Shopware6\Export\Field; |
| 6 | + |
| 7 | +use Omikron\FactFinder\Shopware6\Export\Filter\TextFilter; |
| 8 | +use PhpSpec\ObjectBehavior; |
| 9 | +use Shopware\Core\Content\Category\CategoryEntity; |
| 10 | +use Shopware\Core\Content\Cms\Aggregate\CmsBlock\CmsBlockCollection; |
| 11 | +use Shopware\Core\Content\Cms\Aggregate\CmsBlock\CmsBlockEntity; |
| 12 | +use Shopware\Core\Content\Cms\Aggregate\CmsSection\CmsSectionCollection; |
| 13 | +use Shopware\Core\Content\Cms\Aggregate\CmsSection\CmsSectionEntity; |
| 14 | +use Shopware\Core\Content\Cms\Aggregate\CmsSlot\CmsSlotCollection; |
| 15 | +use Shopware\Core\Content\Cms\Aggregate\CmsSlot\CmsSlotEntity; |
| 16 | +use Shopware\Core\Content\Cms\CmsPageEntity; |
| 17 | + |
| 18 | +class LayoutSpec extends ObjectBehavior |
| 19 | +{ |
| 20 | + public function let(): void |
| 21 | + { |
| 22 | + $this->beConstructedWith(new TextFilter()); |
| 23 | + } |
| 24 | + |
| 25 | + public function it_should_strip_html_tags(CategoryEntity $categoryEntity): void |
| 26 | + { |
| 27 | + $cmsPage = new CmsPageEntity(); |
| 28 | + $cmsPage->setSections( |
| 29 | + new CmsSectionCollection( |
| 30 | + [ |
| 31 | + '1' => $this->createSection( |
| 32 | + [ |
| 33 | + $this->createBlock( |
| 34 | + [ |
| 35 | + $this->createSlot(['content' => ['value' => '<h2>Lorem Ipsum </h2><p>Dolor sit amet</p>']]), |
| 36 | + ] |
| 37 | + ), |
| 38 | + ] |
| 39 | + ), |
| 40 | + ] |
| 41 | + ) |
| 42 | + ); |
| 43 | + $categoryEntity->getCmsPage()->willReturn($cmsPage); |
| 44 | + $this->getValue($categoryEntity)->shouldReturn('Lorem Ipsum Dolor sit amet'); |
| 45 | + } |
| 46 | + |
| 47 | + public function it_should_concatenate_values_from_all_slots_configs(CategoryEntity $categoryEntity): void |
| 48 | + { |
| 49 | + $cmsPage = new CmsPageEntity(); |
| 50 | + $cmsPage->setSections( |
| 51 | + new CmsSectionCollection( |
| 52 | + [ |
| 53 | + '1' => $this->createSection( |
| 54 | + [ |
| 55 | + $this->createBlock( |
| 56 | + [ |
| 57 | + $this->createSlot(['content' => ['value' => 'I am']]), |
| 58 | + ], 1 |
| 59 | + ), |
| 60 | + ], |
| 61 | + ), |
| 62 | + '2' => $this->createSection( |
| 63 | + [ |
| 64 | + $this->createBlock( |
| 65 | + [ |
| 66 | + $this->createSlot(['content' => ['value' => 'concatenated']]), |
| 67 | + ], 2 |
| 68 | + ), |
| 69 | + ], 2 |
| 70 | + ), |
| 71 | + ] |
| 72 | + ) |
| 73 | + ); |
| 74 | + $categoryEntity->getCmsPage()->willReturn($cmsPage); |
| 75 | + $this->getValue($categoryEntity)->shouldReturn('I am concatenated'); |
| 76 | + } |
| 77 | + |
| 78 | + public function it_should_sort_output_by_position(CategoryEntity $categoryEntity): void |
| 79 | + { |
| 80 | + $cmsPage = new CmsPageEntity(); |
| 81 | + $cmsPage->setSections( |
| 82 | + new CmsSectionCollection( |
| 83 | + [ |
| 84 | + '1' => $this->createSection( |
| 85 | + [ |
| 86 | + $this->createBlock( |
| 87 | + [ |
| 88 | + $this->createSlot(['content' => ['value' => 'not']]), |
| 89 | + ], 2 |
| 90 | + ), |
| 91 | + $this->createBlock( |
| 92 | + [ |
| 93 | + $this->createSlot(['content' => ['value' => 'Yoda']]), |
| 94 | + ], |
| 95 | + 3 |
| 96 | + ), |
| 97 | + $this->createBlock( |
| 98 | + [ |
| 99 | + $this->createSlot(['content' => ['value' => 'I am']]), |
| 100 | + ], 1 |
| 101 | + ), |
| 102 | + ] |
| 103 | + ), |
| 104 | + ] |
| 105 | + ) |
| 106 | + ); |
| 107 | + |
| 108 | + $categoryEntity->getCmsPage()->willReturn($cmsPage); |
| 109 | + $this->getValue($categoryEntity)->shouldReturn('I am not Yoda'); |
| 110 | + } |
| 111 | + |
| 112 | + private function createSection(array $blocks, int $position = 1): CmsSectionEntity |
| 113 | + { |
| 114 | + $section = new CmsSectionEntity(); |
| 115 | + $section->setId(uniqid()); |
| 116 | + $section->setPosition($position); |
| 117 | + $section->setBlocks(new CmsBlockCollection($blocks)); |
| 118 | + return $section; |
| 119 | + } |
| 120 | + |
| 121 | + private function createBlock(array $slots, int $position = 1): CmsBlockEntity |
| 122 | + { |
| 123 | + $block = new CmsBlockEntity(); |
| 124 | + $block->setId(uniqid()); |
| 125 | + $block->setPosition($position); |
| 126 | + $block->setSlots(new CmsSlotCollection($slots)); |
| 127 | + return $block; |
| 128 | + } |
| 129 | + |
| 130 | + private function createSlot(array $config): CmsSlotEntity |
| 131 | + { |
| 132 | + $slot = new CmsSlotEntity(); |
| 133 | + $slot->setId(uniqid()); |
| 134 | + $slot->setSlot(uniqid('slot-')); |
| 135 | + $slot->setConfig($config); |
| 136 | + return $slot; |
| 137 | + } |
| 138 | +} |
0 commit comments