diff --git a/core/modules/user/src/Controller/UserController.php b/core/modules/user/src/Controller/UserController.php index 772884b..81e439b 100644 --- a/core/modules/user/src/Controller/UserController.php +++ b/core/modules/user/src/Controller/UserController.php @@ -163,7 +163,7 @@ public function userPage() { * NULL. */ public function userTitle(UserInterface $user = NULL) { - return $user ? ['#markup' => $user->getUsername(), '#allowed_tags' => Xss::getHtmlTagList()] : ''; + return $user ? ['#markup' => $user->getDisplayName(), '#allowed_tags' => Xss::getHtmlTagList()] : ''; } /** diff --git a/core/modules/user/src/Tests/UserDisplayNameTest.php b/core/modules/user/src/Tests/UserDisplayNameTest.php new file mode 100644 index 0000000..69df44e --- /dev/null +++ b/core/modules/user/src/Tests/UserDisplayNameTest.php @@ -0,0 +1,69 @@ +account = $this->drupalCreateUser($permissions); + } + + /** + * Test display name. + */ + function testDisplayName() { + // Set to test the altered username. + \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE); + + // We must login after the alter hook as been enabled or the username will + // be shown instead of the display name. + $this->drupalLogin($this->account); + + // Test if the altered display name is properly shown on pages. + $this->drupalGet('user/' . $this->account->id()); + $this->assertRaw($this->account->getDisplayName(), 'User view page shows altered user display name.'); + + $this->drupalGet('user/' . $this->account->id() . '/edit'); + $this->assertRaw($this->account->getDisplayName(), 'User edit page shows altered user display name.'); + } + +} diff --git a/core/modules/user/src/Tests/UserEntityCallbacksTest.php b/core/modules/user/src/Tests/UserEntityCallbacksTest.php index ce7726a..c6704e6 100644 --- a/core/modules/user/src/Tests/UserEntityCallbacksTest.php +++ b/core/modules/user/src/Tests/UserEntityCallbacksTest.php @@ -38,6 +38,9 @@ class UserEntityCallbacksTest extends WebTestBase { */ protected $anonymous; + /** + * {@inheritdoc} + */ protected function setUp() { parent::setUp(); @@ -56,7 +59,7 @@ function testLabelCallback() { $this->config('user.settings')->set('anonymous', $name)->save(); $this->assertEqual($this->anonymous->label(), $name, 'The variable anonymous should be used for name of uid 0'); $this->assertEqual($this->anonymous->getDisplayName(), $name, 'The variable anonymous should be used for display name of uid 0'); - $this->assertEqual($this->anonymous->getUserName(), '', 'The raw anonymous user name should be empty string'); + $this->assertEqual($this->anonymous->getUsername(), '', 'The raw anonymous user name should be empty string'); // Set to test the altered username. \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE);