ConfigFieldDefinitionTest.php in Drupal 10
File
core/modules/field/tests/src/Kernel/ConfigFieldDefinitionTest.php
View source
<?php
namespace Drupal\Tests\field\Kernel;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
class ConfigFieldDefinitionTest extends FieldKernelTestBase {
private $entityType;
private $bundle;
protected function setUp() : void {
parent::setUp();
$this->entityType = 'entity_test';
$this->bundle = 'entity_test';
$this
->createFieldWithStorage('', $this->entityType, $this->bundle);
$this
->installEntitySchema('entity_test_rev');
$this
->createFieldWithStorage('_rev', 'entity_test_rev', 'entity_test_rev');
}
public function testBundleFieldDefinition() {
$definitions = \Drupal::service('entity_field.manager')
->getFieldDefinitions($this->entityType, $this->bundle);
$this
->assertTrue(isset($definitions[$this->fieldTestData->field
->getName()]));
$this
->assertInstanceOf(FieldDefinitionInterface::class, $definitions[$this->fieldTestData->field
->getName()]);
$this
->assertFalse(isset($definitions[$this->fieldTestData->field_rev
->getName()]));
}
public function testFieldStorageDefinition() {
$field_storage_definitions = \Drupal::service('entity_field.manager')
->getFieldStorageDefinitions($this->entityType);
$this
->assertTrue(isset($field_storage_definitions[$this->fieldTestData->field
->getName()]));
$this
->assertInstanceOf(FieldStorageDefinitionInterface::class, $field_storage_definitions[$this->fieldTestData->field
->getName()]);
$this
->assertFalse(isset($field_storage_definitions[$this->fieldTestData->field_rev
->getName()]));
}
}