Commit d8a6a68b authored by catch's avatar catch

Issue #2787871 by alexpott, yogeshmpawar, Insasse, Prashant.c, catch, hass:...

Issue #2787871 by alexpott, yogeshmpawar, Insasse, Prashant.c, catch, hass: Properly deprecate getUserName() and use getAccountName() instead
parent 37c7dfa4
......@@ -124,6 +124,7 @@ public function getPreferredAdminLangcode($fallback_to_default = TRUE) {
* {@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();
}
......
......@@ -155,6 +155,7 @@ public function getPreferredAdminLangcode($fallback_to_default = TRUE) {
* {@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();
}
......
......@@ -37,15 +37,15 @@ public function testBasicAuth() {
$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 @@ public function testBasicAuth() {
$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 @@ public function testBasicAuth() {
$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 @@ public function testGlobalLoginFloodControl() {
// 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 @@ public function testPerUserLoginFloodControl() {
$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 @@ public function testLocale() {
$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 @@ public function testUnauthorizedErrorMessage() {
$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 @@ public function testControllerNotCalledBeforeAuth() {
$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');
......
......@@ -28,7 +28,7 @@ public function build() {
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.' ,
];
}
......
......@@ -209,7 +209,7 @@ public function testContextAwareUnsatisfiedBlocks() {
* 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);
......
......@@ -65,7 +65,7 @@ public function validate($entity, Constraint $constraint) {
// 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();
......
......@@ -67,12 +67,12 @@ public function testAnonymous() {
// 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 @@ public function testAnonymous() {
// 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.
......
......@@ -108,8 +108,8 @@ public function testCommentInterface() {
// 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();
......
......@@ -139,7 +139,7 @@ public function testCommentEditPreviewSave() {
$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 @@ public function testCommentEditPreviewSave() {
$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.
......
......@@ -163,7 +163,7 @@ protected function doTestAuthoringInfo() {
'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'),
];
......
......@@ -212,12 +212,12 @@ public function testAccessToAdministrativeFields() {
$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 @@ public function testAccessToAdministrativeFields() {
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 @@ public function testAccessToAdministrativeFields() {
$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 @@ public function testAccessToAdministrativeFields() {
$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 @@ public function testAccessToAdministrativeFields() {
$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,
......
......@@ -74,7 +74,7 @@ public function testCommentFields() {
$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');
......
......@@ -65,7 +65,7 @@ protected function setUp() {
*/
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 @@ public function testSendPersonalContactMessage() {
$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.
......
......@@ -680,7 +680,7 @@ public function entityFormValidate($form, FormStateInterface $form_state) {
$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) {
......
......@@ -328,7 +328,7 @@ protected function doTestAuthoringInfo() {
'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)]);
......
......@@ -321,7 +321,7 @@ protected function doTestAuthoringInfo() {
'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)]);
......
......@@ -154,7 +154,7 @@ public function testWorkflows() {
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);
......
......@@ -304,7 +304,7 @@ private function doUser() {
$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);
......
......@@ -61,7 +61,7 @@ public function testUrlRewritingEdgeCases() {
// 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');
}
/**
......
......@@ -140,7 +140,7 @@ public function form(array $form, FormStateInterface $form_state) {
$form['meta']['author'] = [
'#type' => 'item',
'#title' => $this->t('Author'),
'#markup' => $node->getOwner()->getUsername(),
'#markup' => $node->getOwner()->getAccountName(),
'#wrapper_attributes' => ['class' => ['entity-meta__author']],
];
......
......@@ -100,7 +100,7 @@ public function testNodeAccessBasic() {
$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;
......
......@@ -60,7 +60,7 @@ public function testNodeCreation() {
// 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 @@ public function testNodeCreation() {
$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.
......
......@@ -273,7 +273,7 @@ protected function checkVariousAuthoredByValues(NodeInterface $node, $form_eleme
// 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());
......
......@@ -197,7 +197,7 @@ protected function doTestAuthoringInfo() {
'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'],
......
......@@ -60,7 +60,7 @@ protected function setUp($import_test_views = TRUE) {
'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 @@ public function testFilterNodeAccess() {
$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());
}
}
......@@ -107,7 +107,7 @@ public function testNode() {
// 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());
......
......@@ -69,9 +69,9 @@ public function testNodeTokenReplacement() {
$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()]);
......
......@@ -60,7 +60,7 @@ public function testNodeFields() {
$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');
......
......@@ -154,7 +154,7 @@ public function testCommentRdfAuthorMarkup() {
// 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 @@ public function _testBasicCommentRdfaMarkup($graph, CommentInterface $comment, $
}
// 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,
......
......@@ -477,7 +477,7 @@ protected function assertRdfaNodeCommentProperties($graph) {
// 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).');
}
......
......@@ -73,7 +73,7 @@ public function testUserAttributesInMarkup() {
// 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 @@ public function testUserAttributesInMarkup() {
// 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).');
......
......@@ -84,7 +84,7 @@ public function testRestViewsAuthentication() {
// 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',
],
......
......@@ -137,7 +137,7 @@ public function testSearchModuleDisabling() {
'text' => $this->searchNode->label(),
],
'user_search' => [
'keys' => $this->searchUser->getUsername(),
'keys' => $this->searchUser->getAccountName(),
'text' => $this->searchUser->getEmail(),
],
'dummy_search_type' => [
......
......@@ -72,7 +72,7 @@ public function testExactQuery() {
$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 @@ public function testExactQuery() {
$node_type_config->save();
$edit = ['keys' => 'Druplicon'];
$this->drupalPostForm('search/node', $edit, t('Search'));