1<?php 2 3namespace Drupal\Tests\layout_builder\Kernel; 4 5use Drupal\layout_builder\Section; 6use Drupal\layout_builder\SectionListInterface; 7use Drupal\layout_builder\SectionStorage\SectionStorageTrait; 8 9/** 10 * @coversDefaultClass \Drupal\layout_builder\SectionStorage\SectionStorageTrait 11 * 12 * @group layout_builder 13 */ 14class SectionListTraitTest extends SectionStorageTestBase { 15 16 /** 17 * {@inheritdoc} 18 */ 19 protected function getSectionStorage(array $section_data) { 20 return new TestSectionList($section_data); 21 } 22 23 /** 24 * @covers ::addBlankSection 25 */ 26 public function testAddBlankSection() { 27 $this->expectException(\Exception::class); 28 $this->expectExceptionMessage('A blank section must only be added to an empty list'); 29 $this->sectionStorage->addBlankSection(); 30 } 31 32} 33 34class TestSectionList implements SectionListInterface { 35 36 use SectionStorageTrait { 37 addBlankSection as public; 38 } 39 40 /** 41 * An array of sections. 42 * 43 * @var \Drupal\layout_builder\Section[] 44 */ 45 protected $sections; 46 47 /** 48 * TestSectionList constructor. 49 */ 50 public function __construct(array $sections) { 51 // Loop through each section and reconstruct it to ensure that all default 52 // values are present. 53 foreach ($sections as $section) { 54 $this->sections[] = Section::fromArray($section->toArray()); 55 } 56 } 57 58 /** 59 * {@inheritdoc} 60 */ 61 protected function setSections(array $sections) { 62 $this->sections = array_values($sections); 63 return $sections; 64 } 65 66 /** 67 * {@inheritdoc} 68 */ 69 public function getSections() { 70 return $this->sections; 71 } 72 73} 74