function FieldCrudTest::testUpdateField

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

Tests the update of a field.

File

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

Class

FieldCrudTest
Create field entities by attaching fields to entities.

Namespace

Drupal\Tests\field\Kernel

Code

public function testUpdateField() : void {
    FieldConfig::create($this->fieldDefinition)
        ->save();
    // Check that basic changes are saved.
    $field = FieldConfig::load('entity_test.' . $this->fieldDefinition['bundle'] . '.' . $this->fieldDefinition['field_name']);
    $field->setRequired(!$field->isRequired());
    $field->setLabel($this->randomMachineName());
    $field->set('description', $this->randomMachineName());
    $field->setSetting('test_field_setting', $this->randomMachineName());
    $field->save();
    $field_new = FieldConfig::load('entity_test.' . $this->fieldDefinition['bundle'] . '.' . $this->fieldDefinition['field_name']);
    $this->assertEquals($field->isRequired(), $field_new->isRequired(), '"required" change is saved');
    $this->assertEquals($field->getLabel(), $field_new->getLabel(), '"label" change is saved');
    $this->assertEquals($field->getDescription(), $field_new->getDescription(), '"description" change is saved');
    // @todo Test failures.
}

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