You are here

public function PreviewLinkForwardRevisionTest::testDraftRevisionWithParagraphField in Preview Link 2.0.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/PreviewLinkForwardRevisionTest.php \Drupal\Tests\preview_link\Functional\PreviewLinkForwardRevisionTest::testDraftRevisionWithParagraphField()
  2. 2.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 94

Class

PreviewLinkForwardRevisionTest
Test forward revisions are loaded.

Namespace

Drupal\Tests\preview_link\Functional

Code

public function testDraftRevisionWithParagraphField() : void {
  $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()
    ->addEntity($node);
  $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($node));
  $assert
    ->pageTextContains('A section title');
}