View source
<?php
namespace Drupal\Tests\layout_builder\Kernel;
use Drupal\Core\Config\Schema\SchemaIncompleteException;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
class LayoutBuilderEntityViewDisplayTest extends SectionStorageTestBase {
protected function getSectionStorage(array $section_data) {
$display = LayoutBuilderEntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
'status' => TRUE,
'third_party_settings' => [
'layout_builder' => [
'enabled' => TRUE,
'sections' => $section_data,
],
],
]);
$display
->save();
return $display;
}
public function testInvalidConfiguration() {
$this
->expectException(SchemaIncompleteException::class);
$this->sectionStorage
->getSection(0)
->getComponent('first-uuid')
->setConfiguration([
'id' => 'foo',
'bar' => 'baz',
]);
$this->sectionStorage
->save();
}
public function testGetRuntimeSections() {
$this->container
->get('current_user')
->setAccount($this
->createUser());
$entity = EntityTest::create();
$entity
->save();
$reflection = new \ReflectionMethod($this->sectionStorage, 'getRuntimeSections');
$reflection
->setAccessible(TRUE);
$result = $reflection
->invoke($this->sectionStorage, $entity);
$this
->assertEquals($this->sectionStorage
->getSections(), $result);
}
public function testIsLayoutBuilderEnabled($expected, $view_mode, $enabled) {
$display = LayoutBuilderEntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => $view_mode,
'status' => TRUE,
'third_party_settings' => [
'layout_builder' => [
'enabled' => $enabled,
],
],
]);
$result = $display
->isLayoutBuilderEnabled();
$this
->assertSame($expected, $result);
}
public function providerTestIsLayoutBuilderEnabled() {
$data = [];
$data['default enabled'] = [
TRUE,
'default',
TRUE,
];
$data['default disabled'] = [
FALSE,
'default',
FALSE,
];
$data['full enabled'] = [
TRUE,
'full',
TRUE,
];
$data['full disabled'] = [
FALSE,
'full',
FALSE,
];
$data['_custom enabled'] = [
FALSE,
'_custom',
TRUE,
];
$data['_custom disabled'] = [
FALSE,
'_custom',
FALSE,
];
return $data;
}
public function testSetOverridable() {
$this->sectionStorage
->disableLayoutBuilder();
$this->sectionStorage
->setOverridable();
$this
->assertEquals($this->sectionStorage
->isLayoutBuilderEnabled(), TRUE);
$this->sectionStorage
->setOverridable(FALSE);
$this
->assertEquals($this->sectionStorage
->isLayoutBuilderEnabled(), TRUE);
}
}