|
| 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 | + function let(): void |
| 21 | + { |
| 22 | + $this->beConstructedWith(new TextFilter()); |
| 23 | + } |
| 24 | + |
| 25 | + 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 | + '1' => $this->createBlock( |
| 34 | + [ |
| 35 | + '1' => $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 | + 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 | + '1' => $this->createBlock( |
| 56 | + [ |
| 57 | + '1' => $this->createSlot(['content' => ['value' => 'I am']]), |
| 58 | + ], 1 |
| 59 | + ), |
| 60 | + ], |
| 61 | + ), |
| 62 | + '2' => $this->createSection( |
| 63 | + [ |
| 64 | + '1' => $this->createBlock( |
| 65 | + [ |
| 66 | + '1' => $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 | + 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 | + '1' => $this->createBlock( |
| 87 | + [ |
| 88 | + '1' => $this->createSlot(['content' => ['value' => 'not']]), |
| 89 | + ], 2 |
| 90 | + ), |
| 91 | + '2' => $this->createBlock( |
| 92 | + [ |
| 93 | + '1' => $this->createSlot(['content' => ['value' => 'Yoda']]), |
| 94 | + ], |
| 95 | + 3 |
| 96 | + ), |
| 97 | + '3' => $this->createBlock( |
| 98 | + [ |
| 99 | + '1' => $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 | + function it_should_not_throw_if_section_has_no_blocks(CategoryEntity $categoryEntity) |
| 113 | + { |
| 114 | + $cmsPage = new CmsPageEntity(); |
| 115 | + $cmsPage->setSections( |
| 116 | + new CmsSectionCollection( |
| 117 | + [ |
| 118 | + '1' => $this->createSection(), |
| 119 | + '2' => $this->createSection(), |
| 120 | + ] |
| 121 | + ) |
| 122 | + ); |
| 123 | + $categoryEntity->getCmsPage()->willReturn($cmsPage); |
| 124 | + $this->getValue($categoryEntity)->shouldReturn(''); |
| 125 | + } |
| 126 | + |
| 127 | + function it_should_not_throw_if_category_has_no_layout_assigned(CategoryEntity $categoryEntity) |
| 128 | + { |
| 129 | + $categoryEntity->getCmsPage()->willReturn(null); |
| 130 | + $this->getValue($categoryEntity)->shouldReturn(''); |
| 131 | + } |
| 132 | + |
| 133 | + function it_should_not_throw_if_block_has_no_slots(CategoryEntity $categoryEntity) |
| 134 | + { |
| 135 | + $cmsPage = new CmsPageEntity(); |
| 136 | + $cmsPage->setSections( |
| 137 | + new CmsSectionCollection( |
| 138 | + [ |
| 139 | + '1' => $this->createSection( |
| 140 | + [ |
| 141 | + '1' => $this->createBlock(), |
| 142 | + '2' => $this->createBlock(), |
| 143 | + ] |
| 144 | + ) |
| 145 | + ] |
| 146 | + ) |
| 147 | + ); |
| 148 | + |
| 149 | + $categoryEntity->getCmsPage()->willReturn($cmsPage); |
| 150 | + $this->getValue($categoryEntity)->shouldReturn(''); |
| 151 | + } |
| 152 | + |
| 153 | + private function createSection(array $blocks = [], int $position = 1): CmsSectionEntity |
| 154 | + { |
| 155 | + $section = new CmsSectionEntity(); |
| 156 | + $section->setId(uniqid()); |
| 157 | + $section->setPosition($position); |
| 158 | + if (count($blocks)) { |
| 159 | + $section->setBlocks(new CmsBlockCollection($blocks)); |
| 160 | + } |
| 161 | + return $section; |
| 162 | + } |
| 163 | + |
| 164 | + private function createBlock(array $slots = [], int $position = 1): CmsBlockEntity |
| 165 | + { |
| 166 | + $block = new CmsBlockEntity(); |
| 167 | + $block->setId(uniqid()); |
| 168 | + $block->setPosition($position); |
| 169 | + if (count($slots)) { |
| 170 | + $block->setSlots(new CmsSlotCollection($slots)); |
| 171 | + } |
| 172 | + return $block; |
| 173 | + } |
| 174 | + |
| 175 | + private function createSlot(array $config): CmsSlotEntity |
| 176 | + { |
| 177 | + $slot = new CmsSlotEntity(); |
| 178 | + $slot->setId(uniqid()); |
| 179 | + $slot->setSlot(uniqid('slot-')); |
| 180 | + $slot->setConfig($config); |
| 181 | + return $slot; |
| 182 | + } |
| 183 | +} |
0 commit comments