You are here

public function EntityEventVariablesTest::testCommentEvent in Hook Event Dispatcher 8

Test a CommentPreprocessEvent.

File

tests/src/Unit/Preprocess/EntityEventVariablesTest.php, line 49

Class

EntityEventVariablesTest
Class EntityEventVariablesTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\Preprocess

Code

public function testCommentEvent() {
  $comment = new EntityMock('comment', 'comment_bundle', 'comment_view_mode');
  $variablesArray = $this
    ->createVariablesArray();
  $variablesArray['comment'] = $comment;
  $variablesArray['commented_entity'] = 'node';
  $variablesArray['view_mode'] = $comment
    ->getViewMode();

  /** @var \Drupal\hook_event_dispatcher\Event\Preprocess\Variables\CommentEventVariables $variables */
  $variables = $this
    ->getVariablesFromCreatedEvent(CommentPreprocessEvent::class, $variablesArray);
  self::assertInstanceOf(CommentEventVariables::class, $variables);
  $this
    ->assertAbstractEntityEventVariables($variables, $comment);
  $this
    ->assertSame($comment, $variables
    ->getComment());
  $this
    ->assertSame('node', $variables
    ->getCommentedEntity());
}