function FieldMissingTypeTest::testFieldStorageMissingType

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Field/FieldMissingTypeTest.php \Drupal\KernelTests\Core\Field\FieldMissingTypeTest::testFieldStorageMissingType()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Field/FieldMissingTypeTest.php \Drupal\KernelTests\Core\Field\FieldMissingTypeTest::testFieldStorageMissingType()
  3. 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 65

Class

FieldMissingTypeTest
Tests the exception when missing a field type.

Namespace

Drupal\KernelTests\Core\Field

Code

public function testFieldStorageMissingType() : void {
    $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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.