You are here

public function OtherEventVariablesTest::testUsernameEvent 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::testUsernameEvent()

Test a UsernamePreprocessEvent.

File

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

Class

OtherEventVariablesTest
Class OtherEventVariablesTest.

Namespace

Drupal\Tests\preprocess_event_dispatcher\Unit

Code

public function testUsernameEvent() : void {
  $variablesArray = $this
    ->createVariablesArray();
  $accountMock = Mockery::mock(UserInterface::class);
  $accountMock
    ->expects('isAnonymous')
    ->with()
    ->once()
    ->andReturnTrue();
  $variablesArray['account'] = $accountMock;

  /** @var \Drupal\preprocess_event_dispatcher\Variables\UsernameEventVariables $variables */
  $variables = $this
    ->getVariablesFromCreatedEvent(UsernamePreprocessEvent::class, $variablesArray);
  self::assertInstanceOf(UsernameEventVariables::class, $variables);
  $this
    ->assertAbstractEventVariables($variables);
  self::assertSame($accountMock, $variables
    ->getAccount());
  self::assertTrue($variables
    ->userIsAnonymous());
}