class UserEntityLabelTest
Same name and namespace in other branches
- 11.x core/modules/user/tests/src/Kernel/UserEntityLabelTest.php \Drupal\Tests\user\Kernel\UserEntityLabelTest
- 10 core/modules/user/tests/src/Kernel/UserEntityLabelTest.php \Drupal\Tests\user\Kernel\UserEntityLabelTest
- 8.9.x core/modules/user/tests/src/Kernel/UserEntityLabelTest.php \Drupal\Tests\user\Kernel\UserEntityLabelTest
Tests the label callback.
@group user
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\user\Kernel\UserEntityLabelTest uses \Drupal\Tests\user\Traits\UserCreationTrait extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of UserEntityLabelTest
File
-
core/
modules/ user/ tests/ src/ Kernel/ UserEntityLabelTest.php, line 14
Namespace
Drupal\Tests\user\KernelView source
class UserEntityLabelTest 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());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.