You are here

function FieldCrudTest::testUpdateField in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field/src/Tests/FieldCrudTest.php \Drupal\field\Tests\FieldCrudTest::testUpdateField()

Test the update of a field.

File

core/modules/field/src/Tests/FieldCrudTest.php, line 195
Contains \Drupal\field\Tests\FieldCrudTest.

Class

FieldCrudTest
Create field entities by attaching fields to entities.

Namespace

Drupal\field\Tests

Code

function testUpdateField() {
  entity_create('field_config', $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
    ->assertEqual($field
    ->isRequired(), $field_new
    ->isRequired(), '"required" change is saved');
  $this
    ->assertEqual($field
    ->getLabel(), $field_new
    ->getLabel(), '"label" change is saved');
  $this
    ->assertEqual($field
    ->getDescription(), $field_new
    ->getDescription(), '"description" change is saved');

  // TODO: test failures.
}