/** * Checks if additional select columns are readable as volatile data even if we hit the cache while fetching entity. * * https://github.com/Elgg/Elgg/issues/5544 */ public function testSqlAdditionalSelectsAsVolatileDataWithCache() { // remove ignore access as it disables entity cache $access = elgg_set_ignore_access(false); // may not have groups in DB - let's create one $group = new ElggGroup(); $group->name = 'test_group'; $group->access_id = ACCESS_PUBLIC; $this->assertTrue($group->save() !== false); foreach (array('site', 'user', 'group', 'object') as $type) { $entities = elgg_get_entities(array('type' => $type, 'selects' => array('42 as added_col3'), 'limit' => 1)); $entity = array_shift($entities); $this->assertTrue($entity instanceof ElggEntity); $this->assertEqual($entity->added_col3, null, "Additional select columns are leaking to attributes for " . get_class($entity)); $this->assertEqual($entity->getVolatileData('select:added_col3'), 42); // make sure we have cached the entity $this->assertNotEqual(false, _elgg_retrieve_cached_entity($entity->guid)); } // run these again but with different value to make sure cache does not interfere foreach (array('site', 'user', 'group', 'object') as $type) { $entities = elgg_get_entities(array('type' => $type, 'selects' => array('64 as added_col3'), 'limit' => 1)); $entity = array_shift($entities); $this->assertTrue($entity instanceof ElggEntity); $this->assertEqual($entity->added_col3, null, "Additional select columns are leaking to attributes for " . get_class($entity)); $this->assertEqual($entity->getVolatileData('select:added_col3'), 64, "Failed to overwrite volatile data in cached entity"); } elgg_set_ignore_access($access); $group->delete(); }
/** * Ensure that \ElggBatch doesn't go into infinite loop when disabling annotations recursively when show hidden is enabled. * * https://github.com/Elgg/Elgg/issues/5952 */ public function test_disabling_annotations_infinite_loop() { //let's have some entity $group = new \ElggGroup(); $group->name = 'test_group'; $group->access_id = ACCESS_PUBLIC; $this->assertTrue($group->save() !== false); $total = 51; //add some annotations for ($cnt = 0; $cnt < $total; $cnt++) { $group->annotate('test_annotation', 'value_' . $total); } //disable them $show_hidden = access_get_show_hidden_status(); access_show_hidden_entities(true); $options = array('guid' => $group->guid, 'limit' => $total); elgg_disable_annotations($options); access_show_hidden_entities($show_hidden); //confirm all being disabled $annotations = $group->getAnnotations(array('limit' => $total)); foreach ($annotations as $annotation) { $this->assertTrue($annotation->enabled == 'no'); } //delete group and annotations $group->delete(); }
function test_can_write_to_container() { $user = new ElggUser(); $user->username = '******' . rand(); $user->name = 'test_user_name_' . rand(); $user->email = '*****@*****.**'; $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; } } 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)); 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); $this->assertTrue(can_write_to_container($user->guid, $group->guid)); elgg_set_ignore_access($ia); $user->delete(); $object->delete(); $group->delete(); }
public function testJoinLeaveGroupACL() { if (!elgg_is_active_plugin('groups')) { return; } $group = new ElggGroup(); $group->name = 'Test group'; $group->save(); $result = $group->join($this->user); $this->assertTrue($result); // disable security since we run as admin $ia = elgg_set_ignore_access(false); // need to set the page owner to emulate being in a group context. // this is kinda hacky. elgg_set_page_owner_guid($group->getGUID()); if ($result) { $can_edit = can_edit_access_collection($group->group_acl, $this->user->guid); $this->assertTrue($can_edit); } $result = $group->leave($this->user); $this->assertTrue($result); if ($result) { $can_edit = can_edit_access_collection($group->group_acl, $this->user->guid); $this->assertFalse($can_edit); } elgg_set_ignore_access($ia); $group->delete(); }
/** * Make sure entity is loaded from cache during save operations * See #10612 */ public function testNewGroupLoadedFromCacheDuringSaveOperations() { $group = new \ElggGroup(); $group->subtype = 'test_group_subtype'; // Add temporary metadata, annotation and private settings // to extend the scope of tests and catch issues with save operations $group->test_metadata = 'bar'; $group->annotate('test_annotation', 'baz'); $group->setPrivateSetting('test_setting', 'foo'); $metadata_called = false; $metadata_event_handler = function ($event, $type, $metadata) use(&$metadata_called) { /* @var $metadata \ElggMetadata */ $entity = get_entity($metadata->entity_guid); $this->assertEqual($metadata->entity_guid, $entity->guid); $metadata_called = true; }; $annotation_called = false; $annotation_event_handler = function ($event, $type, $annotation) use(&$annotation_called) { /* @var $metadata \ElggAnnotation */ $entity = get_entity($annotation->entity_guid); $this->assertEqual($annotation->entity_guid, $entity->guid); $annotation_called = true; }; elgg_register_event_handler('create', 'metadata', $metadata_event_handler); elgg_register_event_handler('create', 'annotation', $annotation_event_handler); $group->save(); elgg_unregister_event_handler('create', 'metadata', $metadata_event_handler); elgg_unregister_event_handler('create', 'annotation', $annotation_event_handler); $group->delete(); $this->assertTrue($metadata_called); $this->assertTrue($annotation_called); }
/** * Ensure additional select columns do not end up in entity attributes. * * https://github.com/Elgg/Elgg/issues/5538 */ public function test_extra_columns_dont_appear_in_attributes() { global $ENTITY_CACHE; // may not have groups in DB - let's create one $group = new ElggGroup(); $group->name = 'test_group'; $group->access_id = ACCESS_PUBLIC; $this->assertTrue($group->save() !== false); // entity cache interferes with our test $ENTITY_CACHE = array(); foreach (array('site', 'user', 'group', 'object') as $type) { $entities = elgg_get_entities(array('type' => $type, 'selects' => array('1 as _nonexistent_test_column'), 'limit' => 1)); if (!$this->assertTrue($entities, "Query for '{$type}' did not return an entity.")) { continue; } $entity = $entities[0]; $this->assertNull($entity->_nonexistent_test_column, "Additional select columns are leaking to attributes for '{$type}'"); } $group->delete(); }
/** * Called after each test method. */ public function tearDown() { $this->group->delete(); $this->user->delete(); }