class ThemeHookTest

Same name and namespace in other branches
  1. main core/modules/system/tests/src/Kernel/Theme/ThemeHookTest.php \Drupal\Tests\system\Kernel\Theme\ThemeHookTest

Tests low-level theme functions.

Attributes

#[Group('Theme')] #[RunTestsInSeparateProcesses]

Hierarchy

Expanded class hierarchy of ThemeHookTest

File

core/modules/system/tests/src/Kernel/Theme/ThemeHookTest.php, line 15

Namespace

Drupal\Tests\system\Kernel\Theme
View source
class ThemeHookTest extends KernelTestBase {
  
  /**
   * {@inheritdoc}
   */
  public function setUp() : void {
    parent::setUp();
    \Drupal::service('theme_installer')->install([
      'procedural_hook_theme',
    ]);
    \Drupal::theme()->setActiveTheme(\Drupal::service(ThemeInitializationInterface::class)->initTheme('procedural_hook_theme'));
  }
  
  /**
   * Tests that procedural hooks are collected and executed.
   */
  public function testProceduralHookCollection() : void {
    $args = [];
    \Drupal::theme()->alter('procedural', $args);
    $this->assertEquals([
      'Procedural theme hook executed.',
    ], $args);
  }
  
  /**
   * Tests that procedural hooks with #[LegacyHook] are properly ignored.
   */
  public function testLegacyHookInThemes() : void {
    $args = [];
    \Drupal::theme()->alter('procedural_legacy', $args);
    $this->assertEquals([
      'OOP theme hook executed.',
    ], $args);
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.