You are here

public function FieldAccessTest::testFieldAccess in Drupal 8

Same name in this branch
  1. 8 core/tests/Drupal/KernelTests/Core/Field/FieldAccessTest.php \Drupal\KernelTests\Core\Field\FieldAccessTest::testFieldAccess()
  2. 8 core/modules/field/tests/src/Functional/FieldAccessTest.php \Drupal\Tests\field\Functional\FieldAccessTest::testFieldAccess()
Same name and namespace in other branches
  1. 9 core/modules/field/tests/src/Functional/FieldAccessTest.php \Drupal\Tests\field\Functional\FieldAccessTest::testFieldAccess()

Test that hook_entity_field_access() is called.

File

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

Class

FieldAccessTest
Tests Field access.

Namespace

Drupal\Tests\field\Functional

Code

public function testFieldAccess() {

  // Assert the text is visible.
  $this
    ->drupalGet('node/' . $this->node
    ->id());
  $this
    ->assertText($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
    ->assertNoText($this->testViewFieldValue);
}