UserEntityLabelTest.php in Drupal 8
File
core/modules/user/tests/src/Kernel/UserEntityLabelTest.php
View source
<?php
namespace Drupal\Tests\user\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\user\Entity\User;
class UserEntityLabelTest extends KernelTestBase {
use UserCreationTrait;
protected static $modules = [
'system',
'user',
'user_hooks_test',
];
public function testLabelCallback() {
$this
->installSchema('system', [
'sequences',
]);
$this
->installEntitySchema('user');
$account = $this
->createUser();
$anonymous = User::create([
'uid' => 0,
]);
$this
->assertEquals($account
->getAccountName(), $account
->label());
$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());
\Drupal::state()
->set('user_hooks_test_user_format_name_alter', TRUE);
$this
->assertEquals('<em>' . $account
->id() . '</em>', $account
->getDisplayName());
$this
->assertEquals($account->name->value, $account
->getAccountName());
}
}