function NodeTemplateSuggestionsTest::testNodeThemeHookSuggestions
Same name in other branches
- 9 core/modules/node/tests/src/Functional/NodeTemplateSuggestionsTest.php \Drupal\Tests\node\Functional\NodeTemplateSuggestionsTest::testNodeThemeHookSuggestions()
- 8.9.x core/modules/node/tests/src/Functional/NodeTemplateSuggestionsTest.php \Drupal\Tests\node\Functional\NodeTemplateSuggestionsTest::testNodeThemeHookSuggestions()
- 10 core/modules/node/tests/src/Kernel/NodeTemplateSuggestionsTest.php \Drupal\Tests\node\Kernel\NodeTemplateSuggestionsTest::testNodeThemeHookSuggestions()
Tests if template_preprocess_node() generates the correct suggestions.
File
-
core/
modules/ node/ tests/ src/ Kernel/ NodeTemplateSuggestionsTest.php, line 32
Class
- NodeTemplateSuggestionsTest
- Tests node template suggestions.
Namespace
Drupal\Tests\node\KernelCode
public function testNodeThemeHookSuggestions() : void {
$this->installEntitySchema('user');
$this->installEntitySchema('node');
$this->installConfig([
'system',
]);
NodeType::create([
'type' => 'page',
'name' => 'Page',
])->save();
// Create node to be rendered.
$node = $this->createNode();
$view_mode = 'full';
// Simulate theming of the node.
$build = \Drupal::entityTypeManager()->getViewBuilder('node')
->view($node, $view_mode);
$variables['elements'] = $build;
$suggestions = \Drupal::moduleHandler()->invokeAll('theme_suggestions_node', [
$variables,
]);
$this->assertEquals([
'node__full',
'node__page',
'node__page__full',
'node__' . $node->id(),
'node__' . $node->id() . '__full',
], $suggestions, 'Found expected node suggestions.');
// Change the view mode.
$view_mode = 'node.my_custom_view_mode';
$build = \Drupal::entityTypeManager()->getViewBuilder('node')
->view($node, $view_mode);
$variables['elements'] = $build;
$suggestions = \Drupal::moduleHandler()->invokeAll('theme_suggestions_node', [
$variables,
]);
$this->assertEquals([
'node__node_my_custom_view_mode',
'node__page',
'node__page__node_my_custom_view_mode',
'node__' . $node->id(),
'node__' . $node->id() . '__node_my_custom_view_mode',
], $suggestions, 'Found expected node suggestions.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.