You are here

public function OtherEventVariablesTest::testUsernameEvent in Hook Event Dispatcher 8

Test a UsernamePreprocessEvent.

File

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

Class

OtherEventVariablesTest
Class OtherEventVariablesTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\Preprocess

Code

public function testUsernameEvent() {
  $variablesArray = $this
    ->createVariablesArray();
  $accountMock = $this
    ->getMockBuilder(UserInterface::class)
    ->disableOriginalClone()
    ->disableOriginalConstructor()
    ->setMethods([
    'isAnonymous',
  ])
    ->getMock();
  $accountMock
    ->expects($this
    ->once())
    ->method('isAnonymous')
    ->with()
    ->willReturn(TRUE);
  $variablesArray['account'] = $accountMock;

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