Complete the first minor step in testing the various IMAP driver variants.
authorGunnar Wrobel <p@rdus.de>
Tue, 27 Apr 2010 21:41:24 +0000 (23:41 +0200)
committerGunnar Wrobel <wrobel@temple.(none)>
Tue, 27 Apr 2010 21:43:07 +0000 (23:43 +0200)
Add server testing using a shared fixture.

19 files changed:
framework/Kolab_Storage/TODO
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Cclient.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Imap.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Mock.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Pear.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Decorator/Base.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Decorator/Trigger.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Namespace.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Namespace/Element.php
framework/Kolab_Storage/package.xml
framework/Kolab_Storage/script/Horde/Kolab/Storage/test_drivers.php [new file with mode: 0644]
framework/Kolab_Storage/test/Horde/Kolab/Storage/AllTests.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/Class/Driver/CclientTest.php [new file with mode: 0644]
framework/Kolab_Storage/test/Horde/Kolab/Storage/Class/Driver/ImapTest.php [new file with mode: 0644]
framework/Kolab_Storage/test/Horde/Kolab/Storage/Class/Driver/MockTest.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/Class/Driver/PearTest.php [new file with mode: 0644]
framework/Kolab_Storage/test/Horde/Kolab/Storage/DataTest.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/Server/DriverTest.php [new file with mode: 0644]
framework/Kolab_Storage/test/Horde/Kolab/Storage/TriggerTest.php

index 8d2c2fa..c7577c6 100644 (file)
@@ -7,3 +7,7 @@
  - Do not hide the prefix of the shared namespace?
 
  - Fix the triggering decorator
+
+ - Test the Driver implementations
+
+   - getNamespace() [DONE]
index 5f182bf..e4a3419 100644 (file)
@@ -26,7 +26,7 @@
  * @link     http://pear.horde.org/index.php?package=Kolab_Storage
  */
 class Horde_Kolab_Storage_Driver_Cclient
-implements Horde_Kolab_Storage_Driver
+extends Horde_Kolab_Storage_Driver_Base
 {
     /**
      * The group handler for this connection.
@@ -393,36 +393,4 @@ implements Horde_Kolab_Storage_Driver
         return $this->_imap->setMetadata($mailbox_name,
                                          array($entry => $value));
     }
-
-
-    /**
-     * Retrieve the namespace information for this connection.
-     *
-     * @return Horde_Kolab_Storage_Namespace The initialized namespace handler.
-     */
-    public function getNamespace()
-    {
-        if ($this->_imap->queryCapability('NAMESPACE') === true) {
-            return new Horde_Kolab_Storage_Namespace_Imap(
-                $this->_imap->getNamespaces(),
-                isset($this->_params['namespaces']) ? $this->_params['namespaces'] : array()
-            );
-        } else if (isset($this->_params['namespaces'])) {
-            return new Horde_Kolab_Storage_Namespace_Config(
-                $this->_params['namespaces']
-            );
-        }
-        return new Horde_Kolab_Storage_Namespace_Fixed();
-    }
-
-    /**
-     * Get the group handler for this connection.
-     *
-     * @return Horde_Group The group handler.
-     */
-    public function getGroupHandler()
-    {
-        return $this->_groups;
-    }
-
 }
\ No newline at end of file
index 1da8cc3..1f1bf10 100644 (file)
@@ -38,14 +38,16 @@ extends Horde_Kolab_Storage_Driver_Base
     /**
      * Constructor.
      *
-     * @param array  $params Connection parameters.
+     * @param Horde_Imap_Client_Base $imap   The IMAP connection handler.
+     * @param Group                  $groups The groups handler.
+     * @param array                  $params Connection parameters.
      */
     public function __construct(
         Horde_Imap_Client_Base $imap,
         Group $groups,
         $params = array()
     ) {
-        $this->_imap   = $imap;
+        $this->_imap = $imap;
         parent::__construct($groups, $params);
     }
 
index fa550bc..3a94beb 100644 (file)
@@ -420,15 +420,4 @@ extends Horde_Kolab_Storage_Driver_Base
         return $this->_imap->setMetadata($mailbox_name,
                                          array($entry => $value));
     }
-
-    /**
-     * Get the group handler for this connection.
-     *
-     * @return Horde_Group The group handler.
-     */
-    public function getGroupHandler()
-    {
-        return $this->_groups;
-    }
-
 }
\ No newline at end of file
index de54fe7..a26ff73 100644 (file)
@@ -26,7 +26,7 @@
  * @link     http://pear.horde.org/index.php?package=Kolab_Storage
  */
 class Horde_Kolab_Storage_Driver_Pear
