You are here

function FieldSqlNoRevisionsTestCase::testFieldUpdateFailure in Field SQL norevisions 7.2

Same name and namespace in other branches
  1. 7 field_sql_norevisions.test \FieldSqlNoRevisionsTestCase::testFieldUpdateFailure()

Test that failure to create fields is handled gracefully.

File

./field_sql_norevisions.test, line 286
Tests for field_sql_norevisions.module.

Class

FieldSqlNoRevisionsTestCase
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_norevisions_schema($prior_field) as $table_name => $table_info) {
    $this
      ->assertTrue(db_table_exists($table_name), t('Table %table exists.', array(
      '%table' => $table_name,
    )));
  }
}