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' => '
', '#suffix' => '
', - '#markup' => $user ? $user->getUsername() : 'No context mapping selected.' , + '#markup' => $user ? $user->getAccountName() : 'No context mapping selected.' , ]; } diff --git a/core/modules/block/tests/src/Functional/BlockUiTest.php b/core/modules/block/tests/src/Functional/BlockUiTest.php index e6c187544ed..95d1f62da29 100644 --- a/core/modules/block/tests/src/Functional/BlockUiTest.php +++ b/core/modules/block/tests/src/Functional/BlockUiTest.php @@ -209,7 +209,7 @@ class BlockUiTest extends BrowserTestBase { * Tests the behavior of context-aware blocks. */ public function testContextAwareBlocks() { - $expected_text = '
' . \Drupal::currentUser()->getUsername() . '
'; + $expected_text = '
' . \Drupal::currentUser()->getAccountName() . '
'; $this->drupalGet(''); $this->assertNoText('Test context-aware block'); $this->assertNoRaw($expected_text); diff --git a/core/modules/comment/src/Plugin/Validation/Constraint/CommentNameConstraintValidator.php b/core/modules/comment/src/Plugin/Validation/Constraint/CommentNameConstraintValidator.php index 87cdaf91ded..828281ca30a 100644 --- a/core/modules/comment/src/Plugin/Validation/Constraint/CommentNameConstraintValidator.php +++ b/core/modules/comment/src/Plugin/Validation/Constraint/CommentNameConstraintValidator.php @@ -65,7 +65,7 @@ class CommentNameConstraintValidator extends ConstraintValidator implements Cont // If an author name and owner are given, make sure they match. elseif (isset($author_name) && $author_name !== '' && $owner_id) { $owner = $this->userStorage->load($owner_id); - if ($owner->getUsername() != $author_name) { + if ($owner->getAccountName() != $author_name) { $this->context->buildViolation($constraint->messageMatch) ->atPath('name') ->addViolation(); diff --git a/core/modules/comment/tests/src/Functional/CommentAnonymousTest.php b/core/modules/comment/tests/src/Functional/CommentAnonymousTest.php index 31a11f83be3..090b995a947 100644 --- a/core/modules/comment/tests/src/Functional/CommentAnonymousTest.php +++ b/core/modules/comment/tests/src/Functional/CommentAnonymousTest.php @@ -67,12 +67,12 @@ class CommentAnonymousTest extends CommentTestBase { // Ensure anonymous users cannot post in the name of registered users. $edit = [ - 'name' => $this->adminUser->getUsername(), + 'name' => $this->adminUser->getAccountName(), 'comment_body[0][value]' => $this->randomMachineName(), ]; $this->drupalPostForm('comment/reply/node/' . $this->node->id() . '/comment', $edit, t('Save')); $this->assertRaw(t('The name you used (%name) belongs to a registered user.', [ - '%name' => $this->adminUser->getUsername(), + '%name' => $this->adminUser->getAccountName(), ])); // Allow contact info. @@ -98,14 +98,14 @@ class CommentAnonymousTest extends CommentTestBase { // Ensure anonymous users cannot post in the name of registered users. $edit = [ - 'name' => $this->adminUser->getUsername(), + 'name' => $this->adminUser->getAccountName(), 'mail' => $this->randomMachineName() . '@example.com', 'subject[0][value]' => $this->randomMachineName(), 'comment_body[0][value]' => $this->randomMachineName(), ]; $this->drupalPostForm('comment/reply/node/' . $this->node->id() . '/comment', $edit, t('Save')); $this->assertRaw(t('The name you used (%name) belongs to a registered user.', [ - '%name' => $this->adminUser->getUsername(), + '%name' => $this->adminUser->getAccountName(), ])); // Require contact info. diff --git a/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php b/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php index 4a603ca9eca..bee8fec4234 100644 --- a/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php +++ b/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php @@ -108,8 +108,8 @@ class CommentInterfaceTest extends CommentTestBase { // Test changing the comment author to a verified user. $this->drupalGet('comment/' . $comment->id() . '/edit'); - $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->getSubject(), ['uid' => $this->webUser->getUsername() . ' (' . $this->webUser->id() . ')']); - $this->assertTrue($comment->getAuthorName() == $this->webUser->getUsername() && $comment->getOwnerId() == $this->webUser->id(), 'Comment author successfully changed to a registered user.'); + $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->getSubject(), ['uid' => $this->webUser->getAccountName() . ' (' . $this->webUser->id() . ')']); + $this->assertTrue($comment->getAuthorName() == $this->webUser->getAccountName() && $comment->getOwnerId() == $this->webUser->id(), 'Comment author successfully changed to a registered user.'); $this->drupalLogout(); diff --git a/core/modules/comment/tests/src/Functional/CommentPreviewTest.php b/core/modules/comment/tests/src/Functional/CommentPreviewTest.php index 91544b63676..7945fe46452 100644 --- a/core/modules/comment/tests/src/Functional/CommentPreviewTest.php +++ b/core/modules/comment/tests/src/Functional/CommentPreviewTest.php @@ -139,7 +139,7 @@ class CommentPreviewTest extends CommentTestBase { $date = new DrupalDateTime('2008-03-02 17:23'); $edit['subject[0][value]'] = $this->randomMachineName(8); $edit['comment_body[0][value]'] = $this->randomMachineName(16); - $edit['uid'] = $web_user->getUsername() . ' (' . $web_user->id() . ')'; + $edit['uid'] = $web_user->getAccountName() . ' (' . $web_user->id() . ')'; $edit['date[date]'] = $date->format('Y-m-d'); $edit['date[time]'] = $date->format('H:i:s'); $raw_date = $date->getTimestamp(); @@ -153,7 +153,7 @@ class CommentPreviewTest extends CommentTestBase { $this->assertTitle(t('Preview comment | Drupal'), 'Page title is "Preview comment".'); $this->assertText($edit['subject[0][value]'], 'Subject displayed.'); $this->assertText($edit['comment_body[0][value]'], 'Comment displayed.'); - $this->assertText($web_user->getUsername(), 'Author displayed.'); + $this->assertText($web_user->getAccountName(), 'Author displayed.'); $this->assertText($expected_text_date, 'Date displayed.'); // Check that the subject, comment, author and date fields are displayed with the correct values. diff --git a/core/modules/comment/tests/src/Functional/CommentTranslationUITest.php b/core/modules/comment/tests/src/Functional/CommentTranslationUITest.php index f6bec9c7d35..3830e2fde19 100644 --- a/core/modules/comment/tests/src/Functional/CommentTranslationUITest.php +++ b/core/modules/comment/tests/src/Functional/CommentTranslationUITest.php @@ -163,7 +163,7 @@ class CommentTranslationUITest extends ContentTranslationUITestBase { 'created' => REQUEST_TIME - mt_rand(0, 1000), ]; $edit = [ - 'uid' => $user->getUsername() . ' (' . $user->id() . ')', + 'uid' => $user->getAccountName() . ' (' . $user->id() . ')', 'date[date]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d'), 'date[time]' => format_date($values[$langcode]['created'], 'custom', 'H:i:s'), ]; diff --git a/core/modules/comment/tests/src/Kernel/CommentFieldAccessTest.php b/core/modules/comment/tests/src/Kernel/CommentFieldAccessTest.php index c17f247dff0..0a7848718d6 100644 --- a/core/modules/comment/tests/src/Kernel/CommentFieldAccessTest.php +++ b/core/modules/comment/tests/src/Kernel/CommentFieldAccessTest.php @@ -212,12 +212,12 @@ class CommentFieldAccessTest extends EntityKernelTestBase { $may_view = $set['comment']->{$field}->access('view', $set['user']); $may_update = $set['comment']->{$field}->access('edit', $set['user']); $this->assertTrue($may_view, new FormattableMarkup('User @user can view field @field on comment @comment', [ - '@user' => $set['user']->getUsername(), + '@user' => $set['user']->getAccountName(), '@comment' => $set['comment']->getSubject(), '@field' => $field, ])); $this->assertEqual($may_update, $set['user']->hasPermission('administer comments'), new FormattableMarkup('User @user @state update field @field on comment @comment', [ - '@user' => $set['user']->getUsername(), + '@user' => $set['user']->getAccountName(), '@state' => $may_update ? 'can' : 'cannot', '@comment' => $set['comment']->getSubject(), '@field' => $field, @@ -229,7 +229,7 @@ class CommentFieldAccessTest extends EntityKernelTestBase { foreach ($permutations as $set) { $may_update = $set['comment']->access('update', $set['user']) && $set['comment']->subject->access('edit', $set['user']); $this->assertEqual($may_update, $set['user']->hasPermission('administer comments') || ($set['user']->hasPermission('edit own comments') && $set['user']->id() == $set['comment']->getOwnerId()), new FormattableMarkup('User @user @state update field subject on comment @comment', [ - '@user' => $set['user']->getUsername(), + '@user' => $set['user']->getAccountName(), '@state' => $may_update ? 'can' : 'cannot', '@comment' => $set['comment']->getSubject(), ])); @@ -251,13 +251,13 @@ class CommentFieldAccessTest extends EntityKernelTestBase { $state = 'can'; } $this->assertEqual($may_view, $view_access, new FormattableMarkup('User @user @state view field @field on comment @comment', [ - '@user' => $set['user']->getUsername(), + '@user' => $set['user']->getAccountName(), '@comment' => $set['comment']->getSubject(), '@field' => $field, '@state' => $state, ])); $this->assertFalse($may_update, new FormattableMarkup('User @user @state update field @field on comment @comment', [ - '@user' => $set['user']->getUsername(), + '@user' => $set['user']->getAccountName(), '@state' => $may_update ? 'can' : 'cannot', '@comment' => $set['comment']->getSubject(), '@field' => $field, @@ -272,12 +272,12 @@ class CommentFieldAccessTest extends EntityKernelTestBase { $may_view = $set['comment']->{$field}->access('view', $set['user']); $may_update = $set['comment']->{$field}->access('edit', $set['user']); $this->assertEqual($may_view, TRUE, new FormattableMarkup('User @user can view field @field on comment @comment', [ - '@user' => $set['user']->getUsername(), + '@user' => $set['user']->getAccountName(), '@comment' => $set['comment']->getSubject(), '@field' => $field, ])); $this->assertEqual($may_update, $set['user']->hasPermission('post comments') && $set['comment']->isNew(), new FormattableMarkup('User @user @state update field @field on comment @comment', [ - '@user' => $set['user']->getUsername(), + '@user' => $set['user']->getAccountName(), '@state' => $may_update ? 'can' : 'cannot', '@comment' => $set['comment']->getSubject(), '@field' => $field, @@ -299,7 +299,7 @@ class CommentFieldAccessTest extends EntityKernelTestBase { $set['user']->hasPermission('post comments') && $set['comment']->getFieldName() == 'comment_other' ), new FormattableMarkup('User @user @state update field @field on comment @comment', [ - '@user' => $set['user']->getUsername(), + '@user' => $set['user']->getAccountName(), '@state' => $may_update ? 'can' : 'cannot', '@comment' => $set['comment']->getSubject(), '@field' => $field, diff --git a/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php b/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php index 1ca5e43971f..6b3e6b780dd 100644 --- a/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php +++ b/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php @@ -74,7 +74,7 @@ class CommentViewsFieldAccessTest extends FieldFieldAccessTestBase { $this->assertFieldAccess('comment', 'name', 'anonymous'); $this->assertFieldAccess('comment', 'mail', 'test@example.com'); $this->assertFieldAccess('comment', 'homepage', 'https://example.com'); - $this->assertFieldAccess('comment', 'uid', $user->getUsername()); + $this->assertFieldAccess('comment', 'uid', $user->getAccountName()); // $this->assertFieldAccess('comment', 'created', \Drupal::service('date.formatter')->format(123456)); // $this->assertFieldAccess('comment', 'changed', \Drupal::service('date.formatter')->format(REQUEST_TIME)); $this->assertFieldAccess('comment', 'status', 'On'); diff --git a/core/modules/contact/tests/src/Functional/ContactPersonalTest.php b/core/modules/contact/tests/src/Functional/ContactPersonalTest.php index 2a406eb8de3..2c8fae5b5a0 100644 --- a/core/modules/contact/tests/src/Functional/ContactPersonalTest.php +++ b/core/modules/contact/tests/src/Functional/ContactPersonalTest.php @@ -65,7 +65,7 @@ class ContactPersonalTest extends BrowserTestBase { */ public function testSendPersonalContactMessage() { // Ensure that the web user's email needs escaping. - $mail = $this->webUser->getUsername() . '&escaped@example.com'; + $mail = $this->webUser->getAccountName() . '&escaped@example.com'; $this->webUser->setEmail($mail)->save(); $this->drupalLogin($this->webUser); @@ -98,7 +98,7 @@ class ContactPersonalTest extends BrowserTestBase { $placeholders = [ '@sender_name' => $this->webUser->username, '@sender_email' => $this->webUser->getEmail(), - '@recipient_name' => $this->contactUser->getUsername(), + '@recipient_name' => $this->contactUser->getAccountName(), ]; $this->assertRaw(new FormattableMarkup('@sender_name (@sender_email) sent @recipient_name an email.', $placeholders)); // Ensure an unescaped version of the email does not exist anywhere. diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php index 0fef1bed47f..586c4245f52 100644 --- a/core/modules/content_translation/src/ContentTranslationHandler.php +++ b/core/modules/content_translation/src/ContentTranslationHandler.php @@ -680,7 +680,7 @@ class ContentTranslationHandler implements ContentTranslationHandlerInterface, E $translation = $form_state->getValue('content_translation'); // Validate the "authored by" field. if (!empty($translation['uid']) && !($account = User::load($translation['uid']))) { - $form_state->setErrorByName('content_translation][uid', t('The translation authoring username %name does not exist.', ['%name' => $account->getUsername()])); + $form_state->setErrorByName('content_translation][uid', t('The translation authoring username %name does not exist.', ['%name' => $account->getAccountName()])); } // Validate the "authored on" field. if (!empty($translation['created']) && strtotime($translation['created']) === FALSE) { diff --git a/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php b/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php index 12285e11ade..47f2f65a66d 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php @@ -328,7 +328,7 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase { 'created' => REQUEST_TIME - mt_rand(0, 1000), ]; $edit = [ - 'content_translation[uid]' => $user->getUsername(), + 'content_translation[uid]' => $user->getAccountName(), 'content_translation[created]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d H:i:s O'), ]; $url = $entity->urlInfo('edit-form', ['language' => ConfigurableLanguage::load($langcode)]); diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php index 7e7bf1f84b0..6e2a2d79aa1 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php @@ -321,7 +321,7 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase { 'created' => REQUEST_TIME - mt_rand(0, 1000), ]; $edit = [ - 'content_translation[uid]' => $user->getUsername(), + 'content_translation[uid]' => $user->getAccountName(), 'content_translation[created]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d H:i:s O'), ]; $url = $entity->urlInfo('edit-form', ['language' => ConfigurableLanguage::load($langcode)]); diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php index c778404f641..eaa638efcb8 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php @@ -154,7 +154,7 @@ class ContentTranslationWorkflowsTest extends ContentTranslationTestBase { protected function doTestWorkflows(UserInterface $user, $expected_status) { $default_langcode = $this->langcodes[0]; $languages = $this->container->get('language_manager')->getLanguages(); - $args = ['@user_label' => $user->getUsername()]; + $args = ['@user_label' => $user->getAccountName()]; $options = ['language' => $languages[$default_langcode], 'absolute' => TRUE]; $this->drupalLogin($user); diff --git a/core/modules/dblog/tests/src/Functional/DbLogTest.php b/core/modules/dblog/tests/src/Functional/DbLogTest.php index 4ad02b699c8..fcf05c41e9c 100644 --- a/core/modules/dblog/tests/src/Functional/DbLogTest.php +++ b/core/modules/dblog/tests/src/Functional/DbLogTest.php @@ -304,7 +304,7 @@ class DbLogTest extends BrowserTestBase { $ids[] = $row->wid; } $count_before = (isset($ids)) ? count($ids) : 0; - $this->assertTrue($count_before > 0, format_string('DBLog contains @count records for @name', ['@count' => $count_before, '@name' => $user->getUsername()])); + $this->assertTrue($count_before > 0, format_string('DBLog contains @count records for @name', ['@count' => $count_before, '@name' => $user->getAccountName()])); // Log in the admin user. $this->drupalLogin($this->adminUser); diff --git a/core/modules/language/tests/src/Functional/LanguageUrlRewritingTest.php b/core/modules/language/tests/src/Functional/LanguageUrlRewritingTest.php index 07eec52514d..10a0c4e7dfb 100644 --- a/core/modules/language/tests/src/Functional/LanguageUrlRewritingTest.php +++ b/core/modules/language/tests/src/Functional/LanguageUrlRewritingTest.php @@ -61,7 +61,7 @@ class LanguageUrlRewritingTest extends BrowserTestBase { // Check that URL rewriting is not applied to subrequests. $this->drupalGet('language_test/subrequest'); - $this->assertText($this->webUser->getUsername(), 'Page correctly retrieved'); + $this->assertText($this->webUser->getAccountName(), 'Page correctly retrieved'); } /** diff --git a/core/modules/node/src/NodeForm.php b/core/modules/node/src/NodeForm.php index 702d8d74a5c..3fe71d3b207 100644 --- a/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -140,7 +140,7 @@ class NodeForm extends ContentEntityForm { $form['meta']['author'] = [ '#type' => 'item', '#title' => $this->t('Author'), - '#markup' => $node->getOwner()->getUsername(), + '#markup' => $node->getOwner()->getAccountName(), '#wrapper_attributes' => ['class' => ['entity-meta__author']], ]; diff --git a/core/modules/node/tests/src/Functional/NodeAccessBaseTableTest.php b/core/modules/node/tests/src/Functional/NodeAccessBaseTableTest.php index d9e4e8b0924..20b5f63eb37 100644 --- a/core/modules/node/tests/src/Functional/NodeAccessBaseTableTest.php +++ b/core/modules/node/tests/src/Functional/NodeAccessBaseTableTest.php @@ -100,7 +100,7 @@ class NodeAccessBaseTableTest extends NodeTestBase { $this->drupalLogin($this->webUser); foreach ([0 => 'Public', 1 => 'Private'] as $is_private => $type) { $edit = [ - 'title[0][value]' => t('@private_public Article created by @user', ['@private_public' => $type, '@user' => $this->webUser->getUsername()]), + 'title[0][value]' => t('@private_public Article created by @user', ['@private_public' => $type, '@user' => $this->webUser->getAccountName()]), ]; if ($is_private) { $edit['private[0][value]'] = TRUE; diff --git a/core/modules/node/tests/src/Functional/NodeCreationTest.php b/core/modules/node/tests/src/Functional/NodeCreationTest.php index 1ea8fcc3326..0e4a4adb103 100644 --- a/core/modules/node/tests/src/Functional/NodeCreationTest.php +++ b/core/modules/node/tests/src/Functional/NodeCreationTest.php @@ -60,7 +60,7 @@ class NodeCreationTest extends NodeTestBase { // Verify that pages do not show submitted information by default. $this->drupalGet('node/' . $node->id()); - $this->assertNoText($node->getOwner()->getUsername()); + $this->assertNoText($node->getOwner()->getAccountName()); $this->assertNoText(format_date($node->getCreatedTime())); // Change the node type setting to show submitted by information. @@ -70,7 +70,7 @@ class NodeCreationTest extends NodeTestBase { $node_type->save(); $this->drupalGet('node/' . $node->id()); - $this->assertText($node->getOwner()->getUsername()); + $this->assertText($node->getOwner()->getAccountName()); $this->assertText(format_date($node->getCreatedTime())); // Check if the node revision checkbox is not rendered on node creation form. diff --git a/core/modules/node/tests/src/Functional/NodeEditFormTest.php b/core/modules/node/tests/src/Functional/NodeEditFormTest.php index 17f0734f697..9a45452ee91 100644 --- a/core/modules/node/tests/src/Functional/NodeEditFormTest.php +++ b/core/modules/node/tests/src/Functional/NodeEditFormTest.php @@ -273,7 +273,7 @@ class NodeEditFormTest extends NodeTestBase { // Change the authored by field to another user's name (that is not // logged in). - $edit[$form_element_name] = $this->webUser->getUsername(); + $edit[$form_element_name] = $this->webUser->getAccountName(); $this->drupalPostForm(NULL, $edit, t('Save')); $this->nodeStorage->resetCache([$node->id()]); $node = $this->nodeStorage->load($node->id()); diff --git a/core/modules/node/tests/src/Functional/NodeTranslationUITest.php b/core/modules/node/tests/src/Functional/NodeTranslationUITest.php index 54d9c730384..b32a4b0a031 100644 --- a/core/modules/node/tests/src/Functional/NodeTranslationUITest.php +++ b/core/modules/node/tests/src/Functional/NodeTranslationUITest.php @@ -197,7 +197,7 @@ class NodeTranslationUITest extends ContentTranslationUITestBase { 'promote' => (bool) mt_rand(0, 1), ]; $edit = [ - 'uid[0][target_id]' => $user->getUsername(), + 'uid[0][target_id]' => $user->getAccountName(), 'created[0][value][date]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d'), 'created[0][value][time]' => format_date($values[$langcode]['created'], 'custom', 'H:i:s'), 'sticky[value]' => $values[$langcode]['sticky'], diff --git a/core/modules/node/tests/src/Functional/Views/FilterNodeAccessTest.php b/core/modules/node/tests/src/Functional/Views/FilterNodeAccessTest.php index 7eb7097d9db..f5195906246 100644 --- a/core/modules/node/tests/src/Functional/Views/FilterNodeAccessTest.php +++ b/core/modules/node/tests/src/Functional/Views/FilterNodeAccessTest.php @@ -60,7 +60,7 @@ class FilterNodeAccessTest extends NodeTestBase { 'format' => filter_default_format(), ], ], - 'title' => t('@private_public Article created by @user', ['@private_public' => $type, '@user' => $web_user->getUsername()]), + 'title' => t('@private_public Article created by @user', ['@private_public' => $type, '@user' => $web_user->getAccountName()]), 'type' => 'article', 'uid' => $web_user->id(), 'private' => (bool) $is_private, @@ -79,38 +79,38 @@ class FilterNodeAccessTest extends NodeTestBase { $this->drupalLogin($this->users[0]); $this->drupalGet('test_filter_node_access'); // Test that the private node of the current user is shown. - $this->assertText('Private Article created by ' . $this->users[0]->getUsername()); + $this->assertText('Private Article created by ' . $this->users[0]->getAccountName()); // Test that the private node of the other use isn't shown. - $this->assertNoText('Private Article created by ' . $this->users[1]->getUsername()); + $this->assertNoText('Private Article created by ' . $this->users[1]->getAccountName()); // Test that both public nodes are shown. - $this->assertText('Public Article created by ' . $this->users[0]->getUsername()); - $this->assertText('Public Article created by ' . $this->users[1]->getUsername()); + $this->assertText('Public Article created by ' . $this->users[0]->getAccountName()); + $this->assertText('Public Article created by ' . $this->users[1]->getAccountName()); // Switch users and test the other private node is shown. $this->drupalLogin($this->users[1]); $this->drupalGet('test_filter_node_access'); // Test that the private node of the current user is shown. - $this->assertText('Private Article created by ' . $this->users[1]->getUsername()); + $this->assertText('Private Article created by ' . $this->users[1]->getAccountName()); // Test that the private node of the other use isn't shown. - $this->assertNoText('Private Article created by ' . $this->users[0]->getUsername()); + $this->assertNoText('Private Article created by ' . $this->users[0]->getAccountName()); // Test that a user with administer nodes permission can't see all nodes. $administer_nodes_user = $this->drupalCreateUser(['access content', 'administer nodes']); $this->drupalLogin($administer_nodes_user); $this->drupalGet('test_filter_node_access'); - $this->assertNoText('Private Article created by ' . $this->users[0]->getUsername()); - $this->assertNoText('Private Article created by ' . $this->users[1]->getUsername()); - $this->assertText('Public Article created by ' . $this->users[0]->getUsername()); - $this->assertText('Public Article created by ' . $this->users[1]->getUsername()); + $this->assertNoText('Private Article created by ' . $this->users[0]->getAccountName()); + $this->assertNoText('Private Article created by ' . $this->users[1]->getAccountName()); + $this->assertText('Public Article created by ' . $this->users[0]->getAccountName()); + $this->assertText('Public Article created by ' . $this->users[1]->getAccountName()); // Test that a user with bypass node access can see all nodes. $bypass_access_user = $this->drupalCreateUser(['access content', 'bypass node access']); $this->drupalLogin($bypass_access_user); $this->drupalGet('test_filter_node_access'); - $this->assertText('Private Article created by ' . $this->users[0]->getUsername()); - $this->assertText('Private Article created by ' . $this->users[1]->getUsername()); - $this->assertText('Public Article created by ' . $this->users[0]->getUsername()); - $this->assertText('Public Article created by ' . $this->users[1]->getUsername()); + $this->assertText('Private Article created by ' . $this->users[0]->getAccountName()); + $this->assertText('Private Article created by ' . $this->users[1]->getAccountName()); + $this->assertText('Public Article created by ' . $this->users[0]->getAccountName()); + $this->assertText('Public Article created by ' . $this->users[1]->getAccountName()); } } diff --git a/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php b/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php index 700311c8711..b8cb30e75a7 100644 --- a/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php +++ b/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php @@ -107,7 +107,7 @@ class MigrateNodeTest extends MigrateNodeTestBase { // Test that user reference field values were migrated. $this->assertCount(1, $node->field_commander); - $this->assertSame('joe.roe', $node->field_commander[0]->entity->getUsername()); + $this->assertSame('joe.roe', $node->field_commander[0]->entity->getAccountName()); $node = Node::load(2); $this->assertIdentical('Test title rev 3', $node->getTitle()); diff --git a/core/modules/node/tests/src/Kernel/NodeTokenReplaceTest.php b/core/modules/node/tests/src/Kernel/NodeTokenReplaceTest.php index dd39b6d26d3..969287a40b6 100644 --- a/core/modules/node/tests/src/Kernel/NodeTokenReplaceTest.php +++ b/core/modules/node/tests/src/Kernel/NodeTokenReplaceTest.php @@ -69,9 +69,9 @@ class NodeTokenReplaceTest extends TokenReplaceKernelTestBase { $tests['[node:langcode]'] = $node->language()->getId(); $tests['[node:url]'] = $node->url('canonical', $url_options); $tests['[node:edit-url]'] = $node->url('edit-form', $url_options); - $tests['[node:author]'] = $account->getUsername(); + $tests['[node:author]'] = $account->getAccountName(); $tests['[node:author:uid]'] = $node->getOwnerId(); - $tests['[node:author:name]'] = $account->getUsername(); + $tests['[node:author:name]'] = $account->getAccountName(); $tests['[node:created:since]'] = \Drupal::service('date.formatter')->formatTimeDiffSince($node->getCreatedTime(), ['langcode' => $this->interfaceLanguage->getId()]); $tests['[node:changed:since]'] = \Drupal::service('date.formatter')->formatTimeDiffSince($node->getChangedTime(), ['langcode' => $this->interfaceLanguage->getId()]); diff --git a/core/modules/node/tests/src/Kernel/Views/NodeViewsFieldAccessTest.php b/core/modules/node/tests/src/Kernel/Views/NodeViewsFieldAccessTest.php index 7c68e8899d1..9240cf75966 100644 --- a/core/modules/node/tests/src/Kernel/Views/NodeViewsFieldAccessTest.php +++ b/core/modules/node/tests/src/Kernel/Views/NodeViewsFieldAccessTest.php @@ -60,7 +60,7 @@ class NodeViewsFieldAccessTest extends FieldFieldAccessTestBase { $this->assertFieldAccess('node', 'type', $node->type->entity->label()); $this->assertFieldAccess('node', 'langcode', $node->language()->getName()); $this->assertFieldAccess('node', 'title', 'Test title'); - $this->assertFieldAccess('node', 'uid', $user->getUsername()); + $this->assertFieldAccess('node', 'uid', $user->getAccountName()); // @todo Don't we want to display Published / Unpublished by default, // see https://www.drupal.org/node/2465623 $this->assertFieldAccess('node', 'status', 'On'); diff --git a/core/modules/rdf/tests/src/Functional/CommentAttributesTest.php b/core/modules/rdf/tests/src/Functional/CommentAttributesTest.php index 0c194382ba1..1caf6cb48ac 100644 --- a/core/modules/rdf/tests/src/Functional/CommentAttributesTest.php +++ b/core/modules/rdf/tests/src/Functional/CommentAttributesTest.php @@ -154,7 +154,7 @@ class CommentAttributesTest extends CommentTestBase { // Ensure that the author link still works properly after the author output // is modified by the RDF module. $this->drupalGet('node/' . $this->node->id()); - $this->assertLink($this->webUser->getUsername()); + $this->assertLink($this->webUser->getAccountName()); $this->assertLinkByHref('user/' . $this->webUser->id()); } @@ -320,7 +320,7 @@ class CommentAttributesTest extends CommentTestBase { } // Author name. - $name = empty($account["name"]) ? $this->webUser->getUsername() : $account["name"] . " (not verified)"; + $name = empty($account["name"]) ? $this->webUser->getAccountName() : $account["name"] . " (not verified)"; $expected_value = [ 'type' => 'literal', 'value' => $name, diff --git a/core/modules/rdf/tests/src/Functional/StandardProfileTest.php b/core/modules/rdf/tests/src/Functional/StandardProfileTest.php index 6d953117406..84372e05820 100644 --- a/core/modules/rdf/tests/src/Functional/StandardProfileTest.php +++ b/core/modules/rdf/tests/src/Functional/StandardProfileTest.php @@ -477,7 +477,7 @@ class StandardProfileTest extends BrowserTestBase { // Comment author name. $expected_value = [ 'type' => 'literal', - 'value' => $this->webUser->getUsername(), + 'value' => $this->webUser->getAccountName(), ]; $this->assertTrue($graph->hasProperty($this->commenterUri, 'http://schema.org/name', $expected_value), 'Comment author name was found (schema:name).'); } diff --git a/core/modules/rdf/tests/src/Functional/UserAttributesTest.php b/core/modules/rdf/tests/src/Functional/UserAttributesTest.php index fddd440894e..1b8c0b1897e 100644 --- a/core/modules/rdf/tests/src/Functional/UserAttributesTest.php +++ b/core/modules/rdf/tests/src/Functional/UserAttributesTest.php @@ -73,7 +73,7 @@ class UserAttributesTest extends BrowserTestBase { // User name. $expected_value = [ 'type' => 'literal', - 'value' => $author->getUsername(), + 'value' => $author->getAccountName(), ]; $this->assertTrue($graph->hasProperty($account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).'); @@ -98,7 +98,7 @@ class UserAttributesTest extends BrowserTestBase { // User name. $expected_value = [ 'type' => 'literal', - 'value' => $author->getUsername(), + 'value' => $author->getAccountName(), ]; $this->assertTrue($graph->hasProperty($account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).'); diff --git a/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php b/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php index 192002532a9..5a039eb0aa9 100644 --- a/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php +++ b/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php @@ -84,7 +84,7 @@ class StyleSerializerTest extends ViewTestBase { // to see the page. $url = $this->buildUrl('test/serialize/auth_with_perm'); $response = \Drupal::httpClient()->get($url, [ - 'auth' => [$this->adminUser->getUsername(), $this->adminUser->pass_raw], + 'auth' => [$this->adminUser->getAccountName(), $this->adminUser->pass_raw], 'query' => [ '_format' => 'json', ], diff --git a/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php b/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php index fc507e90758..5b7b6164c7c 100644 --- a/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php +++ b/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php @@ -137,7 +137,7 @@ class SearchConfigSettingsFormTest extends BrowserTestBase { 'text' => $this->searchNode->label(), ], 'user_search' => [ - 'keys' => $this->searchUser->getUsername(), + 'keys' => $this->searchUser->getAccountName(), 'text' => $this->searchUser->getEmail(), ], 'dummy_search_type' => [ diff --git a/core/modules/search/tests/src/Functional/SearchExactTest.php b/core/modules/search/tests/src/Functional/SearchExactTest.php index 7faae546568..7eac8ffe328 100644 --- a/core/modules/search/tests/src/Functional/SearchExactTest.php +++ b/core/modules/search/tests/src/Functional/SearchExactTest.php @@ -72,7 +72,7 @@ class SearchExactTest extends BrowserTestBase { $edit = ['keys' => 'Druplicon']; $this->drupalPostForm('search/node', $edit, t('Search')); - $this->assertText($user->getUsername(), 'Basic page node displays author name when post settings are on.'); + $this->assertText($user->getAccountName(), 'Basic page node displays author name when post settings are on.'); $this->assertText(format_date($node->getChangedTime(), 'short'), 'Basic page node displays post date when post settings are on.'); // Check that with post settings turned off the user and changed date @@ -81,7 +81,7 @@ class SearchExactTest extends BrowserTestBase { $node_type_config->save(); $edit = ['keys' => 'Druplicon']; $this->drupalPostForm('search/node', $edit, t('Search')); - $this->assertNoText($user->getUsername(), 'Basic page node does not display author name when post settings are off.'); + $this->assertNoText($user->getAccountName(), 'Basic page node does not display author name when post settings are off.'); $this->assertNoText(format_date($node->getChangedTime(), 'short'), 'Basic page node does not display post date when post settings are off.'); } diff --git a/core/modules/search/tests/src/Functional/SearchNodePunctuationTest.php b/core/modules/search/tests/src/Functional/SearchNodePunctuationTest.php index b292fdc6d72..0c85714921c 100644 --- a/core/modules/search/tests/src/Functional/SearchNodePunctuationTest.php +++ b/core/modules/search/tests/src/Functional/SearchNodePunctuationTest.php @@ -54,7 +54,7 @@ class SearchNodePunctuationTest extends BrowserTestBase { $this->assertText($node->label()); // Check if the author is linked correctly to the user profile page. - $username = $node->getOwner()->getUsername(); + $username = $node->getOwner()->getAccountName(); $this->assertLink($username); // Search for "&" and verify entities are not broken up in the output. diff --git a/core/modules/search/tests/src/Functional/SearchPageCacheTagsTest.php b/core/modules/search/tests/src/Functional/SearchPageCacheTagsTest.php index d11304bb4b6..2b36a33c4fa 100644 --- a/core/modules/search/tests/src/Functional/SearchPageCacheTagsTest.php +++ b/core/modules/search/tests/src/Functional/SearchPageCacheTagsTest.php @@ -115,7 +115,7 @@ class SearchPageCacheTagsTest extends BrowserTestBase { $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'search_index:user_search'); // User search results. - $edit['keys'] = $this->searchingUser->getUsername(); + $edit['keys'] = $this->searchingUser->getAccountName(); $this->drupalPostForm('search/user', $edit, t('Search')); $this->assertCacheTag('config:search.page.user_search'); $this->assertCacheTag('user_list'); diff --git a/core/modules/search/tests/src/Functional/SearchPageTextTest.php b/core/modules/search/tests/src/Functional/SearchPageTextTest.php index 85a9d0fa4ec..d126bf92711 100644 --- a/core/modules/search/tests/src/Functional/SearchPageTextTest.php +++ b/core/modules/search/tests/src/Functional/SearchPageTextTest.php @@ -95,10 +95,10 @@ class SearchPageTextTest extends BrowserTestBase { $actual_title = $this->xpath('//title')[0]->getText(); $this->assertEqual($actual_title, Html::decodeEntities(t($title_source, ['@keywords' => Unicode::truncate($search_terms, 60, TRUE, TRUE)])), 'Search page title is correct'); - $edit['keys'] = $this->searchingUser->getUsername(); + $edit['keys'] = $this->searchingUser->getAccountName(); $this->drupalPostForm('search/user', $edit, t('Search')); $this->assertText(t('Search')); - $this->assertTitle(t($title_source, ['@keywords' => Unicode::truncate($this->searchingUser->getUsername(), 60, TRUE, TRUE)])); + $this->assertTitle(t($title_source, ['@keywords' => Unicode::truncate($this->searchingUser->getAccountName(), 60, TRUE, TRUE)])); $this->clickLink('Search help'); $this->assertText('Search help', 'Correct title is on search help page'); diff --git a/core/modules/serialization/tests/modules/entity_serialization_test/entity_serialization_test.module b/core/modules/serialization/tests/modules/entity_serialization_test/entity_serialization_test.module index 26bd88c0db6..00a97cdea26 100644 --- a/core/modules/serialization/tests/modules/entity_serialization_test/entity_serialization_test.module +++ b/core/modules/serialization/tests/modules/entity_serialization_test/entity_serialization_test.module @@ -17,7 +17,7 @@ use Drupal\Core\Access\AccessResult; function entity_serialization_test_entity_field_access_alter(array &$grants, array $context) { // Override default access control from UserAccessControlHandler to allow // access to 'pass' field for the test user. - if ($context['field_definition']->getName() == 'pass' && $context['account']->getUsername() == 'serialization_test_user') { + if ($context['field_definition']->getName() == 'pass' && $context['account']->getAccountName() == 'serialization_test_user') { $grants[':default'] = AccessResult::allowed()->inheritCacheability($grants[':default'])->addCacheableDependency($context['items']->getEntity()); } } diff --git a/core/modules/simpletest/src/Tests/BrowserTest.php b/core/modules/simpletest/src/Tests/BrowserTest.php index fdfaff851d8..7cde7e0d316 100644 --- a/core/modules/simpletest/src/Tests/BrowserTest.php +++ b/core/modules/simpletest/src/Tests/BrowserTest.php @@ -91,7 +91,7 @@ EOF; public function testCookies() { // Check that the $this->cookies property is populated when a user logs in. $user = $this->drupalCreateUser(); - $edit = ['name' => $user->getUsername(), 'pass' => $user->pass_raw]; + $edit = ['name' => $user->getAccountName(), 'pass' => $user->pass_raw]; $this->drupalPostForm('', $edit, t('Log in')); $this->assertEqual(count($this->cookies), 1, 'A cookie is set when the user logs in.'); diff --git a/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php b/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php index 957391db76c..8131227a550 100644 --- a/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php +++ b/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php @@ -58,7 +58,7 @@ class SimpleTestBrowserTest extends WebTestBase { // Test the maximum redirection option. $this->maximumRedirects = 1; $edit = [ - 'name' => $user->getUsername(), + 'name' => $user->getAccountName(), 'pass' => $user->pass_raw, ]; $this->drupalPostForm('user/login', $edit, t('Log in'), [ diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index d614bc2b11b..54d64e78564 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -285,7 +285,7 @@ abstract class WebTestBase extends TestBase { } $edit = [ - 'name' => $account->getUsername(), + 'name' => $account->getAccountName(), 'pass' => $account->pass_raw, ]; $this->drupalPostForm('user/login', $edit, t('Log in')); @@ -294,7 +294,7 @@ abstract class WebTestBase extends TestBase { if (isset($this->sessionId)) { $account->session_id = $this->sessionId; } - $pass = $this->assert($this->drupalUserIsLoggedIn($account), format_string('User %name successfully logged in.', ['%name' => $account->getUsername()]), 'User login'); + $pass = $this->assert($this->drupalUserIsLoggedIn($account), format_string('User %name successfully logged in.', ['%name' => $account->getAccountName()]), 'User login'); if ($pass) { $this->loggedInUser = $account; $this->container->get('current_user')->setAccount($account); diff --git a/core/modules/system/src/Tests/Routing/RouterTest.php b/core/modules/system/src/Tests/Routing/RouterTest.php index 83a9c55b397..839f944d4f0 100644 --- a/core/modules/system/src/Tests/Routing/RouterTest.php +++ b/core/modules/system/src/Tests/Routing/RouterTest.php @@ -263,11 +263,11 @@ class RouterTest extends WebTestBase { $second_account = $this->drupalCreateUser(); $this->drupalGet('router_test/test12/' . $second_account->id()); - $this->assertText($account->getUsername() . ':' . $second_account->getUsername()); + $this->assertText($account->getAccountName() . ':' . $second_account->getAccountName()); $this->assertEqual($account->id(), $this->loggedInUser->id(), 'Ensure that the user was not changed.'); $this->drupalGet('router_test/test13/' . $second_account->id()); - $this->assertText($account->getUsername() . ':' . $second_account->getUsername()); + $this->assertText($account->getAccountName() . ':' . $second_account->getAccountName()); $this->assertEqual($account->id(), $this->loggedInUser->id(), 'Ensure that the user was not changed.'); } diff --git a/core/modules/system/src/Tests/Session/SessionAuthenticationTest.php b/core/modules/system/src/Tests/Session/SessionAuthenticationTest.php index ffdc08d1928..aeda6e2f375 100644 --- a/core/modules/system/src/Tests/Session/SessionAuthenticationTest.php +++ b/core/modules/system/src/Tests/Session/SessionAuthenticationTest.php @@ -55,7 +55,7 @@ class SessionAuthenticationTest extends WebTestBase { $this->assertResponse(401, 'An anonymous user cannot access a route protected with basic authentication.'); // We should be able to access the route with basic authentication. - $this->basicAuthGet($protected_url, $this->user->getUsername(), $this->user->pass_raw); + $this->basicAuthGet($protected_url, $this->user->getAccountName(), $this->user->pass_raw); $this->assertResponse(200, 'A route protected with basic authentication can be accessed by an authenticated user.'); // Check that the correct user is logged in. @@ -79,12 +79,12 @@ class SessionAuthenticationTest extends WebTestBase { public function testBasicAuthSession() { // Set a session value on a request through basic auth. $test_value = 'alpaca'; - $response = $this->basicAuthGet('session-test/set-session/' . $test_value, $this->user->getUsername(), $this->user->pass_raw); + $response = $this->basicAuthGet('session-test/set-session/' . $test_value, $this->user->getAccountName(), $this->user->pass_raw); $this->assertSessionData($response, $test_value); $this->assertResponse(200, 'The request to set a session value was successful.'); // Test that on a subsequent request the session value is still present. - $response = $this->basicAuthGet('session-test/get-session', $this->user->getUsername(), $this->user->pass_raw); + $response = $this->basicAuthGet('session-test/get-session', $this->user->getAccountName(), $this->user->pass_raw); $this->assertSessionData($response, $test_value); $this->assertResponse(200, 'The request to get a session value was successful.'); } @@ -118,12 +118,12 @@ class SessionAuthenticationTest extends WebTestBase { // If we authenticate with a third party authentication system then no // session cookie should be set, the third party system is responsible for // sustaining the session. - $this->basicAuthGet($no_cookie_url, $this->user->getUsername(), $this->user->pass_raw); + $this->basicAuthGet($no_cookie_url, $this->user->getAccountName(), $this->user->pass_raw); $this->assertResponse(200, 'The user is successfully authenticated using basic authentication.'); $this->assertFalse($this->drupalGetHeader('set-cookie', TRUE), 'No cookie is set on a route protected with basic authentication.'); // On the other hand, authenticating using Cookie sets a cookie. - $edit = ['name' => $this->user->getUsername(), 'pass' => $this->user->pass_raw]; + $edit = ['name' => $this->user->getAccountName(), 'pass' => $this->user->pass_raw]; $this->drupalPostForm($cookie_url, $edit, t('Log in')); $this->assertResponse(200, 'The user is successfully authenticated using cookie authentication.'); $this->assertTrue($this->drupalGetHeader('set-cookie', TRUE), 'A cookie is set on a route protected with cookie authentication.'); diff --git a/core/modules/system/src/Tests/Session/SessionHttpsTest.php b/core/modules/system/src/Tests/Session/SessionHttpsTest.php index 9a4666fd615..134ea0961a4 100644 --- a/core/modules/system/src/Tests/Session/SessionHttpsTest.php +++ b/core/modules/system/src/Tests/Session/SessionHttpsTest.php @@ -117,7 +117,7 @@ class SessionHttpsTest extends WebTestBase { // creates a mock HTTP request on HTTPS test environments. $form = $this->xpath('//form[@id="user-login-form"]'); $form[0]['action'] = $this->httpUrl('user/login'); - $edit = ['name' => $account->getUsername(), 'pass' => $account->pass_raw]; + $edit = ['name' => $account->getAccountName(), 'pass' => $account->pass_raw]; // When posting directly to the HTTP or HTTPS mock front controller, the // location header on the returned response is an absolute URL. That URL @@ -148,7 +148,7 @@ class SessionHttpsTest extends WebTestBase { // creates a mock HTTPS request on HTTP test environments. $form = $this->xpath('//form[@id="user-login-form"]'); $form[0]['action'] = $this->httpsUrl('user/login'); - $edit = ['name' => $account->getUsername(), 'pass' => $account->pass_raw]; + $edit = ['name' => $account->getAccountName(), 'pass' => $account->pass_raw]; // When posting directly to the HTTP or HTTPS mock front controller, the // location header on the returned response is an absolute URL. That URL diff --git a/core/modules/system/src/Tests/Session/SessionTest.php b/core/modules/system/src/Tests/Session/SessionTest.php index 0f219c5036b..56c346e5028 100644 --- a/core/modules/system/src/Tests/Session/SessionTest.php +++ b/core/modules/system/src/Tests/Session/SessionTest.php @@ -56,12 +56,12 @@ class SessionTest extends WebTestBase { // We cannot use $this->drupalLogin($user); because we exit in // session_test_user_login() which breaks a normal assertion. $edit = [ - 'name' => $user->getUsername(), + 'name' => $user->getAccountName(), 'pass' => $user->pass_raw, ]; $this->drupalPostForm('user/login', $edit, t('Log in')); $this->drupalGet('user'); - $pass = $this->assertText($user->getUsername(), format_string('Found name: %name', ['%name' => $user->getUsername()]), 'User login'); + $pass = $this->assertText($user->getAccountName(), format_string('Found name: %name', ['%name' => $user->getAccountName()]), 'User login'); $this->_logged_in = $pass; $this->drupalGet('session-test/id'); diff --git a/core/modules/system/src/Tests/Update/UpdatePathTestBase.php b/core/modules/system/src/Tests/Update/UpdatePathTestBase.php index 05719fb6d4b..49d96ac4b9f 100644 --- a/core/modules/system/src/Tests/Update/UpdatePathTestBase.php +++ b/core/modules/system/src/Tests/Update/UpdatePathTestBase.php @@ -345,7 +345,7 @@ abstract class UpdatePathTestBase extends WebTestBase { $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/modules/system/tests/modules/database_test/src/Form/DatabaseTestForm.php b/core/modules/system/tests/modules/database_test/src/Form/DatabaseTestForm.php index afb585e24b7..95355e98faf 100644 --- a/core/modules/system/tests/modules/database_test/src/Form/DatabaseTestForm.php +++ b/core/modules/system/tests/modules/database_test/src/Form/DatabaseTestForm.php @@ -53,8 +53,8 @@ class DatabaseTestForm extends FormBase { foreach (User::loadMultiple($uids) as $account) { $options[$account->id()] = [ - 'title' => ['data' => ['#title' => $account->getUsername()]], - 'username' => $account->getUsername(), + 'title' => ['data' => ['#title' => $account->getAccountName()]], + 'username' => $account->getAccountName(), 'status' => $account->isActive() ? t('active') : t('blocked'), ]; } diff --git a/core/modules/system/tests/modules/form_test/src/Controller/FormTestController.php b/core/modules/system/tests/modules/form_test/src/Controller/FormTestController.php index 4c9fbe2c8c2..b571c2da24a 100644 --- a/core/modules/system/tests/modules/form_test/src/Controller/FormTestController.php +++ b/core/modules/system/tests/modules/form_test/src/Controller/FormTestController.php @@ -22,7 +22,7 @@ class FormTestController extends ControllerBase { $user = $this->currentUser(); $values = [ 'uid' => $user->id(), - 'name' => $user->getUsername(), + 'name' => $user->getAccountName(), 'type' => 'page', 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, ]; diff --git a/core/modules/system/tests/modules/router_test_directory/src/TestContent.php b/core/modules/system/tests/modules/router_test_directory/src/TestContent.php index f392a81e85e..7f4166078b0 100644 --- a/core/modules/system/tests/modules/router_test_directory/src/TestContent.php +++ b/core/modules/system/tests/modules/router_test_directory/src/TestContent.php @@ -49,13 +49,13 @@ class TestContent extends ControllerBase { */ public function test11() { $account = $this->currentUser(); - return ['#markup' => $account->getUsername()]; + return ['#markup' => $account->getAccountName()]; } public function testAccount(UserInterface $user) { - $current_user_name = $this->currentUser()->getUsername(); + $current_user_name = $this->currentUser()->getAccountName(); $this->currentUser()->setAccount($user); - return ['#markup' => $current_user_name . ':' . $user->getUsername()]; + return ['#markup' => $current_user_name . ':' . $user->getAccountName()]; } /** diff --git a/core/modules/system/tests/modules/session_test/session_test.module b/core/modules/system/tests/modules/session_test/session_test.module index 6eb48afbc71..1555f9c06b6 100644 --- a/core/modules/system/tests/modules/session_test/session_test.module +++ b/core/modules/system/tests/modules/session_test/session_test.module @@ -11,7 +11,7 @@ use Drupal\user\UserInterface; * Implements hook_user_login(). */ function session_test_user_login(UserInterface $account) { - if ($account->getUsername() == 'session_test_user') { + if ($account->getAccountName() == 'session_test_user') { // Exit so we can verify that the session was regenerated // before hook_user_login() was called. exit; diff --git a/core/modules/system/tests/modules/url_alter_test/src/PathProcessorTest.php b/core/modules/system/tests/modules/url_alter_test/src/PathProcessorTest.php index 9a89df9b821..13e4105c039 100644 --- a/core/modules/system/tests/modules/url_alter_test/src/PathProcessorTest.php +++ b/core/modules/system/tests/modules/url_alter_test/src/PathProcessorTest.php @@ -42,7 +42,7 @@ class PathProcessorTest implements InboundPathProcessorInterface, OutboundPathPr if (preg_match('!^/user/([0-9]+)(/.*)?!', $path, $matches)) { if ($account = User::load($matches[1])) { $matches += [2 => '']; - $path = '/user/' . $account->getUsername() . $matches[2]; + $path = '/user/' . $account->getAccountName() . $matches[2]; if ($bubbleable_metadata) { $bubbleable_metadata->addCacheTags($account->getCacheTags()); } diff --git a/core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php b/core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php index 70944b9750b..aefaec23aa3 100644 --- a/core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php +++ b/core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php @@ -270,7 +270,7 @@ class EntityReferenceSelectionAccessTest extends KernelTestBase { $account = $values; } $users[$key] = $account; - $user_labels[$key] = Html::escape($account->getUsername()); + $user_labels[$key] = Html::escape($account->getAccountName()); } // Test as a non-admin. diff --git a/core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php b/core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php index 0e493e5d688..d58db8e0511 100644 --- a/core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php +++ b/core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php @@ -316,17 +316,17 @@ class BreadcrumbTest extends BrowserTestBase { // Verify breadcrumb on user pages (without menu link) for anonymous user. $trail = $home; $this->assertBreadcrumb('user', $trail, t('Log in')); - $this->assertBreadcrumb('user/' . $this->adminUser->id(), $trail, $this->adminUser->getUsername()); + $this->assertBreadcrumb('user/' . $this->adminUser->id(), $trail, $this->adminUser->getAccountName()); // Verify breadcrumb on user pages (without menu link) for registered users. $this->drupalLogin($this->adminUser); $trail = $home; - $this->assertBreadcrumb('user', $trail, $this->adminUser->getUsername()); - $this->assertBreadcrumb('user/' . $this->adminUser->id(), $trail, $this->adminUser->getUsername()); + $this->assertBreadcrumb('user', $trail, $this->adminUser->getAccountName()); + $this->assertBreadcrumb('user/' . $this->adminUser->id(), $trail, $this->adminUser->getAccountName()); $trail += [ - 'user/' . $this->adminUser->id() => $this->adminUser->getUsername(), + 'user/' . $this->adminUser->id() => $this->adminUser->getAccountName(), ]; - $this->assertBreadcrumb('user/' . $this->adminUser->id() . '/edit', $trail, $this->adminUser->getUsername()); + $this->assertBreadcrumb('user/' . $this->adminUser->id() . '/edit', $trail, $this->adminUser->getAccountName()); // Create a second user to verify breadcrumb on user pages again. $this->webUser = $this->drupalCreateUser([ @@ -337,19 +337,19 @@ class BreadcrumbTest extends BrowserTestBase { // Verify correct breadcrumb and page title on another user's account pages. $trail = $home; - $this->assertBreadcrumb('user/' . $this->adminUser->id(), $trail, $this->adminUser->getUsername()); + $this->assertBreadcrumb('user/' . $this->adminUser->id(), $trail, $this->adminUser->getAccountName()); $trail += [ - 'user/' . $this->adminUser->id() => $this->adminUser->getUsername(), + 'user/' . $this->adminUser->id() => $this->adminUser->getAccountName(), ]; - $this->assertBreadcrumb('user/' . $this->adminUser->id() . '/edit', $trail, $this->adminUser->getUsername()); + $this->assertBreadcrumb('user/' . $this->adminUser->id() . '/edit', $trail, $this->adminUser->getAccountName()); // Verify correct breadcrumb and page title when viewing own user account. $trail = $home; - $this->assertBreadcrumb('user/' . $this->webUser->id(), $trail, $this->webUser->getUsername()); + $this->assertBreadcrumb('user/' . $this->webUser->id(), $trail, $this->webUser->getAccountName()); $trail += [ - 'user/' . $this->webUser->id() => $this->webUser->getUsername(), + 'user/' . $this->webUser->id() => $this->webUser->getAccountName(), ]; - $this->assertBreadcrumb('user/' . $this->webUser->id() . '/edit', $trail, $this->webUser->getUsername()); + $this->assertBreadcrumb('user/' . $this->webUser->id() . '/edit', $trail, $this->webUser->getAccountName()); // Create an only slightly privileged user being able to access site reports // but not administration pages. diff --git a/core/modules/system/tests/src/Functional/Path/UrlAlterFunctionalTest.php b/core/modules/system/tests/src/Functional/Path/UrlAlterFunctionalTest.php index 271774169f0..afd697a5826 100644 --- a/core/modules/system/tests/src/Functional/Path/UrlAlterFunctionalTest.php +++ b/core/modules/system/tests/src/Functional/Path/UrlAlterFunctionalTest.php @@ -34,7 +34,7 @@ class UrlAlterFunctionalTest extends BrowserTestBase { $this->drupalLogin($account); $uid = $account->id(); - $name = $account->getUsername(); + $name = $account->getAccountName(); // Test a single altered path. $this->drupalGet("user/$name"); diff --git a/core/modules/system/tests/src/Functional/System/AccessDeniedTest.php b/core/modules/system/tests/src/Functional/System/AccessDeniedTest.php index 6490910bee7..c0749b490ca 100644 --- a/core/modules/system/tests/src/Functional/System/AccessDeniedTest.php +++ b/core/modules/system/tests/src/Functional/System/AccessDeniedTest.php @@ -75,7 +75,7 @@ class AccessDeniedTest extends BrowserTestBase { // Log out and check that the user login block is shown on custom 403 pages. $this->drupalLogout(); $this->drupalGet('admin'); - $this->assertText($this->adminUser->getUsername(), 'Found the custom 403 page'); + $this->assertText($this->adminUser->getAccountName(), 'Found the custom 403 page'); $this->assertText(t('Username'), 'Blocks are shown on the custom 403 page'); // Log back in and remove the custom 403 page. @@ -100,7 +100,7 @@ class AccessDeniedTest extends BrowserTestBase { // Check that we can log in from the 403 page. $this->drupalLogout(); $edit = [ - 'name' => $this->adminUser->getUsername(), + 'name' => $this->adminUser->getAccountName(), 'pass' => $this->adminUser->pass_raw, ]; $this->drupalPostForm('admin/config/system/site-information', $edit, t('Log in')); diff --git a/core/modules/system/tests/src/Functional/System/PageNotFoundTest.php b/core/modules/system/tests/src/Functional/System/PageNotFoundTest.php index ab9b54b491d..060f53aa196 100644 --- a/core/modules/system/tests/src/Functional/System/PageNotFoundTest.php +++ b/core/modules/system/tests/src/Functional/System/PageNotFoundTest.php @@ -56,7 +56,7 @@ class PageNotFoundTest extends BrowserTestBase { $this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration')); $this->drupalGet($this->randomMachineName(10)); - $this->assertText($this->adminUser->getUsername(), 'Found the custom 404 page'); + $this->assertText($this->adminUser->getAccountName(), 'Found the custom 404 page'); } /** diff --git a/core/modules/system/tests/src/Functional/System/SiteMaintenanceTest.php b/core/modules/system/tests/src/Functional/System/SiteMaintenanceTest.php index 389b3f75660..45d2d0fdd32 100644 --- a/core/modules/system/tests/src/Functional/System/SiteMaintenanceTest.php +++ b/core/modules/system/tests/src/Functional/System/SiteMaintenanceTest.php @@ -94,7 +94,7 @@ class SiteMaintenanceTest extends BrowserTestBase { // Log in user and verify that maintenance mode message is displayed // directly after login. $edit = [ - 'name' => $this->user->getUsername(), + 'name' => $this->user->getAccountName(), 'pass' => $this->user->pass_raw, ]; $this->drupalPostForm(NULL, $edit, t('Log in')); @@ -124,7 +124,7 @@ class SiteMaintenanceTest extends BrowserTestBase { // Submit password reset form. $edit = [ - 'name' => $this->user->getUsername(), + 'name' => $this->user->getAccountName(), ]; $this->drupalPostForm('user/password', $edit, t('Submit')); $mails = $this->drupalGetMails(); diff --git a/core/modules/system/tests/src/Functional/Theme/FastTest.php b/core/modules/system/tests/src/Functional/Theme/FastTest.php index d8f85f1f4a4..977f54dfced 100644 --- a/core/modules/system/tests/src/Functional/Theme/FastTest.php +++ b/core/modules/system/tests/src/Functional/Theme/FastTest.php @@ -28,8 +28,8 @@ class FastTest extends BrowserTestBase { */ public function testUserAutocomplete() { $this->drupalLogin($this->account); - $this->drupalGet('user/autocomplete', ['query' => ['q' => $this->account->getUsername()]]); - $this->assertRaw($this->account->getUsername()); + $this->drupalGet('user/autocomplete', ['query' => ['q' => $this->account->getAccountName()]]); + $this->assertRaw($this->account->getAccountName()); $this->assertNoText('registry initialized', 'The registry was not initialized'); } diff --git a/core/modules/tracker/src/Controller/TrackerUserTab.php b/core/modules/tracker/src/Controller/TrackerUserTab.php index d9c774d0268..c57aff0655b 100644 --- a/core/modules/tracker/src/Controller/TrackerUserTab.php +++ b/core/modules/tracker/src/Controller/TrackerUserTab.php @@ -22,7 +22,7 @@ class TrackerUserTab extends ControllerBase { * Title callback for the tracker.user_tab route. */ public function getTitle(UserInterface $user) { - return $user->getUsername(); + return $user->getAccountName(); } } diff --git a/core/modules/tracker/tests/src/Functional/TrackerTest.php b/core/modules/tracker/tests/src/Functional/TrackerTest.php index 4302ce3d2cc..bd13151c779 100644 --- a/core/modules/tracker/tests/src/Functional/TrackerTest.php +++ b/core/modules/tracker/tests/src/Functional/TrackerTest.php @@ -200,7 +200,7 @@ class TrackerTest extends BrowserTestBase { $this->assertNoLink($unpublished->label()); // Verify that title and tab title have been set correctly. $this->assertText('Activity', 'The user activity tab has the name "Activity".'); - $this->assertTitle(t('@name | @site', ['@name' => $this->user->getUsername(), '@site' => $this->config('system.site')->get('name')]), 'The user tracker page has the correct page title.'); + $this->assertTitle(t('@name | @site', ['@name' => $this->user->getAccountName(), '@site' => $this->config('system.site')->get('name')]), 'The user tracker page has the correct page title.'); // Verify that unpublished comments are removed from the tracker. $admin_user = $this->drupalCreateUser(['post comments', 'administer comments', 'access user profiles']); diff --git a/core/modules/user/src/Controller/UserController.php b/core/modules/user/src/Controller/UserController.php index 09544aa6380..05316684e62 100644 --- a/core/modules/user/src/Controller/UserController.php +++ b/core/modules/user/src/Controller/UserController.php @@ -123,8 +123,8 @@ class UserController extends ControllerBase { $this->messenger() ->addWarning($this->t('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' => $account->getUsername(), - '%resetting_user' => $reset_link_user->getUsername(), + '%other_user' => $account->getAccountName(), + '%resetting_user' => $reset_link_user->getAccountName(), ':logout' => $this->url('user.logout'), ])); } diff --git a/core/modules/user/src/Entity/User.php b/core/modules/user/src/Entity/User.php index b8675866f6f..ebb11341282 100644 --- a/core/modules/user/src/Entity/User.php +++ b/core/modules/user/src/Entity/User.php @@ -367,6 +367,7 @@ class User extends ContentEntityBase implements UserInterface { * {@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/user/src/Form/UserPasswordForm.php b/core/modules/user/src/Form/UserPasswordForm.php index b8056419897..0bcb82a2ac3 100644 --- a/core/modules/user/src/Form/UserPasswordForm.php +++ b/core/modules/user/src/Form/UserPasswordForm.php @@ -139,7 +139,7 @@ class UserPasswordForm extends FormBase { // Mail one time login URL and instructions using current language. $mail = _user_mail_notify('password_reset', $account, $langcode); if (!empty($mail)) { - $this->logger('user')->notice('Password reset instructions mailed to %name at %email.', ['%name' => $account->getUsername(), '%email' => $account->getEmail()]); + $this->logger('user')->notice('Password reset instructions mailed to %name at %email.', ['%name' => $account->getAccountName(), '%email' => $account->getEmail()]); $this->messenger()->addStatus($this->t('Further instructions have been sent to your email address.')); } diff --git a/core/modules/user/src/Form/UserPasswordResetForm.php b/core/modules/user/src/Form/UserPasswordResetForm.php index bf9538c0257..1f5ab59b836 100644 --- a/core/modules/user/src/Form/UserPasswordResetForm.php +++ b/core/modules/user/src/Form/UserPasswordResetForm.php @@ -40,12 +40,12 @@ class UserPasswordResetForm extends FormBase { */ public function buildForm(array $form, FormStateInterface $form_state, AccountInterface $user = NULL, $expiration_date = NULL, $timestamp = NULL, $hash = NULL) { if ($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->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'));