Mercurial > hg > cmmr2012-drupal-site
diff core/modules/user/tests/src/Kernel/UserEntityLabelCallbackTest.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/modules/user/tests/src/Kernel/UserEntityLabelCallbackTest.php Thu May 09 15:34:47 2019 +0100 @@ -0,0 +1,55 @@ +<?php + +namespace Drupal\Tests\user\Kernel; + +use Drupal\KernelTests\KernelTestBase; +use Drupal\Tests\user\Traits\UserCreationTrait; +use Drupal\user\Entity\User; + +/** + * Tests the label callback. + * + * @group user + */ +class UserEntityLabelCallbackTest extends KernelTestBase { + + use UserCreationTrait; + + /** + * {@inheritdoc} + */ + protected static $modules = [ + 'system', + 'user', + 'user_hooks_test', + ]; + + /** + * Tests label callback. + */ + public function testLabelCallback() { + $this->installSchema('system', ['sequences']); + $this->installEntitySchema('user'); + + $account = $this->createUser(); + $anonymous = User::create(['uid' => 0]); + + $this->assertEquals($account->getAccountName(), $account->label()); + + // Setup a random anonymous name to be sure the name is used. + $name = $this->randomMachineName(); + $this->config('user.settings')->set('anonymous', $name)->save(); + $this->assertEquals($name, $anonymous->label()); + $this->assertEquals($name, $anonymous->getDisplayName()); + $this->assertEmpty($anonymous->getAccountName()); + + // Set to test the altered username. + \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE); + + // The user display name should be altered. + $this->assertEquals('<em>' . $account->id() . '</em>', $account->getDisplayName()); + // The user login name should not be altered. + $this->assertEquals($account->name->value, $account->getAccountName()); + } + +}