You are here

public function UserFieldsAccessChangeTest::testUserFieldAccess in Drupal 8

Same name and namespace in other branches
  1. 9 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() {
  $this
    ->drupalGet('test_user_fields_access');

  // User has access to name and created date by default.
  $this
    ->assertText(t('Name'));
  $this
    ->assertText(t('Created'));

  // User does not by default have access to init, mail and status.
  $this
    ->assertNoText(t('Init'));
  $this
    ->assertNoText(t('Email'));
  $this
    ->assertNoText(t('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
    ->assertText(t('Init'));
  $this
    ->assertText(t('Email'));
  $this
    ->assertText(t('Status'));
}