Permalink
Browse files

fix(annotations): fixes time-based annotations searches

Fixes #9785
  • Loading branch information...
mrclay committed May 10, 2016
1 parent b6d9e11 commit 6d5e1b781866dc4b79300f57424873049314a6ff
@@ -365,11 +365,11 @@ function getEntities(array $options = array()) {
}
}
$time_wheres = _elgg_get_entity_time_where_sql('a', $options['annotation_created_time_upper'],
$time_wheres = _elgg_get_entity_time_where_sql('n_table', $options['annotation_created_time_upper'],
$options['annotation_created_time_lower']);
if ($time_wheres) {
$options['wheres'] = array_merge($options['wheres'], $time_wheres);
$options['wheres'][] = $time_wheres;
}
return elgg_get_entities_from_metadata($options);
@@ -23,6 +23,60 @@ protected function createRandomAnnotations($entity, $max = 1) {
return $annotations;
}
public function testCanGetEntitiesByAnnotationCreationTime() {
$prefix = elgg_get_config('dbprefix');
$users = elgg_get_entities(array('type' => 'user', 'limit' => 1));
// create some test annotations
$subtypes = $this->getRandomValidSubtypes(array('object'), 1);
$subtype = $subtypes[0];
$annotation_name = 'test_annotation_name_' . rand();
// our targets
$valid1 = new \ElggObject();
$valid1->subtype = $subtype;
$valid1->save();
$id1 = $valid1->annotate($annotation_name, 1, ACCESS_PUBLIC, $users[0]->guid);
// this one earlier
$yesterday = time() - 86400;
update_data("
UPDATE {$prefix}annotations
SET time_created = $yesterday
WHERE id = $id1
");
$valid2 = new \ElggObject();
$valid2->subtype = $subtype;
$valid2->save();
$valid2->annotate($annotation_name, 1, ACCESS_PUBLIC, $users[0]->guid);
$options = array(
'annotation_owner_guid' => $users[0]->guid,
'annotation_created_time_lower' => (time() - 3600),
'annotation_name' => $annotation_name,
);
$entities = elgg_get_entities_from_annotations($options);
$this->assertEqual(1, count($entities));
$this->assertEqual($valid2->guid, $entities[0]->guid);
$options = array(
'annotation_owner_guid' => $users[0]->guid,
'annotation_created_time_upper' => (time() - 3600),
'annotation_name' => $annotation_name,
);
$entities = elgg_get_entities_from_annotations($options);
$this->assertEqual(1, count($entities));
$this->assertEqual($valid1->guid, $entities[0]->guid);
$valid1->delete();
$valid2->delete();
}
public function testElggApiGettersEntitiesFromAnnotation() {
// grab a few different users to annotation

0 comments on commit 6d5e1b7

Please sign in to comment.