Mercurial > hg > isophonics-drupal-site
comparison core/modules/user/tests/src/Kernel/UserEntityLabelCallbackTest.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
17:129ea1e6d783 | 18:af1871eacc83 |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\user\Kernel; | |
4 | |
5 use Drupal\KernelTests\KernelTestBase; | |
6 use Drupal\Tests\user\Traits\UserCreationTrait; | |
7 use Drupal\user\Entity\User; | |
8 | |
9 /** | |
10 * Tests the label callback. | |
11 * | |
12 * @group user | |
13 */ | |
14 class UserEntityLabelCallbackTest extends KernelTestBase { | |
15 | |
16 use UserCreationTrait; | |
17 | |
18 /** | |
19 * {@inheritdoc} | |
20 */ | |
21 protected static $modules = [ | |
22 'system', | |
23 'user', | |
24 'user_hooks_test', | |
25 ]; | |
26 | |
27 /** | |
28 * Tests label callback. | |
29 */ | |
30 public function testLabelCallback() { | |
31 $this->installSchema('system', ['sequences']); | |
32 $this->installEntitySchema('user'); | |
33 | |
34 $account = $this->createUser(); | |
35 $anonymous = User::create(['uid' => 0]); | |
36 | |
37 $this->assertEquals($account->getAccountName(), $account->label()); | |
38 | |
39 // Setup a random anonymous name to be sure the name is used. | |
40 $name = $this->randomMachineName(); | |
41 $this->config('user.settings')->set('anonymous', $name)->save(); | |
42 $this->assertEquals($name, $anonymous->label()); | |
43 $this->assertEquals($name, $anonymous->getDisplayName()); | |
44 $this->assertEmpty($anonymous->getAccountName()); | |
45 | |
46 // Set to test the altered username. | |
47 \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE); | |
48 | |
49 // The user display name should be altered. | |
50 $this->assertEquals('<em>' . $account->id() . '</em>', $account->getDisplayName()); | |
51 // The user login name should not be altered. | |
52 $this->assertEquals($account->name->value, $account->getAccountName()); | |
53 } | |
54 | |
55 } |