function UserFieldsAccessChangeTest::testUserFieldAccess

Same name in other branches
  1. 9 core/modules/user/tests/src/Functional/Views/UserFieldsAccessChangeTest.php \Drupal\Tests\user\Functional\Views\UserFieldsAccessChangeTest::testUserFieldAccess()
  2. 8.9.x core/modules/user/tests/src/Functional/Views/UserFieldsAccessChangeTest.php \Drupal\Tests\user\Functional\Views\UserFieldsAccessChangeTest::testUserFieldAccess()
  3. 11.x 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\Views

Code

public function testUserFieldAccess() : void {
    $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');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.