function FieldAccessTest::testFieldAccess

Same name in this branch
  1. 11.x core/tests/Drupal/KernelTests/Core/Field/FieldAccessTest.php \Drupal\KernelTests\Core\Field\FieldAccessTest::testFieldAccess()
Same name in other branches
  1. 9 core/modules/field/tests/src/Functional/FieldAccessTest.php \Drupal\Tests\field\Functional\FieldAccessTest::testFieldAccess()
  2. 9 core/tests/Drupal/KernelTests/Core/Field/FieldAccessTest.php \Drupal\KernelTests\Core\Field\FieldAccessTest::testFieldAccess()
  3. 8.9.x core/modules/field/tests/src/Functional/FieldAccessTest.php \Drupal\Tests\field\Functional\FieldAccessTest::testFieldAccess()
  4. 8.9.x core/tests/Drupal/KernelTests/Core/Field/FieldAccessTest.php \Drupal\KernelTests\Core\Field\FieldAccessTest::testFieldAccess()
  5. 10 core/modules/field/tests/src/Functional/FieldAccessTest.php \Drupal\Tests\field\Functional\FieldAccessTest::testFieldAccess()
  6. 10 core/tests/Drupal/KernelTests/Core/Field/FieldAccessTest.php \Drupal\KernelTests\Core\Field\FieldAccessTest::testFieldAccess()

Tests that hook_entity_field_access() is called.

File

core/modules/field/tests/src/Functional/FieldAccessTest.php, line 87

Class

FieldAccessTest
Tests Field access.

Namespace

Drupal\Tests\field\Functional

Code

public function testFieldAccess() : void {
    // Assert the text is visible.
    $this->drupalGet('node/' . $this->node
        ->id());
    $this->assertSession()
        ->pageTextContains($this->testViewFieldValue);
    // Assert the text is not visible for anonymous users.
    // The field_test module implements hook_entity_field_access() which will
    // specifically target the 'test_view_field' field.
    $this->drupalLogout();
    $this->drupalGet('node/' . $this->node
        ->id());
    $this->assertSession()
        ->pageTextNotContains($this->testViewFieldValue);
}

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