You are here

public function ThemeSuggestionsAlterEventTest::testThemeSuggestionsAlterEventWithSetSuggestions in Hook Event Dispatcher 8

Tests the themeSuggestionsAlterEvent with setSuggestion.

File

tests/src/Unit/Theme/ThemeSuggestionsAlterEventTest.php, line 62

Class

ThemeSuggestionsAlterEventTest
Class ThemeSuggestionsAlterEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\Theme

Code

public function testThemeSuggestionsAlterEventWithSetSuggestions() {
  $this->manager
    ->setMaxEventCount(2);
  $suggestions = [
    'container_theme_function_1',
    'container_theme_function_2',
    'container_theme_function_3',
  ];
  $variables = [
    'content' => 'test',
  ];
  $hook = 'container';
  $newSuggestions = [
    'container_theme_function_1',
    'container_theme_function_2',
  ];
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::THEME_SUGGESTIONS_ALTER => function (ThemeSuggestionsAlterEvent $event) use ($newSuggestions) {
      $event
        ->setSuggestions($newSuggestions);
    },
  ]);
  hook_event_dispatcher_theme_suggestions_alter($suggestions, $variables, $hook);

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