function UserAccessControlHandlerTest::assertFieldAccess

Same name in other branches
  1. 8.9.x core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php \Drupal\Tests\user\Unit\UserAccessControlHandlerTest::assertFieldAccess()
  2. 10 core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php \Drupal\Tests\user\Unit\UserAccessControlHandlerTest::assertFieldAccess()
  3. 11.x core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php \Drupal\Tests\user\Unit\UserAccessControlHandlerTest::assertFieldAccess()

Asserts correct field access grants for a field.

@internal

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 138

Class

UserAccessControlHandlerTest
Tests the user access controller.

Namespace

Drupal\Tests\user\Unit

Code

public function assertFieldAccess(string $field, string $viewer, string $target, bool $view, bool $edit) : void {
    $field_definition = $this->createMock('Drupal\\Core\\Field\\FieldDefinitionInterface');
    $field_definition->expects($this->any())
        ->method('getName')
        ->willReturn($field);
    $this->items
        ->expects($this->any())
        ->method('getEntity')
        ->willReturn($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);
    }
}

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