public function RealnameBasicTest::testRealnameUsernameAlter in Real Name 8
Same name and namespace in other branches
- 2.x tests/src/Functional/RealnameBasicTest.php \Drupal\Tests\realname\Functional\RealnameBasicTest::testRealnameUsernameAlter()
Test realname alter functions.
File
- tests/
src/ Functional/ RealnameBasicTest.php, line 96
Class
- RealnameBasicTest
- Test basic functionality of Realname module.
Namespace
Drupal\Tests\realname\FunctionalCode
public function testRealnameUsernameAlter() {
$assert_session = $this
->assertSession();
// Add a test string and see if core username has been replaced by realname.
$edit['realname_pattern'] = '[user:account-name] (UID: [user:uid])';
$this
->drupalGet('admin/config/people/realname');
$this
->submitForm($edit, 'Save configuration');
// Assert real name is shown on the user page.
$this
->drupalGet('user/' . $this->adminUser
->id());
$assert_session
->pageTextContains($this->adminUser
->getDisplayName());
// Assert real name is shown on the user edit page.
$this
->drupalGet('user/' . $this->adminUser
->id() . '/edit');
$assert_session
->pageTextContains($this->adminUser
->getDisplayName());
/** @var \Drupal\user\Entity\User $user_account */
$user_account = $this->adminUser;
$username_before = $user_account
->getAccountName();
$user_account
->save();
$username_after = $user_account
->getAccountName();
$this
->assertEquals($username_after, $username_before, 'Username did not change after save');
}