function PagePreviewTest::testSimultaneousPreview

Same name in other branches
  1. 9 core/modules/node/tests/src/Functional/PagePreviewTest.php \Drupal\Tests\node\Functional\PagePreviewTest::testSimultaneousPreview()
  2. 8.9.x core/modules/node/tests/src/Functional/PagePreviewTest.php \Drupal\Tests\node\Functional\PagePreviewTest::testSimultaneousPreview()
  3. 10 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 508

Class

PagePreviewTest
Tests the node entity preview functionality.

Namespace

Drupal\Tests\node\Functional

Code

public function testSimultaneousPreview() : void {
    $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]);
}

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