You are here

public function PreviewLinkForwardRevisionTest::testDraftRevisionWithParagraphField in Preview Link 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/PreviewLinkForwardRevisionTest.php \Drupal\Tests\preview_link\Functional\PreviewLinkForwardRevisionTest::testDraftRevisionWithParagraphField()
  2. 2.0.x tests/src/Functional/PreviewLinkForwardRevisionTest.php \Drupal\Tests\preview_link\Functional\PreviewLinkForwardRevisionTest::testDraftRevisionWithParagraphField()

Tests draft revision with paragraph field.

File

tests/src/Functional/PreviewLinkForwardRevisionTest.php, line 95

Class

PreviewLinkForwardRevisionTest
Test forward revisions are loaded.

Namespace

Drupal\Tests\preview_link\Functional

Code

public function testDraftRevisionWithParagraphField() {
  $this
    ->setupParagraphTypeAndField();

  // Create a paragraph.
  $paragraph = Paragraph::create([
    'type' => 'section',
    'section' => 'A section title',
    'status' => 1,
  ]);
  $paragraph
    ->save();

  // Reference the paragraph from the node.
  $node = $this
    ->createNode([
    'title' => 'A draft with paragraph content',
    'paragraphs' => [
      $paragraph,
    ],
    'moderation_state' => 'draft',
  ]);

  // Create the preview link.
  $previewLink = PreviewLink::create([
    'entity_type_id' => 'node',
    'entity_id' => $node
      ->id(),
  ]);
  $previewLink
    ->save();

  // Login as user who can view unpublished content.
  $this
    ->drupalLogin($this
    ->drupalCreateUser(array_keys($this->container
    ->get('user.permissions')
    ->getPermissions())));
  $this
    ->drupalGet($node
    ->toUrl());
  $assert = $this
    ->assertSession();

  // Section title shown to admin on viewing draft.
  $assert
    ->pageTextContains('A section title');

  // Now visit preview link as anonymous, and verify paragraph content is
  // shown.
  $this
    ->drupalLogout();
  $this
    ->drupalGet($previewLink
    ->getUrl());
  $assert
    ->pageTextContains('A section title');
}