You are here

private function EntityEventTest::createAndAssertEntityEvent in Hook Event Dispatcher 8

Create and assert the given entity event class.

Parameters

string $class: Event class name.

5 calls to EntityEventTest::createAndAssertEntityEvent()
EntityEventTest::testCommentEvent in tests/src/Unit/Preprocess/EntityEventTest.php
Test a BlockPreprocessEvent.
EntityEventTest::testEckEntityEvent in tests/src/Unit/Preprocess/EntityEventTest.php
Test a EckEntityPreprocessEvent.
EntityEventTest::testNodeEvent in tests/src/Unit/Preprocess/EntityEventTest.php
Test a NodePreprocessEvent.
EntityEventTest::testParagraphEvent in tests/src/Unit/Preprocess/EntityEventTest.php
Test a ParagraphPreprocessEvent.
EntityEventTest::testTaxonomyTermEvent in tests/src/Unit/Preprocess/EntityEventTest.php
Test a TaxonomyTermPreprocessEvent.

File

tests/src/Unit/Preprocess/EntityEventTest.php, line 126

Class

EntityEventTest
Class EntityEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\Preprocess

Code

private function createAndAssertEntityEvent($class) {
  $this->dispatcher
    ->setExpectedEventCount(3);

  /** @var \Drupal\hook_event_dispatcher\Event\Preprocess\AbstractPreprocessEntityEvent $class */
  $this->service
    ->createAndDispatchKnownEvents($class::getHook(), $this->variables);

  /** @var \Drupal\hook_event_dispatcher\Event\Preprocess\AbstractPreprocessEntityEvent[] $events */
  $events = $this->dispatcher
    ->getEvents();
  $expectedName = $class::DISPATCH_NAME_PREFIX . $class::getHook();
  $firstEvent = \reset($events);
  $firstName = \key($events);
  self::assertSame($expectedName, $firstName);
  self::assertInstanceOf($class, $firstEvent);
  self::assertInstanceOf(AbstractEventVariables::class, $firstEvent
    ->getVariables());
  $secondEvent = \next($events);
  $secondName = \key($events);
  $bundle = $secondEvent
    ->getVariables()
    ->getEntityBundle();
  self::assertNotNull($bundle);
  self::assertInternalType('string', $bundle);
  $expectedName .= '.' . $bundle;
  self::assertSame($expectedName, $secondName);
  self::assertInstanceOf($class, $secondEvent);
  self::assertInstanceOf(AbstractEventVariables::class, $secondEvent
    ->getVariables());
  $thirdEvent = \next($events);
  $thirdName = \key($events);
  $viewMode = $thirdEvent
    ->getVariables()
    ->getViewMode();
  self::assertNotNull($viewMode);
  self::assertInternalType('string', $viewMode);
  $expectedName .= '.' . $viewMode;
  self::assertSame($expectedName, $thirdName);
  self::assertInstanceOf($class, $thirdEvent);
  self::assertInstanceOf(AbstractEventVariables::class, $thirdEvent
    ->getVariables());
}