You are here

public function PagePreviewTest::testSimultaneousPreview in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/node/tests/src/Functional/PagePreviewTest.php \Drupal\Tests\node\Functional\PagePreviewTest::testSimultaneousPreview()

Checks the node preview accessible for simultaneous node editing.

File

core/modules/node/tests/src/Functional/PagePreviewTest.php, line 497

Class

PagePreviewTest
Tests the node entity preview functionality.

Namespace

Drupal\Tests\node\Functional

Code

public function testSimultaneousPreview() {
  $title_key = 'title[0][value]';
  $node = $this
    ->drupalCreateNode([]);
  $edit = [
    $title_key => 'New page title',
  ];
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');
  $this
    ->submitForm($edit, 'Preview');
  $this
    ->assertSession()
    ->pageTextContains($edit[$title_key]);
  $user2 = $this
    ->drupalCreateUser([
    'edit any page content',
  ]);
  $this
    ->drupalLogin($user2);
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');
  $this
    ->assertSession()
    ->fieldValueEquals($title_key, $node
    ->label());
  $edit2 = [
    $title_key => 'Another page title',
  ];
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');
  $this
    ->submitForm($edit2, 'Preview');
  $this
    ->assertSession()
    ->addressEquals(Url::fromRoute('entity.node.preview', [
    'node_preview' => $node
      ->uuid(),
    'view_mode_id' => 'full',
  ]));
  $this
    ->assertSession()
    ->pageTextContains($edit2[$title_key]);
}