You are here

class BlockEventTest in Hook Event Dispatcher 3.x

Same name and namespace in other branches
  1. 8.2 modules/core_event_dispatcher/tests/src/Unit/Block/BlockEventTest.php \Drupal\Tests\core_event_dispatcher\Unit\Block\BlockEventTest

Class BlockEventTest.

@group hook_event_dispatcher

Hierarchy

  • class \Drupal\Tests\core_event_dispatcher\Unit\Block\BlockEventTest extends \PHPUnit\Framework\TestCase

Expanded class hierarchy of BlockEventTest

File

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

Namespace

Drupal\Tests\core_event_dispatcher\Unit\Block
View source
class BlockEventTest extends TestCase {

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

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

  /**
   * Test the BlockBuildAlterEvent.
   */
  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());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BlockEventTest::$manager private property The manager.
BlockEventTest::setUp public function
BlockEventTest::testBlockBuildAlterEvent public function Test the BlockBuildAlterEvent.