Mercurial > hg > isophonics-drupal-site
comparison core/modules/user/tests/src/Functional/UserEntityCallbacksTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\user\Functional; | |
4 | |
5 use Drupal\Tests\BrowserTestBase; | |
6 use Drupal\user\Entity\User; | |
7 | |
8 /** | |
9 * Tests specific parts of the user entity like the URI callback and the label | |
10 * callback. | |
11 * | |
12 * @group user | |
13 */ | |
14 class UserEntityCallbacksTest extends BrowserTestBase { | |
15 | |
16 /** | |
17 * Modules to enable. | |
18 * | |
19 * @var array | |
20 */ | |
21 public static $modules = ['user', 'user_hooks_test']; | |
22 | |
23 /** | |
24 * An authenticated user to use for testing. | |
25 * | |
26 * @var \Drupal\user\UserInterface | |
27 */ | |
28 protected $account; | |
29 | |
30 /** | |
31 * An anonymous user to use for testing. | |
32 * | |
33 * @var \Drupal\user\UserInterface | |
34 */ | |
35 protected $anonymous; | |
36 | |
37 protected function setUp() { | |
38 parent::setUp(); | |
39 | |
40 $this->account = $this->drupalCreateUser(); | |
41 $this->anonymous = User::create(['uid' => 0]); | |
42 } | |
43 | |
44 /** | |
45 * Test label callback. | |
46 */ | |
47 public function testLabelCallback() { | |
48 $this->assertEqual($this->account->label(), $this->account->getUsername(), 'The username should be used as label'); | |
49 | |
50 // Setup a random anonymous name to be sure the name is used. | |
51 $name = $this->randomMachineName(); | |
52 $this->config('user.settings')->set('anonymous', $name)->save(); | |
53 $this->assertEqual($this->anonymous->label(), $name, 'The variable anonymous should be used for name of uid 0'); | |
54 $this->assertEqual($this->anonymous->getDisplayName(), $name, 'The variable anonymous should be used for display name of uid 0'); | |
55 $this->assertEqual($this->anonymous->getUserName(), '', 'The raw anonymous user name should be empty string'); | |
56 | |
57 // Set to test the altered username. | |
58 \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE); | |
59 | |
60 $this->assertEqual($this->account->getDisplayName(), '<em>' . $this->account->id() . '</em>', 'The user display name should be altered.'); | |
61 $this->assertEqual($this->account->getUsername(), $this->account->name->value, 'The user name should not be altered.'); | |
62 } | |
63 | |
64 } |