function LayoutBuilderRevisionTest::testInlineBlocksRevisioning
Same name and namespace in other branches
- 11.x core/modules/layout_builder/tests/src/Functional/LayoutBuilderRevisionTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderRevisionTest::testInlineBlocksRevisioning()
Tests entity blocks revisioning.
File
-
core/
modules/ layout_builder/ tests/ src/ Functional/ LayoutBuilderRevisionTest.php, line 128
Class
- LayoutBuilderRevisionTest
- Tests that entity revisions work with Layout Builder.
Namespace
Drupal\Tests\layout_builder\FunctionalCode
public function testInlineBlocksRevisioning() : void {
$assert_session = $this->assertSession();
$page = $this->getSession()
->getPage();
LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')->enableLayoutBuilder()
->setOverridable()
->save();
$this->drupalLogin($this->drupalCreateUser([
'access contextual links',
'configure any layout',
'administer node display',
'administer node fields',
'administer nodes',
'bypass node access',
'create and edit custom blocks',
]));
$this->drupalGet('node/1/layout');
$this->clickLink('Add block');
$this->clickLink('Create content block');
$this->submitForm([
'settings[label]' => 'Block title',
'settings[block_form][body][0][value]' => 'The DEFAULT block body',
], 'Add block');
$this->submitForm([], 'Save layout');
$this->drupalGet('node/1');
$assert_session->pageTextContains('The DEFAULT block body');
/** @var \Drupal\node\NodeStorageInterface $node_storage */
$node_storage = $this->container
->get('entity_type.manager')
->getStorage('node');
$original_revision_id = $node_storage->getLatestRevisionId(1);
// Create a new revision.
$this->drupalGet('node/1/edit');
$page->findField('title[0][value]')
->setValue('Node updated');
$page->pressButton('Save');
$this->drupalGet('node/1');
$assert_session->pageTextContains('The DEFAULT block body');
$assert_session->linkExists('Revisions');
// Update the block.
$components = Node::load(1)->get(OverridesSectionStorage::FIELD_NAME)
->getSection(0)
->getComponents();
end($components);
$uuid = key($components);
$this->drupalGet('layout_builder/update/block/overrides/node.1/0/content/' . $uuid);
$this->submitForm([
'settings[label]' => 'Block title',
'settings[block_form][body][0][value]' => 'The NEW block body',
], 'Update');
$this->drupalGet('node/1/layout');
$this->submitForm([], 'Save layout');
$this->drupalGet('node/1');
$assert_session->pageTextContains('The NEW block body');
$assert_session->pageTextNotContains('The DEFAULT block body');
$revision_url = "node/1/revisions/{$original_revision_id}";
// Ensure viewing the previous revision shows the previous block revision.
$this->drupalGet("{$revision_url}/view");
$assert_session->pageTextContains('The DEFAULT block body');
$assert_session->pageTextNotContains('The NEW block body');
// Revert to first revision.
$revision_url = "{$revision_url}/revert";
$this->drupalGet($revision_url);
$page->pressButton('Revert');
$this->drupalGet('node/1');
$assert_session->pageTextContains('The DEFAULT block body');
$assert_session->pageTextNotContains('The NEW block body');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.