1 field_ui.test FieldUIManageFieldsTestCase::testDeleteField()

Tests that deletion removes fields and instances as expected.

File

core/modules/field_ui/tests/field_ui.test, line 421
Tests for field_ui.module.

Class

FieldUIManageFieldsTestCase
Tests the functionality of the 'Manage fields' screen.

Code

function testDeleteField() {
  // Create a new field.
  $bundle_path1 = 'admin/structure/types/manage/' . $this->hyphen_type;
  $edit1 = array(
    'fields[_add_new_field][label]' => $this->field_label,
    'fields[_add_new_field][field_name]' => $this->field_name_input,
  );
  $this->fieldUIAddNewField($bundle_path1, $edit1);

  // Add an instance to the user entity.
  $bundle_path2 = 'admin/config/people/manage';
  $bundle_name2 = 'user';
  $bundle_label2 = entity_get_info('user')['bundles'][$bundle_name2]['label'];
  $edit2 = array(
    'fields[_add_existing_field][label]' => $this->field_label,
    'fields[_add_existing_field][field_name]' => $this->field_name,
  );
  $this->fieldUIAddExistingField($bundle_path2, $edit2);

  // Make sure the Delete Field button works on the content type.
  $this->backdropPost($bundle_path1 . '/fields/' . $this->field_name, array(), 'Delete field');
  $this->assertResponse(200);

  // Delete the first instance.
  $this->fieldUIDeleteField($bundle_path1, $this->field_name, $this->field_label, $this->type);

  // Reset the fields info.
  _field_info_collate_fields_reset();
  // Check that the field instance was deleted.
  $this->assertNull(field_info_instance('node', $this->field_name, $this->type), 'Field instance was deleted.');
  // Check that the field was not deleted
  $this->assertNotNull(field_info_field($this->field_name), 'Field was not deleted.');

  // Make sure the Delete Field button works on the user entity.
  $this->backdropPost($bundle_path2 . '/fields/' . $this->field_name, array(), 'Delete field');
  $this->assertResponse(200);

  // Delete the second instance.
  $this->fieldUIDeleteField($bundle_path2, $this->field_name, $this->field_label, $bundle_label2);

  // Reset the fields info.
  _field_info_collate_fields_reset();
  // Check that the field instance was deleted.
  $this->assertNull(field_info_instance('user', $this->field_name, $bundle_name2), 'Field instance was deleted.');
  // Check that the field was deleted too.
  $this->assertNull(field_info_field($this->field_name), 'Field was deleted.');
}