3 namespace Drupal\KernelTests\Core\Field;
5 use Drupal\Component\Utility\Unicode;
6 use Drupal\entity_test\Entity\EntityTestMulRev;
7 use Drupal\field\Entity\FieldConfig;
8 use Drupal\field\Entity\FieldStorageConfig;
9 use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
12 * Tests the exception when missing a field type.
16 class FieldMissingTypeTest extends EntityKernelTestBase {
19 * Set to FALSE because we are hacking a field storage to use a fake type.
21 * @see \Drupal\Core\Config\Development\ConfigSchemaChecker
25 protected $strictConfigSchema = FALSE;
35 protected function setUp() {
38 $entity_type_id = 'entity_test_mulrev';
39 $this->installEntitySchema($entity_type_id);
40 $this->fieldName = Unicode::strtolower($this->randomMachineName());
42 /** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
43 FieldStorageConfig::create([
44 'field_name' => $this->fieldName,
46 'entity_type' => $entity_type_id,
51 'entity_type' => $entity_type_id,
52 'field_name' => $this->fieldName,
53 'bundle' => $entity_type_id,
54 'label' => 'Test field',
59 * Tests the exception thrown when missing a field type in field storages.
61 * @see \Drupal\field\FieldStorageConfigStorage::mapFromStorageRecords()
63 public function testFieldStorageMissingType() {
64 $this->setExpectedException(\RuntimeException::class, "Unable to determine class for field type 'foo_field_storage' found in the 'field.storage.entity_test_mulrev.{$this->fieldName}' configuration");
65 $entity = EntityTestMulRev::create([
66 'name' => $this->randomString(),
67 'field_test_item' => $this->randomString(),
68 $this->fieldName => $this->randomString(),
71 // Hack the field storage to use a non-existent field type.
72 $this->config('field.storage.entity_test_mulrev.' . $this->fieldName)->set('type', 'foo_field_storage')->save();
73 \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
74 EntityTestMulRev::load($entity->id());
78 * Tests the exception thrown when missing a field type in fields.
80 * @see \Drupal\field\FieldConfigStorageBase::mapFromStorageRecords()
82 public function testFieldMissingType() {
83 $this->setExpectedException(\RuntimeException::class, "Unable to determine class for field type 'foo_field' found in the 'field.field.entity_test_mulrev.entity_test_mulrev.{$this->fieldName}' configuration");
84 $entity = EntityTestMulRev::create([
85 'name' => $this->randomString(),
86 'field_test_item' => $this->randomString(),
87 $this->fieldName => $this->randomString(),
90 // Hack the field to use a non-existent field type.
91 $this->config('field.field.entity_test_mulrev.entity_test_mulrev.' . $this->fieldName)->set('field_type', 'foo_field')->save();
92 \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
93 EntityTestMulRev::load($entity->id());