SectionListTraitTest.php in Drupal 9
File
core/modules/layout_builder/tests/src/Kernel/SectionListTraitTest.php
View source
<?php
namespace Drupal\Tests\layout_builder\Kernel;
use Drupal\layout_builder\Section;
use Drupal\layout_builder\SectionListInterface;
use Drupal\layout_builder\SectionListTrait;
class SectionListTraitTest extends SectionListTestBase {
protected function getSectionList(array $section_data) {
return new TestSectionList($section_data);
}
public function testAddBlankSection() {
$this
->expectException(\Exception::class);
$this
->expectExceptionMessage('A blank section must only be added to an empty list');
$this->sectionList
->addBlankSection();
}
}
class TestSectionList implements SectionListInterface {
use SectionListTrait {
addBlankSection as public;
}
protected $sections;
public function __construct(array $sections) {
foreach ($sections as $section) {
$this->sections[] = Section::fromArray($section
->toArray());
}
}
protected function setSections(array $sections) {
$this->sections = array_values($sections);
return $sections;
}
public function getSections() {
return $this->sections;
}
}