You are here

public function OtherEventVariablesTest::testBlockEvent in Hook Event Dispatcher 8

Test a BlockPreprocessEvent.

File

tests/src/Unit/Preprocess/OtherEventVariablesTest.php, line 61

Class

OtherEventVariablesTest
Class OtherEventVariablesTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\Preprocess

Code

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

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