You are here

final class JsAlterEventTest in Hook Event Dispatcher 8.2

Same name and namespace in other branches
  1. 3.x modules/core_event_dispatcher/tests/src/Unit/Theme/JsAlterEventTest.php \Drupal\Tests\core_event_dispatcher\Unit\Theme\JsAlterEventTest

Class JsAlterEventTest.

@group hook_event_dispatcher

Hierarchy

  • class \Drupal\Tests\core_event_dispatcher\Unit\Theme\JsAlterEventTest extends \PHPUnit\Framework\TestCase

Expanded class hierarchy of JsAlterEventTest

File

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

Namespace

Drupal\Tests\core_event_dispatcher\Unit\Theme
View source
final class JsAlterEventTest extends TestCase {

  /**
   * The manager.
   *
   * @var \Drupal\Tests\hook_event_dispatcher\Unit\HookEventDispatcherManagerSpy
   */
  private $manager;

  /**
   * Sets up the test.
   */
  public function setUp() : void {
    $builder = new ContainerBuilder();
    $this->manager = new HookEventDispatcherManagerSpy();
    $builder
      ->set('hook_event_dispatcher.manager', $this->manager);
    $builder
      ->compile();
    Drupal::setContainer($builder);
  }

  /**
   * JsAlterEvent test.
   */
  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());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
JsAlterEventTest::$manager private property The manager.
JsAlterEventTest::setUp public function Sets up the test.
JsAlterEventTest::testJsAlterEvent public function JsAlterEvent test.