function ModuleHandlerTest::testOopPreprocess

Tests Oop preprocess functions.

File

core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php, line 392

Class

ModuleHandlerTest
Tests ModuleHandler functionality.

Namespace

Drupal\Tests\system\Kernel\Extension

Code

public function testOopPreprocess() : void {
  $this->moduleInstaller()
    ->install([
    'module_test_oop_preprocess',
  ]);
  $preprocess_function = [];
  $preprocess_invoke = [];
  $prefix = 'module_test_oop_preprocess';
  $hook = 'test';
  if ($this->moduleHandler()
    ->hasImplementations('preprocess', [
    $prefix,
  ], TRUE)) {
    $function = "{$prefix}_preprocess";
    $preprocess_function[] = $function;
    $preprocess_invoke[$function] = [
      'module' => $prefix,
      'hook' => 'preprocess',
    ];
  }
  if ($this->moduleHandler()
    ->hasImplementations('preprocess_' . $hook, [
    $prefix,
  ], TRUE)) {
    $function = "{$prefix}_preprocess_{$hook}";
    $preprocess_function[] = $function;
    $preprocess_invoke[$function] = [
      'module' => $prefix,
      'hook' => 'preprocess_' . $hook,
    ];
  }
  foreach ($preprocess_function as $function) {
    $this->assertTrue($this->moduleHandler()
      ->invoke(...$preprocess_invoke[$function], args: [
      TRUE,
    ]), 'Procedural hook_preprocess runs.');
  }
}

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