function FieldAccessTest::testFieldAccess

Same name in this branch
  1. 8.x drupal/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php \Drupal\field\Tests\FieldAccessTest::testFieldAccess()
  2. 8.x drupal/core/modules/system/lib/Drupal/system/Tests/Entity/FieldAccessTest.php \Drupal\system\Tests\Entity\FieldAccessTest::testFieldAccess()

Test that hook_field_access() is called.

File

drupal/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php, line 71
Definition of Drupal\field\Tests\FieldAccessTest.

Class

FieldAccessTest
Tests the functionality of field access.

Namespace

Drupal\field\Tests

Code

function testFieldAccess() {

  // Assert the text is visible.
  $this
    ->drupalGet('node/' . $this->node->nid);
  $this
    ->assertText($this->test_view_field_value);

  // Assert the text is not visible for anonymous users.
  // The field_test module implements hook_field_access() which will
  // specifically target the 'test_view_field' field.
  $this
    ->drupalLogout();
  $this
    ->drupalGet('node/' . $this->node->nid);
  $this
    ->assertNoText($this->test_view_field_value);
}