SectionListTraitTest.php in Drupal 8
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\SectionStorage\SectionStorageTrait;
class SectionListTraitTest extends SectionStorageTestBase {
protected function getSectionStorage(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->sectionStorage
->addBlankSection();
}
}
class TestSectionList implements SectionListInterface {
use SectionStorageTrait {
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;
}
}