function UserFieldsAccessChangeTest::testUserNameLink
Same name in other branches
- 9 core/modules/user/tests/src/Functional/Views/UserFieldsAccessChangeTest.php \Drupal\Tests\user\Functional\Views\UserFieldsAccessChangeTest::testUserNameLink()
- 8.9.x core/modules/user/tests/src/Functional/Views/UserFieldsAccessChangeTest.php \Drupal\Tests\user\Functional\Views\UserFieldsAccessChangeTest::testUserNameLink()
- 10 core/modules/user/tests/src/Functional/Views/UserFieldsAccessChangeTest.php \Drupal\Tests\user\Functional\Views\UserFieldsAccessChangeTest::testUserNameLink()
Test user name link.
Tests that the user name formatter shows a link to the user when there is access but not otherwise.
File
-
core/
modules/ user/ tests/ src/ Functional/ Views/ UserFieldsAccessChangeTest.php, line 63
Class
- UserFieldsAccessChangeTest
- Checks changing entity and field access.
Namespace
Drupal\Tests\user\Functional\ViewsCode
public function testUserNameLink() : void {
$test_user = $this->drupalCreateUser();
$xpath = "//td/a[.='" . $test_user->getAccountName() . "']/@href[.='" . $test_user->toUrl()
->toString() . "']";
$attributes = [
'title' => 'View user profile.',
];
$link = $test_user->toLink(NULL, 'canonical', [
'attributes' => $attributes,
])
->toString();
// No access, so no link.
$this->drupalGet('test_user_fields_access');
$this->assertSession()
->pageTextContains($test_user->getAccountName());
$this->assertSession()
->elementNotExists('xpath', $xpath);
// Assign sub-admin role to grant extra access.
$user = $this->drupalCreateUser([
'sub-admin',
]);
$this->drupalLogin($user);
$this->drupalGet('test_user_fields_access');
$this->assertSession()
->elementsCount('xpath', $xpath, 1);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.