You are here

public function UserEventTest::testUserFormatNameAlterEventWithSet in Hook Event Dispatcher 8

User format name alter event with set test.

File

tests/src/Unit/User/UserEventTest.php, line 151

Class

UserEventTest
Class UserEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\User

Code

public function testUserFormatNameAlterEventWithSet() {
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::USER_FORMAT_NAME_ALTER => function (UserFormatNameAlterEvent $event) {
      $event
        ->setName('New name!');
    },
  ]);
  $name = 'Test name';

  /** @var \Drupal\Core\Session\AccountInterface $account */
  $account = $this
    ->createMock(AccountInterface::class);
  hook_event_dispatcher_user_format_name_alter($name, $account);

  /** @var \Drupal\hook_event_dispatcher\Event\User\UserFormatNameAlterEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::USER_FORMAT_NAME_ALTER);
  self::assertSame('New name!', $event
    ->getName());
  self::assertSame($account, $event
    ->getAccount());
}