function EntityViewTest::testEntityViewHook
Tests that rules_entity_view() can be invoked correctly.
File
-
tests/
src/ Kernel/ EntityViewTest.php, line 35
Class
- EntityViewTest
- Tests that rules_entity_view() does not throw fatal errors.
Namespace
Drupal\Tests\rules\KernelCode
public function testEntityViewHook() {
// Create a node.
$entity_type_manager = $this->container
->get('entity_type.manager');
$entity_type_manager->getStorage('node_type')
->create([
'type' => 'page',
'display_submitted' => FALSE,
])
->save();
$node = $entity_type_manager->getStorage('node')
->create([
'title' => 'test',
'type' => 'page',
]);
$node->save();
// Build the node render array and render it, so that hook_entity_view() is
// invoked.
$view_builder = $entity_type_manager->getViewBuilder('node');
$build = $view_builder->view($node);
$this->container
->get('renderer')
->renderPlain($build);
}