Issue #2787871 by alexpott, yogeshmpawar, Insasse, Prashant.c, catch, hass: Properly deprecate getUserName() and use getAccountName() instead

8.7.x
Nathaniel Catchpole 2018-10-08 11:24:56 +01:00
parent 37c7dfa47c
commit d8a6a68bbf
96 changed files with 246 additions and 243 deletions

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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');

View File

@ -28,7 +28,7 @@ class TestContextAwareBlock extends BlockBase {
return [
'#prefix' => '<div id="' . $this->getPluginId() . '--username">',
'#suffix' => '</div>',
'#markup' => $user ? $user->getUsername() : 'No context mapping selected.' ,
'#markup' => $user ? $user->getAccountName() : 'No context mapping selected.' ,
];
}

View File

@ -209,7 +209,7 @@ class BlockUiTest extends BrowserTestBase {
* Tests the behavior of context-aware blocks.
*/
public function testContextAwareBlocks() {
$expected_text = '<div id="test_context_aware--username">' . \Drupal::currentUser()->getUsername() . '</div>';
$expected_text = '<div id="test_context_aware--username">' . \Drupal::currentUser()->getAccountName() . '</div>';
$this->drupalGet('');
$this->assertNoText('Test context-aware block');
$this->assertNoRaw($expected_text);

View File

@ -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();

View File

@ -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.

View File

@ -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();

View File

@ -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.

View File

@ -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'),
];

View File

@ -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,

View File

@ -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');

View File

@ -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.

View File

@ -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) {

View File

@ -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)]);

View File

@ -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)]);

View File

@ -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);

View File

@ -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);

View File

@ -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');
}
/**

View File

@ -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']],
];

View File

@ -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;

View File

@ -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.

View File

@ -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());

View File

@ -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'],

View File

@ -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());
}
}

View File

@ -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());

View File

@ -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()]);

View File

@ -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');

View File

@ -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,

View File

@ -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).');
}

View File

@ -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).');

View File

@ -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',
],

View File

@ -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' => [

View File

@ -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.');
}

View File

@ -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.

View File

@ -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');

View File

@ -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');

View File

@ -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());
}
}

View File

@ -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('<front>', $edit, t('Log in'));
$this->assertEqual(count($this->cookies), 1, 'A cookie is set when the user logs in.');

View File

@ -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'), [

View File

@ -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);

View File

@ -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.');
}

View File

@ -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.');

View File

@ -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

View File

@ -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');

View File

@ -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();
}

View File

@ -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'),
];
}

View File

@ -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,
];

View File

@ -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()];
}
/**

View File

@ -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;

View File

@ -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());
}

View File

@ -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.

View File

@ -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.

View File

@ -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");

View File

@ -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'));

View File

@ -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');
}
/**

View File

@ -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();

View File

@ -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');
}

View File

@ -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();
}
}

View File

@ -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']);

View File

@ -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 <a href=":logout">log out</a> 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'),
]));
}

View File

@ -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();
}

View File

@ -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.'));
}

View File

@ -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('<p>This is a one-time login for %user_name and will expire on %expiration_date.</p><p>Click on this button to log in to the site and change your password.</p>', ['%user_name' => $user->getUsername(), '%expiration_date' => $expiration_date])];
$form['message'] = ['#markup' => $this->t('<p>This is a one-time login for %user_name and will expire on %expiration_date.</p><p>Click on this button to log in to the site and change your password.</p>', ['%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('<p>This is a one-time login for %user_name.</p><p>Click on this button to log in to the site and change your password.</p>', ['%user_name' => $user->getUsername()])];
$form['message'] = ['#markup' => $this->t('<p>This is a one-time login for %user_name.</p><p>Click on this button to log in to the site and change your password.</p>', ['%user_name' => $user->getAccountName()])];
$form['#title'] = $this->t('Set password');
}

View File

@ -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;
}
}

View File

@ -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 <a href=":url">%name</a>. No email has been sent.', [':url' => $account->url(), '%name' => $account->getUsername()]));
$this->messenger()->addStatus($this->t('Created a new user account for <a href=":url">%name</a>. 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 <a href=":url">%name</a> 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 <a href=":url">%name</a> 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 <a href=":url">%name</a>.', [':url' => $account->url(), '%name' => $account->getUsername()]));
$this->messenger()->addStatus($this->t('A welcome message with further instructions has been emailed to the new user <a href=":url">%name</a>.', [':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.'));

View File

@ -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();
}

View File

@ -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 = [];

View File

@ -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.');

View File

@ -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());
}

View File

@ -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']]));

View File

@ -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(), '<em>' . $this->account->id() . '</em>', '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.');
}
}

View File

@ -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);

View File

@ -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'));

View File

@ -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 <a href=":logout">log out</a> 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.');
}

View File

@ -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());

View File

@ -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'));

View File

@ -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.');

View File

@ -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']));

View File

@ -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

View File

@ -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();

View File

@ -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]);
}

View File

@ -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.');
}
}

View File

@ -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(),
];
}

View File

@ -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' => ''])));
}

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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';

View File

@ -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');

View File

@ -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');
}

View File

@ -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();
}

View File

@ -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]));
}

View File

@ -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

View File

@ -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.

View File

@ -258,7 +258,7 @@ trait UiHelperTrait {
$this->drupalGet('user/login');
$this->submitForm([
'name' => $account->getUsername(),
'name' => $account->getAccountName(),
'pass' => $account->passRaw,
], t('Log in'));