Add server testing using a shared fixture.
- Do not hide the prefix of the shared namespace?
- Fix the triggering decorator
+
+ - Test the Driver implementations
+
+ - getNamespace() [DONE]
* @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.
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
/**
* 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);
}
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
* @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.
/**
* 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);
}
/**
*/
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
*
* @return array An array with IMAP ACL.
*/
- public function getACL()
+ public function getAcl()
{
- return $this->_folder->getACL();
+ return $this->_folder->getAcl();
}
/**
*
* @return NULL
*/
- public function setACL($user, $acl)
+ public function setAcl($user, $acl)
{
- $this->_folder->setACL($user, $acl);
+ $this->_folder->setAcl($user, $acl);
}
/**
*
* @return NULL
*/
- public function deleteACL($user)
+ public function deleteAcl($user)
{
- $this->_folder->deleteACL($user);
+ $this->_folder->deleteAcl($user);
}
}
/**
* 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.
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
* @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)
{
//@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;
}
/**
//@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;
}
/**
* @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();
}
/**
*
* @return NULL
*/
- public function setACL($user, $acl)
+ public function setAcl($user, $acl)
{
- $this->_folder->setACL($user, $acl);
-
+ $this->_folder->setAcl($user, $acl);
$this->trigger();
}
*
* @return NULL
*/
- public function deleteACL($user)
+ public function deleteAcl($user)
{
- $this->_folder->deleteACL($user);
-
+ $this->_folder->deleteAcl($user);
$this->trigger();
}
* @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';
protected $_primaryPersonalNamespace;
/**
+ * A helper for iteration over the namespaces.
+ *
+ * @var array
+ */
+ protected $_iteration;
+
+ /**
* Constructor.
*/
public function __construct()
}
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
}
/**
+ * 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.
<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>
--- /dev/null
+<?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
*/
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__);
--- /dev/null
+<?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
+ );
+ }
+}
--- /dev/null
+<?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;
+ }
+}
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(
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
+ );
+ }
}
--- /dev/null
+<?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;
+ }
+}
*/
public function testGetCacheKey()
{
+ $this->markTestIncomplete();
+
$data = new Horde_Kolab_Storage_Data('test');
$folder = new Horde_Kolab_Storage_Folder_Base('INBOX/Test');
*/
public function testSave()
{
+ $this->markTestIncomplete();
+
require_once 'Horde/Group.php';
require_once 'Horde/Group/mock.php';
--- /dev/null
+<?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
$this->_connection = $this->getMock('Horde_Kolab_Storage_Driver');
}
+ public function testNothing()
+ {
+ }
}
\ No newline at end of file