remove resources container on resource delete
authorCornelius Weiß <mail@corneliusweiss.de>
Wed, 25 Jun 2014 16:54:54 +0000 (18:54 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 30 Jun 2014 14:42:38 +0000 (16:42 +0200)
* fixes #1711

Change-Id: I3bf6eb1c90ad5d312b536da9745c91648dc3a47a
Reviewed-on: http://gerrit.tine20.com/customers/795
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Calendar/Controller/ResourceTest.php
tine20/Calendar/Controller/Resource.php

index ecf3c46..0874b92 100644 (file)
@@ -49,6 +49,12 @@ class Calendar_Controller_ResourceTest extends Calendar_TestCase
         
         $this->assertEquals($resource->name, $persistentResource->name);
         
+        // assert autocreated resource container
+        $resourceContainer = Tinebase_Container::getInstance()->getContainerById($resource->container_id);
+        $this->assertEquals($resource->name, $resourceContainer->name);
+        $this->assertEquals(Tinebase_Model_Container::TYPE_SHARED, $resourceContainer->type);
+        $this->assertEquals('Calendar_Model_Event', $resourceContainer->model);
+        
         return $resource;
     }
     
@@ -95,4 +101,15 @@ class Calendar_Controller_ResourceTest extends Calendar_TestCase
         $this->setExpectedException('Calendar_Exception_AttendeeBusy');
         $conflictingEvent = Calendar_Controller_Event::getInstance()->create($event, TRUE);
     }
+    
+    public function testDeleteResource()
+    {
+        $resource = $this->testCreateResource();
+        
+        Calendar_Controller_Resource::getInstance()->delete($resource->getId());
+        
+        $this->assertEquals(0, count(Calendar_Controller_Resource::getInstance()->getMultiple(array($resource->getId()))));
+        $this->setExpectedException('Tinebase_Exception_NotFound');
+        Tinebase_Container::getInstance()->getContainerById($resource->container_id);
+    }
 }
index 0d23da6..f6377b8 100644 (file)
@@ -150,4 +150,15 @@ class Calendar_Controller_Resource extends Tinebase_Controller_Record_Abstract
                break;
         }
     }
+    
+    /**
+     * delete linked objects (notes, relations, ...) of record
+     *
+     * @param Tinebase_Record_Interface $_record
+     */
+    protected function _deleteLinkedObjects(Tinebase_Record_Interface $_record)
+    {
+        Tinebase_Container::getInstance()->deleteContainer($_record->container_id, true);
+        return parent::_deleteLinkedObjects($_record);
+    }
 }