class NodeTemplateSuggestionsTest in Drupal 10
Same name and namespace in other branches
- 8 core/modules/node/tests/src/Functional/NodeTemplateSuggestionsTest.php \Drupal\Tests\node\Functional\NodeTemplateSuggestionsTest
- 9 core/modules/node/tests/src/Functional/NodeTemplateSuggestionsTest.php \Drupal\Tests\node\Functional\NodeTemplateSuggestionsTest
Tests node template suggestions.
@group node
Hierarchy
- class \Drupal\Tests\BrowserTestBase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, FunctionalTestSetupTrait, TestSetupTrait, BlockCreationTrait, ConfigTestTrait, ExtensionListTestTrait, ContentTypeCreationTrait, NodeCreationTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings, UiHelperTrait, UserCreationTrait, XdebugRequestTrait
- class \Drupal\Tests\node\Functional\NodeTestBase
- class \Drupal\Tests\node\Functional\NodeTemplateSuggestionsTest
- class \Drupal\Tests\node\Functional\NodeTestBase
Expanded class hierarchy of NodeTemplateSuggestionsTest
File
- core/
modules/ node/ tests/ src/ Functional/ NodeTemplateSuggestionsTest.php, line 10
Namespace
Drupal\Tests\node\FunctionalView source
class NodeTemplateSuggestionsTest extends NodeTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests if template_preprocess_node() generates the correct suggestions.
*/
public function testNodeThemeHookSuggestions() {
// Create node to be rendered.
$node = $this
->drupalCreateNode();
$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.');
}
}