FieldMissingTypeTest.php in Drupal 10
File
core/tests/Drupal/KernelTests/Core/Field/FieldMissingTypeTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Field;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\entity_test\Entity\EntityTestMulRev;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
class FieldMissingTypeTest extends EntityKernelTestBase {
protected $strictConfigSchema = FALSE;
protected $fieldName;
protected function setUp() : void {
parent::setUp();
$entity_type_id = 'entity_test_mulrev';
$this
->installEntitySchema($entity_type_id);
$this->fieldName = mb_strtolower($this
->randomMachineName());
FieldStorageConfig::create([
'field_name' => $this->fieldName,
'type' => 'text',
'entity_type' => $entity_type_id,
'cardinality' => 1,
])
->save();
FieldConfig::create([
'entity_type' => $entity_type_id,
'field_name' => $this->fieldName,
'bundle' => $entity_type_id,
'label' => 'Test field',
])
->save();
}
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();
$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());
}
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();
$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());
}
}