1.20.x field.test FieldCrudTestCase::testCreateFieldFail()

Test failure to create a field.

File

modules/field/tests/field.test, line 2297
Tests for field.module.

Class

FieldCrudTestCase

Code

function testCreateFieldFail() {
  $field_name = 'duplicate';
  $field_definition = array('field_name' => $field_name, 'type' => 'test_field', 'storage' => array('type' => 'field_test_storage_failure'));

  // The field does not appear in field_config.
  $config = config('field.field.' . $field_name);
  $this->assertTrue($config->isNew(), 'A field config file for the field does not exist.');

  // Try to create the field.
  try {
    field_create_field($field_definition);
    $this->assertTrue(FALSE, 'Field creation (correctly) fails.');
  }
  catch (Exception $e) {
    $this->assertTrue(TRUE, 'Field creation (correctly) fails.');
  }

  // The field should still not exist in config.
  $config = config('field.field.' . $field_name);
  $this->assertTrue($config->isNew(), 'A field config file for the field does not exist.');
}