Test failure to create a field.
function testCreateFieldFail() {
$field_name = 'duplicate';
$field_definition = array(
'field_name' => $field_name,
'type' => 'test_field',
'storage' => array(
'type' => 'field_test_storage_failure',
),
);
$field = entity_load('field_entity', $field_name);
// The field does not exist.
$this
->assertFalse($field, 'The field does not exist.');
// Try to create the field.
try {
$field = field_create_field($field_definition);
$this
->assertTrue(FALSE, 'Field creation (correctly) fails.');
} catch (\Exception $e) {
$this
->assertTrue(TRUE, 'Field creation (correctly) fails.');
}
// The field does not exist.
$field = entity_load('field_entity', $field_name);
$this
->assertFalse($field, 'The field does not exist.');
}