You are here

public function PreviewLinkForwardRevisionTest::testForwardRevision in Preview Link 2.x

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

Test the latest forward revision is loaded.

File

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

Class

PreviewLinkForwardRevisionTest
Test forward revisions are loaded.

Namespace

Drupal\Tests\preview_link\Functional

Code

public function testForwardRevision() : void {
  $original_random_text = 'Original Title';
  $latest_random_text = 'Latest Title';

  // Create a node with some random text.
  $node = $this
    ->createNode([
    'title' => $original_random_text,
    'moderation_state' => 'published',
  ]);

  // Create a forward revision with new text.
  $node
    ->setTitle($latest_random_text);
  $node->moderation_state = 'draft';
  $node
    ->save();

  // Create the preview link.
  $previewLink = PreviewLink::create()
    ->addEntity($node);
  $previewLink
    ->save();

  // Visit the node and assert the original text.
  $this
    ->drupalGet($node
    ->toUrl());
  $this
    ->assertSession()
    ->pageTextNotContains($latest_random_text);
  $this
    ->assertSession()
    ->pageTextContains($original_random_text);

  // Visit the preview link and assert the forward revision text.
  $this
    ->drupalGet($previewLink
    ->getUrl($node));
  $this
    ->assertSession()
    ->pageTextContains($latest_random_text);
  $this
    ->assertSession()
    ->pageTextNotContains($original_random_text);
}