diff --git a/core/lib/Drupal/Core/Session/AccountProxy.php b/core/lib/Drupal/Core/Session/AccountProxy.php index afe800bfacb..cedf93edec3 100644 --- a/core/lib/Drupal/Core/Session/AccountProxy.php +++ b/core/lib/Drupal/Core/Session/AccountProxy.php @@ -124,6 +124,7 @@ class AccountProxy implements AccountProxyInterface { * {@inheritdoc} */ public function getUsername() { + @trigger_error('\Drupal\Core\Session\AccountInterface::getUsername() is deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0. Use \Drupal\Core\Session\AccountInterface::getAccountName() or \Drupal\user\UserInterface::getDisplayName() instead. See https://www.drupal.org/node/2572493', E_USER_DEPRECATED); return $this->getAccountName(); } diff --git a/core/lib/Drupal/Core/Session/UserSession.php b/core/lib/Drupal/Core/Session/UserSession.php index 3fdf94ceaaf..ec002beb732 100644 --- a/core/lib/Drupal/Core/Session/UserSession.php +++ b/core/lib/Drupal/Core/Session/UserSession.php @@ -155,6 +155,7 @@ class UserSession implements AccountInterface { * {@inheritdoc} */ public function getUsername() { + @trigger_error('\Drupal\Core\Session\AccountInterface::getUsername() is deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0. Use \Drupal\Core\Session\AccountInterface::getAccountName() or \Drupal\user\UserInterface::getDisplayName() instead. See https://www.drupal.org/node/2572493', E_USER_DEPRECATED); return $this->getAccountName(); } diff --git a/core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php b/core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php index ed13ea5d38f..fc69ee59126 100644 --- a/core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php +++ b/core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php @@ -37,15 +37,15 @@ class BasicAuthTest extends BrowserTestBase { $account = $this->drupalCreateUser(); $url = Url::fromRoute('router_test.11'); - $this->basicAuthGet($url, $account->getUsername(), $account->pass_raw); - $this->assertText($account->getUsername(), 'Account name is displayed.'); + $this->basicAuthGet($url, $account->getAccountName(), $account->pass_raw); + $this->assertText($account->getAccountName(), 'Account name is displayed.'); $this->assertResponse('200', 'HTTP response is OK'); $this->mink->resetSessions(); $this->assertFalse($this->drupalGetHeader('X-Drupal-Cache')); $this->assertIdentical(strpos($this->drupalGetHeader('Cache-Control'), 'public'), FALSE, 'Cache-Control is not set to public'); - $this->basicAuthGet($url, $account->getUsername(), $this->randomMachineName()); - $this->assertNoText($account->getUsername(), 'Bad basic auth credentials do not authenticate the user.'); + $this->basicAuthGet($url, $account->getAccountName(), $this->randomMachineName()); + $this->assertNoText($account->getAccountName(), 'Bad basic auth credentials do not authenticate the user.'); $this->assertResponse('403', 'Access is not granted.'); $this->mink->resetSessions(); @@ -58,7 +58,7 @@ class BasicAuthTest extends BrowserTestBase { $account = $this->drupalCreateUser(['access administration pages']); - $this->basicAuthGet(Url::fromRoute('system.admin'), $account->getUsername(), $account->pass_raw); + $this->basicAuthGet(Url::fromRoute('system.admin'), $account->getAccountName(), $account->pass_raw); $this->assertNoLink('Log out', 'User is not logged in'); $this->assertResponse('403', 'No basic authentication for routes not explicitly defining authentication providers.'); $this->mink->resetSessions(); @@ -68,7 +68,7 @@ class BasicAuthTest extends BrowserTestBase { $url = Url::fromRoute('router_test.10'); $this->drupalGet($url); $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS'); - $this->basicAuthGet($url, $account->getUsername(), $account->pass_raw); + $this->basicAuthGet($url, $account->getAccountName(), $account->pass_raw); $this->assertFalse($this->drupalGetHeader('X-Drupal-Cache')); $this->assertIdentical(strpos($this->drupalGetHeader('Cache-Control'), 'public'), FALSE, 'No page cache response when requesting a cached page with basic auth credentials.'); } @@ -90,11 +90,11 @@ class BasicAuthTest extends BrowserTestBase { // Try 2 failed logins. for ($i = 0; $i < 2; $i++) { - $this->basicAuthGet($url, $incorrect_user->getUsername(), $incorrect_user->pass_raw); + $this->basicAuthGet($url, $incorrect_user->getAccountName(), $incorrect_user->pass_raw); } // IP limit has reached to its limit. Even valid user credentials will fail. - $this->basicAuthGet($url, $user->getUsername(), $user->pass_raw); + $this->basicAuthGet($url, $user->getAccountName(), $user->pass_raw); $this->assertResponse('403', 'Access is blocked because of IP based flood prevention.'); } @@ -115,24 +115,24 @@ class BasicAuthTest extends BrowserTestBase { $url = Url::fromRoute('router_test.11'); // Try a failed login. - $this->basicAuthGet($url, $incorrect_user->getUsername(), $incorrect_user->pass_raw); + $this->basicAuthGet($url, $incorrect_user->getAccountName(), $incorrect_user->pass_raw); // A successful login will reset the per-user flood control count. - $this->basicAuthGet($url, $user->getUsername(), $user->pass_raw); + $this->basicAuthGet($url, $user->getAccountName(), $user->pass_raw); $this->assertResponse('200', 'Per user flood prevention gets reset on a successful login.'); // Try 2 failed logins for a user. They will trigger flood control. for ($i = 0; $i < 2; $i++) { - $this->basicAuthGet($url, $incorrect_user->getUsername(), $incorrect_user->pass_raw); + $this->basicAuthGet($url, $incorrect_user->getAccountName(), $incorrect_user->pass_raw); } // Now the user account is blocked. - $this->basicAuthGet($url, $user->getUsername(), $user->pass_raw); + $this->basicAuthGet($url, $user->getAccountName(), $user->pass_raw); $this->assertResponse('403', 'The user account is blocked due to per user flood prevention.'); // Try one successful attempt for a different user, it should not trigger // any flood control. - $this->basicAuthGet($url, $user2->getUsername(), $user2->pass_raw); + $this->basicAuthGet($url, $user2->getAccountName(), $user2->pass_raw); $this->assertResponse('200', 'Per user flood prevention does not block access for other users.'); } @@ -146,8 +146,8 @@ class BasicAuthTest extends BrowserTestBase { $account = $this->drupalCreateUser(); $url = Url::fromRoute('router_test.11'); - $this->basicAuthGet($url, $account->getUsername(), $account->pass_raw); - $this->assertText($account->getUsername(), 'Account name is displayed.'); + $this->basicAuthGet($url, $account->getAccountName(), $account->pass_raw); + $this->assertText($account->getAccountName(), 'Account name is displayed.'); $this->assertResponse('200', 'HTTP response is OK'); } @@ -170,13 +170,13 @@ class BasicAuthTest extends BrowserTestBase { $this->assertText('Access denied', "A user friendly access denied message is displayed"); // Case when wrong credentials are passed. - $this->basicAuthGet($url, $account->getUsername(), $this->randomMachineName()); + $this->basicAuthGet($url, $account->getAccountName(), $this->randomMachineName()); $this->assertResponse('403', 'The user is blocked when wrong credentials are passed.'); $this->assertText('Access denied', "A user friendly access denied message is displayed"); // Case when correct credentials but hasn't access to the route. $url = Url::fromRoute('router_test.15'); - $this->basicAuthGet($url, $account->getUsername(), $account->pass_raw); + $this->basicAuthGet($url, $account->getAccountName(), $account->pass_raw); $this->assertResponse('403', 'The used authentication method is not allowed on this route.'); $this->assertText('Access denied', "A user friendly access denied message is displayed"); } @@ -235,7 +235,7 @@ class BasicAuthTest extends BrowserTestBase { $this->assertRaw('nope'); $account = $this->drupalCreateUser(); - $this->basicAuthGet('/basic_auth_test/state/modify', $account->getUsername(), $account->pass_raw); + $this->basicAuthGet('/basic_auth_test/state/modify', $account->getAccountName(), $account->pass_raw); $this->assertResponse(200); $this->assertRaw('Done'); diff --git a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php index 51f60b473af..e5017f54488 100644 --- a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php +++ b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php @@ -28,7 +28,7 @@ class TestContextAwareBlock extends BlockBase { return [ '#prefix' => '
This is a one-time login for %user_name and will expire on %expiration_date.
Click on this button to log in to the site and change your password.
', ['%user_name' => $user->getUsername(), '%expiration_date' => $expiration_date])]; + $form['message'] = ['#markup' => $this->t('This is a one-time login for %user_name and will expire on %expiration_date.
Click on this button to log in to the site and change your password.
', ['%user_name' => $user->getAccountName(), '%expiration_date' => $expiration_date])]; $form['#title'] = $this->t('Reset password'); } else { // No expiration for first time login. - $form['message'] = ['#markup' => $this->t('This is a one-time login for %user_name.
Click on this button to log in to the site and change your password.
', ['%user_name' => $user->getUsername()])]; + $form['message'] = ['#markup' => $this->t('This is a one-time login for %user_name.
Click on this button to log in to the site and change your password.
', ['%user_name' => $user->getAccountName()])]; $form['#title'] = $this->t('Set password'); } diff --git a/core/modules/user/src/Plugin/views/argument_validator/UserName.php b/core/modules/user/src/Plugin/views/argument_validator/UserName.php index 8ef4999b342..da8bdbba848 100644 --- a/core/modules/user/src/Plugin/views/argument_validator/UserName.php +++ b/core/modules/user/src/Plugin/views/argument_validator/UserName.php @@ -56,7 +56,7 @@ class UserName extends User { // Validate each account. If any fails break out and return false. foreach ($accounts as $account) { - if (!in_array($account->getUserName(), $names) || !$this->validateEntity($account)) { + if (!in_array($account->getAccountName(), $names) || !$this->validateEntity($account)) { return FALSE; } } diff --git a/core/modules/user/src/RegisterForm.php b/core/modules/user/src/RegisterForm.php index 3ffa88a54b5..a1ea5e944fc 100644 --- a/core/modules/user/src/RegisterForm.php +++ b/core/modules/user/src/RegisterForm.php @@ -110,7 +110,7 @@ class RegisterForm extends AccountForm { // New administrative account without notification. if ($admin && !$notify) { - $this->messenger()->addStatus($this->t('Created a new user account for %name. No email has been sent.', [':url' => $account->url(), '%name' => $account->getUsername()])); + $this->messenger()->addStatus($this->t('Created a new user account for %name. No email has been sent.', [':url' => $account->url(), '%name' => $account->getAccountName()])); } // No email verification required; log in user immediately. elseif (!$admin && !\Drupal::config('user.settings')->get('verify_mail') && $account->isActive()) { @@ -122,13 +122,13 @@ class RegisterForm extends AccountForm { // No administrator approval required. elseif ($account->isActive() || $notify) { if (!$account->getEmail() && $notify) { - $this->messenger()->addStatus($this->t('The new user %name was created without an email address, so no welcome message was sent.', [':url' => $account->url(), '%name' => $account->getUsername()])); + $this->messenger()->addStatus($this->t('The new user %name was created without an email address, so no welcome message was sent.', [':url' => $account->url(), '%name' => $account->getAccountName()])); } else { $op = $notify ? 'register_admin_created' : 'register_no_approval_required'; if (_user_mail_notify($op, $account)) { if ($notify) { - $this->messenger()->addStatus($this->t('A welcome message with further instructions has been emailed to the new user %name.', [':url' => $account->url(), '%name' => $account->getUsername()])); + $this->messenger()->addStatus($this->t('A welcome message with further instructions has been emailed to the new user %name.', [':url' => $account->url(), '%name' => $account->getAccountName()])); } else { $this->messenger()->addStatus($this->t('A welcome message with further instructions has been sent to your email address.')); diff --git a/core/modules/user/tests/modules/user_access_test/user_access_test.module b/core/modules/user/tests/modules/user_access_test/user_access_test.module index 94da298a640..a5cdb4b3f5b 100644 --- a/core/modules/user/tests/modules/user_access_test/user_access_test.module +++ b/core/modules/user/tests/modules/user_access_test/user_access_test.module @@ -15,11 +15,11 @@ use Drupal\user\Entity\User; * Implements hook_ENTITY_TYPE_access() for entity type "user". */ function user_access_test_user_access(User $entity, $operation, $account) { - if ($entity->getUsername() == "no_edit" && $operation == "update") { + if ($entity->getAccountName() == "no_edit" && $operation == "update") { // Deny edit access. return AccessResult::forbidden(); } - if ($entity->getUsername() == "no_delete" && $operation == "delete") { + if ($entity->getAccountName() == "no_delete" && $operation == "delete") { // Deny delete access. return AccessResult::forbidden(); } diff --git a/core/modules/user/tests/src/Functional/UserAdminTest.php b/core/modules/user/tests/src/Functional/UserAdminTest.php index 82e5df807c1..cc0d20456d4 100644 --- a/core/modules/user/tests/src/Functional/UserAdminTest.php +++ b/core/modules/user/tests/src/Functional/UserAdminTest.php @@ -50,10 +50,10 @@ class UserAdminTest extends BrowserTestBase { $admin_user->save(); $this->drupalLogin($admin_user); $this->drupalGet('admin/people'); - $this->assertText($user_a->getUsername(), 'Found user A on admin users page'); - $this->assertText($user_b->getUsername(), 'Found user B on admin users page'); - $this->assertText($user_c->getUsername(), 'Found user C on admin users page'); - $this->assertText($admin_user->getUsername(), 'Found Admin user on admin users page'); + $this->assertText($user_a->getAccountName(), 'Found user A on admin users page'); + $this->assertText($user_b->getAccountName(), 'Found user B on admin users page'); + $this->assertText($user_c->getAccountName(), 'Found user C on admin users page'); + $this->assertText($admin_user->getAccountName(), 'Found Admin user on admin users page'); // Test for existence of edit link in table. $link = $user_a->link(t('Edit'), 'edit-form', ['query' => ['destination' => $user_a->url('collection')]]); @@ -68,23 +68,23 @@ class UserAdminTest extends BrowserTestBase { $this->assertNoField('edit-reduce-duplicates', 'Reduce duplicates form element not found in exposed filters.'); // Filter the users by name/email. - $this->drupalGet('admin/people', ['query' => ['user' => $user_a->getUsername()]]); + $this->drupalGet('admin/people', ['query' => ['user' => $user_a->getAccountName()]]); $result = $this->xpath('//table/tbody/tr'); $this->assertEqual(1, count($result), 'Filter by username returned the right amount.'); - $this->assertEqual($user_a->getUsername(), $result[0]->find('xpath', '/td[2]/span')->getText(), 'Filter by username returned the right user.'); + $this->assertEqual($user_a->getAccountName(), $result[0]->find('xpath', '/td[2]/span')->getText(), 'Filter by username returned the right user.'); $this->drupalGet('admin/people', ['query' => ['user' => $user_a->getEmail()]]); $result = $this->xpath('//table/tbody/tr'); $this->assertEqual(1, count($result), 'Filter by username returned the right amount.'); - $this->assertEqual($user_a->getUsername(), $result[0]->find('xpath', '/td[2]/span')->getText(), 'Filter by username returned the right user.'); + $this->assertEqual($user_a->getAccountName(), $result[0]->find('xpath', '/td[2]/span')->getText(), 'Filter by username returned the right user.'); // Filter the users by permission 'administer taxonomy'. $this->drupalGet('admin/people', ['query' => ['permission' => 'administer taxonomy']]); // Check if the correct users show up. - $this->assertNoText($user_a->getUsername(), 'User A not on filtered by perm admin users page'); - $this->assertText($user_b->getUsername(), 'Found user B on filtered by perm admin users page'); - $this->assertText($user_c->getUsername(), 'Found user C on filtered by perm admin users page'); + $this->assertNoText($user_a->getAccountName(), 'User A not on filtered by perm admin users page'); + $this->assertText($user_b->getAccountName(), 'Found user B on filtered by perm admin users page'); + $this->assertText($user_c->getAccountName(), 'Found user C on filtered by perm admin users page'); // Filter the users by role. Grab the system-generated role name for User C. $roles = $user_c->getRoles(); @@ -92,9 +92,9 @@ class UserAdminTest extends BrowserTestBase { $this->drupalGet('admin/people', ['query' => ['role' => reset($roles)]]); // Check if the correct users show up when filtered by role. - $this->assertNoText($user_a->getUsername(), 'User A not on filtered by role on admin users page'); - $this->assertNoText($user_b->getUsername(), 'User B not on filtered by role on admin users page'); - $this->assertText($user_c->getUsername(), 'User C on filtered by role on admin users page'); + $this->assertNoText($user_a->getAccountName(), 'User A not on filtered by role on admin users page'); + $this->assertNoText($user_b->getAccountName(), 'User B not on filtered by role on admin users page'); + $this->assertText($user_c->getAccountName(), 'User C on filtered by role on admin users page'); // Test blocking of a user. $account = $user_storage->load($user_c->id()); @@ -118,9 +118,9 @@ class UserAdminTest extends BrowserTestBase { // Test filtering on admin page for blocked users $this->drupalGet('admin/people', ['query' => ['status' => 2]]); - $this->assertNoText($user_a->getUsername(), 'User A not on filtered by status on admin users page'); - $this->assertNoText($user_b->getUsername(), 'User B not on filtered by status on admin users page'); - $this->assertText($user_c->getUsername(), 'User C on filtered by status on admin users page'); + $this->assertNoText($user_a->getAccountName(), 'User A not on filtered by status on admin users page'); + $this->assertNoText($user_b->getAccountName(), 'User B not on filtered by status on admin users page'); + $this->assertText($user_c->getAccountName(), 'User C on filtered by status on admin users page'); // Test unblocking of a user from /admin/people page and sending of activation mail $editunblock = []; diff --git a/core/modules/user/tests/src/Functional/UserBlocksTest.php b/core/modules/user/tests/src/Functional/UserBlocksTest.php index 8f74ac0df28..f44d2a6b646 100644 --- a/core/modules/user/tests/src/Functional/UserBlocksTest.php +++ b/core/modules/user/tests/src/Functional/UserBlocksTest.php @@ -69,7 +69,7 @@ class UserBlocksTest extends BrowserTestBase { // Log in using the block. $edit = []; - $edit['name'] = $user->getUsername(); + $edit['name'] = $user->getAccountName(); $edit['pass'] = $user->passRaw; $this->drupalPostForm('admin/people/permissions', $edit, t('Log in')); $this->assertNoText(t('User login'), 'Logged in.'); diff --git a/core/modules/user/tests/src/Functional/UserCancelTest.php b/core/modules/user/tests/src/Functional/UserCancelTest.php index 869cd37bdd5..b216a5a5755 100644 --- a/core/modules/user/tests/src/Functional/UserCancelTest.php +++ b/core/modules/user/tests/src/Functional/UserCancelTest.php @@ -84,7 +84,7 @@ class UserCancelTest extends BrowserTestBase { $this->drupalPostForm('user_form_test_cancel/' . $account->id(), [], t('Cancel account')); // Confirm deletion. - $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getUsername()]), 'User deleted.'); + $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getAccountName()]), 'User deleted.'); $this->assertFalse(User::load($account->id()), 'User is not found in the database.'); } @@ -198,7 +198,7 @@ class UserCancelTest extends BrowserTestBase { $this->assertTrue($account->isBlocked(), 'User has been blocked.'); // Confirm that the confirmation message made it through to the end user. - $this->assertRaw(t('%name has been disabled.', ['%name' => $account->getUsername()]), "Confirmation message displayed to user."); + $this->assertRaw(t('%name has been disabled.', ['%name' => $account->getAccountName()]), "Confirmation message displayed to user."); } /** @@ -255,7 +255,7 @@ class UserCancelTest extends BrowserTestBase { $this->assertSession()->addressEquals(''); $this->assertSession()->statusCodeEquals(200); // Confirm that the confirmation message made it through to the end user. - $this->assertRaw(t('%name has been disabled.', ['%name' => $account->getUsername()]), "Confirmation message displayed to user."); + $this->assertRaw(t('%name has been disabled.', ['%name' => $account->getAccountName()]), "Confirmation message displayed to user."); $user_storage->resetCache([$account->id()]); $account = $user_storage->load($account->id()); @@ -352,7 +352,7 @@ class UserCancelTest extends BrowserTestBase { $this->assertEqual($test_comment->getAuthorName(), $anonymous_user->getDisplayName(), 'Comment of the user has been attributed to anonymous user name.'); // Confirm that the confirmation message made it through to the end user. - $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getUsername()]), "Confirmation message displayed to user."); + $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getAccountName()]), "Confirmation message displayed to user."); } /** @@ -471,7 +471,7 @@ class UserCancelTest extends BrowserTestBase { $this->assertFalse(Comment::load($comment->id()), 'Comment of the user has been deleted.'); // Confirm that the confirmation message made it through to the end user. - $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getUsername()]), "Confirmation message displayed to user."); + $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getAccountName()]), "Confirmation message displayed to user."); } /** @@ -490,12 +490,12 @@ class UserCancelTest extends BrowserTestBase { // Delete regular user. $this->drupalGet('user/' . $account->id() . '/edit'); $this->drupalPostForm(NULL, NULL, t('Cancel account')); - $this->assertRaw(t('Are you sure you want to cancel the account %name?', ['%name' => $account->getUsername()]), 'Confirmation form to cancel account displayed.'); + $this->assertRaw(t('Are you sure you want to cancel the account %name?', ['%name' => $account->getAccountName()]), 'Confirmation form to cancel account displayed.'); $this->assertText(t('Select the method to cancel the account above.'), 'Allows to select account cancellation method.'); // Confirm deletion. $this->drupalPostForm(NULL, NULL, t('Cancel account')); - $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getUsername()]), 'User deleted.'); + $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getAccountName()]), 'User deleted.'); $this->assertFalse(User::load($account->id()), 'User is not found in the database.'); } @@ -518,12 +518,12 @@ class UserCancelTest extends BrowserTestBase { // Delete regular user without email address. $this->drupalGet('user/' . $account->id() . '/edit'); $this->drupalPostForm(NULL, NULL, t('Cancel account')); - $this->assertRaw(t('Are you sure you want to cancel the account %name?', ['%name' => $account->getUsername()]), 'Confirmation form to cancel account displayed.'); + $this->assertRaw(t('Are you sure you want to cancel the account %name?', ['%name' => $account->getAccountName()]), 'Confirmation form to cancel account displayed.'); $this->assertText(t('Select the method to cancel the account above.'), 'Allows to select account cancellation method.'); // Confirm deletion. $this->drupalPostForm(NULL, NULL, t('Cancel account')); - $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getUsername()]), 'User deleted.'); + $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getAccountName()]), 'User deleted.'); $this->assertFalse(User::load($account->id()), 'User is not found in the database.'); } @@ -565,7 +565,7 @@ class UserCancelTest extends BrowserTestBase { $this->drupalPostForm(NULL, NULL, t('Cancel accounts')); $status = TRUE; foreach ($users as $account) { - $status = $status && (strpos($this->getTextContent(), $account->getUsername() . ' has been deleted.') !== FALSE); + $status = $status && (strpos($this->getTextContent(), $account->getAccountName() . ' has been deleted.') !== FALSE); $user_storage->resetCache([$account->id()]); $status = $status && !$user_storage->load($account->id()); } diff --git a/core/modules/user/tests/src/Functional/UserEditTest.php b/core/modules/user/tests/src/Functional/UserEditTest.php index 5cdbc19f050..6791b1e3929 100644 --- a/core/modules/user/tests/src/Functional/UserEditTest.php +++ b/core/modules/user/tests/src/Functional/UserEditTest.php @@ -22,7 +22,7 @@ class UserEditTest extends BrowserTestBase { $this->drupalLogin($user1); // Test that error message appears when attempting to use a non-unique user name. - $edit['name'] = $user2->getUsername(); + $edit['name'] = $user2->getAccountName(); $this->drupalPostForm("user/" . $user1->id() . "/edit", $edit, t('Save')); $this->assertRaw(t('The username %name is already taken.', ['%name' => $edit['name']])); diff --git a/core/modules/user/tests/src/Functional/UserEntityCallbacksTest.php b/core/modules/user/tests/src/Functional/UserEntityCallbacksTest.php index feea805afd1..381ee1402bb 100644 --- a/core/modules/user/tests/src/Functional/UserEntityCallbacksTest.php +++ b/core/modules/user/tests/src/Functional/UserEntityCallbacksTest.php @@ -45,20 +45,20 @@ class UserEntityCallbacksTest extends BrowserTestBase { * Test label callback. */ public function testLabelCallback() { - $this->assertEqual($this->account->label(), $this->account->getUsername(), 'The username should be used as label'); + $this->assertEqual($this->account->label(), $this->account->getAccountName(), 'The username should be used as label'); // Setup a random anonymous name to be sure the name is used. $name = $this->randomMachineName(); $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->getAccountName(), '', '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); $this->assertEqual($this->account->getDisplayName(), '' . $this->account->id() . '', 'The user display name should be altered.'); - $this->assertEqual($this->account->getUsername(), $this->account->name->value, 'The user name should not be altered.'); + $this->assertEqual($this->account->getAccountName(), $this->account->name->value, 'The user name should not be altered.'); } } diff --git a/core/modules/user/tests/src/Functional/UserLoginHttpTest.php b/core/modules/user/tests/src/Functional/UserLoginHttpTest.php index 079affaf54a..47287810e01 100644 --- a/core/modules/user/tests/src/Functional/UserLoginHttpTest.php +++ b/core/modules/user/tests/src/Functional/UserLoginHttpTest.php @@ -119,7 +119,7 @@ class UserLoginHttpTest extends BrowserTestBase { // Grant the user administer users permissions to they can see the // 'roles' field. $account = $this->drupalCreateUser(['administer users']); - $name = $account->getUsername(); + $name = $account->getAccountName(); $pass = $account->passRaw; $login_status_url = $this->getLoginStatusUrlString($format); @@ -295,12 +295,12 @@ class UserLoginHttpTest extends BrowserTestBase { // Try 2 failed logins. for ($i = 0; $i < 2; $i++) { - $response = $this->loginRequest($incorrect_user->getUsername(), $incorrect_user->passRaw); + $response = $this->loginRequest($incorrect_user->getAccountName(), $incorrect_user->passRaw); $this->assertEquals('400', $response->getStatusCode()); } // IP limit has reached to its limit. Even valid user credentials will fail. - $response = $this->loginRequest($user->getUsername(), $user->passRaw); + $response = $this->loginRequest($user->getAccountName(), $user->passRaw); $this->assertHttpResponseWithMessage($response, '403', 'Access is blocked because of IP based flood prevention.'); } @@ -359,18 +359,18 @@ class UserLoginHttpTest extends BrowserTestBase { // Try 2 failed logins. for ($i = 0; $i < 2; $i++) { - $response = $this->loginRequest($incorrect_user1->getUsername(), $incorrect_user1->passRaw); + $response = $this->loginRequest($incorrect_user1->getAccountName(), $incorrect_user1->passRaw); $this->assertHttpResponseWithMessage($response, 400, 'Sorry, unrecognized username or password.'); } // A successful login will reset the per-user flood control count. - $response = $this->loginRequest($user1->getUsername(), $user1->passRaw); + $response = $this->loginRequest($user1->getAccountName(), $user1->passRaw); $result_data = $this->serializer->decode($response->getBody(), 'json'); $this->logoutRequest('json', $result_data['logout_token']); // Try 3 failed logins for user 1, they will not trigger flood control. for ($i = 0; $i < 3; $i++) { - $response = $this->loginRequest($incorrect_user1->getUsername(), $incorrect_user1->passRaw); + $response = $this->loginRequest($incorrect_user1->getAccountName(), $incorrect_user1->passRaw); $this->assertHttpResponseWithMessage($response, 400, 'Sorry, unrecognized username or password.'); } @@ -381,7 +381,7 @@ class UserLoginHttpTest extends BrowserTestBase { // Try one more attempt for user 1, it should be rejected, even if the // correct password has been used. - $response = $this->loginRequest($user1->getUsername(), $user1->passRaw); + $response = $this->loginRequest($user1->getAccountName(), $user1->passRaw); // Depending on the uid_only setting the error message will be different. if ($uid_only_setting) { $excepted_message = 'There have been more than 3 failed login attempts for this account. It is temporarily blocked. Try again later or request a new password.'; @@ -433,7 +433,7 @@ class UserLoginHttpTest extends BrowserTestBase { $client = \Drupal::httpClient(); $login_status_url = $this->getLoginStatusUrlString(); $account = $this->drupalCreateUser(); - $name = $account->getUsername(); + $name = $account->getAccountName(); $pass = $account->passRaw; $response = $this->loginRequest($name, $pass); diff --git a/core/modules/user/tests/src/Functional/UserLoginTest.php b/core/modules/user/tests/src/Functional/UserLoginTest.php index 3021bc8fbde..cd244a73969 100644 --- a/core/modules/user/tests/src/Functional/UserLoginTest.php +++ b/core/modules/user/tests/src/Functional/UserLoginTest.php @@ -23,7 +23,7 @@ class UserLoginTest extends BrowserTestBase { $user = $this->drupalCreateUser([]); $this->drupalGet('user/login', ['query' => ['destination' => 'foo']]); - $edit = ['name' => $user->getUserName(), 'pass' => $user->passRaw]; + $edit = ['name' => $user->getAccountName(), 'pass' => $user->passRaw]; $this->drupalPostForm(NULL, $edit, t('Log in')); $this->assertUrl('foo', [], 'Redirected to the correct URL'); } @@ -156,7 +156,7 @@ class UserLoginTest extends BrowserTestBase { */ public function assertFailedLogin($account, $flood_trigger = NULL) { $edit = [ - 'name' => $account->getUsername(), + 'name' => $account->getAccountName(), 'pass' => $account->passRaw, ]; $this->drupalPostForm('user/login', $edit, t('Log in')); diff --git a/core/modules/user/tests/src/Functional/UserPasswordResetTest.php b/core/modules/user/tests/src/Functional/UserPasswordResetTest.php index ba71ddaceed..2f73e555067 100644 --- a/core/modules/user/tests/src/Functional/UserPasswordResetTest.php +++ b/core/modules/user/tests/src/Functional/UserPasswordResetTest.php @@ -80,12 +80,12 @@ class UserPasswordResetTest extends PageCacheTagsTestBase { $this->assertEqual(count($this->drupalGetMails(['id' => 'user_password_reset'])), 0, 'No email was sent when requesting a password for an invalid account.'); // Reset the password by username via the password reset page. - $edit['name'] = $this->account->getUsername(); + $edit['name'] = $this->account->getAccountName(); $this->drupalPostForm(NULL, $edit, t('Submit')); // Verify that the user was sent an email. $this->assertMail('to', $this->account->getEmail(), 'Password email sent to user.'); - $subject = t('Replacement login information for @username at @site', ['@username' => $this->account->getUsername(), '@site' => $this->config('system.site')->get('name')]); + $subject = t('Replacement login information for @username at @site', ['@username' => $this->account->getAccountName(), '@site' => $this->config('system.site')->get('name')]); $this->assertMail('subject', $subject, 'Password reset email subject is correct.'); $resetURL = $this->getResetURL(); @@ -100,14 +100,14 @@ class UserPasswordResetTest extends PageCacheTagsTestBase { $this->assertFalse($this->drupalGetHeader('X-Drupal-Cache')); // Check the one-time login page. - $this->assertText($this->account->getUsername(), 'One-time login page contains the correct username.'); + $this->assertText($this->account->getAccountName(), 'One-time login page contains the correct username.'); $this->assertText(t('This login can be used only once.'), 'Found warning about one-time login.'); $this->assertTitle(t('Reset password | Drupal'), 'Page title is "Reset password".'); // Check successful login. $this->drupalPostForm(NULL, NULL, t('Log in')); $this->assertLink(t('Log out')); - $this->assertTitle(t('@name | @site', ['@name' => $this->account->getUsername(), '@site' => $this->config('system.site')->get('name')]), 'Logged in using password reset link.'); + $this->assertTitle(t('@name | @site', ['@name' => $this->account->getAccountName(), '@site' => $this->config('system.site')->get('name')]), 'Logged in using password reset link.'); // Change the forgotten password. $password = user_password(); @@ -161,14 +161,14 @@ class UserPasswordResetTest extends PageCacheTagsTestBase { $this->drupalGet('user/password'); // Count email messages before to compare with after. $before = count($this->drupalGetMails(['id' => 'user_password_reset'])); - $edit = ['name' => $blocked_account->getUsername()]; + $edit = ['name' => $blocked_account->getAccountName()]; $this->drupalPostForm(NULL, $edit, t('Submit')); - $this->assertRaw(t('%name is blocked or has not been activated yet.', ['%name' => $blocked_account->getUsername()]), 'Notified user blocked accounts can not request a new password'); + $this->assertRaw(t('%name is blocked or has not been activated yet.', ['%name' => $blocked_account->getAccountName()]), 'Notified user blocked accounts can not request a new password'); $this->assertTrue(count($this->drupalGetMails(['id' => 'user_password_reset'])) === $before, 'No email was sent when requesting password reset for a blocked account'); // Verify a password reset link is invalidated when the user's email address changes. $this->drupalGet('user/password'); - $edit = ['name' => $this->account->getUsername()]; + $edit = ['name' => $this->account->getAccountName()]; $this->drupalPostForm(NULL, $edit, t('Submit')); $old_email_reset_link = $this->getResetURL(); $this->account->setEmail("1" . $this->account->getEmail()); @@ -180,12 +180,12 @@ class UserPasswordResetTest extends PageCacheTagsTestBase { // Verify a password reset link will automatically log a user when /login is // appended. $this->drupalGet('user/password'); - $edit = ['name' => $this->account->getUsername()]; + $edit = ['name' => $this->account->getAccountName()]; $this->drupalPostForm(NULL, $edit, t('Submit')); $reset_url = $this->getResetURL(); $this->drupalGet($reset_url . '/login'); $this->assertLink(t('Log out')); - $this->assertTitle(t('@name | @site', ['@name' => $this->account->getUsername(), '@site' => $this->config('system.site')->get('name')]), 'Logged in using password reset link.'); + $this->assertTitle(t('@name | @site', ['@name' => $this->account->getAccountName(), '@site' => $this->config('system.site')->get('name')]), 'Logged in using password reset link.'); // Ensure blocked and deleted accounts can't access the user.reset.login // route. @@ -230,7 +230,7 @@ class UserPasswordResetTest extends PageCacheTagsTestBase { $this->drupalGet($resetURL); $this->assertRaw(new FormattableMarkup( 'Another user (%other_user) is already logged into the site on this computer, but you tried to use a one-time link for user %resetting_user. Please log out and try using the link again.', - ['%other_user' => $this->account->getUsername(), '%resetting_user' => $another_account->getUsername(), ':logout' => Url::fromRoute('user.logout')->toString()] + ['%other_user' => $this->account->getAccountName(), '%resetting_user' => $another_account->getAccountName(), ':logout' => Url::fromRoute('user.logout')->toString()] )); $another_account->delete(); @@ -319,7 +319,7 @@ class UserPasswordResetTest extends PageCacheTagsTestBase { $attack_reset_url = str_replace("user/reset/{$user1->id()}", "user/reset/{$user2->id()}", $reset_url); $this->drupalGet($attack_reset_url); $this->drupalPostForm(NULL, NULL, t('Log in')); - $this->assertNoText($user2->getUsername(), 'The invalid password reset page does not show the user name.'); + $this->assertNoText($user2->getAccountName(), 'The invalid password reset page does not show the user name.'); $this->assertUrl('user/password', [], 'The user is redirected to the password reset request page.'); $this->assertText('You have tried to use a one-time login link that has either been used or is no longer valid. Please request a new one using the form below.'); } diff --git a/core/modules/user/tests/src/Functional/UserPictureTest.php b/core/modules/user/tests/src/Functional/UserPictureTest.php index 9f26671a1b7..e8941019e86 100644 --- a/core/modules/user/tests/src/Functional/UserPictureTest.php +++ b/core/modules/user/tests/src/Functional/UserPictureTest.php @@ -108,7 +108,7 @@ class UserPictureTest extends BrowserTestBase { $image_style_id = $this->config('core.entity_view_display.user.user.compact')->get('content.user_picture.settings.image_style'); $style = ImageStyle::load($image_style_id); $image_url = file_url_transform_relative($style->buildUrl($file->getfileUri())); - $alt_text = 'Profile picture for user ' . $this->webUser->getUsername(); + $alt_text = 'Profile picture for user ' . $this->webUser->getAccountName(); // Verify that the image is displayed on the node page. $this->drupalGet('node/' . $node->id()); diff --git a/core/modules/user/tests/src/Functional/UserRegistrationTest.php b/core/modules/user/tests/src/Functional/UserRegistrationTest.php index 78c1af42ce9..a329dec0efb 100644 --- a/core/modules/user/tests/src/Functional/UserRegistrationTest.php +++ b/core/modules/user/tests/src/Functional/UserRegistrationTest.php @@ -252,7 +252,7 @@ class UserRegistrationTest extends BrowserTestBase { $accounts = $this->container->get('entity_type.manager')->getStorage('user') ->loadByProperties(['name' => $name, 'mail' => $mail]); $new_user = reset($accounts); - $this->assertEqual($new_user->getUsername(), $name, 'Username matches.'); + $this->assertEqual($new_user->getAccountName(), $name, 'Username matches.'); $this->assertEqual($new_user->getEmail(), $mail, 'Email address matches.'); $this->assertTrue(($new_user->getCreatedTime() > REQUEST_TIME - 20), 'Correct creation time.'); $this->assertEqual($new_user->isActive(), $config_user_settings->get('register') == USER_REGISTER_VISITORS ? 1 : 0, 'Correct status field.'); @@ -271,9 +271,9 @@ class UserRegistrationTest extends BrowserTestBase { public function testUniqueFields() { $account = $this->drupalCreateUser(); - $edit = ['mail' => 'test@example.com', 'name' => $account->getUsername()]; + $edit = ['mail' => 'test@example.com', 'name' => $account->getAccountName()]; $this->drupalPostForm('user/register', $edit, t('Create new account')); - $this->assertRaw(new FormattableMarkup('The username %value is already taken.', ['%value' => $account->getUsername()])); + $this->assertRaw(new FormattableMarkup('The username %value is already taken.', ['%value' => $account->getAccountName()])); $edit = ['mail' => $account->getEmail(), 'name' => $this->randomString()]; $this->drupalPostForm('user/register', $edit, t('Create new account')); diff --git a/core/modules/user/tests/src/Functional/UserSearchTest.php b/core/modules/user/tests/src/Functional/UserSearchTest.php index 8ce0319bf62..24ab0afef55 100644 --- a/core/modules/user/tests/src/Functional/UserSearchTest.php +++ b/core/modules/user/tests/src/Functional/UserSearchTest.php @@ -38,7 +38,7 @@ class UserSearchTest extends BrowserTestBase { $this->assertText('no results', 'Non-matching search gave appropriate message'); // Verify that a user with search permission can search for users by name. - $keys = $user1->getUsername(); + $keys = $user1->getAccountName(); $edit = ['keys' => $keys]; $this->drupalPostForm('search/user', $edit, t('Search')); $this->assertLink($keys, 0, 'Search by username worked for non-admin user'); @@ -63,23 +63,23 @@ class UserSearchTest extends BrowserTestBase { $edit = ['keys' => $keys]; $this->drupalPostForm('search/user', $edit, t('Search')); $this->assertText($keys, 'Search by email works for administrative user'); - $this->assertText($user2->getUsername(), 'Search by email resulted in username on page for administrative user'); + $this->assertText($user2->getAccountName(), 'Search by email resulted in username on page for administrative user'); // Verify that a substring works too for email. $subkey = substr($keys, 1, 5); $edit = ['keys' => $subkey]; $this->drupalPostForm('search/user', $edit, t('Search')); $this->assertText($keys, 'Search by email substring works for administrative user'); - $this->assertText($user2->getUsername(), 'Search by email substring resulted in username on page for administrative user'); + $this->assertText($user2->getAccountName(), 'Search by email substring resulted in username on page for administrative user'); // Verify that wildcard search works for email $subkey = substr($keys, 0, 2) . '*' . substr($keys, 4, 2); $edit = ['keys' => $subkey]; $this->drupalPostForm('search/user', $edit, t('Search')); - $this->assertText($user2->getUsername(), 'Search for email wildcard resulted in username on page for administrative user'); + $this->assertText($user2->getAccountName(), 'Search for email wildcard resulted in username on page for administrative user'); // Verify that if they search by user name, they see email address too. - $keys = $user1->getUsername(); + $keys = $user1->getAccountName(); $edit = ['keys' => $keys]; $this->drupalPostForm('search/user', $edit, t('Search')); $this->assertText($keys, 'Search by username works for admin user'); @@ -92,14 +92,14 @@ class UserSearchTest extends BrowserTestBase { // Verify that users with "administer users" permissions can see blocked // accounts in search results. - $edit = ['keys' => $blocked_user->getUsername()]; + $edit = ['keys' => $blocked_user->getAccountName()]; $this->drupalPostForm('search/user', $edit, t('Search')); - $this->assertText($blocked_user->getUsername(), 'Blocked users are listed on the user search results for users with the "administer users" permission.'); + $this->assertText($blocked_user->getAccountName(), 'Blocked users are listed on the user search results for users with the "administer users" permission.'); // Verify that users without "administer users" permissions do not see // blocked accounts in search results. $this->drupalLogin($user1); - $edit = ['keys' => $blocked_user->getUsername()]; + $edit = ['keys' => $blocked_user->getAccountName()]; $this->drupalPostForm('search/user', $edit, t('Search')); $this->assertText(t('Your search yielded no results.'), 'Blocked users are hidden from the user search results.'); diff --git a/core/modules/user/tests/src/Functional/UserSubAdminTest.php b/core/modules/user/tests/src/Functional/UserSubAdminTest.php index 9b8e6daa134..029df0301ac 100644 --- a/core/modules/user/tests/src/Functional/UserSubAdminTest.php +++ b/core/modules/user/tests/src/Functional/UserSubAdminTest.php @@ -46,12 +46,12 @@ class UserSubAdminTest extends BrowserTestBase { // Test that the cancel user page has admin fields. $cancel_user = $this->createUser(); $this->drupalGet('user/' . $cancel_user->id() . '/cancel'); - $this->assertSession()->responseContains('Are you sure you want to cancel the account ' . $cancel_user->getUsername() . '?'); + $this->assertSession()->responseContains('Are you sure you want to cancel the account ' . $cancel_user->getAccountName() . '?'); $this->assertSession()->responseContains('Disable the account and keep its content. This action cannot be undone.'); // Test that cancel confirmation gives an admin style message. $this->drupalPostForm(NULL, NULL, t('Cancel account')); - $this->assertSession()->pageTextContains($cancel_user->getUsername() . ' has been disabled.'); + $this->assertSession()->pageTextContains($cancel_user->getAccountName() . ' has been disabled.'); // Repeat with permission to select account cancellation method. $user->addRole($this->drupalCreateRole(['select account cancellation method'])); diff --git a/core/modules/user/tests/src/Functional/Views/ArgumentValidateTest.php b/core/modules/user/tests/src/Functional/Views/ArgumentValidateTest.php index ab396804012..e28641d6361 100644 --- a/core/modules/user/tests/src/Functional/Views/ArgumentValidateTest.php +++ b/core/modules/user/tests/src/Functional/Views/ArgumentValidateTest.php @@ -64,7 +64,7 @@ class ArgumentValidateTest extends UserTestBase { $view = Views::getView('test_view_argument_validate_username'); $this->executeView($view); - $this->assertTrue($view->argument['null']->validateArgument($account->getUsername())); + $this->assertTrue($view->argument['null']->validateArgument($account->getAccountName())); // Reset argument validation. $view->argument['null']->argument_validated = NULL; // Fail for a valid string, but for a user that doesn't exist diff --git a/core/modules/user/tests/src/FunctionalJavascript/UserPasswordResetTest.php b/core/modules/user/tests/src/FunctionalJavascript/UserPasswordResetTest.php index e74b53ca289..f9ea85efa9d 100644 --- a/core/modules/user/tests/src/FunctionalJavascript/UserPasswordResetTest.php +++ b/core/modules/user/tests/src/FunctionalJavascript/UserPasswordResetTest.php @@ -85,7 +85,7 @@ class UserPasswordResetTest extends WebDriverTestBase { $this->drupalGet('user/password'); // Reset the password by username via the password reset page. - $edit['name'] = $this->account->getUsername(); + $edit['name'] = $this->account->getAccountName(); $this->drupalPostForm(NULL, $edit, t('Submit')); $resetURL = $this->getResetURL(); diff --git a/core/modules/user/tests/src/Kernel/Migrate/MigrateUserAdminPassTest.php b/core/modules/user/tests/src/Kernel/Migrate/MigrateUserAdminPassTest.php index 85cd761bc3e..7f74ad16ed5 100644 --- a/core/modules/user/tests/src/Kernel/Migrate/MigrateUserAdminPassTest.php +++ b/core/modules/user/tests/src/Kernel/Migrate/MigrateUserAdminPassTest.php @@ -94,14 +94,14 @@ class MigrateUserAdminPassTest extends MigrateTestBase { // Verify that admin username and email were changed, but password was not. /** @var \Drupal\user\Entity\User $admin_account */ $admin_account = User::load(1); - $this->assertIdentical($admin_account->getUsername(), 'site_admin'); + $this->assertIdentical($admin_account->getAccountName(), 'site_admin'); $this->assertIdentical($admin_account->getEmail(), 'site_admin@example.com'); $this->assertIdentical($admin_account->getPassword(), $this->originalPasswords[1]); // Verify that everything changed for the regular user. /** @var \Drupal\user\Entity\User $user_account */ $user_account = User::load(2); - $this->assertIdentical($user_account->getUsername(), 'random_user'); + $this->assertIdentical($user_account->getAccountName(), 'random_user'); $this->assertIdentical($user_account->getEmail(), 'random_user@example.com'); $this->assertNotIdentical($user_account->getPassword(), $this->originalPasswords[2]); } diff --git a/core/modules/user/tests/src/Kernel/WhosOnlineBlockTest.php b/core/modules/user/tests/src/Kernel/WhosOnlineBlockTest.php index 02844a1610f..2779090700e 100644 --- a/core/modules/user/tests/src/Kernel/WhosOnlineBlockTest.php +++ b/core/modules/user/tests/src/Kernel/WhosOnlineBlockTest.php @@ -109,10 +109,10 @@ class WhosOnlineBlockTest extends KernelTestBase { $output = entity_view($entity, 'block'); $this->setRawContent($this->renderer->renderRoot($output)); $this->assertRaw('2 users', 'Correct number of online users (2 users).'); - $this->assertText($user1->getUsername(), 'Active user 1 found in online list.'); - $this->assertText($user2->getUsername(), 'Active user 2 found in online list.'); - $this->assertNoText($user3->getUsername(), 'Inactive user not found in online list.'); - $this->assertTrue(strpos($this->getRawContent(), $user1->getUsername()) > strpos($this->getRawContent(), $user2->getUsername()), 'Online users are ordered correctly.'); + $this->assertText($user1->getAccountName(), 'Active user 1 found in online list.'); + $this->assertText($user2->getAccountName(), 'Active user 2 found in online list.'); + $this->assertNoText($user3->getAccountName(), 'Inactive user not found in online list.'); + $this->assertTrue(strpos($this->getRawContent(), $user1->getAccountName()) > strpos($this->getRawContent(), $user2->getAccountName()), 'Online users are ordered correctly.'); } } diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 053429f4b87..12bc5ed0749 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -409,7 +409,7 @@ function user_user_view_alter(array &$build, UserInterface $account, EntityViewD foreach (Element::children($build['user_picture']) as $key) { $item = $build['user_picture'][$key]['#item']; if (!$item->get('alt')->getValue()) { - $item->get('alt')->setValue(\Drupal::translation()->translate('Profile picture for user @username', ['@username' => $account->getUsername()])); + $item->get('alt')->setValue(\Drupal::translation()->translate('Profile picture for user @username', ['@username' => $account->getAccountName()])); } } } @@ -492,7 +492,7 @@ function template_preprocess_username(&$variables) { // their own shortening logic or add markup. If they do so, they must ensure // that $variables['name'] is safe for printing. $name = $account->getDisplayName(); - $variables['name_raw'] = $account->getUsername(); + $variables['name_raw'] = $account->getAccountName(); if (mb_strlen($name) > 20) { $name = Unicode::truncate($name, 15, FALSE, TRUE); $variables['truncated'] = TRUE; @@ -549,7 +549,7 @@ function template_preprocess_username(&$variables) { */ function user_login_finalize(UserInterface $account) { \Drupal::currentUser()->setAccount($account); - \Drupal::logger('user')->notice('Session opened for %name.', ['%name' => $account->getUsername()]); + \Drupal::logger('user')->notice('Session opened for %name.', ['%name' => $account->getAccountName()]); // Update the user table timestamp noting user has logged in. // This is also used to invalidate one-time login links. $account->setLastLoginTime(REQUEST_TIME); @@ -1281,7 +1281,7 @@ function user_form_process_password_confirm($element) { 'fair' => t('Fair'), 'good' => t('Good'), 'strong' => t('Strong'), - 'username' => \Drupal::currentUser()->getUsername(), + 'username' => \Drupal::currentUser()->getAccountName(), ]; } diff --git a/core/modules/views/tests/src/Kernel/Plugin/RelationshipTest.php b/core/modules/views/tests/src/Kernel/Plugin/RelationshipTest.php index 9395b8eb830..55b30734a25 100644 --- a/core/modules/views/tests/src/Kernel/Plugin/RelationshipTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/RelationshipTest.php @@ -170,8 +170,8 @@ class RelationshipTest extends RelationshipJoinTestBase { // Check that the output contains correct values. $xpath = '//div[@class="views-row" and div[@class="views-field views-field-id"]=:id and div[@class="views-field views-field-author"]=:author]'; - $this->assertEqual(1, count($this->xpath($xpath, [':id' => 1, ':author' => $author1->getUsername()]))); - $this->assertEqual(1, count($this->xpath($xpath, [':id' => 2, ':author' => $author2->getUsername()]))); + $this->assertEqual(1, count($this->xpath($xpath, [':id' => 1, ':author' => $author1->getAccountName()]))); + $this->assertEqual(1, count($this->xpath($xpath, [':id' => 2, ':author' => $author2->getAccountName()]))); $this->assertEqual(1, count($this->xpath($xpath, [':id' => 3, ':author' => '']))); } diff --git a/core/modules/workspaces/tests/src/Functional/WorkspaceTest.php b/core/modules/workspaces/tests/src/Functional/WorkspaceTest.php index 5c7bea6e6a6..89f76e71fe6 100644 --- a/core/modules/workspaces/tests/src/Functional/WorkspaceTest.php +++ b/core/modules/workspaces/tests/src/Functional/WorkspaceTest.php @@ -85,7 +85,7 @@ class WorkspaceTest extends BrowserTestBase { $this->assertEquals($this->editor1->id(), $test_workspace->getOwnerId()); $this->drupalPostForm('/admin/config/workflow/workspaces/manage/test_workspace/edit', [ - 'uid[0][target_id]' => $this->editor2->getUsername(), + 'uid[0][target_id]' => $this->editor2->getAccountName(), ], 'Save'); $test_workspace = $storage->loadUnchanged('test_workspace'); diff --git a/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileExistingSettingsTest.php b/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileExistingSettingsTest.php index acaf2c2b325..60f3d0aa0d8 100644 --- a/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileExistingSettingsTest.php +++ b/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileExistingSettingsTest.php @@ -115,7 +115,7 @@ class DistributionProfileExistingSettingsTest extends InstallerTestBase { $this->assertUrl('user/1'); $this->assertResponse(200); // Confirm that we are logged-in after installation. - $this->assertText($this->rootUser->getUsername()); + $this->assertText($this->rootUser->getAccountName()); // Confirm that Drupal recognizes this distribution as the current profile. $this->assertEqual(\Drupal::installProfile(), 'mydistro'); diff --git a/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTest.php b/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTest.php index 630ec1558d8..00819cb02d1 100644 --- a/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTest.php +++ b/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTest.php @@ -69,7 +69,7 @@ class DistributionProfileTest extends InstallerTestBase { $this->assertUrl('myrootuser'); $this->assertResponse(200); // Confirm that we are logged-in after installation. - $this->assertText($this->rootUser->getUsername()); + $this->assertText($this->rootUser->getAccountName()); // Confirm that Drupal recognizes this distribution as the current profile. $this->assertEqual(\Drupal::installProfile(), 'mydistro'); diff --git a/core/tests/Drupal/FunctionalTests/Installer/InstallerTest.php b/core/tests/Drupal/FunctionalTests/Installer/InstallerTest.php index 2f6deba4dee..92aed1917a0 100644 --- a/core/tests/Drupal/FunctionalTests/Installer/InstallerTest.php +++ b/core/tests/Drupal/FunctionalTests/Installer/InstallerTest.php @@ -16,7 +16,7 @@ class InstallerTest extends InstallerTestBase { $this->assertUrl('user/1'); $this->assertResponse(200); // Confirm that we are logged-in after installation. - $this->assertText($this->rootUser->getUsername()); + $this->assertText($this->rootUser->getAccountName()); // Verify that the confirmation message appears. require_once $this->root . '/core/includes/install.inc'; diff --git a/core/tests/Drupal/FunctionalTests/Installer/MultipleDistributionsProfileTest.php b/core/tests/Drupal/FunctionalTests/Installer/MultipleDistributionsProfileTest.php index fe3b3d9a909..14ff26da994 100644 --- a/core/tests/Drupal/FunctionalTests/Installer/MultipleDistributionsProfileTest.php +++ b/core/tests/Drupal/FunctionalTests/Installer/MultipleDistributionsProfileTest.php @@ -73,7 +73,7 @@ class MultipleDistributionsProfileTest extends InstallerTestBase { $this->assertUrl('user/1'); $this->assertResponse(200); // Confirm that we are logged-in after installation. - $this->assertText($this->rootUser->getUsername()); + $this->assertText($this->rootUser->getAccountName()); // Confirm that Drupal recognizes this distribution as the current profile. $this->assertEqual(\Drupal::installProfile(), 'distribution_one'); diff --git a/core/tests/Drupal/FunctionalTests/Installer/SingleVisibleProfileTest.php b/core/tests/Drupal/FunctionalTests/Installer/SingleVisibleProfileTest.php index b7c92dfdad2..a11fd05a014 100644 --- a/core/tests/Drupal/FunctionalTests/Installer/SingleVisibleProfileTest.php +++ b/core/tests/Drupal/FunctionalTests/Installer/SingleVisibleProfileTest.php @@ -54,7 +54,7 @@ class SingleVisibleProfileTest extends InstallerTestBase { $this->assertUrl('user/1'); $this->assertResponse(200); // Confirm that we are logged-in after installation. - $this->assertText($this->rootUser->getUsername()); + $this->assertText($this->rootUser->getAccountName()); // Confirm that the minimal profile was installed. $this->assertEqual(drupal_get_profile(), 'minimal'); } diff --git a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php index 19598407bd9..85a45de1ec5 100644 --- a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php +++ b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php @@ -423,7 +423,7 @@ abstract class UpdatePathTestBase extends BrowserTestBase { $account = User::load(1); $account->setPassword($this->rootUser->pass_raw); $account->setEmail($this->rootUser->getEmail()); - $account->setUsername($this->rootUser->getUsername()); + $account->setUsername($this->rootUser->getAccountName()); $account->save(); } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php index 3fd17d86b47..11841e1ec91 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php @@ -136,19 +136,19 @@ class EntityFieldTest extends EntityKernelTestBase { $this->assertTrue($entity->user_id[0] instanceof FieldItemInterface, format_string('%entity_type: Field item implements interface', ['%entity_type' => $entity_type])); $this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($this->entityUser->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($this->entityUser->getAccountName(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', ['%entity_type' => $entity_type])); // Change the assigned user by entity. $new_user1 = $this->createUser(); $entity->user_id->entity = $new_user1; $this->assertEqual($new_user1->id(), $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($new_user1->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated username value can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($new_user1->getAccountName(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated username value can be read.', ['%entity_type' => $entity_type])); // Change the assigned user by id. $new_user2 = $this->createUser(); $entity->user_id->target_id = $new_user2->id(); $this->assertEqual($new_user2->id(), $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($new_user2->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated username value can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($new_user2->getAccountName(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated username value can be read.', ['%entity_type' => $entity_type])); // Try unsetting a field property. $entity->name->value = NULL; @@ -161,12 +161,12 @@ class EntityFieldTest extends EntityKernelTestBase { // Change the assigned user by entity. $entity->user_id->first()->get('entity')->setValue($new_user2); $this->assertEqual($new_user2->id(), $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($new_user2->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated user name value can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($new_user2->getAccountName(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated user name value can be read.', ['%entity_type' => $entity_type])); // Change the assigned user by id. $entity->user_id->first()->get('target_id')->setValue($new_user2->id()); $this->assertEqual($new_user2->id(), $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($new_user2->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated user name value can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($new_user2->getAccountName(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated user name value can be read.', ['%entity_type' => $entity_type])); // Try unsetting a field. $entity->name->first()->get('value')->setValue(NULL); @@ -271,7 +271,7 @@ class EntityFieldTest extends EntityKernelTestBase { ]); $this->assertEqual($this->entityName, $entity->name->value, format_string('%entity_type: Name value can be read.', ['%entity_type' => $entity_type])); $this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($this->entityUser->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($this->entityUser->getAccountName(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', ['%entity_type' => $entity_type])); $this->assertEqual($this->entityFieldText, $entity->field_test_text->value, format_string('%entity_type: Text field can be read.', ['%entity_type' => $entity_type])); // Tests copying field values by assigning the TypedData objects. @@ -391,7 +391,7 @@ class EntityFieldTest extends EntityKernelTestBase { $this->assertEqual('en', $entity->{$langcode_key}->value, format_string('%entity_type: Language code can be read.', ['%entity_type' => $entity_type])); $this->assertEqual(\Drupal::languageManager()->getLanguage('en'), $entity->{$langcode_key}->language, format_string('%entity_type: Language object can be read.', ['%entity_type' => $entity_type])); $this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($this->entityUser->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($this->entityUser->getAccountName(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', ['%entity_type' => $entity_type])); $this->assertEqual($this->entityFieldText, $entity->field_test_text->value, format_string('%entity_type: Text field can be read.', ['%entity_type' => $entity_type])); } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryRelationshipTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryRelationshipTest.php index 0c86ba8a707..1b1ffd03de1 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryRelationshipTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryRelationshipTest.php @@ -114,12 +114,12 @@ class EntityQueryRelationshipTest extends EntityKernelTestBase { // This returns the 0th entity as that's the only one pointing to the 0th // account. $this->queryResults = $storage->getQuery() - ->condition("user_id.entity.name", $this->accounts[0]->getUsername()) + ->condition("user_id.entity.name", $this->accounts[0]->getAccountName()) ->execute(); $this->assertResults([0]); // This returns the 1st and 2nd entity as those point to the 1st account. $this->queryResults = $storage->getQuery() - ->condition("user_id.entity.name", $this->accounts[0]->getUsername(), '<>') + ->condition("user_id.entity.name", $this->accounts[0]->getAccountName(), '<>') ->execute(); $this->assertResults([1, 2]); // This returns all three entities because all of them point to an @@ -153,12 +153,12 @@ class EntityQueryRelationshipTest extends EntityKernelTestBase { // This returns the 0th entity as that's only one pointing to the 0th // account. $this->queryResults = $storage->getQuery() - ->condition("user_id.entity:user.name", $this->accounts[0]->getUsername()) + ->condition("user_id.entity:user.name", $this->accounts[0]->getAccountName()) ->execute(); $this->assertResults([0]); // This returns the 1st and 2nd entity as those point to the 1st account. $this->queryResults = $storage->getQuery() - ->condition("user_id.entity:user.name", $this->accounts[0]->getUsername(), '<>') + ->condition("user_id.entity:user.name", $this->accounts[0]->getAccountName(), '<>') ->execute(); $this->assertResults([1, 2]); // This returns all three entities because all of them point to an diff --git a/core/tests/Drupal/KernelTests/Core/Plugin/ContextPluginTest.php b/core/tests/Drupal/KernelTests/Core/Plugin/ContextPluginTest.php index 8a1fa4842f9..52458247878 100644 --- a/core/tests/Drupal/KernelTests/Core/Plugin/ContextPluginTest.php +++ b/core/tests/Drupal/KernelTests/Core/Plugin/ContextPluginTest.php @@ -72,7 +72,7 @@ class ContextPluginTest extends KernelTestBase { $user = User::create(['name' => $name]); $plugin->setContextValue('user', $user); - $this->assertEqual($plugin->getContextValue('user')->getUsername(), $user->getUsername()); + $this->assertEqual($plugin->getContextValue('user')->getAccountName(), $user->getAccountName()); $this->assertEqual($user->label(), $plugin->getTitle()); // Test Optional context handling. diff --git a/core/tests/Drupal/Tests/UiHelperTrait.php b/core/tests/Drupal/Tests/UiHelperTrait.php index d0817f6076f..b935efdb511 100644 --- a/core/tests/Drupal/Tests/UiHelperTrait.php +++ b/core/tests/Drupal/Tests/UiHelperTrait.php @@ -258,7 +258,7 @@ trait UiHelperTrait { $this->drupalGet('user/login'); $this->submitForm([ - 'name' => $account->getUsername(), + 'name' => $account->getAccountName(), 'pass' => $account->passRaw, ], t('Log in'));