function FieldSqlStorageTest::testFieldUpdateFailure

Test that failure to create fields is handled gracefully.

File

drupal/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php, line 328
Definition of Drupal\field_sql_storage\FieldSqlStorageTest.

Class

FieldSqlStorageTest
Tests field storage.

Namespace

Drupal\field_sql_storage\Tests

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), t('Table %table exists.', array(
      '%table' => $table_name,
    )));
  }
}