function FieldSqlStorageTestCase::testFieldUpdateFailure

7.x field_sql_storage.test FieldSqlStorageTestCase::testFieldUpdateFailure()

Test that failure to create fields is handled gracefully.

File

drupal-7.x/modules/field/modules/field_sql_storage/field_sql_storage.test, line 311
Tests for field_sql_storage.module.

Class

FieldSqlStorageTestCase
Tests field storage.

Code

function testFieldUpdateFailure() {
  // Create a text field.
  $field = array('field_name' => 'test_text', 'type' => 'text', 'settings' => array('max_length' => 255));
  $field = field_create_field($field);

  // Attempt to update the field in a way that would break the storage.
  $prior_field = $field;
  $field['settings']['max_length'] = -1;
  try {
    field_update_field($field);
    $this->fail(t('Update succeeded.'));
  }
  catch (Exception $e) {
    $this->pass(t('Update properly failed.'));
  }

  // Ensure that the field tables are still there.
  foreach (_field_sql_storage_schema($prior_field) as $table_name => $table_info) {
    $this->assertTrue(db_table_exists($table_name), format_string('Table %table exists.', array('%table' => $table_name)));
  }
}