You are here

public function ThemeRegistryAlterEventTest::testThemeRegistryAlterEventWithThemeAlter in Hook Event Dispatcher 3.x

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

ThemeRegistryAlterEvent with theme implementation alter test.

File

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

Class

ThemeRegistryAlterEventTest
Class ThemeRegistryAlterEventTest.

Namespace

Drupal\Tests\core_event_dispatcher\Unit\Theme

Code

public function testThemeRegistryAlterEventWithThemeAlter() : void {
  $themeRegistry = $expected = [
    'existing_theme_hook__with_information' => [
      'variables' => [
        'variable1' => NULL,
        'variable2' => FALSE,
        'variable3' => [],
      ],
      'type' => 'base_theme_engine',
      'template' => 'existing-theme-hook--with-information',
    ],
  ];
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::THEME_REGISTRY_ALTER => static function (ThemeRegistryAlterEvent $event) {
      $themeRegistry =& $event
        ->getThemeRegistry();
      $themeRegistry['existing_theme_hook__with_information']['variables']['variable2'] = TRUE;
    },
  ]);
  core_event_dispatcher_theme_registry_alter($themeRegistry);
  $expected['existing_theme_hook__with_information']['variables']['variable2'] = TRUE;
  self::assertSame($expected, $themeRegistry);

  /** @var \Drupal\core_event_dispatcher\Event\Theme\ThemeRegistryAlterEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::THEME_REGISTRY_ALTER);
  self::assertSame($expected, $event
    ->getThemeRegistry());
}