From 21e808b132b47baf9d525650349ae276d4d751ec Mon Sep 17 00:00:00 2001 From: Brett Profitt Date: Sun, 2 Oct 2011 19:00:07 -0700 Subject: Merged test for can_write_to_container(). --- engine/tests/regression/trac_bugs.php | 87 +++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) (limited to 'engine/tests/regression/trac_bugs.php') diff --git a/engine/tests/regression/trac_bugs.php b/engine/tests/regression/trac_bugs.php index 6f98c67bd..23d6d1dc6 100644 --- a/engine/tests/regression/trac_bugs.php +++ b/engine/tests/regression/trac_bugs.php @@ -112,4 +112,91 @@ class ElggCoreRegressionBugsTest extends ElggCoreUnitTest { $this->assertEqual($params['xoffset'], $options['x1']); $this->assertEqual($params['yoffset'], $options['y1']); } + + // #3722 Check canEdit() works for contains regardless of groups + function test_can_write_to_container() { + $user = new ElggUser(); + $user->username = 'test_user_' . rand(); + $user->name = 'test_user_name_' . rand(); + $user->email = 'test@user.net'; + $user->container_guid = 0; + $user->owner_guid = 0; + $user->save(); + + $object = new ElggObject(); + $object->save(); + + $group = new ElggGroup(); + $group->save(); + + // disable access overrides because we're admin. + $ia = elgg_set_ignore_access(false); + + $this->assertFalse(can_write_to_container($user->guid, $object->guid)); + + global $elgg_test_user; + $elgg_test_user = $user; + + // register hook to allow access + function can_write_to_container_test_hook($hook, $type, $value, $params) { + global $elgg_test_user; + + if ($params['user']->getGUID() == $elgg_test_user->getGUID()) { + return true; + } + } + + register_plugin_hook('container_permissions_check', 'all', 'can_write_to_container_test_hook'); + $this->assertTrue(can_write_to_container($user->guid, $object->guid)); + unregister_plugin_hook('container_permissions_check', 'all', 'can_write_to_container_test_hook'); + + $this->assertFalse(can_write_to_container($user->guid, $group->guid)); + $group->join($user); + $this->assertTrue(can_write_to_container($user->guid, $group->guid)); + + elgg_set_ignore_access($ia); + + $user->delete(); + $object->delete(); + $group->delete(); + } + + function test_db_shutdown_links() { + global $DB_DELAYED_QUERIES, $test_results; + $DB_DELAYED_QUERIES = array(); + + function test_delayed_results($results) { + global $test_results; + $test_results = $results; + } + + $q = 'SELECT 1 as test'; + + $links = array('read', 'write', get_db_link('read'), get_db_link('write')); + + foreach ($links as $link) { + $DB_DELAYED_QUERIES = array(); + + $result = execute_delayed_query($q, $link, 'test_delayed_results'); + + $this->assertTrue($result, "Failed with link = $link"); + $this->assertEqual(count($DB_DELAYED_QUERIES), 1); + $this->assertEqual($DB_DELAYED_QUERIES[0]['q'], $q); + $this->assertEqual($DB_DELAYED_QUERIES[0]['l'], $link); + $this->assertEqual($DB_DELAYED_QUERIES[0]['h'], 'test_delayed_results'); + + db_delayedexecution_shutdown_hook(); + + $num_rows = mysql_num_rows($test_results); + $this->assertEqual($num_rows, 1); + $row = mysql_fetch_assoc($test_results); + $this->assertEqual($row['test'], 1); + } + + // test bad case + $DB_DELAYED_QUERIES = array(); + $result = execute_delayed_query($q, 'not_a_link', 'test_delayed_results'); + $this->assertFalse($result); + $this->assertEqual(array(), $DB_DELAYED_QUERIES); + } } -- cgit v1.2.3 From ba4bbf484d33fe24332ff63ac3b063f346a2a74c Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Sat, 8 Oct 2011 21:52:34 -0400 Subject: Fixes #3942 fixed all the warnings and notices in the unit tests --- engine/classes/ElggAnnotation.php | 2 +- engine/lib/access.php | 2 +- engine/lib/annotations.php | 8 ++++---- engine/tests/api/access_collections.php | 8 ++++---- engine/tests/api/helpers.php | 8 ++++++-- engine/tests/api/metadata.php | 7 ------- engine/tests/objects/entities.php | 12 ++++++------ engine/tests/objects/users.php | 23 ----------------------- engine/tests/regression/trac_bugs.php | 4 ++-- mod/groups/start.php | 6 ++++-- 10 files changed, 28 insertions(+), 52 deletions(-) (limited to 'engine/tests/regression/trac_bugs.php') diff --git a/engine/classes/ElggAnnotation.php b/engine/classes/ElggAnnotation.php index 78d29ee7f..511b5151f 100644 --- a/engine/classes/ElggAnnotation.php +++ b/engine/classes/ElggAnnotation.php @@ -78,7 +78,7 @@ class ElggAnnotation extends ElggExtender { * @return bool */ function delete() { - remove_from_river_by_annotation($this->id); + elgg_delete_river(array('annotation_id' => $this->id)); return elgg_delete_metastring_based_object_by_id($this->id, 'annotations'); } diff --git a/engine/lib/access.php b/engine/lib/access.php index e8cec50d0..ae64f832a 100644 --- a/engine/lib/access.php +++ b/engine/lib/access.php @@ -460,7 +460,7 @@ function can_edit_access_collection($collection_id, $user_guid = null) { if ($user_guid) { $user = get_entity((int) $user_guid); } else { - $user = get_loggedin_user(); + $user = elgg_get_logged_in_user_entity(); } $collection = get_access_collection($collection_id); diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php index 814c3555b..c227c5516 100644 --- a/engine/lib/annotations.php +++ b/engine/lib/annotations.php @@ -56,14 +56,14 @@ function elgg_delete_annotation_by_id($id) { * @param int $entity_guid Entity Guid * @param string $name Name of annotation * @param string $value Value of annotation - * @param string $value_type Type of value - * @param int $owner_guid Owner of annotation + * @param string $value_type Type of value (default is auto detection) + * @param int $owner_guid Owner of annotation (default is logged in user) * @param int $access_id Access level of annotation * * @return int|bool id on success or false on failure */ -function create_annotation($entity_guid, $name, $value, $value_type, -$owner_guid, $access_id = ACCESS_PRIVATE) { +function create_annotation($entity_guid, $name, $value, $value_type = '', +$owner_guid = 0, $access_id = ACCESS_PRIVATE) { global $CONFIG; $result = false; diff --git a/engine/tests/api/access_collections.php b/engine/tests/api/access_collections.php index 1e61c45bb..bc5408546 100644 --- a/engine/tests/api/access_collections.php +++ b/engine/tests/api/access_collections.php @@ -194,7 +194,7 @@ class ElggCoreAccessCollectionsTest extends ElggCoreUnitTest { return $value; } - register_plugin_hook('access:collections:write', 'all', 'test_acl_access_hook'); + elgg_register_plugin_hook_handler('access:collections:write', 'all', 'test_acl_access_hook'); // enable security since we usually run as admin $ia = elgg_set_ignore_access(false); @@ -202,14 +202,14 @@ class ElggCoreAccessCollectionsTest extends ElggCoreUnitTest { $this->assertTrue($result); $ia = elgg_set_ignore_access($ia); - unregister_plugin_hook('access:collections:write', 'all', 'test_acl_access_hook'); + elgg_unregister_plugin_hook_handler('access:collections:write', 'all', 'test_acl_access_hook'); } // groups interface // only runs if the groups plugin is enabled because implementation is split between // core and the plugin. public function testCreateDeleteGroupACL() { - if (!is_plugin_enabled('groups')) { + if (!elgg_is_active_plugin('groups')) { return; } @@ -231,7 +231,7 @@ class ElggCoreAccessCollectionsTest extends ElggCoreUnitTest { } public function testJoinLeaveGroupACL() { - if (!is_plugin_enabled('groups')) { + if (!elgg_is_active_plugin('groups')) { return; } diff --git a/engine/tests/api/helpers.php b/engine/tests/api/helpers.php index 36d680d54..3f41400c8 100644 --- a/engine/tests/api/helpers.php +++ b/engine/tests/api/helpers.php @@ -166,7 +166,9 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest { $this->assertFalse(isset($CONFIG->externals_map['js']['id1'])); foreach ($elements as $element) { - $this->assertFalse($element->name == 'id1'); + if (isset($element->name)) { + $this->assertFalse($element->name == 'id1'); + } } $result = elgg_unregister_js('id1'); @@ -180,7 +182,9 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest { $this->assertFalse(isset($CONFIG->externals_map['js']['id2'])); foreach ($elements as $element) { - $this->assertFalse($element->name == 'id2'); + if (isset($element->name)) { + $this->assertFalse($element->name == 'id2'); + } } $this->assertTrue(isset($CONFIG->externals_map['js']['id3'])); diff --git a/engine/tests/api/metadata.php b/engine/tests/api/metadata.php index d9113b68a..208024e65 100644 --- a/engine/tests/api/metadata.php +++ b/engine/tests/api/metadata.php @@ -75,13 +75,6 @@ class ElggCoreMetadataAPITest extends ElggCoreUnitTest { $this->assertIdentical($case_true, $case_false); - // check deprecated get_entities_from_metadata() function - $deprecated = get_entities_from_metadata('metaUnitTest', 'tested', '', '', 0, 10, 0, '', 0, FALSE, TRUE); - $this->assertIdentical($deprecated, $case_true); - - // check entity list - //$this->dump(list_entities_from_metadata('metaUnitTest', 'Tested', '', '', 0, 10, TRUE, TRUE, TRUE, FALSE)); - // clean up $this->delete_metastrings(); $this->object->delete(); diff --git a/engine/tests/objects/entities.php b/engine/tests/objects/entities.php index c04bc60ff..c0a7b96b3 100644 --- a/engine/tests/objects/entities.php +++ b/engine/tests/objects/entities.php @@ -125,7 +125,7 @@ class ElggCoreEntityTest extends ElggCoreUnitTest { $this->assertIdentical(FALSE, elgg_get_annotations(array('guid' => $this->entity->getGUID(), 'type' => 'site', 'subtype' => 'fail'))); // clear annotation - $this->assertTrue($this->entity->clearAnnotations()); + $this->assertTrue($this->entity->deleteAnnotations()); $this->assertEqual($this->entity->countAnnotations('non_existent'), 0); $this->assertIdentical(array(), elgg_get_annotations(array('guid' => $this->entity->getGUID()))); @@ -226,8 +226,8 @@ class ElggCoreEntityTest extends ElggCoreUnitTest { } public function testElggEntityMetadata() { - // let's delte a non-existent metadata - $this->assertFalse($this->entity->clearMetaData('important')); + // let's delete a non-existent metadata + $this->assertFalse($this->entity->deleteMetadata('important')); // let's add the meatadata $this->assertTrue($this->entity->important = 'indeed!'); @@ -236,16 +236,16 @@ class ElggCoreEntityTest extends ElggCoreUnitTest { // test deleting incorrectly // @link http://trac.elgg.org/ticket/2273 - $this->assertFalse($this->entity->clearMetaData('impotent')); + $this->assertFalse($this->entity->deleteMetadata('impotent')); $this->assertEqual($this->entity->important, 'indeed!'); // get rid of one metadata $this->assertEqual($this->entity->important, 'indeed!'); - $this->assertTrue($this->entity->clearMetaData('important')); + $this->assertTrue($this->entity->deleteMetadata('important')); $this->assertEqual($this->entity->important, ''); // get rid of all metadata - $this->assertTrue($this->entity->clearMetaData()); + $this->assertTrue($this->entity->deleteMetadata()); $this->assertEqual($this->entity->less_important, ''); // clean up database diff --git a/engine/tests/objects/users.php b/engine/tests/objects/users.php index ba93c2439..d1533c3d2 100644 --- a/engine/tests/objects/users.php +++ b/engine/tests/objects/users.php @@ -220,29 +220,6 @@ class ElggCoreUserTest extends ElggCoreUnitTest { $this->user->delete(); } - // remove in 1.9 - public function testElggUserIsAdminLegacy() { - $this->user->save(); - $this->user->makeAdmin(); - - $this->assertTrue($this->user->admin); - $this->assertTrue($this->user->siteadmin); - - $this->user->removeAdmin(); - $this->user->delete(); - } - - public function testElggUserIsNotAdminLegacy() { - $this->user->save(); - $this->user->removeAdmin(); - - $this->assertFalse($this->user->admin); - $this->assertFalse($this->user->siteadmin); - - $this->user->removeAdmin(); - $this->user->delete(); - } - protected function fetchUser($guid) { global $CONFIG; diff --git a/engine/tests/regression/trac_bugs.php b/engine/tests/regression/trac_bugs.php index 23d6d1dc6..2bfc37558 100644 --- a/engine/tests/regression/trac_bugs.php +++ b/engine/tests/regression/trac_bugs.php @@ -146,9 +146,9 @@ class ElggCoreRegressionBugsTest extends ElggCoreUnitTest { } } - register_plugin_hook('container_permissions_check', 'all', 'can_write_to_container_test_hook'); + elgg_register_plugin_hook_handler('container_permissions_check', 'all', 'can_write_to_container_test_hook'); $this->assertTrue(can_write_to_container($user->guid, $object->guid)); - unregister_plugin_hook('container_permissions_check', 'all', 'can_write_to_container_test_hook'); + elgg_unregister_plugin_hook_handler('container_permissions_check', 'all', 'can_write_to_container_test_hook'); $this->assertFalse(can_write_to_container($user->guid, $group->guid)); $group->join($user); diff --git a/mod/groups/start.php b/mod/groups/start.php index 0425bdea6..1b5b03ce7 100644 --- a/mod/groups/start.php +++ b/mod/groups/start.php @@ -562,8 +562,10 @@ function groups_user_join_event_listener($event, $object_type, $object) { * Make sure users are added to the access collection */ function groups_access_collection_override($hook, $entity_type, $returnvalue, $params) { - if (elgg_instanceof(get_entity($params['collection']->owner_guid), 'group')) { - return true; + if (isset($params['collection'])) { + if (elgg_instanceof(get_entity($params['collection']->owner_guid), 'group')) { + return true; + } } } -- cgit v1.2.3