You are here

function FieldSqlStorageTestCase::testUpdateFieldSchemaWithData in Drupal 7

Test trying to update a field with data.

File

modules/field/modules/field_sql_storage/field_sql_storage.test, line 350
Tests for field_sql_storage.module.

Class

FieldSqlStorageTestCase
Tests field storage.

Code

function testUpdateFieldSchemaWithData() {

  // Create a decimal 5.2 field and add some data.
  $field = array(
    'field_name' => 'decimal52',
    'type' => 'number_decimal',
    'settings' => array(
      'precision' => 5,
      'scale' => 2,
    ),
  );
  $field = field_create_field($field);
  $instance = array(
    'field_name' => 'decimal52',
    'entity_type' => 'test_entity',
    'bundle' => 'test_bundle',
  );
  $instance = field_create_instance($instance);
  $entity = field_test_create_stub_entity(0, 0, $instance['bundle']);
  $entity->decimal52[LANGUAGE_NONE][0]['value'] = '1.235';
  field_attach_insert('test_entity', $entity);

  // Attempt to update the field in a way that would work without data.
  $field['settings']['scale'] = 3;
  try {
    field_update_field($field);
    $this
      ->fail(t('Cannot update field schema with data.'));
  } catch (FieldException $e) {
    $this
      ->pass(t('Cannot update field schema with data.'));
  }
}