UserFieldsAccessChangeTest.php in Drupal 8
File
core/modules/user/tests/src/Functional/Views/UserFieldsAccessChangeTest.php
View source
<?php
namespace Drupal\Tests\user\Functional\Views;
class UserFieldsAccessChangeTest extends UserTestBase {
public 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
->assertText(t('Name'));
$this
->assertText(t('Created'));
$this
->assertNoText(t('Init'));
$this
->assertNoText(t('Email'));
$this
->assertNoText(t('Status'));
$user = $this
->drupalCreateUser([
'sub-admin',
]);
$this
->drupalLogin($user);
$this
->drupalGet('test_user_fields_access');
$this
->assertText(t('Init'));
$this
->assertText(t('Email'));
$this
->assertText(t('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
->assertText($test_user
->getAccountName(), 'Found user in view');
$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');
}
}