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()
- 10 core/modules/user/tests/src/Functional/Views/UserFieldsAccessChangeTest.php \Drupal\Tests\user\Functional\Views\UserFieldsAccessChangeTest::testUserNameLink()
- 11.x core/modules/user/tests/src/Functional/Views/UserFieldsAccessChangeTest.php \Drupal\Tests\user\Functional\Views\UserFieldsAccessChangeTest::testUserNameLink()
Tests 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 61
Class
- UserFieldsAccessChangeTest
- Checks changing entity and field access.
Namespace
Drupal\Tests\user\Functional\ViewsCode
public function testUserNameLink() {
$test_user = $this->drupalCreateUser();
$xpath = "//td/a[.='" . $test_user->getAccountName() . "'][@class='username']/@href[.='" . $test_user->toUrl()
->toString() . "']";
$attributes = [
'title' => 'View user profile.',
'class' => 'username',
];
$link = $test_user->toLink(NULL, 'canonical', [
'attributes' => $attributes,
])
->toString();
// No access, so no link.
$this->drupalGet('test_user_fields_access');
$this->assertText($test_user->getAccountName(), 'Found user in view');
$result = $this->xpath($xpath);
$this->assertCount(0, $result, 'User is not a link');
// Assign sub-admin role to grant extra access.
$user = $this->drupalCreateUser([
'sub-admin',
]);
$this->drupalLogin($user);
$this->drupalGet('test_user_fields_access');
$result = $this->xpath($xpath);
$this->assertCount(1, $result, 'User is a link');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.