You are here

protected function FieldNoteItemTest::doAccessAssertion in Examples for Developers 8

Same name and namespace in other branches
  1. 3.x modules/field_permission_example/tests/src/Kernel/FieldNoteItemTest.php \Drupal\Tests\field_permission_example\Kernel\FieldNoteItemTest::doAccessAssertion()

Helper routine to run the assertions.

1 call to FieldNoteItemTest::doAccessAssertion()
FieldNoteItemTest::testFieldNoteAccess in field_permission_example/tests/src/Kernel/FieldNoteItemTest.php
Test multiple access scenarios for the fieldnote field.

File

field_permission_example/tests/src/Kernel/FieldNoteItemTest.php, line 279

Class

FieldNoteItemTest
Tests our sticky-note field type.

Namespace

Drupal\Tests\field_permission_example\Kernel

Code

protected function doAccessAssertion($entity, $field_name, $account, $name, $op, $expected) {
  $expect_str = $expected ? "CAN" : "CANNOT";
  $assert_str = "{$name} {$expect_str} do {$op} on field {$field_name}";
  $operation = preg_match('/edit/', $op) ? "edit" : "view";
  $result = $entity->{$field_name}
    ->access($operation, $account);
  if ($expected) {
    $this
      ->assertTrue($result, $assert_str);
  }
  else {
    $this
      ->assertFalse($result, $assert_str);
  }
}