public function ManagerTest::testCreateInstance in Field Permissions 8
Same name and namespace in other branches
- 8.2 tests/src/Kernel/Plugin/FieldPermissionType/ManagerTest.php \Drupal\Tests\field_permissions\Kernel\Plugin\FieldPermissionType\ManagerTest::testCreateInstance()
Test that plugin instances can be created.
@covers ::createInstance
See also
\Drupal\field_permissions_test\Plugin\FieldPermissionType\TestAccess
File
- tests/src/ Kernel/ Plugin/ FieldPermissionType/ ManagerTest.php, line 68 
Class
- ManagerTest
- Integration tests for the field permission type plugin manager.
Namespace
Drupal\Tests\field_permissions\Kernel\Plugin\FieldPermissionTypeCode
public function testCreateInstance() {
  $entity = EntityTest::create();
  $field_storage = FieldStorageConfig::create([
    'field_name' => 'test_foo',
    'type' => 'text',
    'entity_type' => 'entity_test',
  ]);
  $plugin = $this->fieldPermissionTypeManager
    ->createInstance('test_access', [], $field_storage);
  // All 'view' operations are accessible.
  $this
    ->assertTrue($plugin
    ->hasFieldAccess('view', $entity, $this->account));
  // Edit access is only granted if the field doesn't start with 'edit_'.
  $this
    ->assertFalse($plugin
    ->hasFieldAccess('edit', $entity, $this->account));
}