function NodeViewBuilderTest::testPendingRevisionLinks

Same name and namespace in other branches
  1. 9 core/modules/node/tests/src/Kernel/NodeViewBuilderTest.php \Drupal\Tests\node\Kernel\NodeViewBuilderTest::testPendingRevisionLinks()
  2. 8.9.x core/modules/node/tests/src/Kernel/NodeViewBuilderTest.php \Drupal\Tests\node\Kernel\NodeViewBuilderTest::testPendingRevisionLinks()
  3. 10 core/modules/node/tests/src/Kernel/NodeViewBuilderTest.php \Drupal\Tests\node\Kernel\NodeViewBuilderTest::testPendingRevisionLinks()

Tests that node links are displayed correctly in pending revisions.

@covers ::buildComponents @covers ::renderLinks @covers ::buildLinks

File

core/modules/node/tests/src/Kernel/NodeViewBuilderTest.php, line 74

Class

NodeViewBuilderTest
Tests the node view builder.

Namespace

Drupal\Tests\node\Kernel

Code

public function testPendingRevisionLinks() : void {
    $account = User::create([
        'name' => $this->randomString(),
    ]);
    $account->save();
    $title = $this->randomMachineName();
    $node = Node::create([
        'type' => 'article',
        'title' => $title,
        'uid' => $account->id(),
    ]);
    $node->save();
    
    /** @var \Drupal\node\NodeInterface $pending_revision */
    $pending_revision = $this->storage
        ->createRevision($node, FALSE);
    $draft_title = $title . ' draft';
    $pending_revision->setTitle($draft_title);
    $pending_revision->save();
    $build = $this->viewBuilder
        ->view($node, 'teaser');
    $output = (string) $this->renderer
        ->renderInIsolation($build);
    $this->assertStringContainsString("title=\"{$title}\"", $output);
    $build = $this->viewBuilder
        ->view($pending_revision, 'teaser');
    $output = (string) $this->renderer
        ->renderInIsolation($build);
    $this->assertStringContainsString("title=\"{$draft_title}\"", $output);
}

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