diff options
Diffstat (limited to 'engine/tests/api/entity_getter_functions.php')
-rw-r--r-- | engine/tests/api/entity_getter_functions.php | 189 |
1 files changed, 188 insertions, 1 deletions
diff --git a/engine/tests/api/entity_getter_functions.php b/engine/tests/api/entity_getter_functions.php index faa91db34..f193fda41 100644 --- a/engine/tests/api/entity_getter_functions.php +++ b/engine/tests/api/entity_getter_functions.php @@ -2168,7 +2168,7 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest { ); $es = elgg_get_entities_from_relationship($options); - + $this->assertTrue(empty($es)); foreach ($guids as $guid) { @@ -2176,4 +2176,191 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest { $e->delete(); } } + + public function testElggApiGettersEntitySiteSingular() { + global $CONFIG; + + $guids = array(); + + $obj1 = new ElggObject(); + $obj1->test_md = 'test'; + // luckily this is never checked. + $obj1->site_guid = 2; + $obj1->save(); + $guids[] = $obj1->guid; + $right_guid = $obj1->guid; + + $obj2 = new ElggObject(); + $obj2->test_md = 'test'; + $obj2->site_guid = $CONFIG->site->guid; + $obj2->save(); + $guids[] = $obj2->guid; + + $options = array( + 'metadata_name' => 'test_md', + 'metadata_value' => 'test', + 'site_guid' => 2 + ); + + $es = elgg_get_entities_from_metadata($options); + $this->assertTrue(is_array($es)); + $this->assertEqual(1, count($es)); + $this->assertEqual($right_guid, $es[0]->guid); + + foreach ($guids as $guid) { + get_entity($guid)->delete(); + } + } + + public function testElggApiGettersEntitySiteSingularAny() { + global $CONFIG; + + $guids = array(); + + $obj1 = new ElggObject(); + $obj1->test_md = 'test'; + // luckily this is never checked. + $obj1->site_guid = 2; + $obj1->save(); + $guids[] = $obj1->guid; + + $obj2 = new ElggObject(); + $obj2->test_md = 'test'; + $obj2->site_guid = $CONFIG->site->guid; + $obj2->save(); + $guids[] = $obj2->guid; + + $options = array( + 'metadata_name' => 'test_md', + 'metadata_value' => 'test', + 'site_guid' => ELGG_ENTITIES_ANY_VALUE, + 'limit' => 2, + 'order_by' => 'e.guid DESC' + ); + + $es = elgg_get_entities_from_metadata($options); + $this->assertTrue(is_array($es)); + $this->assertEqual(2, count($es)); + + foreach ($es as $e) { + $this->assertTrue(in_array($e->guid, $guids)); + } + + foreach ($guids as $guid) { + get_entity($guid)->delete(); + } + } + + public function testElggApiGettersEntitySitePlural() { + global $CONFIG; + + $guids = array(); + + $obj1 = new ElggObject(); + $obj1->test_md = 'test'; + // luckily this is never checked. + $obj1->site_guid = 2; + $obj1->save(); + $guids[] = $obj1->guid; + + $obj2 = new ElggObject(); + $obj2->test_md = 'test'; + $obj2->site_guid = $CONFIG->site->guid; + $obj2->save(); + $guids[] = $obj2->guid; + + $options = array( + 'metadata_name' => 'test_md', + 'metadata_value' => 'test', + 'site_guids' => array($CONFIG->site->guid, 2), + 'limit' => 2, + 'order_by' => 'e.guid DESC' + ); + + $es = elgg_get_entities_from_metadata($options); + $this->assertTrue(is_array($es)); + $this->assertEqual(2, count($es)); + + foreach ($es as $e) { + $this->assertTrue(in_array($e->guid, $guids)); + } + + foreach ($guids as $guid) { + get_entity($guid)->delete(); + } + } + + public function testElggApiGettersEntitySitePluralSomeInvalid() { + global $CONFIG; + + $guids = array(); + + $obj1 = new ElggObject(); + $obj1->test_md = 'test'; + // luckily this is never checked. + $obj1->site_guid = 2; + $obj1->save(); + $guids[] = $obj1->guid; + + $obj2 = new ElggObject(); + $obj2->test_md = 'test'; + $obj2->save(); + $guids[] = $obj2->guid; + $right_guid = $obj2->guid; + + $options = array( + 'metadata_name' => 'test_md', + 'metadata_value' => 'test', + // just created the first entity so nothing will be "sited" by it. + 'site_guids' => array($CONFIG->site->guid, $guids[0]), + 'limit' => 2, + 'order_by' => 'e.guid DESC' + ); + + $es = elgg_get_entities_from_metadata($options); + + $this->assertTrue(is_array($es)); + $this->assertEqual(1, count($es)); + $this->assertEqual($es[0]->guid, $right_guid); + + foreach ($guids as $guid) { + get_entity($guid)->delete(); + } + } + + public function testElggApiGettersEntitySitePluralAllInvalid() { + global $CONFIG; + + $guids = array(); + + $obj1 = new ElggObject(); + $obj1->test_md = 'test'; + // luckily this is never checked. + $obj1->site_guid = 2; + $obj1->save(); + $guids[] = $obj1->guid; + + $obj2 = new ElggObject(); + $obj2->test_md = 'test'; + $obj2->save(); + $guids[] = $obj2->guid; + $right_guid = $obj2->guid; + + $options = array( + 'metadata_name' => 'test_md', + 'metadata_value' => 'test', + // just created the first entity so nothing will be "sited" by it. + 'site_guids' => array($guids[0], $guids[1]), + 'limit' => 2, + 'order_by' => 'e.guid DESC' + ); + + $es = elgg_get_entities_from_metadata($options); + + $this->assertTrue(empty($es)); + + foreach ($guids as $guid) { + get_entity($guid)->delete(); + } + } } |