-implements Horde_Kolab_Storage_Driver
+extends Horde_Kolab_Storage_Driver_Base
 {
     /**
      * The group handler for this connection.
@@ -38,12 +38,17 @@ implements Horde_Kolab_Storage_Driver
     /**
      * Constructor.
      *
-     * @param array  $params Connection parameters.
+     * @param Net_IMAP $imap   The IMAP connection handler.
+     * @param Group    $groups The groups handler.
+     * @param array    $params Connection parameters.
      */
     public function __construct(
-        Group $groups
+        Net_IMAP $imap,
+        Group $groups,
+        $params = array()
     ) {
-        $this->_groups = $groups;
+        $this->_imap = $imap;
+        parent::__construct($groups, $params);
     }
 
     /**
@@ -402,27 +407,30 @@ implements Horde_Kolab_Storage_Driver
      */
     public function getNamespace()
     {
-        if ($this->_imap->queryCapability('NAMESPACE') === true) {
+        if ($this->_imap->hasCapability('NAMESPACE') === true) {
+            $namespaces = array();
+            foreach ($this->_imap->getNamespace() as $type => $elements) {
+                foreach ($elements as $namespace) {
+                    switch ($type) {
+                    case 'personal':
+                        $namespace['type'] = 'personal';
+                        break;
+                    case 'others':
+                        $namespace['type'] = 'other';
+                        break;
+                    case 'shared':
+                        $namespace['type'] = 'shared';
+                        break;
+                    }
+                    $namespace['delimiter'] = $namespace['delimter'];
+                    $namespaces[] = $namespace;
+                }
+            }
             return new Horde_Kolab_Storage_Namespace_Imap(
-                $this->_imap->getNamespaces(),
-                isset($this->_params['namespaces']) ? $this->_params['namespaces'] : array()
-            );
-        } else if (isset($this->_params['namespaces'])) {
-            return new Horde_Kolab_Storage_Namespace_Config(
-                $this->_params['namespaces']
+                $namespaces,
+                $this->getParam('namespaces', array())
             );
         }
-        return new Horde_Kolab_Storage_Namespace_Fixed();
+        return parent::getNamespace();
     }
-
-    /**
-     * Get the group handler for this connection.
-     *
-     * @return Horde_Group The group handler.
-     */
-    public function getGroupHandler()
-    {
-        return $this->_groups;
-    }
-
 }
\ No newline at end of file
index eb35e39..eea3ee6 100644 (file)
@@ -157,9 +157,9 @@ implements Horde_Kolab_Storage_Folder
      *
      * @return array An array with IMAP ACL.
      */
-    public function getACL()
+    public function getAcl()
     {
-        return $this->_folder->getACL();
+        return $this->_folder->getAcl();
     }
 
     /**
@@ -170,9 +170,9 @@ implements Horde_Kolab_Storage_Folder
      *
      * @return NULL
      */
-    public function setACL($user, $acl)
+    public function setAcl($user, $acl)
     {
-        $this->_folder->setACL($user, $acl);
+        $this->_folder->setAcl($user, $acl);
     }
 
     /**
@@ -182,9 +182,9 @@ implements Horde_Kolab_Storage_Folder
      *
      * @return NULL
      */
-    public function deleteACL($user)
+    public function deleteAcl($user)
     {
-        $this->_folder->deleteACL($user);
+        $this->_folder->deleteAcl($user);
     }
 
 }
index fa345fb..fa45be7 100644 (file)
@@ -14,7 +14,7 @@
 /**
  * This decorator triggers a URL following certain actions on the folder.
  *
- * Copyright 2010 The Horde Project (http://www.horde.org/)
+ * Copyright 2008-2010 Klarälvdalens Datakonsult AB
  *
  * See the enclosed file COPYING for license information (LGPL). If you
  * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
@@ -26,6 +26,27 @@ class Horde_Kolab_Storage_Folder_Decorator_Trigger
 extends Horde_Kolab_Storage_Folder_Decorator_Base
 {
     /**
+     * An output for log messages.
+     *
+     * @var Horde_Log_Logger
+     */
+    private $_logger;
+
+    /**
+     * Constructor
+     *
+     * @param Horde_Kolab_Storage_Folder $folder The folder to be decorated.
+     * @param Horde_Log_Logger           $logger The logger.
+     */
+    public function __construct(
+        Horde_Kolab_Storage_Folder $folder,
+        Horde_Log_Logger $logger
+    ) {
+        $this->_logger = $logger;
+        parent::__construct($folder);
+    }
+
+    /**
      * Saves the folder.
      *
      * @param array $attributes An array of folder attributes. You can
@@ -92,7 +113,7 @@ extends Horde_Kolab_Storage_Folder_Decorator_Base
      * @param string $id     IMAP id of the message to be moved.
      * @param string $folder Name of the receiving folder.
      *
-     * @return boolean True if successful.
+     * @return NULL
      */
     public function moveMessage($id, $folder)
     {
@@ -101,12 +122,6 @@ extends Horde_Kolab_Storage_Folder_Decorator_Base
         //@todo: shouldn't we trigger both folders here?
 
         $result = $this->trigger();
-        if (is_a($result, 'PEAR_Error')) {
-            Horde::logMessage(sprintf('Failed triggering folder %s! Error was: %s',
-                                      $this->name, $result->getMessage()), 'ERR');
-        }
-
-        return true;
     }
 
     /**
@@ -123,11 +138,6 @@ extends Horde_Kolab_Storage_Folder_Decorator_Base
 
         //@todo: shouldn't we trigger both folders here?
         $result = $this->trigger();
-        if (is_a($result, 'PEAR_Error')) {
-            Horde::logMessage(sprintf('Failed triggering folder %s! Error was: %s',
-                                      $this->name, $result->getMessage()), 'ERR');
-        }
-        return $success;
     }
 
     /**
@@ -141,20 +151,13 @@ extends Horde_Kolab_Storage_Folder_Decorator_Base
      * @param array  $old_object   The array that holds the current data of the
      *                             object.
      *
-     * @return boolean True on success.
+     * @return NULL
      */
     public function saveObject(&$object, $data_version, $object_type, $id = null,
                                &$old_object = null)
     {
         $this->_folder->saveObject($object, $data_version, $object_type, $id, $old_object);
-        try {
-            $this->trigger();
-        } catch (Horde_Kolab_Storage_Exception $e) {
-            Horde::logMessage(sprintf('Failed triggering folder %s! Error was: %s',
-                                      $this->name, $result->getMessage()), 'ERR');
-        }
-
-        return true;
+        $this->trigger();
     }
 
     /**
@@ -165,10 +168,9 @@ extends Horde_Kolab_Storage_Folder_Decorator_Base
      *
      * @return NULL
      */
