function InlineBlockTest::testInlineBlocksRevisioningIntegrity

Same name in other branches
  1. 10 core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\InlineBlockTest::testInlineBlocksRevisioningIntegrity()
  2. 11.x core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\InlineBlockTest::testInlineBlocksRevisioningIntegrity()

Tests entity blocks revisioning.

File

core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockTest.php, line 271

Class

InlineBlockTest
Tests that the inline block feature works correctly.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

public function testInlineBlocksRevisioningIntegrity() {
    $this->drupalLogin($this->drupalCreateUser([
        'access contextual links',
        'configure any layout',
        'administer node display',
        'view all revisions',
        'access content',
        'create and edit custom blocks',
    ]));
    $this->drupalGet(static::FIELD_UI_PREFIX . '/display/default');
    $this->submitForm([
        'layout[enabled]' => TRUE,
        'layout[allow_custom]' => TRUE,
    ], 'Save');
    $block_1_locator = static::INLINE_BLOCK_LOCATOR;
    $block_2_locator = sprintf('%s + %s', static::INLINE_BLOCK_LOCATOR, static::INLINE_BLOCK_LOCATOR);
    // Add two blocks to the page and assert the content in each.
    $this->drupalGet('node/1/layout');
    $this->addInlineBlockToLayout('Block 1', 'Block 1 original');
    $this->addInlineBlockToLayout('Block 2', 'Block 2 original');
    $this->assertSaveLayout();
    $this->assertNodeRevisionContent(3, [
        'Block 1 original',
        'Block 2 original',
    ]);
    $this->assertBlockRevisionCountByTitle('Block 1', 1);
    $this->assertBlockRevisionCountByTitle('Block 2', 1);
    // Update the contents of one of the blocks and assert the updated content
    // appears on the next revision.
    $this->drupalGet('node/1/layout');
    $this->configureInlineBlock('Block 2 original', 'Block 2 updated', $block_2_locator);
    $this->assertSaveLayout();
    $this->assertNodeRevisionContent(4, [
        'Block 1 original',
        'Block 2 updated',
    ]);
    $this->assertBlockRevisionCountByTitle('Block 1', 1);
    $this->assertBlockRevisionCountByTitle('Block 2', 2);
    // Update block 1 without creating a new revision of the parent.
    $this->drupalGet('node/1/layout');
    $this->configureInlineBlock('Block 1 original', 'Block 1 updated', $block_1_locator);
    $this->getSession()
        ->getPage()
        ->uncheckField('revision');
    $this->getSession()
        ->getPage()
        ->pressButton('Save layout');
    $this->assertNotEmpty($this->assertSession()
        ->waitForElement('css', '.messages--status'));
    $this->assertNodeRevisionContent(4, [
        'Block 1 updated',
        'Block 2 updated',
    ]);
    $this->assertBlockRevisionCountByTitle('Block 1', 2);
    $this->assertBlockRevisionCountByTitle('Block 2', 2);
    // Reassert all of the parent revisions contain the correct block content
    // and the integrity of the revisions was preserved.
    $this->assertNodeRevisionContent(3, [
        'Block 1 original',
        'Block 2 original',
    ]);
}

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