Folder type support.
authorGunnar Wrobel <p@rdus.de>
Sat, 15 Jan 2011 22:46:15 +0000 (23:46 +0100)
committerGunnar Wrobel <p@rdus.de>
Mon, 17 Jan 2011 10:33:06 +0000 (11:33 +0100)
framework/Share/lib/Horde/Share/Kolab.php
framework/Share/test/Horde/Share/Kolab/UnitTest.php

index 90b97b3..82404fb 100644 (file)
@@ -27,7 +27,7 @@ class Horde_Share_Kolab extends Horde_Share_Base
     protected $_storage;
 
     /**
-     * The share type
+     * The folder type in the storage backend.
      *
      * @var string
      */
@@ -41,6 +41,36 @@ class Horde_Share_Kolab extends Horde_Share_Base
     protected $_listCacheValidity;
 
     /**
+     * Constructor.
+     *
+     * @param string $app          The application that the shares belong to
+     * @param string $user         The current user
+     * @param Horde_Perms $perms   The permissions object
+     * @param Horde_Group $groups  The Horde_Group object
+     *
+     */
+    public function __construct($app, $user, Horde_Perms $perms, Horde_Group $groups)
+    {
+        switch ($app) {
+        case 'mnemo':
+            $this->_type = 'note';
+            break;
+        case 'kronolith':
+            $this->_type = 'event';
+            break;
+        case 'turba':
+            $this->_type = 'contact';
+            break;
+        case 'nag':
+            $this->_type = 'task';
+            break;
+        default:
+            throw new Horde_Share_Exception(sprintf(Horde_Share_Translation::t("The Horde/Kolab integration engine does not support \"%s\""), $app));
+        }
+        parent::__construct($app, $user, $perms, $groups);
+    }
+
+    /**
      * Set the Kolab storage backend.
      *
      * @param Horde_Kolab_Storage $driver The Kolab storage driver.
@@ -138,23 +168,17 @@ class Horde_Share_Kolab extends Horde_Share_Base
         return array();
     }
 
-
-    private function _getFolderType($app)
+    /**
+     * Return the type of folder this share driver will access in the Kolab
+     * storage backend (depends on the application calling the share driver).
+     *
+     * @return string
+     */
+    public function getType()
     {
-        switch ($app) {
-        case 'mnemo':
-            return 'note';
-        case 'kronolith':
-            return 'event';
-        case 'turba':
-            return 'contact';
-        case 'nag':
-            return 'task';
-        default:
-            throw new Horde_Share_Exception(sprintf(Horde_Share_Translation::t("The Horde/Kolab integration engine does not support \"%s\""), $app));
-        }
+        return $this->_type;
     }
-
+    
     /**
      * (re)connect the share object to this share driver. Userful for when
      * share objects are unserialized from a cache separate from the share
index b75bedb..4eafbd9 100644 (file)
@@ -67,6 +67,51 @@ extends PHPUnit_Framework_TestCase
         );
     }
 
+    public function testGetTypeString()
+    {
+        $driver = new Horde_Share_Kolab(
+            'mnemo', 'john', new Horde_Perms(), new Horde_Group_Test()
+        );        
+        $this->assertType('string', $driver->getType());
+    }
+
+    public function testMnemoSupport()
+    {
+        $driver = new Horde_Share_Kolab(
+            'mnemo', 'john', new Horde_Perms(), new Horde_Group_Test()
+        );        
+        $this->assertEquals('note', $driver->getType());
+    }
+
+    public function testKronolithSupport()
+    {
+        $driver = new Horde_Share_Kolab(
+            'kronolith', 'john', new Horde_Perms(), new Horde_Group_Test()
+        );        
+        $this->assertEquals('event', $driver->getType());
+    }
+
+    public function testTurbaSupport()
+    {
+        $driver = new Horde_Share_Kolab(
+            'turba', 'john', new Horde_Perms(), new Horde_Group_Test()
+        );        
+        $this->assertEquals('contact', $driver->getType());
+    }
+
+    public function testNagSupport()
+    {
+        $driver = new Horde_Share_Kolab(
+            'nag', 'john', new Horde_Perms(), new Horde_Group_Test()
+        );        
+        $this->assertEquals('task', $driver->getType());
+    }
+
+    /**
+     * @todo: Reminder: Check that external modification of the Storage system
+     * works (former list->validity).
+     */
+
     private function _getCompleteDriver()
     {
         $factory = new Horde_Kolab_Storage_Factory();
@@ -88,7 +133,7 @@ extends PHPUnit_Framework_TestCase
     private function _getDriver()
     {
         return new Horde_Share_Kolab(
-            'test', 'john', new Horde_Perms(), new Horde_Group_Test()
+            'mnemo', 'john', new Horde_Perms(), new Horde_Group_Test()
         );
     }
 }
\ No newline at end of file