You are here

public function JsAlterEventTest::testJsAlterEvent in Hook Event Dispatcher 3.x

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

JsAlterEvent test.

File

modules/core_event_dispatcher/tests/src/Unit/Theme/JsAlterEventTest.php, line 42

Class

JsAlterEventTest
Class JsAlterEventTest.

Namespace

Drupal\Tests\core_event_dispatcher\Unit\Theme

Code

public function testJsAlterEvent() : void {
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::JS_ALTER => static function (JsAlterEvent $event) {
      $javascript =& $event
        ->getJavascript();
      unset($javascript['unset']);
    },
  ]);
  $javascript = $expectedJavascript = [
    'unset' => [
      'data',
    ],
    'other' => [
      'other_data',
    ],
  ];
  unset($expectedJavascript['unset']);
  $attachedAssets = new AttachedAssets();
  core_event_dispatcher_js_alter($javascript, $attachedAssets);

  /** @var \Drupal\core_event_dispatcher\Event\Theme\JsAlterEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::JS_ALTER);
  self::assertSame($expectedJavascript, $event
    ->getJavascript());
  self::assertSame($attachedAssets, $event
    ->getAttachedAssets());
}