3 namespace Drupal\Tests\field\Kernel;
5 use Drupal\Core\Field\FieldDefinitionInterface;
6 use Drupal\Core\Field\FieldStorageDefinitionInterface;
9 * Tests exposing field definitions for configurable fields.
13 class ConfigFieldDefinitionTest extends FieldKernelTestBase {
16 * The entity manager service.
18 * @var \Drupal\Core\Entity\EntityManagerInterface;
20 protected $entityManager;
35 protected function setUp() {
38 // Create a field and a storage of type 'test_field', on the 'entity_test'
40 $this->entityType = 'entity_test';
41 $this->bundle = 'entity_test';
42 $this->createFieldWithStorage('', $this->entityType, $this->bundle);
43 $this->entityManager = $this->container->get('entity.manager');
45 // Create a second field on 'entity_test_rev'.
46 $this->createFieldWithStorage('_rev', 'entity_test_rev', 'entity_test_rev');
50 * Makes sure a field definition is exposed for a configurable field.
52 public function testBundleFieldDefinition() {
53 $definitions = $this->entityManager->getFieldDefinitions($this->entityType, $this->bundle);
54 $this->assertTrue(isset($definitions[$this->fieldTestData->field->getName()]));
55 $this->assertTrue($definitions[$this->fieldTestData->field->getName()] instanceof FieldDefinitionInterface);
56 // Make sure fields on other entity types are not exposed.
57 $this->assertFalse(isset($definitions[$this->fieldTestData->field_rev->getName()]));
61 * Makes sure a field storage definition is exposed for a configurable field.
63 public function testFieldStorageDefinition() {
64 $field_storage_definitions = $this->entityManager->getFieldStorageDefinitions($this->entityType);
65 $this->assertTrue(isset($field_storage_definitions[$this->fieldTestData->field->getName()]));
66 $this->assertTrue($field_storage_definitions[$this->fieldTestData->field->getName()] instanceof FieldStorageDefinitionInterface);
67 // Make sure storages on other entity types are not exposed.
68 $this->assertFalse(isset($field_storage_definitions[$this->fieldTestData->field_rev->getName()]));