diff options
Diffstat (limited to 'engine/tests/objects/objects.php')
| -rw-r--r-- | engine/tests/objects/objects.php | 102 |
1 files changed, 97 insertions, 5 deletions
diff --git a/engine/tests/objects/objects.php b/engine/tests/objects/objects.php index 55734be13..263ab2414 100644 --- a/engine/tests/objects/objects.php +++ b/engine/tests/objects/objects.php @@ -41,8 +41,8 @@ class ElggCoreObjectTest extends ElggCoreUnitTest { $attributes['guid'] = NULL; $attributes['type'] = 'object'; $attributes['subtype'] = NULL; - $attributes['owner_guid'] = get_loggedin_userid(); - $attributes['container_guid'] = get_loggedin_userid(); + $attributes['owner_guid'] = elgg_get_logged_in_user_guid(); + $attributes['container_guid'] = elgg_get_logged_in_user_guid(); $attributes['site_guid'] = NULL; $attributes['access_id'] = ACCESS_PRIVATE; $attributes['time_created'] = NULL; @@ -87,11 +87,11 @@ class ElggCoreObjectTest extends ElggCoreUnitTest { public function testElggObjectLoad() { // fail on wrong type try { - $error = new ElggObjectTest(get_loggedin_userid()); + $error = new ElggObjectTest(elgg_get_logged_in_user_guid()); $this->assertTrue(FALSE); } catch (Exception $e) { $this->assertIsA($e, 'InvalidClassException'); - $message = sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), get_loggedin_userid(), 'ElggObject'); + $message = sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), elgg_get_logged_in_user_guid(), 'ElggObject'); $this->assertIdentical($e->getMessage(), $message); } } @@ -144,7 +144,7 @@ class ElggCoreObjectTest extends ElggCoreUnitTest { } public function testElggObjectContainer() { - $this->assertEqual($this->entity->getContainerGUID(), get_loggedin_userid()); + $this->assertEqual($this->entity->getContainerGUID(), elgg_get_logged_in_user_guid()); // create and save to group $group = new ElggGroup(); @@ -194,7 +194,99 @@ class ElggCoreObjectTest extends ElggCoreUnitTest { $old = elgg_set_ignore_access(true); } + // see https://github.com/elgg/elgg/issues/1196 + public function testElggEntityRecursiveDisableWhenLoggedOut() { + $e1 = new ElggObject(); + $e1->access_id = ACCESS_PUBLIC; + $e1->owner_guid = 0; + $e1->container_guid = 0; + $e1->save(); + $guid1 = $e1->getGUID(); + + $e2 = new ElggObject(); + $e2->container_guid = $guid1; + $e2->access_id = ACCESS_PUBLIC; + $e2->owner_guid = 0; + $e2->save(); + $guid2 = $e2->getGUID(); + + // fake being logged out + $user = $_SESSION['user']; + unset($_SESSION['user']); + $ia = elgg_set_ignore_access(true); + + $this->assertTrue(disable_entity($guid1, null, true)); + + // "log in" original user + $_SESSION['user'] = $user; + elgg_set_ignore_access($ia); + + $this->assertFalse(get_entity($guid1)); + $this->assertFalse(get_entity($guid2)); + + $db_prefix = get_config('dbprefix'); + $q = "SELECT * FROM {$db_prefix}entities WHERE guid = $guid1"; + $r = get_data_row($q); + $this->assertEqual('no', $r->enabled); + + $q = "SELECT * FROM {$db_prefix}entities WHERE guid = $guid2"; + $r = get_data_row($q); + $this->assertEqual('no', $r->enabled); + + access_show_hidden_entities(true); + delete_entity($guid1); + delete_entity($guid2); + access_show_hidden_entities(false); + } + + public function testElggRecursiveDelete() { + $types = array('ElggGroup', 'ElggObject', 'ElggUser', 'ElggSite'); + $db_prefix = elgg_get_config('dbprefix'); + + foreach ($types as $type) { + $parent = new $type(); + $this->assertTrue($parent->save()); + + $child = new ElggObject(); + $child->container_guid = $parent->guid; + $this->assertTrue($child->save()); + + $grandchild = new ElggObject(); + $grandchild->container_guid = $child->guid; + $this->assertTrue($grandchild->save()); + + $this->assertTrue($parent->delete(true)); + + $q = "SELECT * FROM {$db_prefix}entities WHERE guid = $parent->guid"; + $r = get_data($q); + $this->assertFalse($r); + + $q = "SELECT * FROM {$db_prefix}entities WHERE guid = $child->guid"; + $r = get_data($q); + $this->assertFalse($r); + $q = "SELECT * FROM {$db_prefix}entities WHERE guid = $grandchild->guid"; + $r = get_data($q); + $this->assertFalse($r); + } + + // object that owns itself + // can't check container_guid because of infinite loops in can_edit_entity() + $obj = new ElggObject(); + $obj->save(); + $obj->owner_guid = $obj->guid; + $obj->save(); + + $q = "SELECT * FROM {$db_prefix}entities WHERE guid = $obj->guid"; + $r = get_data_row($q); + $this->assertEqual($obj->guid, $r->owner_guid); + + $this->assertTrue($obj->delete(true)); + + $q = "SELECT * FROM {$db_prefix}entities WHERE guid = $obj->guid"; + $r = get_data_row($q); + $this->assertFalse($r); + } protected function get_object_row($guid) { global $CONFIG; |
