diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-02-11 02:03:08 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-02-11 02:03:08 +0000 |
commit | 0c65a46b3ff62fefb9efb1e4324291b8cb33e1c8 (patch) | |
tree | 121e252066fea851515415183f00b47924d36c14 /engine/tests/api/entity_getter_functions.php | |
parent | a665ef2e94312ed5479c1e730d0d429c33c4dea8 (diff) | |
download | elgg-0c65a46b3ff62fefb9efb1e4324291b8cb33e1c8.tar.gz elgg-0c65a46b3ff62fefb9efb1e4324291b8cb33e1c8.tar.bz2 |
Refs #650. Deprecated get_annotations() for elgg_get_annotations().
git-svn-id: http://code.elgg.org/elgg/trunk@8109 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/tests/api/entity_getter_functions.php')
-rw-r--r-- | engine/tests/api/entity_getter_functions.php | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/engine/tests/api/entity_getter_functions.php b/engine/tests/api/entity_getter_functions.php index c2e7b8dd1..e3e265d21 100644 --- a/engine/tests/api/entity_getter_functions.php +++ b/engine/tests/api/entity_getter_functions.php @@ -227,6 +227,24 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest { return $r; } + /** + * Creates random annotations on $entity + * + * @param unknown_type $entity + * @param unknown_type $max + */ + public function createRandomAnnotations($entity, $max = 1) { + $annotations = array(); + for ($i=0; $i<$max; $i++) { + $name = 'test_annotation_name_' . rand(); + $value = rand(); + $id = create_annotation($entity->getGUID(), $name, $value, 'integer', $entity->getGUID()); + $annotations[] = get_annotation($id); + } + + return $annotations; + } + /*********************************** * TYPE TESTS @@ -2690,4 +2708,84 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest { } } } + + public function testElggGetAnnotationsAnnotationNames() { + $options = array('annotation_names' => array()); + $a_e_map = array(); + + // create test annotations on a few entities. + for ($i=0; $i<3; $i++) { + do { + $e = $this->entities[array_rand($this->entities)]; + } while(in_array($e->guid, $a_e_map)); + $annotations = $this->createRandomAnnotations($e); + + foreach($annotations as $a) { + $options['annotation_names'][] = $a->name; + $a_e_map[$a->id] = $e->guid; + } + } + + $as = elgg_get_annotations($options); + + $this->assertEqual(count($a_e_map), count($as)); + + foreach ($as as $a) { + $this->assertEqual($a_e_map[$a->id], $a->entity_guid); + } + } + + public function testElggGetAnnotationsAnnotationValues() { + $options = array('annotation_values' => array()); + $a_e_map = array(); + + // create test annotations on a few entities. + for ($i=0; $i<3; $i++) { + do { + $e = $this->entities[array_rand($this->entities)]; + } while(in_array($e->guid, $a_e_map)); + $annotations = $this->createRandomAnnotations($e); + + foreach($annotations as $a) { + $options['annotation_values'][] = $a->value; + $a_e_map[$a->id] = $e->guid; + } + } + + $as = elgg_get_annotations($options); + + $this->assertEqual(count($a_e_map), count($as)); + + foreach ($as as $a) { + $this->assertEqual($a_e_map[$a->id], $a->entity_guid); + } + } + + public function testElggGetAnnotationsAnnotationOwnerGuids() { + $options = array('annotation_owner_guids' => array()); + $a_e_map = array(); + + // create test annotations on a single entity + for ($i=0; $i<3; $i++) { + do { + $e = $this->entities[array_rand($this->entities)]; + } while(in_array($e->guid, $a_e_map)); + + // remove annotations left over from previous tests. + clear_annotations($e->guid); + $annotations = $this->createRandomAnnotations($e); + + foreach($annotations as $a) { + $options['annotation_owner_guids'][] = $e->guid; + $a_e_map[$a->id] = $e->guid; + } + } + + $as = elgg_get_annotations($options); + $this->assertEqual(count($a_e_map), count($as)); + + foreach ($as as $a) { + $this->assertEqual($a_e_map[$a->id], $a->owner_guid); + } + } } |