]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #1558: Applied Cash's patch. Added unit tests to test for regressions for...
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Mon, 1 Mar 2010 16:21:36 +0000 (16:21 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Mon, 1 Mar 2010 16:21:36 +0000 (16:21 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@3979 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/annotations.php
engine/lib/elgglib.php
engine/tests/regression/trac_bugs.php [new file with mode: 0644]

index 666b83309b8a361205813415d034942986f65077..b18475d5710737f69466d80280024c9252b3e513 100644 (file)
@@ -1146,6 +1146,7 @@ function delete_annotation($id) {
  * Clear all the annotations for a given entity, assuming you have access to that metadata.
  *
  * @param int $guid
+ * @return number of annotations deleted or false if an error
  */
 function clear_annotations($guid, $name = "") {
        global $CONFIG;
@@ -1154,6 +1155,10 @@ function clear_annotations($guid, $name = "") {
 
        if (!empty($name)) {
                $name = get_metastring_id($name);
+               if ($name === false) {
+                       // name doesn't exist so 0 rows were deleted
+                       return 0;
+               }
        }
 
        $entity_guid = (int) $guid;
@@ -1173,6 +1178,8 @@ function clear_annotations($guid, $name = "") {
                        return delete_data($query);
                }
        }
+       
+       return FALSE;
 }
 
 /**
index 9b5b34d865588e60c193cc2060f17bc554aac996..c6a03cc4f73d2a3534b02e741a45499300cd2f88 100644 (file)
@@ -2757,6 +2757,7 @@ function elgg_boot() {
 function elgg_api_test($hook, $type, $value, $params) {
        global $CONFIG;
        $value[] = $CONFIG->path . 'engine/tests/api/entity_getter_functions.php';
+       $value[] = $CONFIG->path . 'engine/tests/regression/trac_bugs.php';
        return $value;
 }
 
@@ -2774,4 +2775,4 @@ define('ELGG_ENTITIES_NO_VALUE', 0);
 
 register_elgg_event_handler('init', 'system', 'elgg_init');
 register_elgg_event_handler('boot', 'system', 'elgg_boot', 1000);
-register_plugin_hook('unit_test', 'system', 'elgg_api_test');
\ No newline at end of file
+register_plugin_hook('unit_test', 'system', 'elgg_api_test');
diff --git a/engine/tests/regression/trac_bugs.php b/engine/tests/regression/trac_bugs.php
new file mode 100644 (file)
index 0000000..01900b8
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+/**
+ * Elgg Regression Tests -- Trac Bugfixes
+ * Any bugfixes from Trac that require testing belong here.
+ *
+ * @package Elgg
+ * @subpackage Test
+ * @author Curverider Ltd
+ * @link http://elgg.org/
+ */
+class ElggCoreRegressionBugsTest extends ElggCoreUnitTest {
+
+       /**
+        * Called before each test object.
+        */
+       public function __construct() {
+               $this->ia = elgg_set_ignore_access(TRUE);
+               parent::__construct();
+               
+               // all __construct() code should come after here
+       }
+
+       /**
+        * Called before each test method.
+        */
+       public function setUp() {
+
+       }
+
+       /**
+        * Called after each test method.
+        */
+       public function tearDown() {
+               // do not allow SimpleTest to interpret Elgg notices as exceptions
+               $this->swallowErrors();
+       }
+
+       /**
+        * Called after each test object.
+        */
+       public function __destruct() {
+               elgg_set_ignore_access($this->ia);
+               // all __destruct() code should go above here
+               parent::__destruct();
+       }
+
+       /**
+        * #1558
+        */
+       public function testElggObjectClearAnnotations() {
+               $this->entity = new ElggObject();
+               $guid = $this->entity->save();
+               
+               $this->entity->annotate('test', 'hello', ACCESS_PUBLIC);
+               
+               $this->entity->clearAnnotations('does not exist');
+               
+               $num = $this->entity->countAnnotations('test');
+               
+               //$this->assertIdentical($num, 1);
+               $this->assertEqual($num, 1);
+               
+               // clean up
+               $this->entity->delete();
+       }
+}