-    public function setACL($user, $acl)
+    public function setAcl($user, $acl)
     {
-        $this->_folder->setACL($user, $acl);
-
+        $this->_folder->setAcl($user, $acl);
         $this->trigger();
     }
 
@@ -179,10 +181,9 @@ extends Horde_Kolab_Storage_Folder_Decorator_Base
      *
      * @return NULL
      */
-    public function deleteACL($user)
+    public function deleteAcl($user)
     {
-        $this->_folder->deleteACL($user);
-
+        $this->_folder->deleteAcl($user);
         $this->trigger();
     }
 
index 639c71a..d162881 100644 (file)
@@ -28,6 +28,7 @@
  * @link     http://pear.horde.org/index.php?package=Kolab_Storage
  */
 abstract class Horde_Kolab_Storage_Namespace
+implements Iterator
 {
     /** The possible namespace types (RFC 2342 [5]) */
     const PERSONAL = 'personal';
@@ -72,6 +73,13 @@ abstract class Horde_Kolab_Storage_Namespace
     protected $_primaryPersonalNamespace;
 
     /**
+     * A helper for iteration over the namespaces.
+     *
+     * @var array
+     */
+    protected $_iteration;
+
+    /**
      * Constructor.
      */
     public function __construct()
@@ -188,4 +196,31 @@ abstract class Horde_Kolab_Storage_Namespace
         }
         return Horde_String::convertCharset($namespace->generateName($path), $this->_charset, 'UTF7-IMAP');
     }
+
+    function rewind()
+    {
+        $this->_iterator = $this->_namespaces;
+        $this->_iterator[] = $this->_any;
+        return reset($this->_iterator);
+    }
+
+    function current()
+    {
+        return current($this->_iterator);
+    }
+
+    function key()
+    {
+        return key($this->_iterator);
+    }
+
+    function next()
+    {
+        return next($this->_iterator);
+    }
+
+    function valid()
+    {
+        return key($this->_iterator) !== null;
+    }
 }
