You are here

public function InlineBlockTest::testInlineBlocksRevisioning in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\InlineBlockTest::testInlineBlocksRevisioning()

Tests entity blocks revisioning.

File

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

Class

InlineBlockTest
Tests that the inline block feature works correctly.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

public function testInlineBlocksRevisioning() {
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();
  $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',
  ]));

  // Enable layout builder and overrides.
  $this
    ->drupalPostForm(static::FIELD_UI_PREFIX . '/display/default', [
    'layout[enabled]' => TRUE,
    'layout[allow_custom]' => TRUE,
  ], 'Save');
  $this
    ->drupalGet('node/1/layout');

  // Add an inline block.
  $this
    ->addInlineBlockToLayout('Block title', 'The DEFAULT block body');
  $this
    ->assertSaveLayout();
  $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.
  $this
    ->drupalGet('node/1/layout');
  $this
    ->configureInlineBlock('The DEFAULT block body', 'The NEW block body');
  $this
    ->assertSaveLayout();
  $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');
}