NodeTemplateSuggestionsTest.php in Drupal 10
File
core/modules/node/tests/src/Functional/NodeTemplateSuggestionsTest.php
View source
<?php
namespace Drupal\Tests\node\Functional;
class NodeTemplateSuggestionsTest extends NodeTestBase {
protected $defaultTheme = 'stark';
public function testNodeThemeHookSuggestions() {
$node = $this
->drupalCreateNode();
$view_mode = 'full';
$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.');
$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.');
}
}