]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Requesting annotations from a non-existent subtype will now return nothing instead...
authornickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 2 Jun 2010 20:26:50 +0000 (20:26 +0000)
committernickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 2 Jun 2010 20:26:50 +0000 (20:26 +0000)
This functionality is required to preserve context.

git-svn-id: http://code.elgg.org/elgg/trunk@6331 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/annotations.php
engine/tests/objects/entities.php

index 31c83fb8c02e2a3771c436bc3240bd46e518571c..a956a95cc98f81cd8d04fd59906a3b38c9f7cd7c 100644 (file)
@@ -297,8 +297,16 @@ $value = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "asc", $time
        } else {
                $entity_guid = (int)$entity_guid;
        }
+       
        $entity_type = sanitise_string($entity_type);
-       $entity_subtype = get_subtype_id($entity_type, $entity_subtype);
+       
+       if ($entity_subtype) {
+               if (!$entity_subtype = get_subtype_id($entity_type, $entity_subtype)) {
+                       // requesting a non-existing subtype: return false
+                       return FALSE;
+               }
+       }
+       
        if ($name) {
                $name = get_metastring_id($name);
 
index 1504c2f933ffaff8a764cc2b89654866bd65e0fd..eb6eee2a3ba78177fe02c455e25f9cd31eaf862e 100644 (file)
@@ -109,16 +109,26 @@ class ElggCoreEntityTest extends ElggCoreUnitTest {
                $this->assertTrue(array_key_exists('non_existent', $this->entity->expose_annotations()));
 
                // save entity and check for annotation
+               $this->entity->subtype = 'testing';
                $this->save_entity();
                $this->assertFalse(array_key_exists('non_existent', $this->entity->expose_annotations()));
                $annotations = $this->entity->getAnnotations('non_existent');
                $this->assertIsA($annotations[0], 'ElggAnnotation');
                $this->assertIdentical($annotations[0]->name, 'non_existent');
                $this->assertEqual($this->entity->countAnnotations('non_existent'), 1);
+               
+               $this->assertIdentical($annotations, get_annotations($this->entity->getGUID()));
+               $this->assertIdentical($annotations, get_annotations($this->entity->getGUID(), 'site'));
+               $this->assertIdentical($annotations, get_annotations($this->entity->getGUID(), 'site', 'testing'));
+               $this->assertIdentical(FALSE, get_annotations($this->entity->getGUID(), 'site', 'fail'));
 
                //  clear annotation
                $this->assertTrue($this->entity->clearAnnotations());
                $this->assertEqual($this->entity->countAnnotations('non_existent'), 0);
+               
+               $this->assertIdentical(FALSE, get_annotations($this->entity->getGUID()));
+               $this->assertIdentical(FALSE, get_annotations($this->entity->getGUID(), 'site'));
+               $this->assertIdentical(FALSE, get_annotations($this->entity->getGUID(), 'site', 'testing'));
 
                // clean up
                $this->assertTrue($this->entity->delete());