function FieldCrudTest::testReadField

Same name in other branches
  1. 8.9.x core/modules/field/tests/src/Kernel/FieldCrudTest.php \Drupal\Tests\field\Kernel\FieldCrudTest::testReadField()
  2. 10 core/modules/field/tests/src/Kernel/FieldCrudTest.php \Drupal\Tests\field\Kernel\FieldCrudTest::testReadField()
  3. 11.x core/modules/field/tests/src/Kernel/FieldCrudTest.php \Drupal\Tests\field\Kernel\FieldCrudTest::testReadField()

Tests reading back a field definition.

File

core/modules/field/tests/src/Kernel/FieldCrudTest.php, line 241

Class

FieldCrudTest
Create field entities by attaching fields to entities.

Namespace

Drupal\Tests\field\Kernel

Code

public function testReadField() {
    FieldConfig::create($this->fieldDefinition)
        ->save();
    // Read the field back.
    $field = FieldConfig::load('entity_test.' . $this->fieldDefinition['bundle'] . '.' . $this->fieldDefinition['field_name']);
    $this->assertSame($this->fieldDefinition['field_name'], $field->getName(), 'The field was properly read.');
    $this->assertSame($this->fieldDefinition['entity_type'], $field->getTargetEntityTypeId(), 'The field was properly read.');
    $this->assertSame($this->fieldDefinition['bundle'], $field->getTargetBundle(), 'The field was properly read.');
}

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