You are here

public function UserAccessControlHandlerTest::assertFieldAccess in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php \Drupal\Tests\user\Unit\UserAccessControlHandlerTest::assertFieldAccess()

Asserts correct field access grants for a field.

6 calls to UserAccessControlHandlerTest::assertFieldAccess()
UserAccessControlHandlerTest::testAdminFieldAccess in core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php
Tests that private user settings cannot be viewed by other users.
UserAccessControlHandlerTest::testCreatedAccess in core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php
Tests the user created field access.
UserAccessControlHandlerTest::testHiddenUserSettings in core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php
Tests that private user settings cannot be viewed by other users.
UserAccessControlHandlerTest::testNonExistingFieldAccess in core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php
Tests access to a non-existing base field.
UserAccessControlHandlerTest::testPasswordAccess in core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php
Tests that passwords cannot be viewed, just edited.

... See full list

File

core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php, line 139

Class

UserAccessControlHandlerTest
Tests the user access controller.

Namespace

Drupal\Tests\user\Unit

Code

public function assertFieldAccess($field, $viewer, $target, $view, $edit) {
  $field_definition = $this
    ->createMock('Drupal\\Core\\Field\\FieldDefinitionInterface');
  $field_definition
    ->expects($this
    ->any())
    ->method('getName')
    ->will($this
    ->returnValue($field));
  $this->items
    ->expects($this
    ->any())
    ->method('getEntity')
    ->will($this
    ->returnValue($this->{$target}));
  foreach ([
    'view' => $view,
    'edit' => $edit,
  ] as $operation => $result) {
    $result_text = !isset($result) ? 'null' : ($result ? 'true' : 'false');
    $message = "User '{$field}' field access returns '{$result_text}' with operation '{$operation}' for '{$viewer}' accessing '{$target}'";
    $this
      ->assertSame($result, $this->accessControlHandler
      ->fieldAccess($operation, $field_definition, $this->{$viewer}, $this->items), $message);
  }
}