
| Current Path : /var/www/html/rocksensor1/web/core/modules/user/tests/src/Kernel/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/rocksensor1/web/core/modules/user/tests/src/Kernel/UserEntityLabelTest.php |
<?php
declare(strict_types=1);
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 UserEntityLabelTest extends KernelTestBase {
use UserCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
'user',
'user_hooks_test',
];
/**
* Tests label callback.
*/
public function testLabelCallback(): void {
$this->installEntitySchema('user');
$this->installConfig(['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());
}
}