You are here

public function FieldMissingTypeTest::testFieldMissingType in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Field/FieldMissingTypeTest.php \Drupal\KernelTests\Core\Field\FieldMissingTypeTest::testFieldMissingType()
  2. 10 core/tests/Drupal/KernelTests/Core/Field/FieldMissingTypeTest.php \Drupal\KernelTests\Core\Field\FieldMissingTypeTest::testFieldMissingType()

Tests the exception thrown when missing a field type in fields.

See also

\Drupal\field\FieldConfigStorageBase::mapFromStorageRecords()

File

core/tests/Drupal/KernelTests/Core/Field/FieldMissingTypeTest.php, line 83

Class

FieldMissingTypeTest
Tests the exception when missing a field type.

Namespace

Drupal\KernelTests\Core\Field

Code

public function testFieldMissingType() {
  $this
    ->expectException(PluginNotFoundException::class);
  $this
    ->expectExceptionMessage("Unable to determine class for field type 'foo_field' found in the 'field.field.entity_test_mulrev.entity_test_mulrev.{$this->fieldName}' configuration");
  $entity = EntityTestMulRev::create([
    'name' => $this
      ->randomString(),
    'field_test_item' => $this
      ->randomString(),
    $this->fieldName => $this
      ->randomString(),
  ]);
  $entity
    ->save();

  // Hack the field to use a non-existent field type.
  $this
    ->config('field.field.entity_test_mulrev.entity_test_mulrev.' . $this->fieldName)
    ->set('field_type', 'foo_field')
    ->save();
  \Drupal::service('entity_field.manager')
    ->clearCachedFieldDefinitions();
  EntityTestMulRev::load($entity
    ->id());
}