diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-01-30 02:22:01 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-01-30 02:22:01 +0000 |
commit | e5f48f0f780ac0ea08ecbf31c85f9bcdc80147ac (patch) | |
tree | 53338c4beb77d716f2905f0212883cc07af98ba0 /modules/field/tests | |
parent | 02c1eeee3fc904ecc7845902cc11ba545dd9466b (diff) | |
download | brdo-e5f48f0f780ac0ea08ecbf31c85f9bcdc80147ac.tar.gz brdo-e5f48f0f780ac0ea08ecbf31c85f9bcdc80147ac.tar.bz2 |
#680910 by yched and bjaspan: Allow fields to be restricted to entity types.
Diffstat (limited to 'modules/field/tests')
-rw-r--r-- | modules/field/tests/field.test | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/modules/field/tests/field.test b/modules/field/tests/field.test index 3052af9ad..94c94afd7 100644 --- a/modules/field/tests/field.test +++ b/modules/field/tests/field.test @@ -2297,7 +2297,6 @@ class FieldInstanceCrudTestCase extends FieldTestCase { $this->instance_definition = array( 'field_name' => $this->field['field_name'], 'object_type' => 'test_entity', - 'object_type' => 'test_entity', 'bundle' => 'test_bundle', ); } @@ -2355,6 +2354,39 @@ class FieldInstanceCrudTestCase extends FieldTestCase { $this->pass(t('Cannot create an instance of a non-existing field.')); } + // Create a field restricted to a specific entity type. + $field_restricted = array( + 'field_name' => drupal_strtolower($this->randomName()), + 'type' => 'test_field', + 'object_types' => array('test_cacheable_entity'), + ); + field_create_field($field_restricted); + + // Check that an instance can be added to an object type allowed + // by the field. + try { + $instance = $this->instance_definition; + $instance['field_name'] = $field_restricted['field_name']; + $instance['object_type'] = 'test_cacheable_entity'; + field_create_instance($instance); + $this->pass(t('Can create an instance on a object type allowed by the field.')); + } + catch (FieldException $e) { + $this->fail(t('Can create an instance on a object type allowed by the field.')); + } + + // Check that an instance cannot be added to an object type + // forbidden by the field. + try { + $instance = $this->instance_definition; + $instance['field_name'] = $field_restricted['field_name']; + field_create_instance($instance); + $this->fail(t('Cannot create an instance on a object type forbidden by the field.')); + } + catch (FieldException $e) { + $this->pass(t('Cannot create an instance on a object type forbidden by the field.')); + } + // TODO: test other failures. } |