public function UserFieldsAccessChangeTest::testUserFieldAccess in Drupal 9
Same name and namespace in other branches
- 8 core/modules/user/tests/src/Functional/Views/UserFieldsAccessChangeTest.php \Drupal\Tests\user\Functional\Views\UserFieldsAccessChangeTest::testUserFieldAccess()
Tests if another module can change field access.
File
- core/
modules/ user/ tests/ src/ Functional/ Views/ UserFieldsAccessChangeTest.php, line 34
Class
- UserFieldsAccessChangeTest
- Checks changing entity and field access.
Namespace
Drupal\Tests\user\Functional\ViewsCode
public function testUserFieldAccess() {
$this
->drupalGet('test_user_fields_access');
// User has access to name and created date by default.
$this
->assertSession()
->pageTextContains('Name');
$this
->assertSession()
->pageTextContains('Created');
// User does not by default have access to init, mail and status.
$this
->assertSession()
->pageTextNotContains('Init');
$this
->assertSession()
->pageTextNotContains('Email');
$this
->assertSession()
->pageTextNotContains('Status');
// Assign sub-admin role to grant extra access.
$user = $this
->drupalCreateUser([
'sub-admin',
]);
$this
->drupalLogin($user);
$this
->drupalGet('test_user_fields_access');
// Access for init, mail and status is added in hook_entity_field_access().
$this
->assertSession()
->pageTextContains('Init');
$this
->assertSession()
->pageTextContains('Email');
$this
->assertSession()
->pageTextContains('Status');
}