LayoutSelectionFieldTest.php in Layout builder library 8
File
tests/src/Kernel/LayoutSelectionFieldTest.php
View source
<?php
namespace Drupal\Tests\layout_library\Kernel;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\FieldConfigInterface;
use Drupal\KernelTests\KernelTestBase;
use Drupal\layout_builder\Entity\LayoutEntityDisplayInterface;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
class LayoutSelectionFieldTest extends KernelTestBase {
use ContentTypeCreationTrait;
protected static $modules = [
'field',
'layout_builder',
'layout_discovery',
'layout_library',
'node',
'system',
'text',
'user',
];
protected function setUp() {
parent::setUp();
$this
->installConfig('node');
$this
->installSchema('system', [
'key_value_expire',
]);
$this
->createContentType([
'type' => 'test',
]);
}
public function testFieldPersistsForMultipleDisplays() {
$full_display = \Drupal::service('entity_display.repository')
->getViewDisplay('node', 'test', 'full');
$this
->assertInstanceOf(LayoutEntityDisplayInterface::class, $full_display);
$full_display
->enableLayoutBuilder()
->setThirdPartySetting('layout_library', 'enable', TRUE)
->save();
$this
->assertFieldExists();
$teaser_display = \Drupal::service('entity_display.repository')
->getViewDisplay('node', 'test', 'teaser');
$this
->assertInstanceOf(LayoutEntityDisplayInterface::class, $teaser_display);
$teaser_display
->enableLayoutBuilder()
->setThirdPartySetting('layout_library', 'enable', TRUE)
->save();
$this
->assertFieldExists();
$teaser_display
->setThirdPartySetting('layout_library', 'enable', FALSE)
->save();
$this
->assertFieldExists();
}
private function assertFieldExists() {
$field = FieldConfig::loadByName('node', 'test', 'layout_selection');
$this
->assertInstanceOf(FieldConfigInterface::class, $field);
}
}