You are here

public function FieldMissingTypeTest::testFieldStorageMissingType 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::testFieldStorageMissingType()
  2. 10 core/tests/Drupal/KernelTests/Core/Field/FieldMissingTypeTest.php \Drupal\KernelTests\Core\Field\FieldMissingTypeTest::testFieldStorageMissingType()

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

See also

\Drupal\field\FieldStorageConfigStorage::mapFromStorageRecords()

File

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

Class

FieldMissingTypeTest
Tests the exception when missing a field type.

Namespace

Drupal\KernelTests\Core\Field

Code

public function testFieldStorageMissingType() {
  $this
    ->expectException(PluginNotFoundException::class);
  $this
    ->expectExceptionMessage("Unable to determine class for field type 'foo_field_storage' found in the 'field.storage.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 storage to use a non-existent field type.
  $this
    ->config('field.storage.entity_test_mulrev.' . $this->fieldName)
    ->set('type', 'foo_field_storage')
    ->save();
  \Drupal::service('entity_field.manager')
    ->clearCachedFieldDefinitions();
  EntityTestMulRev::load($entity
    ->id());
}