Commit 243ecdaf authored by webchick's avatar webchick

#394246 by flobruit: Check to ensure that field type is specified.

parent 9f7aaa23
...@@ -178,6 +178,10 @@ function field_create_field($field) { ...@@ -178,6 +178,10 @@ function field_create_field($field) {
if (empty($field['field_name'])) { if (empty($field['field_name'])) {
throw new FieldException('Attempt to create an unnamed field.'); throw new FieldException('Attempt to create an unnamed field.');
} }
// Field type is required.
if (empty($field['type'])) {
throw new FieldException('Attempt to create a field with no type.');
}
// Field name cannot contain invalid characters. // Field name cannot contain invalid characters.
if (preg_match('/[^a-z0-9_]/', $field['field_name'])) { if (preg_match('/[^a-z0-9_]/', $field['field_name'])) {
throw new FieldException('Attempt to create a field with invalid characters. Only alphanumeric characters and underscores are allowed.'); throw new FieldException('Attempt to create a field with invalid characters. Only alphanumeric characters and underscores are allowed.');
......
...@@ -939,6 +939,26 @@ class FieldTestCase extends DrupalWebTestCase { ...@@ -939,6 +939,26 @@ class FieldTestCase extends DrupalWebTestCase {
* Test the creation of a field. * Test the creation of a field.
*/ */
function testCreateField() { function testCreateField() {
// Check that field type is required.
try {
$field_definition = array(
'field_name' => drupal_strtolower($this->randomName()),
);
field_create_field($field_definition);
$this->fail(t('Cannot create a field with no type.'));
} catch (FieldException $e) {
$this->pass(t('Cannot create a field with no type.'));
}
// Check that field name is required.
try {
$field_definition = array('type' => 'test_field');
field_create_field($field_definition);
$this->fail(t('Cannot create an unnamed field.'));
} catch (FieldException $e) {
$this->pass(t('Cannot create an unnamed field.'));
}
$field_definition = array( $field_definition = array(
'field_name' => drupal_strtolower($this->randomName()), 'field_name' => drupal_strtolower($this->randomName()),
'type' => 'test_field', 'type' => 'test_field',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment