diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-09-11 06:03:12 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-09-11 06:03:12 +0000 |
commit | b06d19e34957bd3e719dfcff9e6d180ea95330e5 (patch) | |
tree | 495a089976fe40c9cf2389066e3fafbb0d2381ab /modules/field/tests | |
parent | f096a70e67a75e30dafd3e15448b579bfb1909c2 (diff) | |
download | brdo-b06d19e34957bd3e719dfcff9e6d180ea95330e5.tar.gz brdo-b06d19e34957bd3e719dfcff9e6d180ea95330e5.tar.bz2 |
#629484 by Amitaibu, fago, et al: Added Add entity 'label' key info (e.g. title on node).
Diffstat (limited to 'modules/field/tests')
-rw-r--r-- | modules/field/tests/field.test | 48 | ||||
-rw-r--r-- | modules/field/tests/field_test.entity.inc | 47 | ||||
-rw-r--r-- | modules/field/tests/field_test.install | 7 | ||||
-rw-r--r-- | modules/field/tests/field_test.module | 13 |
4 files changed, 114 insertions, 1 deletions
diff --git a/modules/field/tests/field.test b/modules/field/tests/field.test index 479b0a966..e865ac22d 100644 --- a/modules/field/tests/field.test +++ b/modules/field/tests/field.test @@ -2988,3 +2988,51 @@ class FieldBulkDeleteTestCase extends FieldTestCase { $this->assertEqual(count($fields), 0, 'The field is purged.'); } } + +/** + * Tests entity properties. + */ +class EntityPropertiesTestCase extends FieldTestCase { + public static function getInfo() { + return array( + 'name' => 'Entity properties', + 'description'=> 'Tests entity properties.', + 'group' => 'Entity API', + ); + } + + function setUp() { + parent::setUp('field_test'); + } + + /** + * Tests label key and label callback of an entity. + */ + function testEntityLabel() { + $entity_types = array( + 'test_entity_no_label', + 'test_entity_label', + 'test_entity_label_callback', + ); + + $entity = field_test_create_stub_entity(); + + foreach ($entity_types as $entity_type) { + $label = entity_label($entity_type, $entity); + + switch ($entity_type) { + case 'test_entity_no_label': + $this->assertFalse($label, 'Entity with no label property or callback returned FALSE.'); + break; + + case 'test_entity_label': + $this->assertEqual($label, $entity->ftlabel, 'Entity with label key returned correct label.'); + break; + + case 'test_entity_label_callback': + $this->assertEqual($label, 'label callback ' . $entity->ftlabel, 'Entity with label callback returned correct label.'); + break; + } + } + } +} diff --git a/modules/field/tests/field_test.entity.inc b/modules/field/tests/field_test.entity.inc index b7887c812..149c09a2c 100644 --- a/modules/field/tests/field_test.entity.inc +++ b/modules/field/tests/field_test.entity.inc @@ -73,6 +73,48 @@ function field_test_entity_info() { 'bundles' => array('test_entity_2' => array('label' => 'Test entity 2')), 'view modes' => $test_entity_modes, ), + // @see EntityPropertiesTestCase::testEntityLabel() + 'test_entity_no_label' => array( + 'name' => t('Test entity without label'), + 'fieldable' => TRUE, + 'field cache' => FALSE, + 'base table' => 'test_entity', + 'entity keys' => array( + 'id' => 'ftid', + 'revision' => 'ftvid', + 'bundle' => 'fttype', + ), + 'bundles' => $bundles, + 'view modes' => $test_entity_modes, + ), + 'test_entity_label' => array( + 'name' => t('Test entity label'), + 'fieldable' => TRUE, + 'field cache' => FALSE, + 'base table' => 'test_entity', + 'entity keys' => array( + 'id' => 'ftid', + 'revision' => 'ftvid', + 'bundle' => 'fttype', + 'label' => 'ftlabel', + ), + 'bundles' => $bundles, + 'view modes' => $test_entity_modes, + ), + 'test_entity_label_callback' => array( + 'name' => t('Test entity label callback'), + 'fieldable' => TRUE, + 'field cache' => FALSE, + 'base table' => 'test_entity', + 'label callback' => 'field_test_entity_label_callback', + 'entity keys' => array( + 'id' => 'ftid', + 'revision' => 'ftvid', + 'bundle' => 'fttype', + ), + 'bundles' => $bundles, + 'view modes' => $test_entity_modes, + ), ); } @@ -163,7 +205,7 @@ function field_test_delete_bundle($bundle) { /** * Creates a basic test_entity entity. */ -function field_test_create_stub_entity($id = 1, $vid = 1, $bundle = 'test_bundle') { +function field_test_create_stub_entity($id = 1, $vid = 1, $bundle = 'test_bundle', $label = '') { $entity = new stdClass(); // Only set id and vid properties if they don't come as NULL (creation form). if (isset($id)) { @@ -174,6 +216,9 @@ function field_test_create_stub_entity($id = 1, $vid = 1, $bundle = 'test_bundle } $entity->fttype = $bundle; + $label = !empty($label) ? $label : $bundle . ' label'; + $entity->ftlabel = $label; + return $entity; } diff --git a/modules/field/tests/field_test.install b/modules/field/tests/field_test.install index d4937b620..268d271c7 100644 --- a/modules/field/tests/field_test.install +++ b/modules/field/tests/field_test.install @@ -44,6 +44,13 @@ function field_test_schema() { 'not null' => TRUE, 'default' => '', ), + 'ftlabel' => array( + 'description' => 'The label of this test_entity.', + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + ), ), 'unique keys' => array( 'ftvid' => array('ftvid'), diff --git a/modules/field/tests/field_test.module b/modules/field/tests/field_test.module index f615129ff..5adc3a4c1 100644 --- a/modules/field/tests/field_test.module +++ b/modules/field/tests/field_test.module @@ -214,3 +214,16 @@ function field_test_dummy_field_storage_query(EntityFieldQuery $query) { ), ); } + +/** + * Entity label callback. + * + * @param $entity + * The entity object. + * + * @return + * The label of the entity prefixed with "label callback". + */ +function field_test_entity_label_callback($entity) { + return 'label callback ' . $entity->ftlabel; +} |