aboutsummaryrefslogtreecommitdiff
path: root/engine/tests/api
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-02-24 02:20:15 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-02-24 02:20:15 +0000
commitd15b5098d14bb2a3f8f887b5e68f174928f0d0a4 (patch)
tree61afe6d9ae4b73458a22b3c51e9cbfe419e1d8fa /engine/tests/api
parent66d12dbe4e14e36f8ab1c8014be0665cf8ee17c7 (diff)
downloadelgg-d15b5098d14bb2a3f8f887b5e68f174928f0d0a4.tar.gz
elgg-d15b5098d14bb2a3f8f887b5e68f174928f0d0a4.tar.bz2
Fixes #1542: Pulled in Kevin's patch to add ability to sort by metadata. Added unit tests for this.
git-svn-id: http://code.elgg.org/elgg/trunk@3970 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/tests/api')
-rw-r--r--engine/tests/api/entity_getter_functions.php120
1 files changed, 120 insertions, 0 deletions
diff --git a/engine/tests/api/entity_getter_functions.php b/engine/tests/api/entity_getter_functions.php
index 04fa3e4e5..49fd4ec0d 100644
--- a/engine/tests/api/entity_getter_functions.php
+++ b/engine/tests/api/entity_getter_functions.php
@@ -1610,4 +1610,124 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest {
}
}
}
+
+ function testElggApiGettersEntityMetadataNVPOrderByMDText() {
+ $subtypes = $this->getRandomValidSubtypes(array('object'), 1);
+ $subtype = $subtypes[0];
+ $md_name = 'test_metadata_name_' . rand();
+ $md_value = 2;
+ $guids = array();
+ $valid_guids = array();
+
+ // our targets
+ $valid = new ElggObject();
+ $valid->subtype = $subtype;
+ $valid->$md_name = $md_value;
+ $valid->save();
+ $guids[] = $valid->getGUID();
+ $valid_guids[] = $valid->getGUID();
+
+ $valid2 = new ElggObject();
+ $valid2->subtype = $subtype;
+ $valid2->$md_name = 3;
+ $valid2->save();
+ $guids[] = $valid->getGUID();
+ $valid_guids[] = $valid2->getGUID();
+
+ $valid3 = new ElggObject();
+ $valid3->subtype = $subtype;
+ $valid3->$md_name = 1;
+ $valid3->save();
+ $guids[] = $valid->getGUID();
+ $valid_guids[] = $valid3->getGUID();
+
+ $md_valid_values = array($md_value, $md_value2);
+
+ $options = array(
+ 'type' => 'object',
+ 'subtype' => $subtype,
+ //'metadata_name' => $md_name,
+ 'order_by_metadata' => array('name' => $md_name, 'as' => 'integer')
+ );
+
+ $entities = elgg_get_entities_from_metadata($options);
+
+ $this->assertIsa($entities, 'array');
+ $this->assertEqual(count($entities), 3);
+
+ $i = 1;
+ foreach ($entities as $entity) {
+ $this->assertTrue(in_array($entity->getGUID(), $valid_guids));
+ $this->assertEqual($entity->$md_name, $i);
+ $i++;
+ $entity->delete();
+ }
+
+ foreach ($guids as $guid) {
+ if ($e = get_entity($guid)) {
+ $e->delete();
+ }
+ }
+ }
+
+ function testElggApiGettersEntityMetadataNVPOrderByMDString() {
+ $subtypes = $this->getRandomValidSubtypes(array('object'), 1);
+ $subtype = $subtypes[0];
+ $md_name = 'test_metadata_name_' . rand();
+ $md_value = 'b';
+ $guids = array();
+ $valid_guids = array();
+
+ // our targets
+ $valid = new ElggObject();
+ $valid->subtype = $subtype;
+ $valid->$md_name = $md_value;
+ $valid->save();
+ $guids[] = $valid->getGUID();
+ $valid_guids[] = $valid->getGUID();
+
+ $valid2 = new ElggObject();
+ $valid2->subtype = $subtype;
+ $valid2->$md_name = 'c';
+ $valid2->save();
+ $guids[] = $valid->getGUID();
+ $valid_guids[] = $valid2->getGUID();
+
+ $valid3 = new ElggObject();
+ $valid3->subtype = $subtype;
+ $valid3->$md_name = 'a';
+ $valid3->save();
+ $guids[] = $valid->getGUID();
+ $valid_guids[] = $valid3->getGUID();
+
+ $md_valid_values = array($md_value, $md_value2);
+
+ $options = array(
+ 'type' => 'object',
+ 'subtype' => $subtype,
+ 'metadata_name' => $md_name,
+ 'order_by_metadata' => array('name' => $md_name, 'as' => 'text')
+ );
+
+ $entities = elgg_get_entities_from_metadata($options);
+
+ $this->assertIsa($entities, 'array');
+ $this->assertEqual(count($entities), 3);
+
+ $alpha = array('a', 'b', 'c');
+
+ $i = 0;
+ foreach ($entities as $entity) {
+ $this->assertTrue(in_array($entity->getGUID(), $valid_guids));
+ $this->assertEqual($entity->$md_name, $alpha[$i]);
+ $i++;
+ $entity->delete();
+ }
+
+ foreach ($guids as $guid) {
+ if ($e = get_entity($guid)) {
+ $e->delete();
+ }
+ }
+ }
}