class NodeViewBuilderTest in Drupal 10
Same name and namespace in other branches
- 8 core/modules/node/tests/src/Kernel/NodeViewBuilderTest.php \Drupal\Tests\node\Kernel\NodeViewBuilderTest
- 9 core/modules/node/tests/src/Kernel/NodeViewBuilderTest.php \Drupal\Tests\node\Kernel\NodeViewBuilderTest
Tests the node view builder.
@group node
@coversDefaultClass \Drupal\node\NodeViewBuilder
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements ServiceProviderInterface uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, AssertContentTrait, ConfigTestTrait, ExtensionListTestTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings
- class \Drupal\KernelTests\Core\Entity\EntityKernelTestBase uses UserCreationTrait
- class \Drupal\Tests\node\Kernel\NodeViewBuilderTest
- class \Drupal\KernelTests\Core\Entity\EntityKernelTestBase uses UserCreationTrait
Expanded class hierarchy of NodeViewBuilderTest
File
- core/
modules/ node/ tests/ src/ Kernel/ NodeViewBuilderTest.php, line 17
Namespace
Drupal\Tests\node\KernelView source
class NodeViewBuilderTest extends EntityKernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'node',
];
/**
* The node storage.
*
* @var \Drupal\node\NodeStorageInterface
*/
protected $storage;
/**
* The node view builder.
*
* @var \Drupal\Core\Entity\EntityViewBuilderInterface
*/
protected $viewBuilder;
/**
* The renderer.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->storage = $this->entityTypeManager
->getStorage('node');
$this->viewBuilder = $this->entityTypeManager
->getViewBuilder('node');
$this->renderer = $this->container
->get('renderer');
$type = NodeType::create([
'type' => 'article',
'name' => 'Article',
]);
$type
->save();
$this
->installSchema('node', 'node_access');
$this
->installConfig([
'system',
'node',
]);
}
/**
* Tests that node links are displayed correctly in pending revisions.
*
* @covers ::buildComponents
* @covers ::renderLinks
* @covers ::buildLinks
*/
public function testPendingRevisionLinks() {
$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
->renderPlain($build);
$this
->assertStringContainsString("title=\"{$title}\"", $output);
$build = $this->viewBuilder
->view($pending_revision, 'teaser');
$output = (string) $this->renderer
->renderPlain($build);
$this
->assertStringContainsString("title=\"{$draft_title}\"", $output);
}
}