You are here

public function ThemeSuggestionsAlterEventTest::testThemeSuggestionsAlterEvent in Hook Event Dispatcher 3.x

Same name and namespace in other branches
  1. 8.2 modules/core_event_dispatcher/tests/src/Unit/Theme/ThemeSuggestionsAlterEventTest.php \Drupal\Tests\core_event_dispatcher\Unit\Theme\ThemeSuggestionsAlterEventTest::testThemeSuggestionsAlterEvent()

Tests the themeSuggestionsAlterEvent.

File

modules/core_event_dispatcher/tests/src/Unit/Theme/ThemeSuggestionsAlterEventTest.php, line 41

Class

ThemeSuggestionsAlterEventTest
Class ThemeSuggestionsAlterEventTest.

Namespace

Drupal\Tests\core_event_dispatcher\Unit\Theme

Code

public function testThemeSuggestionsAlterEvent() : void {
  $this->manager
    ->setMaxEventCount(2);
  $suggestions = $expectedSuggestions = [
    'container_theme_function_1',
    'container_theme_function_2',
    'container_theme_function_3',
  ];
  $expectedSuggestions[] = 'extra_suggestion';
  $variables = [
    'content' => 'test',
  ];
  $hook = 'container';
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::THEME_SUGGESTIONS_ALTER => static function (ThemeSuggestionsAlterEvent $event) {
      $suggestions =& $event
        ->getSuggestions();
      $suggestions[] = 'extra_suggestion';
    },
  ]);
  core_event_dispatcher_theme_suggestions_alter($suggestions, $variables, $hook);

  /** @var \Drupal\core_event_dispatcher\Event\Theme\ThemeSuggestionsAlterEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::THEME_SUGGESTIONS_ALTER);
  self::assertSame($expectedSuggestions, $suggestions);
  self::assertEquals($suggestions, $event
    ->getSuggestions());
  self::assertEquals($variables, $event
    ->getVariables());
}