You are here

public function BlockEventTest::testBlockBuildAlterEvent in Hook Event Dispatcher 8.2

Same name and namespace in other branches
  1. 3.x modules/core_event_dispatcher/tests/src/Unit/Block/BlockEventTest.php \Drupal\Tests\core_event_dispatcher\Unit\Block\BlockEventTest::testBlockBuildAlterEvent()

Test the BlockBuildAlterEvent.

File

modules/core_event_dispatcher/tests/src/Unit/Block/BlockEventTest.php, line 42

Class

BlockEventTest
Class BlockEventTest.

Namespace

Drupal\Tests\core_event_dispatcher\Unit\Block

Code

public function testBlockBuildAlterEvent() : void {
  $build = $expectedBuild = [
    'test' => 'build',
  ];
  $block = $this
    ->createMock(BlockPluginInterface::class);
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::BLOCK_BUILD_ALTER => static function (BlockBuildAlterEvent $event) {
      $build =& $event
        ->getBuild();
      $build['other'] = 'some_build';
    },
  ]);
  $expectedBuild['other'] = 'some_build';
  core_event_dispatcher_block_build_alter($build, $block);

  /** @var \Drupal\core_event_dispatcher\Event\Block\BlockBuildAlterEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::BLOCK_BUILD_ALTER);
  self::assertSame($expectedBuild, $event
    ->getBuild());
  self::assertSame($expectedBuild, $build);
  self::assertSame($block, $event
    ->getBlock());
}