\ No newline at end of file
index ab72ec5..fb1ab2e 100644 (file)
@@ -49,6 +49,16 @@ abstract class Horde_Kolab_Storage_Namespace_Element
     }
 
     /**
+     * Return the delimiter for this namespace.
+     *
+     * @return string The delimiter.
+     */
+    public function getDelimiter()
+    {
+        return $this->_delimiter;
+    }
+
+    /**
      * Does the folder name lie in this namespace?
      *
      * @param string $name The name of the folder.
index 5e61a2d..4fa8357 100644 (file)
@@ -32,7 +32,7 @@
   <active>yes</active>
  </lead>
  <date>2010-04-27</date>
- <time>11:44:55</time>
+ <time>23:01:21</time>
  <version>
   <release>0.4.0</release>
   <api>0.1.0</api>
      </dir> <!-- /lib/Horde/Kolab -->
     </dir> <!-- /lib/Horde -->
    </dir> <!-- /lib -->
+   <dir name="script">
+    <dir name="Horde">
+     <dir name="Kolab">
+      <dir name="Storage">
+       <file name="test_drivers.php" role="script">
+        <tasks:replace from="@PHP-TEST-DIR@" to="test_dir" type="pear-config" />
+       </file>
+      </dir> <!-- /script/Horde/Kolab/Storage -->
+     </dir> <!-- /script/Horde/Kolab -->
+    </dir> <!-- /script/Horde -->
+   </dir> <!-- /script -->
    <dir name="test">
     <dir name="Horde">
      <dir name="Kolab">
          <file name="MockTest.php" role="test" />
         </dir> <!-- /test/Horde/Kolab/Storage/Class/Driver -->
        </dir> <!-- /test/Horde/Kolab/Storage/Class -->
+       <dir name="Server">
+        <file name="DriverTest.php" role="test" />
+       </dir> <!-- /test/Horde/Kolab/Storage/Server -->
        <file name="AclTest.php" role="test" />
        <file name="AllTests.php" role="test" />
        <file name="AttachmentTest.php" role="test" />
    <install as="Horde/Kolab/Storage/Namespace/Element/Personal.php" name="lib/Horde/Kolab/Storage/Namespace/Element/Personal.php" />
    <install as="Horde/Kolab/Storage/Namespace/Element/Shared.php" name="lib/Horde/Kolab/Storage/Namespace/Element/Shared.php" />
    <install as="Horde/Kolab/Storage/Namespace/Element/SharedWithPrefix.php" name="lib/Horde/Kolab/Storage/Namespace/Element/SharedWithPrefix.php" />
+   <install as="test_drivers" name="script/Horde/Kolab/Storage/test_drivers.php" />
    <install as="Horde/Kolab/Storage/AclTest.php" name="test/Horde/Kolab/Storage/AclTest.php" />
    <install as="Horde/Kolab/Storage/AllTests.php" name="test/Horde/Kolab/Storage/AllTests.php" />
    <install as="Horde/Kolab/Storage/AttachmentTest.php" name="test/Horde/Kolab/Storage/AttachmentTest.php" />
    <install as="Horde/Kolab/Storage/StorageTest.php" name="test/Horde/Kolab/Storage/StorageTest.php" />
    <install as="Horde/Kolab/Storage/TriggerTest.php" name="test/Horde/Kolab/Storage/TriggerTest.php" />
    <install as="Horde/Kolab/Storage/Class/Driver/MockTest.php" name="test/Horde/Kolab/Storage/Class/Driver/MockTest.php" />
+   <install as="Horde/Kolab/Storage/Server/DriverTest.php" name="test/Horde/Kolab/Storage/Server/DriverTest.php" />
   </filelist>
  </phprelease>
  <changelog>
diff --git a/framework/Kolab_Storage/script/Horde/Kolab/Storage/test_drivers.php b/framework/Kolab_Storage/script/Horde/Kolab/Storage/test_drivers.php
new file mode 100644 (file)
index 0000000..9dc70fb
--- /dev/null
@@ -0,0 +1,95 @@
+<?php
+/**
+ * Test script for the Kolab storage drivers.
+ *
+ * Usage:
+ *   test_drivers.php -u [username]
+ *                    -p [password]
+ *                   [-H [hostname]]
+ *                   [-d [imap_client log file]]
+ *
+ * Username/password/hostspec on the command line will override the $params
+ * values.
+ * Driver on the command line will override the $driver value.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+require_once 'Horde/Autoloader.php';
+
+/** Setup command line */
+$p = new Horde_Argv_Parser(
+    array(
+        'optionList' =>
+        array(
+            new Horde_Argv_Option(
+                '-u',
+                '--user',
+                array(
+                    'help' => 'The user name.',
+                    'type' => 'string',
+                    'nargs' => 1
+                )
+            ),
+            new Horde_Argv_Option(
+                '-p',
+                '--pass',
+                array(
+                    'help' => 'The password.',
+                    'type' => 'string',
+                    'nargs' => 1
+                )
+            ),
+            new Horde_Argv_Option(
+                '-H',
+                '--host',
+                array(
+                    'help' => 'The host to connect to.',
+                    'type' => 'string',
+                    'nargs' => 1,
+                    'default' => 'localhost'
+                )
+            ),
+            new Horde_Argv_Option(
+                '-d',
+                '--debug',
+                array(
+                    'help' => 'The path to the IMAP client debug file.',
+                    'type' => 'string',
+                    'nargs' => 1
+                )
+            ),
+        )
+    )
+);
+
+/** Handle arguments */
+try {
+    list($options, $args) = $p->parseArgs();
+} catch (InvalidArgumentException $e) {
+    print $e->getMessage() . "\n\n" . $p->getUsage() . "\n\n";
+}
+
+/** Setup shared test fixture */
+$fixture = new stdClass;
+$fixture->conf = $options;
+$fixture->drivers = array();
+
+$all_tests = '@PHP-TEST-DIR@/Kolab_Storage/Horde/Kolab/Storage/AllTests.php';
+if (strpos($all_tests, '@PHP-TEST-DIR') !== false) {
+    $all_tests = dirname(__FILE__)
+        . '/../../../../test/Horde/Kolab/Storage/AllTests.php';
+}
+
+define('PHPUnit_MAIN_METHOD', 'PHPUnit_TextUI_Command::main');
+
+require_once $all_tests;
+
+$suite = Horde_Kolab_Storage_AllTests::suite();
+$suite->setSharedFixture($fixture);
+
+PHPUnit_TextUI_TestRunner::run($suite);
\ No newline at end of file
index e5c8ca7..9e378a2 100644 (file)
@@ -30,6 +30,54 @@ require_once 'Horde/Test/AllTests.php';
  */
 class Horde_Kolab_Storage_AllTests extends Horde_Test_AllTests
 {
+    /**
+     * Main entry point for running the suite.
+     */
+    public static function main($package = null, $file = null)
+    {
+        if ($package) {
+            self::$_package = $package;
+        }
+        if ($file) {
+            self::$_file = $file;
+        }
+
+        PHPUnit_TextUI_TestRunner::run(self::detectTestFixture(self::suite()));
+    }
+
+    /**
+     * Collect the unit tests of this directory into a new suite.
+     *
+     * @return PHPUnit_Framework_TestSuite The test suite.
+     */
+    public static function suite()
+    {
+        return self::detectTestFixture(Horde_Test_AllTests::suite());
+    }
+
+    /**
+     * Detect if test configuration is available for the server integration
+     * tests.
+     *
+     * @param PHPUnit_Framework_TestSuite $suite The current test suite.
+     */
+    public static function detectTestFixture(PHPUnit_Framework_TestSuite $suite)
+    {
+        $config = getenv('KOLAB_TEST_CONFIG');
+        if ($config === false) {
+            $config = '/kolab/etc/kolab/php_unit_server_testing.php';
+        }
+        if (file_exists($config)) {
+            require $config;
+            if (isset($conf['kolab']['storage']['test'])) {
+                $fixture = new stdClass;
+                $fixture->conf = $conf['kolab']['storage']['test'];
+                $fixture->drivers = array();
+                $suite->setSharedFixture($fixture);
+            }
+        }
+        return $suite;
+    }
 }
 
 Horde_Kolab_Storage_AllTests::init('Horde_Kolab_Storage', __FILE__);
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Class/Driver/CclientTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Class/Driver/CclientTest.php
new file mode 100644 (file)
index 0000000..75e96f1
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+/**
+ * Test the Kolab mock driver.
+ *
+ * PHP version 5
+ *
+ * @category   Kolab
+ * @package    Kolab_Storage
+ * @subpackage UnitTests
+ * @author     Gunnar Wrobel <wrobel@pardus.de>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link       http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the Kolab mock driver.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category   Kolab
+ * @package    Kolab_Storage
+ * @subpackage UnitTests
+ * @author     Gunnar Wrobel <wrobel@pardus.de>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link       http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Class_Driver_CclientTest
+extends PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        require_once 'Horde/Group.php';
+        require_once 'Horde/Group/mock.php';
+
+        $this->group = new Group_mock();
+    }
+
+    public function testGetNamespaceReturnsNamespaceHandler()
+    {
+        Horde_Nls::setCharset('UTF8');
+        $driver = new Horde_Kolab_Storage_Driver_Cclient(
+            $this->group,
+            array()
+        );
+        $this->assertType(
+            'Horde_Kolab_Storage_Namespace',
+            $driver->getNamespace()
+        );
+    }
+
+    public function testGetNamespaceReturnsExpectedNamespaces()
+    {
+        Horde_Nls::setCharset('UTF8');
+        $driver = new Horde_Kolab_Storage_Driver_Cclient(
+            $this->group,
+            array()
+        );
+        $namespaces = array();
+        foreach ($driver->getNamespace() as $namespace) {
+            $namespaces[$namespace->getName()] = array(
+                'type' => $namespace->getType(),
+                'delimiter' => $namespace->getDelimiter(),
+            );
+        }
+        $this->assertEquals(
+            array(
+                'INBOX' => array(
+                    'type' => 'personal',
+                    'delimiter' => '/',
+                ),
+                'user' => array(
+                    'type' => 'other',
+                    'delimiter' => '/',
+                ),
+                '' => array(
+                    'type' => 'shared',
+                    'delimiter' => '/',
+                ),
+            ),
+            $namespaces
+        );
+    }
+}
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Class/Driver/ImapTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Class/Driver/ImapTest.php
new file mode 100644 (file)
index 0000000..f52ae74
--- /dev/null
@@ -0,0 +1,126 @@
+<?php
+/**
+ * Test the Kolab mock driver.
+ *
+ * PHP version 5
+ *
+ * @category   Kolab
+ * @package    Kolab_Storage
+ * @subpackage UnitTests
+ * @author     Gunnar Wrobel <wrobel@pardus.de>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link       http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the Kolab mock driver.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category   Kolab
+ * @package    Kolab_Storage
+ * @subpackage UnitTests
+ * @author     Gunnar Wrobel <wrobel@pardus.de>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link       http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Class_Driver_ImapTest
+extends PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        require_once 'Horde/Group.php';
+        require_once 'Horde/Group/mock.php';
+
+        $this->group = new Group_mock();
+    }
+
+    public function testGetNamespaceReturnsNamespaceHandler()
+    {
+        Horde_Nls::setCharset('UTF8');
+        $driver = new Horde_Kolab_Storage_Driver_Imap(
+            $this->_getNamespaceMock(),
+            $this->group,
+            array()
+        );
+        $this->assertType(
+            'Horde_Kolab_Storage_Namespace',
+            $driver->getNamespace()
+        );
+    }
+
+    public function testGetNamespaceReturnsExpectedNamespaces()
+    {
+        Horde_Nls::setCharset('UTF8');
+        $driver = new Horde_Kolab_Storage_Driver_Imap(
+            $this->_getNamespaceMock(),
+            $this->group,
+            array()
+        );
+        $namespaces = array();
+        foreach ($driver->getNamespace() as $namespace) {
+            $namespaces[$namespace->getName()] = array(
+                'type' => $namespace->getType(),
+                'delimiter' => $namespace->getDelimiter(),
+            );
+        }
+        $this->assertEquals(
+            array(
+                'INBOX' => array(
+                    'type' => 'personal',
+                    'delimiter' => '/',
+                ),
+                'user' => array(
+                    'type' => 'other',
+                    'delimiter' => '/',
+                ),
+                '' => array(
+                    'type' => 'shared',
+                    'delimiter' => '/',
+                ),
+            ),
+            $namespaces
+        );
+    }
+
+    private function _getNamespaceMock()
+    {
+        $imap = $this->getMock('Horde_Imap_Client_Socket', array(), array(), '', false, false);
+        $imap->expects($this->once())
+            ->method('queryCapability')
+            ->with('NAMESPACE')
+            ->will($this->returnValue(true));
+        $imap->expects($this->once())
+            ->method('getNamespaces')
+            ->will(
+                $this->returnValue(
+                    array(
+                        array(
+                            'type' => 'personal',
+                            'name' => 'INBOX',
+                            'delimiter' => '/',
+                        ),
+                        array(
+                            'type' => 'other',
+                            'name' => 'user',
+                            'delimiter' => '/',
+                        ),
+                        array(
+                            'type' => 'shared',
+                            'name' => '',
+                            'delimiter' => '/',
+                        ),
+                    )
+                )
+            );
+        return $imap;
+    }
+}
index a51ae33..aaed025 100644 (file)
@@ -45,6 +45,8 @@ extends PHPUnit_Framework_TestCase
 
     public function testGetAnnotationReturnsAnnotationValue()
     {
+        $this->markTestIncomplete();
+
         $data = array();
         $data['INBOX/Contacts']['annotations']['/vendor/kolab/folder-type']['value.shared'] = 'contact.default';
         $driver = new Horde_Kolab_Storage_Driver_Mock(
@@ -60,15 +62,46 @@ extends PHPUnit_Framework_TestCase
     public function testGetNamespaceReturnsNamespaceHandler()
     {
         Horde_Nls::setCharset('UTF8');
-        $data = array();
-        $data['INBOX/Contacts']['annotations']['/vendor/kolab/folder-type']['value.shared'] = 'contact.default';
         $driver = new Horde_Kolab_Storage_Driver_Mock(
             $this->group,
-            $data
+            array()
         );
         $this->assertType(
             'Horde_Kolab_Storage_Namespace',
             $driver->getNamespace()
         );
     }
+
+    public function testGetNamespaceReturnsExpectedNamespaces()
+    {
+        Horde_Nls::setCharset('UTF8');
+        $driver = new Horde_Kolab_Storage_Driver_Mock(
+            $this->group,
+            array()
+        );
+        $namespaces = array();
+        foreach ($driver->getNamespace() as $namespace) {
+            $namespaces[$namespace->getName()] = array(
+                'type' => $namespace->getType(),
+                'delimiter' => $namespace->getDelimiter(),
+            );
+        }
+        $this->assertEquals(
+            array(
+                'INBOX' => array(
+                    'type' => 'personal',
+                    'delimiter' => '/',
+                ),
+                'user' => array(
+                    'type' => 'other',
+                    'delimiter' => '/',
+                ),
+                '' => array(
+                    'type' => 'shared',
+                    'delimiter' => '/',
+                ),
+            ),
+            $namespaces
+        );
+    }
 }
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Class/Driver/PearTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Class/Driver/PearTest.php
new file mode 100644 (file)
index 0000000..af04010
--- /dev/null
@@ -0,0 +1,129 @@
+<?php
+/**
+ * Test the Kolab mock driver.
+ *
+ * PHP version 5
+ *
+ * @category   Kolab
+ * @package    Kolab_Storage
+ * @subpackage UnitTests
+ * @author     Gunnar Wrobel <wrobel@pardus.de>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link       http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the Kolab mock driver.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category   Kolab
+ * @package    Kolab_Storage
+ * @subpackage UnitTests
+ * @author     Gunnar Wrobel <wrobel@pardus.de>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link       http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Class_Driver_PearTest
+extends PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        require_once 'Horde/Group.php';
+        require_once 'Horde/Group/mock.php';
+
+        $this->group = new Group_mock();
+    }
+
+    public function testGetNamespaceReturnsNamespaceHandler()
+    {
+        Horde_Nls::setCharset('UTF8');
+        $driver = new Horde_Kolab_Storage_Driver_Pear(
+            $this->_getNamespaceMock(),
+            $this->group,
+            array()
+        );
+        $this->assertType(
+            'Horde_Kolab_Storage_Namespace',
+            $driver->getNamespace()
+        );
+    }
+
+    public function testGetNamespaceReturnsExpectedNamespaces()
+    {
+        Horde_Nls::setCharset('UTF8');
+        $driver = new Horde_Kolab_Storage_Driver_Pear(
+            $this->_getNamespaceMock(),
+            $this->group,
+            array()
+        );
+        $namespaces = array();
+        foreach ($driver->getNamespace() as $namespace) {
+            $namespaces[$namespace->getName()] = array(
+                'type' => $namespace->getType(),
+                'delimiter' => $namespace->getDelimiter(),
+            );
+        }
+        $this->assertEquals(
+            array(
+                'INBOX' => array(
+                    'type' => 'personal',
+                    'delimiter' => '/',
+                ),
+                'user' => array(
+                    'type' => 'other',
+                    'delimiter' => '/',
+                ),
+                '' => array(
+                    'type' => 'shared',
+                    'delimiter' => '/',
+                ),
+            ),
+            $namespaces
+        );
+    }
+
+    private function _getNamespaceMock()
+    {
+        $imap = $this->getMock('Net_IMAP', array(), array(), '', false, false);
+        $imap->expects($this->once())
+            ->method('hasCapability')
+            ->with('NAMESPACE')
+            ->will($this->returnValue(true));
+        $imap->expects($this->once())
+            ->method('getNamespace')
+            ->will(
+                $this->returnValue(
+                    array(
+                        'personal' => array(
+                            array(
+                                'name' => 'INBOX',
+                                'delimter' => '/',
+                            )
+                        ),
+                        'others' => array(
+                            array(
+                                'name' => 'user',
+                                'delimter' => '/',
+                            )
+                        ),
+                        'shared' => array(
+                            array(
+                                'name' => '',
+                                'delimter' => '/',
+                            )
+                        ),
+                    )
+                )
+            );
+        return $imap;
+    }
+}
index 4b79439..9fd134a 100644 (file)
@@ -51,6 +51,8 @@ class Horde_Kolab_Storage_DataTest extends PHPUnit_Framework_TestCase
      */
     public function testGetCacheKey()
     {
+        $this->markTestIncomplete();
+
         $data = new Horde_Kolab_Storage_Data('test');
 
         $folder = new Horde_Kolab_Storage_Folder_Base('INBOX/Test');
@@ -155,6 +157,8 @@ class Horde_Kolab_Storage_DataTest extends PHPUnit_Framework_TestCase
      */
     public function testSave()
     {
+        $this->markTestIncomplete();
+
         require_once 'Horde/Group.php';
         require_once 'Horde/Group/mock.php';
 
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Server/DriverTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Server/DriverTest.php
new file mode 100644 (file)
index 0000000..51507db
--- /dev/null
@@ -0,0 +1,188 @@
+<?php
+/**
+ * Server test of the different driver implementations.
+ *
+ * PHP version 5
+ *
+ * @category   Kolab
+ * @package    Kolab_Storage
+ * @subpackage UnitTests
+ * @author     Gunnar Wrobel <wrobel@pardus.de>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link       http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../Autoload.php';
+
+/**
+ * Server test of the different driver implementations.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category   Kolab
+ * @package    Kolab_Storage
+ * @subpackage UnitTests
+ * @author     Gunnar Wrobel <wrobel@pardus.de>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link       http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Server_DriverTest extends PHPUnit_Framework_TestCase
+{
+    const MOCK         = 'Mock';
+    const CCLIENT      = 'Cclient';
+    const PEAR         = 'Pear';
+    const IMAP_SOCKET  = 'Imap_Socket';
+    const IMAP_CCLIENT = 'Imap_Cclient';
+
+    public function setUp()
+    {
+        if ($this->sharedFixture === null) {
+            $this->markTestSkipped('Testing of a running server skipped. No configuration fixture available.');
+            return;
+        }
+
+        /** @todo: FIXME -> required for namespace handling */
+        Horde_Nls::setCharset('UTF8');
+
+        /** Setup group handler */
+        require_once 'Horde/Group.php';
+        require_once 'Horde/Group/mock.php';
+        $this->group = new Group_mock();
+
+
+    }
+
+    public function tearDown()
+    {
+        /** Reactivate strict reporting as we need to turn it off for PEAR-Net_IMAP */
+        if (!empty($this->old_error_reporting)) {
+            error_reporting($this->old_error_reporting);
+        }
+    }
+
+    public function provideDrivers()
+    {
+        return array(
+            'mock driver' => array(self::MOCK),
+            'PHP c-client based driver' => array(self::CCLIENT),
+            'PEAR-Net_IMAP based driver' => array(self::PEAR),
+            'Horde_Imap_Client_Socket based driver' => array(self::IMAP_SOCKET),
+            'Horde_Imap_Client_Cclient based driver' => array(self::IMAP_CCLIENT),
+        );
+    }
+
+    private function _getDriver($driver)
+    {
+        if ($driver == self::PEAR) {
+            /** PEAR-Net_IMAP is not E_STRICT */
+            $this->old_error_reporting = error_reporting(E_ALL & ~E_STRICT);
+        }
+        if (!isset($this->sharedFixture->drivers[$driver])) {
+            switch ($driver) {
+            case self::MOCK:
+                $connection = new Horde_Kolab_Storage_Driver_Mock($this->group);
+                break;
+            case self::CCLIENT:
+                $connection = new Horde_Kolab_Storage_Driver_Cclient(
+                    $this->group
+                );
+                break;
+            case self::PEAR:
+                $client = new Net_IMAP($this->sharedFixture->conf['host'], 143, false);
+                $client->login(
+                    $this->sharedFixture->conf['user'],
+                    $this->sharedFixture->conf['pass']
+                );
+
+                $connection = new Horde_Kolab_Storage_Driver_Pear(
+                    $client,
+                    $this->group
+                );
+                break;
+            case self::IMAP_SOCKET:
+                $params = array(
+                    'hostspec' => $this->sharedFixture->conf['host'],
+                    'username' => $this->sharedFixture->conf['user'],
+                    'password' => $this->sharedFixture->conf['pass'],
+                    'debug'    => $this->sharedFixture->conf['debug'],
+                    'port'     => 143,
+                    'secure'   => false
+                );
+                $client = Horde_Imap_Client::factory('socket', $params);
+                $client->login();
+
+                $connection = new Horde_Kolab_Storage_Driver_Imap(
+                    $client,
+                    $this->group
+                );
+                break;
+            case self::IMAP_CCLIENT:
+                $params = array(
+                    'hostspec' => $this->sharedFixture->conf['host'],
+                    'username' => $this->sharedFixture->conf['user'],
+                    'password' => $this->sharedFixture->conf['pass'],
+                    'debug'    => $this->sharedFixture->conf['debug'],
+                    'port'     => 143,
+                    'secure'   => false
+                );
+                $client = Horde_Imap_Client::factory('cclient', $params);
+                $client->login();
+
+                $connection = new Horde_Kolab_Storage_Driver_Imap(
+                    $client,
+                    $this->group
+                );
+                break;
+            default:
+                exit("Undefined storage driver!\n");
+            }
+            $this->sharedFixture->drivers[$driver] = $connection;
+        }
+        return $this->sharedFixture->drivers[$driver];
+    }
+
+    /**
+     * @dataProvider provideDrivers
+     */
+    public function testDriverType($driver)
+    {
+        $this->assertType('Horde_Kolab_Storage_Driver', $this->_getDriver($driver));
+    }
+
+    /**
+     * @dataProvider provideDrivers
+     */
+    public function testGetNamespace($driver)
+    {
+        $namespaces = array();
+        foreach ($this->_getDriver($driver)->getNamespace() as $namespace) {
+            $namespaces[$namespace->getName()] = array(
+                'type' => $namespace->getType(),
+                'delimiter' => $namespace->getDelimiter(),
+            );
+        }
+        $this->assertEquals(
+            array(
+                'INBOX' => array(
+                    'type' => 'personal',
+                    'delimiter' => '/',
+                ),
+                'user' => array(
+                    'type' => 'other',
+                    'delimiter' => '/',
+                ),
+                '' => array(
+                    'type' => 'shared',
+                    'delimiter' => '/',
+                ),
+            ),
+            $namespaces
+        );
+    }
+}
\ No newline at end of file
index 20d1adc..01e371b 100644 (file)
@@ -40,4 +40,7 @@ class Horde_Kolab_Storage_TriggerTest extends PHPUnit_Framework_TestCase
         $this->_connection = $this->getMock('Horde_Kolab_Storage_Driver');
     }
 
+    public function testNothing()
+    {
+    }
 }
\ No newline at end of file