function PagePreviewTest::testSimultaneousPreview

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

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->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Preview'));
    $this->assertText($edit[$title_key]);
    $user2 = $this->drupalCreateUser([
        'edit any page content',
    ]);
    $this->drupalLogin($user2);
    $this->drupalGet('node/' . $node->id() . '/edit');
    $this->assertFieldByName($title_key, $node->label(), 'No title leaked from previous user.');
    $edit2 = [
        $title_key => 'Another page title',
    ];
    $this->drupalPostForm('node/' . $node->id() . '/edit', $edit2, t('Preview'));
    $this->assertUrl(Url::fromRoute('entity.node.preview', [
        'node_preview' => $node->uuid(),
        'view_mode_id' => 'full',
    ], [
        'absolute' => TRUE,
    ])
        ->toString());
    $this->assertText($edit2[$title_key]);
}

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