summaryrefslogtreecommitdiff
path: root/modules/field/field.test
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-08-10 21:19:42 +0000
committerDries Buytaert <dries@buytaert.net>2009-08-10 21:19:42 +0000
commit4a3dd058b5defa96eedec26fa22c4d332e71df49 (patch)
tree21a9112fcfc237c3838991401649df3baf30fe54 /modules/field/field.test
parent8b11e7eb6935678e299dd4bbb1bcaa6cb4dc2b7d (diff)
downloadbrdo-4a3dd058b5defa96eedec26fa22c4d332e71df49.tar.gz
brdo-4a3dd058b5defa96eedec26fa22c4d332e71df49.tar.bz2
- Patch #372330 by fgm, yched, et al: better validation of field names.
Diffstat (limited to 'modules/field/field.test')
-rw-r--r--modules/field/field.test87
1 files changed, 57 insertions, 30 deletions
diff --git a/modules/field/field.test b/modules/field/field.test
index 970b26c98..7b61a4410 100644
--- a/modules/field/field.test
+++ b/modules/field/field.test
@@ -1363,28 +1363,6 @@ class FieldCrudTestCase extends DrupalWebTestCase {
* Test the creation of a field.
*/
function testCreateField() {
- // Check that field type is required.
- try {
- $field_definition = array(
- 'field_name' => 'field_1',
- );
- 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_name' => 'field_2',
'type' => 'test_field',
@@ -1419,19 +1397,68 @@ class FieldCrudTestCase extends DrupalWebTestCase {
$this->pass(t('Cannot create two fields with the same name.'));
}
- // Check that invalid field names are rejected.
- $field_definition = array(
- 'field_name' => 'field_#',
- 'type' => 'test_field',
- );
+ // Check that field type is required.
try {
+ $field_definition = array(
+ 'field_name' => 'field_1',
+ );
+ 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.'));
+ }
+
+ // Check that field name must start with a letter or _.
+ try {
+ $field_definition = array(
+ 'field_name' => '2field_2',
+ 'type' => 'test_field',
+ );
+ field_create_field($field_definition);
+ $this->fail(t('Cannot create a field with a name starting with a digit.'));
+ }
+ catch (FieldException $e) {
+ $this->pass(t('Cannot create a field with a name starting with a digit.'));
+ }
+
+ // Check that field name must only contain lowercase alphanumeric or _.
+ try {
+ $field_definition = array(
+ 'field_name' => 'field#_3',
+ 'type' => 'test_field',
+ );
+ field_create_field($field_definition);
+ $this->fail(t('Cannot create a field with a name containing an illegal character.'));
+ }
+ catch (FieldException $e) {
+ $this->pass(t('Cannot create a field with a name containing an illegal character.'));
+ }
+
+ // Check that field name cannot be longer than 32 characters long.
+ try {
+ $field_definition = array(
+ 'field_name' => '_12345678901234567890123456789012',
+ 'type' => 'test_field',
+ );
field_create_field($field_definition);
- $this->fail(t('Cannot create a field with an invalid name.'));
+ $this->fail(t('Cannot create a field with a name longer than 32 characters.'));
}
catch (FieldException $e) {
- $this->pass(t('Cannot create a field with an invalid name.'));
+ $this->pass(t('Cannot create a field with a name longer than 32 characters.'));
}
- // TODO : other failures
}
/**