UserFieldsAccessChangeTest.php in Drupal 9
File
core/modules/user/tests/src/Functional/Views/UserFieldsAccessChangeTest.php
View source
<?php
namespace Drupal\Tests\user\Functional\Views;
class UserFieldsAccessChangeTest extends UserTestBase {
protected static $modules = [
'user_access_test',
];
protected $defaultTheme = 'classy';
public static $testViews = [
'test_user_fields_access',
];
public function testUserFieldAccess() {
$this
->drupalGet('test_user_fields_access');
$this
->assertSession()
->pageTextContains('Name');
$this
->assertSession()
->pageTextContains('Created');
$this
->assertSession()
->pageTextNotContains('Init');
$this
->assertSession()
->pageTextNotContains('Email');
$this
->assertSession()
->pageTextNotContains('Status');
$user = $this
->drupalCreateUser([
'sub-admin',
]);
$this
->drupalLogin($user);
$this
->drupalGet('test_user_fields_access');
$this
->assertSession()
->pageTextContains('Init');
$this
->assertSession()
->pageTextContains('Email');
$this
->assertSession()
->pageTextContains('Status');
}
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();
$this
->drupalGet('test_user_fields_access');
$this
->assertSession()
->pageTextContains($test_user
->getAccountName());
$result = $this
->xpath($xpath);
$this
->assertCount(0, $result, 'User is not a link');
$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');
}
}