From 55fa58c90b99292f1d19b0f3f6897dd9dc1dd78a Sat, 5 Dec 2015 14:43:01 +0100 From: hass Date: Sat, 5 Dec 2015 14:42:45 +0100 Subject: [PATCH] Issue #2629286 by hass: User title does not show display name 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 @@ * 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..fc00e16 --- /dev/null +++ b/core/modules/user/src/Tests/UserDisplayNameTest.php @@ -0,0 +1,68 @@ +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); + + // Login after the alter hook has been enabled or the username is shown. + $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 @@ */ protected $anonymous; + /** + * {@inheritdoc} + */ protected function setUp() { parent::setUp(); @@ -56,7 +59,7 @@ $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);