function EntityViewDisplayValidationTest::testLayoutSectionPluginIdIsValidated

Same name in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityViewDisplayValidationTest.php \Drupal\KernelTests\Core\Entity\EntityViewDisplayValidationTest::testLayoutSectionPluginIdIsValidated()

Tests that the plugin ID of a Layout Builder section is validated.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityViewDisplayValidationTest.php, line 63

Class

EntityViewDisplayValidationTest
Tests validation of entity_view_display entities.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testLayoutSectionPluginIdIsValidated() : void {
    $this->enableModules([
        'layout_builder',
        'layout_discovery',
    ]);
    $this->entity = $this->container
        ->get('entity_display.repository')
        ->getViewDisplay('user', 'user');
    $this->assertInstanceOf(LayoutEntityDisplayInterface::class, $this->entity);
    $this->entity
        ->enableLayoutBuilder()
        ->save();
    $sections = array_map(fn(Section $section) => $section->toArray(), $this->entity
        ->getSections());
    $this->assertCount(1, $sections);
    $sections[0]['layout_id'] = 'non_existent';
    $this->entity
        ->setThirdPartySetting('layout_builder', 'sections', $sections);
    $this->assertValidationErrors([
        'third_party_settings.layout_builder.sections.0.layout_id' => "The 'non_existent' plugin does not exist.",
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.