You are here

public function LibraryInfoAlterEventTest::testLibraryInfoAlterEvent in Hook Event Dispatcher 3.x

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

Test the LibraryInfoAlterEventTest.

File

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

Class

LibraryInfoAlterEventTest
Class LibraryInfoAlterEventTest.

Namespace

Drupal\Tests\core_event_dispatcher\Unit\Theme

Code

public function testLibraryInfoAlterEvent() : void {
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::LIBRARY_INFO_ALTER => static function (LibraryInfoAlterEvent $event) {
      $libraries =& $event
        ->getLibraries();
      $libraries['test_library'] = 'test_altered';
    },
  ]);
  $libraries = $expectedLibraries = [
    'test_library' => 'test',
  ];
  $extension = 'test_module';
  core_event_dispatcher_library_info_alter($libraries, $extension);
  $expectedLibraries['test_library'] = 'test_altered';
  self::assertSame($expectedLibraries, $libraries);

  /** @var \Drupal\core_event_dispatcher\Event\Theme\LibraryInfoAlterEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::LIBRARY_INFO_ALTER);
  self::assertSame($expectedLibraries, $event
    ->getLibraries());
  self::assertSame($extension, $event
    ->getExtension());
}