public function LayoutBuilderIntegrationTest::test in Core Context 8
Tests that context values are displayed by Layout Builder.
@dataProvider provider
Parameters
array $block_configuration: Configuration for the context block (section component).
bool $layout_overridable: (optional) Whether the layout will be overridable per entity. Defaults to FALSE.
array $third_party_contexts: (optional) Any contexts to store in third-party settings of the entity view display.
array $entity_values: (optional) Any field values to set on the entity.
File
- tests/
src/ Functional/ LayoutBuilderIntegrationTest.php, line 220
Class
- LayoutBuilderIntegrationTest
- @group core_context
Namespace
Drupal\Tests\core_context\FunctionalCode
public function test(array $block_configuration, $layout_overridable = FALSE, $third_party_contexts = [], array $entity_values = []) {
$page = $this
->getSession()
->getPage();
$component = SectionComponent::fromArray([
'uuid' => $this->container
->get('uuid')
->generate(),
'region' => 'content',
'configuration' => $block_configuration,
'additional' => [],
'weight' => 0,
]);
$section = new Section('layout_onecol');
$section
->appendComponent($component);
/** @var \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface $display */
$display = $this->container
->get('entity_display.repository')
->getViewDisplay('node', 'page', 'full');
$display
->enableLayoutBuilder()
->setOverridable($layout_overridable)
->appendSection($section)
->setThirdPartySetting('core_context', 'contexts', $third_party_contexts)
->save();
$account = $this
->drupalCreateUser([
'administer node display',
'configure any layout',
'edit own page content',
]);
$this
->drupalLogin($account);
$entity_values += [
'type' => 'page',
];
$node = $this
->drupalCreateNode($entity_values);
if ($layout_overridable) {
/** @var \Drupal\layout_builder\Field\LayoutSectionItemList $section_list */
$section_list = $node
->get(OverridesSectionStorage::FIELD_NAME);
$section_list
->appendSection($section);
$node
->save();
}
$this
->drupalGet($node
->toUrl());
$assert_session = $this
->assertSession();
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextContains('The context value is 512, brought to you by the letter Charlie.');
// If the layout is customizable per entity, ensure we can visit the Layout
// page without errors.
if ($layout_overridable) {
$page
->clickLink('Layout');
$assert_session
->statusCodeEquals(200);
}
// Ensure that we can edit the default layout without errors, but only if
// there are contexts stored in the entity display.
if ($third_party_contexts || $block_configuration['id'] === 'context_block_optional') {
$this
->drupalGet('/admin/structure/types/manage/page/display/full');
$page
->clickLink('Manage layout');
$assert_session
->statusCodeEquals(200);
}
}