You are here

public function OtherEventVariablesTest::testBlockEvent in Hook Event Dispatcher 8.2

Same name and namespace in other branches
  1. 3.x modules/preprocess_event_dispatcher/tests/src/Unit/OtherEventVariablesTest.php \Drupal\Tests\preprocess_event_dispatcher\Unit\OtherEventVariablesTest::testBlockEvent()

Test a BlockPreprocessEvent.

File

modules/preprocess_event_dispatcher/tests/src/Unit/OtherEventVariablesTest.php, line 68

Class

OtherEventVariablesTest
Class OtherEventVariablesTest.

Namespace

Drupal\Tests\preprocess_event_dispatcher\Unit

Code

public function testBlockEvent() : void {
  $variablesArray = $this
    ->createVariablesArray();
  $block = Mockery::mock(BlockInterface::class);
  $variablesArray['block'] = $block;
  $variablesArray['elements']['#id'] = '22';
  $variablesArray['content']['test'] = [
    'success2',
  ];

  /** @var \Drupal\preprocess_event_dispatcher\Variables\BlockEventVariables $variables */
  $variables = $this
    ->getVariablesFromCreatedEvent(BlockPreprocessEvent::class, $variablesArray);
  self::assertInstanceOf(BlockEventVariables::class, $variables);
  $this
    ->assertAbstractEventVariables($variables);
  self::assertSame($block, $variables
    ->getBlock());
  self::assertSame('22', $variables
    ->getId());
  self::assertSame([
    'success2',
  ], $variables
    ->getContentChild('test'));
  self::assertSame([], $variables
    ->getContentChild('none-existing'));
  self::assertNull($variables
    ->getBlockContent());
}