]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #5418 adds enabled clause for annotations
authorcash <cash.costello@gmail.com>
Fri, 3 May 2013 02:02:41 +0000 (22:02 -0400)
committercash <cash.costello@gmail.com>
Fri, 3 May 2013 02:02:41 +0000 (22:02 -0400)
engine/lib/metastrings.php
engine/tests/api/metastrings.php

index f49b4a163cb30ed272a904845c3505e6972b378a..39a81c6d039f77139514cd67940e680e642e729f 100644 (file)
@@ -421,6 +421,8 @@ function elgg_get_metastring_based_objects($options) {
        if ($metastring_clauses) {
                $wheres = array_merge($wheres, $metastring_clauses['wheres']);
                $joins = array_merge($joins, $metastring_clauses['joins']);
+       } else {
+               $wheres[] = get_access_sql_suffix('n_table');
        }
 
        if ($options['metastring_calculation'] === ELGG_ENTITIES_NO_VALUE) {
@@ -510,7 +512,7 @@ function elgg_get_metastring_sql($table, $names = null, $values = null,
                && !$ids
                && (!$pairs && $pairs !== 0)) {
 
-               return '';
+               return array();
        }
 
        $db_prefix = elgg_get_config('dbprefix');
@@ -520,8 +522,6 @@ function elgg_get_metastring_sql($table, $names = null, $values = null,
        // only supported on values.
        $binary = ($case_sensitive) ? ' BINARY ' : '';
 
-       $access = get_access_sql_suffix($table);
-
        $return = array (
                'joins' => array (),
                'wheres' => array()
@@ -586,13 +586,15 @@ function elgg_get_metastring_sql($table, $names = null, $values = null,
        }
 
        if ($names_where && $values_where) {
-               $wheres[] = "($names_where AND $values_where AND $access)";
+               $wheres[] = "($names_where AND $values_where)";
        } elseif ($names_where) {
-               $wheres[] = "($names_where AND $access)";
+               $wheres[] = $names_where;
        } elseif ($values_where) {
-               $wheres[] = "($values_where AND $access)";
+               $wheres[] = $values_where;
        }
 
+       $wheres[] = get_access_sql_suffix($table);
+
        if ($where = implode(' AND ', $wheres)) {
                $return['wheres'][] = "($where)";
        }
index 0a8945084faab682dd71618d398ed8e6d7f94649..cfcfb6d07457db56771b3c051c5f5062fd404e5f 100644 (file)
@@ -55,8 +55,11 @@ class ElggCoreMetastringsTest extends ElggCoreUnitTest {
         * Called after each test method.
         */
        public function tearDown() {
-               // do not allow SimpleTest to interpret Elgg notices as exceptions
-               $this->swallowErrors();
+               access_show_hidden_entities(true);
+               elgg_delete_annotations(array(
+                       'guid' => $this->object->guid,
+               ));
+               access_show_hidden_entities(false);
        }
 
        /**
@@ -98,6 +101,31 @@ class ElggCoreMetastringsTest extends ElggCoreUnitTest {
                }
        }
 
+       public function testGetMetastringObjectFromIDWithDisabledAnnotation() {
+               $name = 'test_annotation_name' . rand();
+               $value = 'test_annotation_value' . rand();
+               $id = create_annotation($this->object->guid, $name, $value);
+               $annotation = elgg_get_annotation_from_id($id);
+               $this->assertTrue($annotation->disable());
+
+               $test = elgg_get_metastring_based_object_from_id($id, 'annotation');
+               $this->assertEqual(false, $test);
+       }
+
+       public function testGetMetastringBasedObjectWithDisabledAnnotation() {
+               $name = 'test_annotation_name' . rand();
+               $value = 'test_annotation_value' . rand();
+               $id = create_annotation($this->object->guid, $name, $value);
+               $annotation = elgg_get_annotation_from_id($id);
+               $this->assertTrue($annotation->disable());
+
+               $test = elgg_get_metastring_based_objects(array(
+                       'metastring_type' => 'annotations',
+                       'guid' => $this->object->guid,
+               ));
+               $this->assertEqual(array(), $test);
+       }
+
        public function testEnableDisableByID() {
                $db_prefix = elgg_get_config('dbprefix');
                $annotations = $this->createAnnotations(1);