From: Gunnar Wrobel Date: Thu, 24 Sep 2009 08:01:51 +0000 (+0200) Subject: Convert the package and the testsuite to using Horde_Injector. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=d98e23be1d8e6882a2f99d9823d70cb028b53455;p=horde.git Convert the package and the testsuite to using Horde_Injector. --- diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server.php b/framework/Kolab_Server/lib/Horde/Kolab/Server.php index 25acdf42d..47f327d35 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server.php @@ -96,14 +96,10 @@ abstract class Horde_Kolab_Server * @param array $params Parameter array. */ public function __construct(Horde_Kolab_Server_Structure $structure, - Horde_Cache $cache = null, - Horde_Log_Logger $logger = null, $params = array()) { $structure->setServer($this); $this->structure = $structure; - $this->cache = $cache; - $this->logger = $logger; $this->params = $params; if (!isset($this->params['cache_lifetime'])) { @@ -114,38 +110,32 @@ abstract class Horde_Kolab_Server $this->uid = $params['uid']; } - // Initialize the search operations supported by this server. + /** Initialize the search operations supported by this server. */ $this->searches = $this->getSearchOperations(); } /** - * Attempts to return a concrete Horde_Kolab_Server instance based - * on $driver. + * Set the optional log handler. * - * @param mixed $driver The type of concrete Horde_Kolab_Server subclass to - * return. - * @param array $params A hash containing any additional - * configuration or connection parameters a subclass - * might need. + * @param Horde_Log_Logger $logger The log handler. * - * @return Horde_Kolab_Server The newly created concrete Horde_Kolab_Server - * instance. + * @return NULL + */ + public function setLogger(Horde_Log_Logger $logger) + { + $this->logger = $logger; + } + + /** + * Set the optional cache handler. + * + * @param Horde_Cache $cache The cache handler. * - * @throws Horde_Kolab_Server_Exception If the requested Horde_Kolab_Server - * subclass could not be found. + * @return NULL */ - static public function &factory($provider) + public function setCache(Horde_Cache $cache) { - $class = 'Horde_Kolab_Server_' . ucfirst(basename($provider->kolab_server_driver)); - if (class_exists($class)) { - $server = new $class($provider->kolab_server_structure, - isset($provider->cache) ? $provider->cache : null, - isset($provider->logger) ? $provider->logger : null, - $provider->kolab_server_params); - return $server; - } - throw new Horde_Kolab_Server_Exception( - 'Server type definition "' . $class . '" missing.'); + $this->cache = $cache; } /** @@ -228,7 +218,7 @@ abstract class Horde_Kolab_Server $provider->kolab_server_params = $params; - $tmp_server = &Horde_Kolab_Server::factory($provider); + $tmp_server = &Horde_Kolab_Server_Factory::getServer($provider); try { $uid = $tmp_server->uidForIdOrMail($params['user']); @@ -254,7 +244,7 @@ abstract class Horde_Kolab_Server $provider->kolab_server_params = $params; - $instances[$signature] = &Horde_Kolab_Server::factory($provider); + $instances[$signature] = &Horde_Kolab_Server_Factory::getServer($provider); } return $instances[$signature]; @@ -286,7 +276,7 @@ abstract class Horde_Kolab_Server function shutdown() { if (isset($this->attributes)) { - if (!empty($this->cache)) { + if (isset($this->cache)) { foreach ($this->attributes as $key => $value) { $this->cache->set('attributes_' . $key, @serialize($value)); } @@ -461,13 +451,13 @@ abstract class Horde_Kolab_Server public function &getAttributes($class) { if (!isset($this->attributes)) { - if (!empty($this->cache)) { + if (isset($this->cache)) { register_shutdown_function(array($this, 'shutdown')); } } if (empty($this->attributes[$class])) { - if (!empty($this->cache)) { + if (isset($this->cache)) { $this->attributes[$class] = @unserialize($cache->get('attributes_' . $class, $this->params['cache_lifetime'])); } @@ -488,7 +478,7 @@ abstract class Horde_Kolab_Server $classes[] = $childclass; if ($level == self::MAX_HIERARCHY) { - if (!empty($this->logger)) { + if (isset($this->logger)) { $logger->err(sprintf('The maximal level of the object hierarchy has been exceeded for class \"%s\"!', $class)); } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory.php new file mode 100644 index 000000000..ee9a41e35 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory.php @@ -0,0 +1,129 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * The Autoloader allows us to omit "require/include" statements. + */ +require_once 'Horde/Autoloader.php'; + +/** + * A factory for Kolab server objects. + * + * Copyright 2008-2009 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_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Factory +{ + /** + * Attempts to return a concrete Horde_Kolab_Server instance. + * + * @param Horde_Injector $injector The object providing our dependencies. + * + * @return Horde_Kolab_Server The newly created concrete Horde_Kolab_Server + * instance. + * + * @throws Horde_Kolab_Server_Exception If the requested Horde_Kolab_Server + * subclass could not be found. + */ + static public function &getServer(Horde_Injector $injector) + { + $driver = 'Horde_Kolab_Server_Ldap'; + $params = array(); + + try { + $config = $injector->getInstance('Horde_Kolab_Server_Config'); + + if (isset($config->driver)) { + $driver = $config->driver; + } + if (isset($config->params)) { + $params = $config->params; + } + } catch (ReflectionException $e) { + } + + if (class_exists($driver)) { + $class = $driver; + } else { + $class = 'Horde_Kolab_Server_' . ucfirst(basename($driver)); + if (!class_exists($class)) { + throw new Horde_Kolab_Server_Exception('Server type definition "' . $class . '" missing.'); + } + } + + $server = new $class($injector->getInstance('Horde_Kolab_Server_Structure'), + $params); + + try { + $server->setCache($injector->getInstance('Horde_Kolab_Server_Cache')); + } catch (ReflectionException $e) { + } + + try { + $server->setLogger($injector->getInstance('Horde_Kolab_Server_Logger')); + } catch (ReflectionException $e) { + } + + return $server; + } + + /** + * Attempts to return a concrete Horde_Kolab_Server_Structure instance. + * + * @param Horde_Injector $injector The object providing our dependencies. + * + * @return Horde_Kolab_Server_Structure The newly created concrete + * Horde_Kolab_Server_Structure + * instance. + * + * @throws Horde_Kolab_Server_Exception If the requested + * Horde_Kolab_Server_Structure + * subclass could not be found. + */ + static public function &getStructure(Horde_Injector $injector) + { + $driver = 'Horde_Kolab_Server_Structure_Kolab'; + $params = array(); + + try { + $config = $injector->getInstance('Horde_Kolab_Server_Structure_Config'); + + if (isset($config->driver)) { + $driver = $config->driver; + } + if (isset($config->params)) { + $params = $config->params; + } + } catch (ReflectionException $e) { + } + + if (class_exists($driver)) { + $class = $driver; + } else { + $class = 'Horde_Kolab_Server_Structure_' . ucfirst(basename($driver)); + if (!class_exists($class)) { + throw new Horde_Kolab_Server_Exception('Structure type definition "' . $class . '" missing.'); + } + } + $structure = new $class($params); + return $structure; + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/File.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/File.php index e1c990316..5cb63b7d0 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/File.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/File.php @@ -42,8 +42,6 @@ class Horde_Kolab_Server_File extends Horde_Kolab_Server_Test * @param array $params Parameter array. */ public function __construct(Horde_Kolab_Server_Structure $structure, - Horde_Cache $cache = null, - Horde_Log_Logger $logger = null, $params = array()) { if (isset($params['file'])) { @@ -51,7 +49,7 @@ class Horde_Kolab_Server_File extends Horde_Kolab_Server_Test } else { throw new Horde_Kolab_Server_Exception('The file based driver requires a \'file\' parameter.'); } - parent::__construct($structure, $cache, $logger, $params); + parent::__construct($structure, $params); } @@ -69,7 +67,7 @@ class Horde_Kolab_Server_File extends Horde_Kolab_Server_Test $this->data = $data; } else { $error = error_get_last(); - if (!empty($this->logger)) { + if (isset($this->logger)) { $this->logger->warn(sprintf('Horde_Kolab_Server_file failed to read the database from %s. Error was: %s', $this->_file, $error['message'])); } @@ -89,7 +87,7 @@ class Horde_Kolab_Server_File extends Horde_Kolab_Server_Test $result = @file_put_contents($this->_file, $raw_data); if ($result === false) { $error = error_get_last(); - if (!empty($this->logger)) { + if (isset($this->logger)) { $this->logger->warn(sprintf('Horde_Kolab_Server_file failed to store the database in %s. Error was: %s', $this->_file, $error['message'])); } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap.php index f3a41df85..c933c54c3 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap.php @@ -71,8 +71,6 @@ class Horde_Kolab_Server_Ldap extends Horde_Kolab_Server * @param array $params Parameter array. */ public function __construct(Horde_Kolab_Server_Structure $structure, - Horde_Cache $cache = null, - Horde_Log_Logger $logger = null, $params = array()) { if (!isset($params['charset'])) { @@ -101,7 +99,7 @@ class Horde_Kolab_Server_Ldap extends Horde_Kolab_Server $this->connect(); - parent::__construct($structure, $cache, $logger, $params); + parent::__construct($structure, $params); } @@ -264,7 +262,7 @@ class Horde_Kolab_Server_Ldap extends Horde_Kolab_Server Horde_Kolab_Server_Exception::SYSTEM); } } - if (!empty($this->logger)) { + if (isset($this->logger)) { $this->logger->debug(sprintf('The object \"%s\" has been successfully saved!', $uid)); } @@ -287,7 +285,7 @@ class Horde_Kolab_Server_Ldap extends Horde_Kolab_Server throw new Horde_Kolab_Server_Exception($result, Horde_Kolab_Server_Exception::SYSTEM); } - if (!empty($this->logger)) { + if (isset($this->logger)) { $this->logger(sprintf('The object \"%s\" has been successfully deleted!', $uid)); } @@ -313,7 +311,7 @@ class Horde_Kolab_Server_Ldap extends Horde_Kolab_Server throw new Horde_Kolab_Server_Exception($result, Horde_Kolab_Server_Exception::SYSTEM); } - if (!empty($this->logger)) { + if (isset($this->logger)) { $this->logger->debug(sprintf('The object \"%s\" has been successfully renamed to \"%s\"!', $uid, $new)); } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Scenario.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Scenario.php new file mode 100644 index 000000000..9a665a883 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Scenario.php @@ -0,0 +1,1054 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Share + */ + +/** + * The Autoloader allows us to omit "require/include" statements. + */ +require_once 'Horde/Autoloader.php'; + +/** + * Base for PHPUnit scenarios. + * + * Copyright 2008-2009 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_Test + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Share + */ +class Horde_Kolab_Server_Scenario extends PHPUnit_Extensions_Story_TestCase +{ + /** The mock environment */ + const ENVIRONMENT_MOCK = 'mock'; + + /** The real server environment */ + const ENVIRONMENT_REAL = 'real'; + + /** + * The environments we provide to the test. + * + * @var array + */ + protected $_environments; + + /** + * Uid of added objects. Should be removed on tearDown. + * + * @var array + */ + public $added; + + /** + * Handle a "given" step. + * + * @param array &$world Joined "world" of variables. + * @param string $action The description of the step. + * @param array $arguments Additional arguments to the step. + * + * @return mixed The outcome of the step. + */ + public function runGiven(&$world, $action, $arguments) + { + switch($action) { + case 'several injectors': + foreach ($this->getEnvironments() as $environment) { + $this->prepareInjector($environment); + } + break; + case 'several Kolab servers': + foreach ($this->getEnvironments() as $environment) { + $this->prepareInjector($environment); + $this->prepareKolabServerConfiguration($environment); + $this->prepareKolabServer($environment); + } + break; + case 'the test environments': + $this->initializeEnvironments(); + break; + case 'an empty Kolab server': + $world['server'] = $this->prepareKolabServer(self::ENVIRONMENT_MOCK); + break; + case 'a basic Kolab server': + $world['server'] = &$this->prepareBasicKolabServer($world); + break; + default: + return $this->notImplemented($action); + } + } + + /** + * Handle a "when" step. + * + * @param array &$world Joined "world" of variables. + * @param string $action The description of the step. + * @param array $arguments Additional arguments to the step. + * + * @return mixed The outcome of the step. + */ + public function runWhen(&$world, $action, $arguments) + { + switch($action) { + case 'adding a Kolab server object': + $world['result']['add'] = $this->addToServers($arguments[0]); + break; + case 'adding an invalid Kolab server object': + try { + $world['result']['add'] = $this->addToServers($arguments[0]); + } catch (Horde_Kolab_Server_Exception $e) { + $world['result']['add'] = $e; + } + break; + case 'adding an object list': + foreach ($arguments[0] as $object) { + try { + $world['result']['add'][] = $this->addToServers($object); + } catch (Horde_Kolab_Server_Exception $e) { + $world['result']['add'] = $e; + return; + } + } + $world['result']['add'] = true; + break; + case 'adding a distribution list': + $world['result']['add'] = $this->addToServers($this->provideDistributionList()); + break; + case 'listing all users': + $world['list'] = $this->listObjectsOnServer('Horde_Kolab_Server_Object_Kolab_User'); + break; + case 'listing all groups': + $world['list'] = $this->listObjectsOnServer('Horde_Kolab_Server_Object_Kolabgroupofnames'); + break; + case 'listing all objects of type': + $world['list'] = $this->listObjectsOnServer($arguments[0]); + break; + case 'retrieving a hash list with all objects of type': + $world['list'] = array(); + foreach ($this->world['injector'] as $injector) { + $server = $injector->getInstance('Horde_Kolab_Server'); + $world['list'][] = $server->listHash($arguments[0]); + } + break; + default: + return $this->notImplemented($action); + } + } + + /** + * Handle a "then" step. + * + * @param array &$world Joined "world" of variables. + * @param string $action The description of the step. + * @param array $arguments Additional arguments to the step. + * + * @return mixed The outcome of the step. + */ + public function runThen(&$world, $action, $arguments) + { + switch($action) { + case 'the result should be an object of type': + if (!isset($world['result'])) { + $this->fail('Did not receive a result!'); + } + $this->assertRecursiveType($world['result'], $arguments[0]); + break; + case 'the result indicates success.': + if (!isset($world['result'])) { + $this->fail('Did not receive a result!'); + } + $this->assertNoError($world['result']); + break; + case 'the result should indicate an error with': + if (!isset($world['result'])) { + $this->fail('Did not receive a result!'); + } + foreach ($world['result'] as $result) { + if ($result instanceOf Horde_Kolab_Server_Exception) { + $this->assertEquals($arguments[0], $result->getMessage()); + } else { + $this->assertEquals($arguments[0], 'Action succeeded without an error.'); + } + } + break; + case 'the list has a number of entries equal to': + if ($world['list'] instanceOf Horde_Kolab_Server_Exception) { + $this->assertEquals('', $world['list']->getMessage()); + } else { + $this->assertEquals($arguments[0], count($world['list'])); + } + break; + case 'the list is an empty array': + if ($world['list'] instanceOf Horde_Kolab_Server_Exception) { + $this->assertEquals('', $world['list']->getMessage()); + } else { + $this->assertEquals(array(array()), $world['list']); + } + break; + case 'the list is an empty array': + if ($world['list'] instanceOf Horde_Kolab_Server_Exception) { + $this->assertEquals('', $world['list']->getMessage()); + } else { + $this->assertEquals(array(), $world['list']); + } + break; + case 'the provided list and the result list match with regard to these attributes': + if ($world['list'] instanceOf Horde_Kolab_Server_Exception) { + $this->assertEquals('', $world['list']->getMessage()); + } else { + $provided_vals = array(); + foreach ($arguments[2] as $provided_element) { + if (isset($provided_element[$arguments[0]])) { + $provided_vals[] = $provided_element[$arguments[0]]; + } else { + $this->fail(sprintf('The provided element %s does have no value for %s.', + print_r($provided_element, true), + print_r($arguments[0]))); + } + } + $result_vals = array(); + foreach ($world['list'] as $result_set) { + foreach ($result_set as $result_element) { + if (isset($result_element[$arguments[1]])) { + $result_vals[] = $result_element[$arguments[1]]; + } else { + $this->fail(sprintf('The result element %s does have no value for %s.', + print_r($result_element, true), + print_r($arguments[1]))); + } + } + $this->assertEquals(array(), + array_diff($provided_vals, $result_vals)); + } + } + break; + case 'each element in the result list has an attribute': + if ($world['list'] instanceOf Horde_Kolab_Server_Exception) { + $this->assertEquals('', $world['list']->getMessage()); + } else { + $result_vals = array(); + foreach ($world['list'] as $result_set) { + foreach ($result_set as $result_element) { + if (!isset($result_element[$arguments[0]])) { + $this->fail(sprintf('The result element %s does have no value for %s.', + print_r($result_element, true), + print_r($arguments[0], true))); + } + } + } + } + break; + case 'each element in the result list has an attribute set to a given value': + if ($world['list'] instanceOf Horde_Kolab_Server_Exception) { + $this->assertEquals('', $world['list']->getMessage()); + } else { + $result_vals = array(); + foreach ($world['list'] as $result_set) { + foreach ($result_set as $result_element) { + if (!isset($result_element[$arguments[0]])) { + $this->fail(sprintf('The result element %s does have no value for %s.', + print_r($result_element, true), + print_r($arguments[0], true))); + } + if ($result_element[$arguments[0]] != $arguments[1]) { + $this->fail(sprintf('The result element %s has an unexpected value %s for %s.', + print_r($result_element, true), + print_r($result_element[$arguments[0]], true), + print_r($arguments[0], true))); + } + } + } + } + break; + case 'the login was successful': + $this->assertNoError($world['login']); + $this->assertTrue($world['login']); + break; + case 'the list contains a number of elements equal to': + $this->assertEquals($arguments[0], count($world['list'])); + break; + default: + return $this->notImplemented($action); + } + } + + /** + * Identify the environments we want to run our tests in. + * + * @return array The selected environments. + */ + public function getEnvironments() + { + if (empty($this->_environments)) { + /** The mock environment provides our basic test scenario */ + $this->_environments = array(self::ENVIRONMENT_MOCK); + $testing = getenv('KOLAB_TEST'); + if (!empty($testing)) { + $this->_environments[] = array(self::ENVIRONMENT_REAL); + } + } + return $this->_environments; + } + + /** + * Specifically set the environments we whish to support. + * + * @param array $environments The selected environments. + * + * @return NULL + */ + public function setEnvironments($environments) + { + $this->_environments = $environments; + } + + /** + * Initialize an environment for + * + * @param string $environment The name of the environment. + * + * @return NULL + */ + public function initializeEnvironments() + { + foreach ($this->getEnvironments() as $environment) { + $this->initializeEnvironment($environment); + } + } + + /** + * Prepare an injector for the given environment. + * + * @param string $environment The name of the environment. + * + * @return NULL + */ + public function prepareInjector($environment) + { + if (!isset($this->world['injector'][$environment])) { + $this->world['injector'][$environment] = new Horde_Injector(new Horde_Injector_TopLevel()); + } + } + + /** + * Prepare the server configuration for the given environment. + * + * @param string $environment The name of the environment. + * + * @return NULL + */ + public function prepareKolabServerConfiguration($environment) + { + switch ($environment) { + case self::ENVIRONMENT_MOCK: + /** Prepare a Kolab test server */ + $config = new stdClass; + $config->driver = 'test'; + $config->params = array( + 'basedn' => 'dc=example,dc=org', + 'hashtype' => 'plain' + ); + $this->world['injector'][$environment]->setInstance('Horde_Kolab_Server_Config', $config); + break; + default: + throw new Horde_Exception('Not implemented!'); + } + } + + /** + * Prepare the server for the given environment. + * + * @param string $environment The name of the environment. + * + * @return NULL + */ + public function prepareKolabServer($environment) + { + $this->world['injector'][$environment]->bindFactory('Horde_Kolab_Server_Structure', + 'Horde_Kolab_Server_Factory', + 'getStructure'); + $this->world['injector'][$environment]->bindFactory('Horde_Kolab_Server', + 'Horde_Kolab_Server_Factory', + 'getServer'); + } + + /** + * Get a server from a specific environment. + * + * @param string $environment The name of the environment. + * + * @return Horde_Kolab_Server The server. + */ + public function getKolabServer($environment) + { + return $this->world['injector'][$environment]->getInstance('Horde_Kolab_Server'); + } + + /** + * Initialize the given environment. + * + * @param string $environment The name of the environment. + * + * @return NULL + */ + public function initializeEnvironment($environment) + { + $this->prepareInjector($environment); + $this->prepareKolabServerConfiguration($environment); + $this->prepareKolabServer($environment); + } + + /** + * Shortcut to get a Kolab mock server. + * + * @return Horde_Kolab_Server The server. + */ + public function getKolabMockServer() + { + $this->initializeEnvironment(self::ENVIRONMENT_MOCK); + return $this->getKolabServer(self::ENVIRONMENT_MOCK); + } + + /** + * Retrieves the available servers. This assumes all environments have been + * initialied. + * + * @return array The list of test servers. + */ + public function getKolabServers() + { + $servers = array(); + foreach ($this->getEnvironments() as $environment) { + $servers[] = $this->getKolabServer($environment); + } + return $servers; + } + + /** + * Add an object to the registered servers. + * + * @param array $object The object data to store. + * + * @return array An array of objects. + */ + public function addToServers($object) + { + $result = array(); + foreach ($this->world['injector'] as $injector) { + $server = $injector->getInstance('Horde_Kolab_Server'); + $object = $server->add($object); + $result[] = $object; + $this->added[] = array($server, $object->getUid()); + } + return $result; + } + + /** + * Fill a Kolab Server with test users. + * + * @param Horde_Kolab_Server &$server The server to fill. + * + * @return NULL + */ + public function addBasicUsersToServer(&$server) + { + $result = $server->add($this->provideBasicUserOne()); + $this->assertNoError($result); + $result = $server->add($this->provideBasicUserTwo()); + $this->assertNoError($result); + $result = $server->add($this->provideBasicAddress()); + $this->assertNoError($result); + $result = $server->add($this->provideBasicAdmin()); + $this->assertNoError($result); + $result = $server->add($this->provideBasicDomainMaintainer()); + $this->assertNoError($result); + $result = $server->add($this->provideGroupWithoutMembers()); + $this->assertNoError($result); + $result = $server->add($this->provideBasicGroupOne()); + $this->assertNoError($result); + $result = $server->add($this->provideBasicMaintainer()); + $this->assertNoError($result); + $result = $server->add($this->provideBasicSharedFolder()); + $this->assertNoError($result); + } + + /** + * List objects on the registered servers. + * + * @param array $type The type of objects to list. + * + * @return array An array of objects. + */ + public function listObjectsOnServer($type) + { + $result = array(); + foreach ($this->world['injector'] as $injector) { + $server = $injector->getInstance('Horde_Kolab_Server'); + $objects = $server->listObjects($type); + $result[] = $objects; + } + return $result; + } + + /** + * Return a test user. + * + * @return array The test user. + */ + public function provideBasicUserOne() + { + return array('givenName' => 'Gunnar', + 'sn' => 'Wrobel', + 'type' => 'Horde_Kolab_Server_Object_Kolab_User', + 'mail' => 'wrobel@example.org', + 'uid' => 'wrobel', + 'userPassword' => 'none', + 'kolabHomeServer' => 'home.example.org', + 'kolabImapServer' => 'imap.example.org', + 'kolabFreeBusyServer' => 'https://fb.example.org/freebusy', + 'kolabInvitationPolicy' => array('ACT_REJECT_IF_CONFLICTS'), + 'alias' => array('gunnar@example.org', + 'g.wrobel@example.org'), + ); + } + + /** + * Return a test user. + * + * @return array The test user. + */ + public function provideBasicUserTwo() + { + return array('givenName' => 'Test', + 'sn' => 'Test', + 'type' => 'Horde_Kolab_Server_Object_Kolab_User', + 'mail' => 'test@example.org', + 'uid' => 'test', + 'userPassword' => 'test', + 'kolabHomeServer' => 'home.example.org', + 'kolabImapServer' => 'home.example.org', + 'kolabFreeBusyServer' => 'https://fb.example.org/freebusy', + 'alias' => array('t.test@example.org'), + 'kolabDelegate' => 'wrobel@example.org',); + } + + /** + * Return a test address. + * + * @return array The test address. + */ + public function provideBasicAddress() + { + return array('type' => 'Horde_Kolab_Server_Object_Kolab_Address', + Horde_Kolab_Server_Object_Kolab_Administrator::ATTRIBUTE_GIVENNAME => 'Test', + Horde_Kolab_Server_Object_Kolab_Administrator::ATTRIBUTE_SN => 'Address', + Horde_Kolab_Server_Object_Kolab_Administrator::ATTRIBUTE_MAIL => 'address@example.org', + ); + } + + /** + * Return a test administrator. + * + * @return array The test administrator. + */ + public function provideBasicAdmin() + { + return array('type' => 'Horde_Kolab_Server_Object_Kolab_Administrator', + Horde_Kolab_Server_Object_Kolab_Administrator::ATTRIBUTE_GIVENNAME => 'The', + Horde_Kolab_Server_Object_Kolab_Administrator::ATTRIBUTE_SN => 'Administrator', + Horde_Kolab_Server_Object_Kolab_Administrator::ATTRIBUTE_SID => 'admin', + Horde_Kolab_Server_Object_Kolab_Administrator::ATTRIBUTE_USERPASSWORD => 'none', + ); + } + + /** + * Return a test maintainer. + * + * @return array The test maintainer. + */ + public function provideBasicMaintainer() + { + return array('type' => 'Horde_Kolab_Server_Object_Kolab_Maintainer', + Horde_Kolab_Server_Object_Kolab_Maintainer::ATTRIBUTE_GIVENNAME => 'Main', + Horde_Kolab_Server_Object_Kolab_Maintainer::ATTRIBUTE_SN => 'Tainer', + Horde_Kolab_Server_Object_Kolab_Maintainer::ATTRIBUTE_SID => 'maintainer', + Horde_Kolab_Server_Object_Kolab_Maintainer::ATTRIBUTE_USERPASSWORD => 'none', + ); + } + + /** + * Return a test domain maintainer. + * + * @return array The test domain maintainer. + */ + public function provideBasicDomainMaintainer() + { + return array('type' => 'Horde_Kolab_Server_Object_Kolab_Domainmaintainer', + Horde_Kolab_Server_Object_Kolab_Domainmaintainer::ATTRIBUTE_GIVENNAME => 'Domain', + Horde_Kolab_Server_Object_Kolab_Domainmaintainer::ATTRIBUTE_SN => 'Maintainer', + Horde_Kolab_Server_Object_Kolab_Domainmaintainer::ATTRIBUTE_SID => 'domainmaintainer', + Horde_Kolab_Server_Object_Kolab_Domainmaintainer::ATTRIBUTE_USERPASSWORD => 'none', + Horde_Kolab_Server_Object_Kolab_Domainmaintainer::ATTRIBUTE_DOMAIN => array('example.com'), + + ); + } + + /** + * Return a test shared folder. + * + * @return array The test shared folder. + */ + public function provideBasicSharedFolder() + { + return array('type' => 'Horde_Kolab_Server_Object_Kolabsharedfolder', + Horde_Kolab_Server_Object_Kolabsharedfolder::ATTRIBUTE_CN => 'shared@example.org', + Horde_Kolab_Server_Object_Kolabsharedfolder::ATTRIBUTE_HOMESERVER => 'example.org', + ); + } + + /** + * Provide a set of valid groups. + * + * @return array The array of groups. + */ + public function groupLists() + { + $groups = $this->validGroups(); + $result = array(); + foreach ($groups as $group) { + $result[] = array($group); + } + return $result; + } + + /** + * Provide a set of valid groups. + * + * @return array The array of groups. + */ + public function validGroups() + { + return array( + array( + $this->provideGroupWithoutMembers(), + ), + array( + $this->provideBasicGroupOne(), + ), + array( + $this->provideBasicGroupTwo(), + ), + ); + } + + /** + * Return a test group. + * + * @return array The test group. + */ + public function provideGroupWithoutMembers() + { + return array('type' => 'Horde_Kolab_Server_Object_Kolabgroupofnames', + Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MAIL => 'empty.group@example.org', + Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MEMBER => array()); + } + + /** + * Return a test group. + * + * @return array The test group. + */ + public function provideBasicGroupOne() + { + return array('type' => 'Horde_Kolab_Server_Object_Kolabgroupofnames', + Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MAIL => 'group@example.org', + Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MEMBER => array('cn=Test Test,dc=example,dc=org', + 'cn=Gunnar Wrobel,dc=example,dc=org') + ); + } + + /** + * Return a test group. + * + * @return array The test group. + */ + public function provideBasicGroupTwo() + { + return array('type' => 'Horde_Kolab_Server_Object_Kolabgroupofnames', + Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MAIL => 'group2@example.org', + Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MEMBER => array('cn=Gunnar Wrobel,dc=example,dc=org') + ); + } + + public function provideDistributionList() + { + return array('type' => 'Horde_Kolab_Server_Object_Kolab_Distlist', + Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MAIL => 'distlist@example.org', + Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MEMBER => array('cn=Test Test,dc=example,dc=org', + 'cn=Gunnar Wrobel,dc=example,dc=org') + ); + } + + public function provideInvalidUserWithoutPassword() + { + return array('givenName' => 'Test', + 'sn' => 'Test', + 'type' => 'Horde_Kolab_Server_Object_Kolab_User', + 'mail' => 'test@example.org'); + } + + public function provideInvalidUserWithoutGivenName() + { + return array('sn' => 'Test', + 'userPassword' => 'none', + 'type' => 'Horde_Kolab_Server_Object_Kolab_User', + 'mail' => 'test@example.org'); + } + + public function provideInvalidUserWithoutLastName() + { + return array('givenName' => 'Test', + 'userPassword' => 'none', + 'type' => 'Horde_Kolab_Server_Object_Kolab_User', + 'mail' => 'test@example.org'); + } + + public function provideInvalidUserWithoutMail() + { + return array('givenName' => 'Test', + 'sn' => 'Test', + 'userPassword' => 'none', + 'type' => 'Horde_Kolab_Server_Object_Kolab_User'); + } + + public function provideInvalidUsers() + { + return array( + array( + $this->provideInvalidUserWithoutPassword(), + 'The value for "userPassword" is missing!' + ), + array( + $this->provideInvalidUserWithoutGivenName(), + 'Either the last name or the given name is missing!' + ), + array( + $this->provideInvalidUserWithoutLastName(), + 'Either the last name or the given name is missing!' + ), + array( + $this->provideInvalidUserWithoutMail(), + 'The value for "mail" is missing!' + ), + ); + } + + /** FIXME: Prefix the stuff bewlow with provide...() */ + + public function validUsers() + { + return array( + array( + $this->provideBasicUserOne(), + ), + array( + $this->provideBasicUserTwo(), + ), + ); + } + + public function validAddresses() + { + return array( + array( + $this->provideBasicAddress(), + ), + ); + } + + public function validAdmins() + { + return array( + array( + $this->provideBasicAdmin(), + ), + ); + } + + public function validMaintainers() + { + return array( + array( + $this->provideBasicMaintainer(), + ) + ); + } + + public function validDomainMaintainers() + { + return array( + array( + $this->provideBasicDomainMaintainer(), + ) + ); + } + + public function validSharedFolders() + { + return array( + array('cn' => 'Shared', + 'type' => 'Horde_Kolab_Server_Object_Kolabsharedfolder' + ), + ); + } + + + public function userLists() + { + return array( + ); + } + + public function userListByLetter() + { + return array( + ); + } + + public function userListByAttribute() + { + return array( + ); + } + + public function userAdd() + { + return array( + ); + } + + public function invalidMails() + { + return array( + ); + } + + public function largeList() + { + return array( + ); + } + + protected function fetchByCn($server, $cn) + { + $cn_result = $server->uidForCn($cn); + $this->assertNoError($cn_result); + + $object = $server->fetch($cn_result); + $this->assertNoError($object); + + return $object; + } + + /** + * Ensure that the variable contains no Horde_Kolab_Server_Exception and + * fail if it does. + * + * @param mixed $var The variable to check. + * + * @return NULL. + */ + public function assertNoError($var) + { + if (is_array($var)) { + foreach ($var as $element) { + $this->assertNoError($element); + } + } elseif ($var instanceOf Exception) { + $this->assertEquals('', $var->getMessage()); + } else if ($var instanceOf PEAR_Error) { + $this->assertEquals('', $var->getMessage()); + } + } + + /** + * Ensure that the variable contains a Horde_Kolab_Server_Exception and fail + * if it does not. Optionally compare the error message with the provided + * message and fail if both do not match. + * + * @param mixed $var The variable to check. + * @param string $msg The expected error message. + * + * @return NULL. + */ + public function assertError($var, $msg = null) + { + if (!$var instanceOf PEAR_Error) { + $this->assertType('Horde_Kolab_Server_Exception', $var); + if (isset($msg)) { + $this->assertEquals($msg, $var->getMessage()); + } + } else { + if (isset($msg)) { + $this->assertEquals($msg, $var->getMessage()); + } + } + } + + /** + * Assert that creating a new object operation yields some predictable + * attribute results. + * + * @param Horde_Kolab_Server $server The server the object resides on. + * @param array $store The information to save. + * @param array $fetch The expected results. + * + * @return NULL. + */ + protected function assertAdd(Horde_Kolab_Server &$server, + array $store, array $fetch) + { + $object = $server->add($store); + $this->assertNoError($object); + + $this->added[] = array(&$server, $object->getUid()); + $object = $server->fetch($object->getUid()); + + foreach ($fetch as $attribute => $expect) { + $this->assertEquals($expect, $object->get($attribute)); + } + return $object; + } + + /** + * Test simple attributes. + * + * @dataProvider provideServers + * + * @return NULL + */ + public function assertSimpleAttributes(Horde_Kolab_Server_Object $object, + Horde_Kolab_Server $server, array $list) + { + foreach ($list as $item) { + $this->assertSimpleSequence($object, $server, + $item, + array($item, 'öäü/)(="§%$&§§$\'*', '', array('a', 'b'), '0'), + true); + } + } + + /** + * Test easy attributes. + * + * @dataProvider provideServers + * + * @return NULL + */ + public function assertEasyAttributes(Horde_Kolab_Server_Object $object, + Horde_Kolab_Server $server, array $list) + { + foreach ($list as $key => $items) { + $this->assertSimpleSequence($object, $server, + $key, + $items, + true); + } + } + + /** + * Assert that a save() operation yields some predictable attribute results. + * + * @param Horde_Kolab_Server_Object $object The object to work on. + * @param Horde_Kolab_Server $server The server the object resides on. + * @param string $attribute The attribute to work on. + * @param array $sequence The sequence of values to set and expect. + * + * @return NULL. + */ + protected function assertSimpleSequence(Horde_Kolab_Server_Object &$object, + Horde_Kolab_Server &$server, + $attribute, array $sequence, + $pop_arrays = false) + { + foreach ($sequence as $value) { + $this->assertStoreFetch($object, $server, + array($attribute => $value), + array($attribute => $value), + $pop_arrays); + } + } + + /** + * Assert that a save() operation yields some predictable attribute results. + * + * @param Horde_Kolab_Server_Object $object The object to work on. + * @param Horde_Kolab_Server $server The server the object resides on. + * @param array $store The information to save. + * @param array $fetch The expected results. + * + * @return NULL. + */ + protected function assertStoreFetch(Horde_Kolab_Server_Object &$object, + Horde_Kolab_Server &$server, + array $store, array $fetch, + $pop_arrays = false) + { + $result = $object->save($store); + $this->assertNoError($result); + + $object = $server->fetch($object->getUid()); + + foreach ($fetch as $attribute => $expect) { + $actual = $object->get($attribute, false); + if ($pop_arrays && is_array($actual) && count($actual) == 1) { + $actual = array_pop($actual); + } + $this->assertEquals($expect, + $actual); + } + } + + public function assertRecursiveType($results, $type) + { + if (is_array($results)) { + foreach ($results as $result) { + $this->assertRecursiveType($result, $type); + } + } else { + if ($results instanceOf Exception) { + $this->assertEquals('', $results->getMessage()); + } else { + $this->assertType($type, $results); + } + } + } + + /** + * Cleanup function. + * + * @return NULL. + */ + public function tearDown() + { + if (isset($this->added)) { + $added = array_reverse($this->added); + foreach ($added as $add) { + $result = $add[0]->delete($add[1]); + $this->assertNoError($result); + } + } + } +} diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure.php index 857e90e83..17c6fb917 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure.php @@ -62,37 +62,6 @@ abstract class Horde_Kolab_Server_Structure } /** - * Attempts to return a concrete Horde_Kolab_Server_Structure instance based - * on $driver. - * - * @param mixed $driver The type of concrete Horde_Kolab_Server - * subclass to return. - * @param Horde_Kolab_Server &$server A link to the server handler . - * @param array $params A hash containing any additional - * configuration or connection - * parameters a subclass might need. - * - * @return Horde_Kolab_Server_Structure The newly created concrete - * Horde_Kolab_Server_Structure instance. - * - * @throws Horde_Kolab_Server_Exception If the requested Horde_Kolab_Server_Structure - * subclass could not be found. - */ - static public function &factory($driver, $params = array()) - { - if (class_exists($driver)) { - $class = $driver; - } else { - $class = 'Horde_Kolab_Server_Structure_' . ucfirst(basename($driver)); - if (!class_exists($class)) { - throw new Horde_Kolab_Server_Exception('Structure type definition "' . $class . '" missing.'); - } - } - $structure = new $class($params); - return $structure; - } - - /** * Returns the set of objects supported by this structure. * * @return array An array of supported objects. diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Test.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Test.php index af8451f6e..c04e43722 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Test.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Test.php @@ -90,8 +90,6 @@ class Horde_Kolab_Server_Test extends Horde_Kolab_Server_Ldap * @param array $params Parameter array. */ public function __construct(Horde_Kolab_Server_Structure $structure, - Horde_Cache $cache = null, - Horde_Log_Logger $logger = null, $params = array()) { $this->load(); @@ -103,7 +101,7 @@ class Horde_Kolab_Server_Test extends Horde_Kolab_Server_Ldap } } - parent::__construct($structure, $cache, $logger, $params); + parent::__construct($structure, $params); if (isset($this->params['admin']) && isset($this->params['admin']['type'])) { @@ -598,7 +596,7 @@ class Horde_Kolab_Server_Test extends Horde_Kolab_Server_Ldap $this->store(); - if (!empty($this->logger)) { + if (isset($this->logger)) { $logger->debug(sprintf('The object \"%s\" has been successfully saved!', $uid)); } @@ -643,7 +641,7 @@ class Horde_Kolab_Server_Test extends Horde_Kolab_Server_Ldap $uid)); } $this->store(); - if (!empty($this->logger)) { + if (isset($this->logger)) { $logger->debug(sprintf('The object \"%s\" has been successfully deleted!', $uid)); } @@ -667,7 +665,7 @@ class Horde_Kolab_Server_Test extends Horde_Kolab_Server_Ldap unset($this->data[$uid]); } $this->store(); - if (!empty($this->logger)) { + if (isset($this->logger)) { $logger->debug(sprintf('The object \"%s\" has been successfully renamed to \"%s\"!', $uid, $new)); } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Test/Server.php b/framework/Kolab_Server/lib/Horde/Kolab/Test/Server.php deleted file mode 100644 index 358c2c31f..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Test/Server.php +++ /dev/null @@ -1,941 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Share - */ - -/** - * The Autoloader allows us to omit "require/include" statements. - */ -require_once 'Horde/Autoloader.php'; - -/** - * Base for PHPUnit scenarios. - * - * - * Copyright 2008-2009 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_Test - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Share - */ -class Horde_Kolab_Test_Server extends PHPUnit_Extensions_Story_TestCase -{ - /** - * Uid of added objects. Should be removed on tearDown. - * - * @var array - */ - public $added; - - /** - * Handle a "given" step. - * - * @param array &$world Joined "world" of variables. - * @param string $action The description of the step. - * @param array $arguments Additional arguments to the step. - * - * @return mixed The outcome of the step. - */ - public function runGiven(&$world, $action, $arguments) - { - switch($action) { - case 'an empty Kolab server': - $world['server'] = &$this->prepareEmptyKolabServer(); - break; - case 'a basic Kolab server': - $world['server'] = &$this->prepareBasicKolabServer(); - break; - case 'the Kolab auth driver has been selected': - $world['auth'] = &$this->prepareKolabAuthDriver(); - break; - case 'the current Kolab server': - $world['server'] = &$this->prepareCurrentKolabServer(); - break; - default: - return $this->notImplemented($action); - } - } - - /** - * Handle a "when" step. - * - * @param array &$world Joined "world" of variables. - * @param string $action The description of the step. - * @param array $arguments Additional arguments to the step. - * - * @return mixed The outcome of the step. - */ - public function runWhen(&$world, $action, $arguments) - { - switch($action) { - case 'logging in as a user with a password': - $world['login'] = $world['auth']->authenticate($arguments[0], - array('password' => $arguments[1])); - break; - case 'adding a Kolab server object': - $result = $world['server']->add($arguments[0]); - $world['result']['add'] = $result; - break; - case 'adding an invalid Kolab server object': - try { - $result = $world['server']->add($arguments[0]); - $world['result']['add'] = $result; - } catch (Horde_Kolab_Server_Exception $e) { - $world['result']['add'] = $e; - } - break; - case 'adding an object list': - foreach ($arguments[0] as $object) { - try { - $result = $world['server']->add($object); - } catch (Horde_Kolab_Server_Exception $e) { - $world['result']['add'] = $e; - return; - } - } - $world['result']['add'] = true; - break; - case 'adding a distribution list': - $world['result']['add'] = $world['server']->add($this->provideDistributionList()); - break; - case 'listing all users': - $world['list'] = $world['server']->listObjects('Horde_Kolab_Server_Object_Kolab_User'); - break; - case 'listing all groups': - $world['list'] = $world['server']->listObjects('Horde_Kolab_Server_Object_Kolabgroupofnames'); - break; - case 'listing all objects of type': - $world['list'] = $world['server']->listObjects($arguments[0]); - break; - case 'retrieving a hash list with all objects of type': - $world['list'] = $world['server']->listHash($arguments[0]); - break; - default: - return $this->notImplemented($action); - } - } - - /** - * Handle a "then" step. - * - * @param array &$world Joined "world" of variables. - * @param string $action The description of the step. - * @param array $arguments Additional arguments to the step. - * - * @return mixed The outcome of the step. - */ - public function runThen(&$world, $action, $arguments) - { - switch($action) { - case 'the result should be an object of type': - if (!isset($world['result'])) { - $this->fail('Did not receive a result!'); - } - foreach ($world['result'] as $result) { - if ($result instanceOf Horde_Kolab_Server_Exception) { - $this->assertEquals('', $result->getMessage()); - } else { - $this->assertEquals($arguments[0], get_class($result)); - } - } - break; - case 'the result indicates success.': - if (!isset($world['result'])) { - $this->fail('Did not receive a result!'); - } - $this->assertNoError($world['result']); - break; - case 'the result should indicate an error with': - if (!isset($world['result'])) { - $this->fail('Did not receive a result!'); - } - foreach ($world['result'] as $result) { - if ($result instanceOf Horde_Kolab_Server_Exception) { - $this->assertEquals($arguments[0], $result->getMessage()); - } else { - $this->assertEquals($arguments[0], 'Action succeeded without an error.'); - } - } - break; - case 'the list has a number of entries equal to': - if ($world['list'] instanceOf Horde_Kolab_Server_Exception) { - $this->assertEquals('', $world['list']->getMessage()); - } else { - $this->assertEquals($arguments[0], count($world['list'])); - } - break; - case 'the list is an empty array': - if ($world['list'] instanceOf Horde_Kolab_Server_Exception) { - $this->assertEquals('', $world['list']->getMessage()); - } else { - $this->assertEquals(array(), $world['list']); - } - break; - case 'the list is an empty array': - if ($world['list'] instanceOf Horde_Kolab_Server_Exception) { - $this->assertEquals('', $world['list']->getMessage()); - } else { - $this->assertEquals(array(), $world['list']); - } - break; - case 'the provided list and the result list match with regard to these attributes': - if ($world['list'] instanceOf Horde_Kolab_Server_Exception) { - $this->assertEquals('', $world['list']->getMessage()); - } else { - $provided_vals = array(); - foreach ($arguments[2] as $provided_element) { - if (isset($provided_element[$arguments[0]])) { - $provided_vals[] = $provided_element[$arguments[0]]; - } else { - $this->fail(sprintf('The provided element %s does have no value for %s.', - print_r($provided_element, true), - print_r($arguments[0]))); - } - } - $result_vals = array(); - foreach ($world['list'] as $result_element) { - if (isset($result_element[$arguments[1]])) { - $result_vals[] = $result_element[$arguments[1]]; - } else { - $this->fail(sprintf('The result element %s does have no value for %s.', - print_r($result_element, true), - print_r($arguments[1]))); - } - } - $this->assertEquals(array(), - array_diff($provided_vals, $result_vals)); - } - break; - case 'each element in the result list has an attribute': - if ($world['list'] instanceOf Horde_Kolab_Server_Exception) { - $this->assertEquals('', $world['list']->getMessage()); - } else { - $result_vals = array(); - foreach ($world['list'] as $result_element) { - if (!isset($result_element[$arguments[0]])) { - $this->fail(sprintf('The result element %s does have no value for %s.', - print_r($result_element, true), - print_r($arguments[0]))); - } - } - } - break; - case 'each element in the result list has an attribute set to a given value': - if ($world['list'] instanceOf Horde_Kolab_Server_Exception) { - $this->assertEquals('', $world['list']->getMessage()); - } else { - $result_vals = array(); - foreach ($world['list'] as $result_element) { - if (!isset($result_element[$arguments[0]])) { - $this->fail(sprintf('The result element %s does have no value for %s.', - print_r($result_element, true), - print_r($arguments[0], true))); - } - if ($result_element[$arguments[0]] != $arguments[1]) { - $this->fail(sprintf('The result element %s has an unexpected value %s for %s.', - print_r($result_element, true), - print_r($result_element[$arguments[0]], true), - print_r($arguments[0], true))); - } - } - } - break; - case 'the login was successful': - $this->assertNoError($world['login']); - $this->assertTrue($world['login']); - break; - case 'the list contains a number of elements equal to': - $this->assertEquals($arguments[0], count($world['list'])); - break; - default: - return $this->notImplemented($action); - } - } - - - /** - * Prepare an empty Kolab server. - * - * @return Horde_Kolab_Server The empty server. - */ - public function &prepareEmptyKolabServer($type = 'Test') - { - global $conf; - - /** Prepare a Kolab test server */ - $conf['kolab']['server']['driver'] = $type; - $conf['kolab']['server']['params']['basedn'] = 'dc=example,dc=org'; - $conf['kolab']['server']['params']['hashtype'] = 'plain'; - - if ($type == 'file') { - $conf['kolab']['server']['params']['file'] = Horde::getTempFile('fileTest'); - } - - $server = Horde_Kolab_Server::singleton(); - - /** Ensure we don't use a connection from older tests */ - $server->clean(); - - return $server; - } - - /** - * Prepare a connection to a real LDAP server. - * - * @return Horde_Kolab_Server The LDAP server connection. - */ - public function &prepareLdapKolabServer() - { - $base = getenv('HORDE_BASE'); - if (!empty($base)) { - $config = $base . '/config/kolab.php'; - if (file_exists($config)) { - @include $config; - if (!empty($conf['kolab']['server']['params'])) { - $params = $conf['kolab']['server']['params']; - $params['driver'] = 'ldap'; - return Horde_Kolab_Server::singleton($params); - } - } - } - return false; - } - - /** - * Provide different server types. - * - * @return array The different server types. - */ - public function &provideServers() - { - $servers = array(); - /** - * We always use the test server - */ - $servers[] = array($this->prepareEmptyKolabServer()); - $real = $this->prepareLdapKolabServer(); - if (!empty($real)) { - $servers[] = array($real); - } - return $servers; - } - - /** - * Prepare the currently configured Kolab server. - * - * @return Horde_Kolab_Server The current server. - */ - public function &prepareCurrentKolabServer() - { - $server = Horde_Kolab_Server::singleton(); - return $server; - } - - /** - * Prepare a Kolab server with some basic entries. - * - * @return Horde_Kolab_Server The empty server. - */ - public function &prepareBasicServer($type = 'Test') - { - $server = $this->prepareEmptyKolabServer($type); - $this->prepareUsers($server); - return $server; - } - - /** - * Fill a Kolab Server with test users. - * - * @param Kolab_Server &$server The server to populate. - * - * @return Horde_Kolab_Server The empty server. - */ - public function prepareUsers(&$server) - { - $result = $server->add($this->provideBasicUserOne()); - $this->assertNoError($result); - $result = $server->add($this->provideBasicUserTwo()); - $this->assertNoError($result); - $result = $server->add($this->provideBasicAddress()); - $this->assertNoError($result); - $result = $server->add($this->provideBasicAdmin()); - $this->assertNoError($result); - $result = $server->add($this->provideBasicDomainMaintainer()); - $this->assertNoError($result); - $result = $server->add($this->provideGroupWithoutMembers()); - $this->assertNoError($result); - $result = $server->add($this->provideBasicGroupOne()); - $this->assertNoError($result); - $result = $server->add($this->provideBasicMaintainer()); - $this->assertNoError($result); - $result = $server->add($this->provideBasicSharedFolder()); - $this->assertNoError($result); - } - - /** - * Prepare a Kolab Auth Driver. - * - * @return Auth The auth driver. - */ - public function &prepareKolabAuthDriver() - { - include_once 'Horde/Auth.php'; - - $auth = Horde_Auth::singleton('kolab'); - return $auth; - } - - /** - * Return a test user. - * - * @return array The test user. - */ - public function provideBasicUserOne() - { - return array('givenName' => 'Gunnar', - 'sn' => 'Wrobel', - 'type' => 'Horde_Kolab_Server_Object_Kolab_User', - 'mail' => 'wrobel@example.org', - 'uid' => 'wrobel', - 'userPassword' => 'none', - 'kolabHomeServer' => 'home.example.org', - 'kolabImapServer' => 'imap.example.org', - 'kolabFreeBusyServer' => 'https://fb.example.org/freebusy', - 'kolabInvitationPolicy' => array('ACT_REJECT_IF_CONFLICTS'), - 'alias' => array('gunnar@example.org', - 'g.wrobel@example.org'), - ); - } - - /** - * Return a test user. - * - * @return array The test user. - */ - public function provideBasicUserTwo() - { - return array('givenName' => 'Test', - 'sn' => 'Test', - 'type' => 'Horde_Kolab_Server_Object_Kolab_User', - 'mail' => 'test@example.org', - 'uid' => 'test', - 'userPassword' => 'test', - 'kolabHomeServer' => 'home.example.org', - 'kolabImapServer' => 'home.example.org', - 'kolabFreeBusyServer' => 'https://fb.example.org/freebusy', - 'alias' => array('t.test@example.org'), - 'kolabDelegate' => 'wrobel@example.org',); - } - - /** - * Return a test address. - * - * @return array The test address. - */ - public function provideBasicAddress() - { - return array('type' => 'Horde_Kolab_Server_Object_Kolab_Address', - Horde_Kolab_Server_Object_Kolab_Administrator::ATTRIBUTE_GIVENNAME => 'Test', - Horde_Kolab_Server_Object_Kolab_Administrator::ATTRIBUTE_SN => 'Address', - Horde_Kolab_Server_Object_Kolab_Administrator::ATTRIBUTE_MAIL => 'address@example.org', - ); - } - - /** - * Return a test administrator. - * - * @return array The test administrator. - */ - public function provideBasicAdmin() - { - return array('type' => 'Horde_Kolab_Server_Object_Kolab_Administrator', - Horde_Kolab_Server_Object_Kolab_Administrator::ATTRIBUTE_GIVENNAME => 'The', - Horde_Kolab_Server_Object_Kolab_Administrator::ATTRIBUTE_SN => 'Administrator', - Horde_Kolab_Server_Object_Kolab_Administrator::ATTRIBUTE_SID => 'admin', - Horde_Kolab_Server_Object_Kolab_Administrator::ATTRIBUTE_USERPASSWORD => 'none', - ); - } - - /** - * Return a test maintainer. - * - * @return array The test maintainer. - */ - public function provideBasicMaintainer() - { - return array('type' => 'Horde_Kolab_Server_Object_Kolab_Maintainer', - Horde_Kolab_Server_Object_Kolab_Maintainer::ATTRIBUTE_GIVENNAME => 'Main', - Horde_Kolab_Server_Object_Kolab_Maintainer::ATTRIBUTE_SN => 'Tainer', - Horde_Kolab_Server_Object_Kolab_Maintainer::ATTRIBUTE_SID => 'maintainer', - Horde_Kolab_Server_Object_Kolab_Maintainer::ATTRIBUTE_USERPASSWORD => 'none', - ); - } - - /** - * Return a test domain maintainer. - * - * @return array The test domain maintainer. - */ - public function provideBasicDomainMaintainer() - { - return array('type' => 'Horde_Kolab_Server_Object_Kolab_Domainmaintainer', - Horde_Kolab_Server_Object_Kolab_Domainmaintainer::ATTRIBUTE_GIVENNAME => 'Domain', - Horde_Kolab_Server_Object_Kolab_Domainmaintainer::ATTRIBUTE_SN => 'Maintainer', - Horde_Kolab_Server_Object_Kolab_Domainmaintainer::ATTRIBUTE_SID => 'domainmaintainer', - Horde_Kolab_Server_Object_Kolab_Domainmaintainer::ATTRIBUTE_USERPASSWORD => 'none', - Horde_Kolab_Server_Object_Kolab_Domainmaintainer::ATTRIBUTE_DOMAIN => array('example.com'), - - ); - } - - /** - * Return a test shared folder. - * - * @return array The test shared folder. - */ - public function provideBasicSharedFolder() - { - return array('type' => 'Horde_Kolab_Server_Object_Kolabsharedfolder', - Horde_Kolab_Server_Object_Kolabsharedfolder::ATTRIBUTE_CN => 'shared@example.org', - Horde_Kolab_Server_Object_Kolabsharedfolder::ATTRIBUTE_HOMESERVER => 'example.org', - ); - } - - /** - * Provide a set of valid groups. - * - * @return array The array of groups. - */ - public function groupLists() - { - $groups = $this->validGroups(); - $result = array(); - foreach ($groups as $group) { - $result[] = array($group); - } - return $result; - } - - /** - * Provide a set of valid groups. - * - * @return array The array of groups. - */ - public function validGroups() - { - return array( - array( - $this->provideGroupWithoutMembers(), - ), - array( - $this->provideBasicGroupOne(), - ), - array( - $this->provideBasicGroupTwo(), - ), - ); - } - - /** - * Return a test group. - * - * @return array The test group. - */ - public function provideGroupWithoutMembers() - { - return array('type' => 'Horde_Kolab_Server_Object_Kolabgroupofnames', - Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MAIL => 'empty.group@example.org', - Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MEMBER => array()); - } - - /** - * Return a test group. - * - * @return array The test group. - */ - public function provideBasicGroupOne() - { - return array('type' => 'Horde_Kolab_Server_Object_Kolabgroupofnames', - Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MAIL => 'group@example.org', - Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MEMBER => array('cn=Test Test,dc=example,dc=org', - 'cn=Gunnar Wrobel,dc=example,dc=org') - ); - } - - /** - * Return a test group. - * - * @return array The test group. - */ - public function provideBasicGroupTwo() - { - return array('type' => 'Horde_Kolab_Server_Object_Kolabgroupofnames', - Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MAIL => 'group2@example.org', - Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MEMBER => array('cn=Gunnar Wrobel,dc=example,dc=org') - ); - } - - public function provideDistributionList() - { - return array('type' => 'Horde_Kolab_Server_Object_Kolab_Distlist', - Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MAIL => 'distlist@example.org', - Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MEMBER => array('cn=Test Test,dc=example,dc=org', - 'cn=Gunnar Wrobel,dc=example,dc=org') - ); - } - - public function provideInvalidUserWithoutPassword() - { - return array('givenName' => 'Test', - 'sn' => 'Test', - 'type' => 'Horde_Kolab_Server_Object_Kolab_User', - 'mail' => 'test@example.org'); - } - - public function provideInvalidUserWithoutGivenName() - { - return array('sn' => 'Test', - 'userPassword' => 'none', - 'type' => 'Horde_Kolab_Server_Object_Kolab_User', - 'mail' => 'test@example.org'); - } - - public function provideInvalidUserWithoutLastName() - { - return array('givenName' => 'Test', - 'userPassword' => 'none', - 'type' => 'Horde_Kolab_Server_Object_Kolab_User', - 'mail' => 'test@example.org'); - } - - public function provideInvalidUserWithoutMail() - { - return array('givenName' => 'Test', - 'sn' => 'Test', - 'userPassword' => 'none', - 'type' => 'Horde_Kolab_Server_Object_Kolab_User'); - } - - public function provideInvalidUsers() - { - return array( - array( - $this->provideInvalidUserWithoutPassword(), - 'The value for "userPassword" is missing!' - ), - array( - $this->provideInvalidUserWithoutGivenName(), - 'Either the last name or the given name is missing!' - ), - array( - $this->provideInvalidUserWithoutLastName(), - 'Either the last name or the given name is missing!' - ), - array( - $this->provideInvalidUserWithoutMail(), - 'The value for "mail" is missing!' - ), - ); - } - - public function provideServerTypes() - { - return array(array('test'), array('file')); - } - - /** FIXME: Prefix the stuff bewlow with provide...() */ - - public function validUsers() - { - return array( - array( - $this->provideBasicUserOne(), - ), - array( - $this->provideBasicUserTwo(), - ), - ); - } - - public function validAddresses() - { - return array( - array( - $this->provideBasicAddress(), - ), - ); - } - - public function validAdmins() - { - return array( - array( - $this->provideBasicAdmin(), - ), - ); - } - - public function validMaintainers() - { - return array( - array( - $this->provideBasicMaintainer(), - ) - ); - } - - public function validDomainMaintainers() - { - return array( - array( - $this->provideBasicDomainMaintainer(), - ) - ); - } - - public function validSharedFolders() - { - return array( - array('cn' => 'Shared', - 'type' => 'Horde_Kolab_Server_Object_Kolabsharedfolder' - ), - ); - } - - - public function userLists() - { - return array( - ); - } - - public function userListByLetter() - { - return array( - ); - } - - public function userListByAttribute() - { - return array( - ); - } - - public function userAdd() - { - return array( - ); - } - - public function invalidMails() - { - return array( - ); - } - - public function largeList() - { - return array( - ); - } - - /** - * Ensure that the variable contains no Horde_Kolab_Server_Exception and - * fail if it does. - * - * @param mixed $var The variable to check. - * - * @return NULL. - */ - public function assertNoError($var) - { - if (is_array($var)) { - foreach ($var as $element) { - $this->assertNoError($element); - } - } elseif ($var instanceOf Exception) { - $this->assertEquals('', $var->getMessage()); - } else if ($var instanceOf PEAR_Error) { - $this->assertEquals('', $var->getMessage()); - } - } - - /** - * Ensure that the variable contains a Horde_Kolab_Server_Exception and fail - * if it does not. Optionally compare the error message with the provided - * message and fail if both do not match. - * - * @param mixed $var The variable to check. - * @param string $msg The expected error message. - * - * @return NULL. - */ - public function assertError($var, $msg = null) - { - if (!$var instanceOf PEAR_Error) { - $this->assertType('Horde_Kolab_Server_Exception', $var); - if (isset($msg)) { - $this->assertEquals($msg, $var->getMessage()); - } - } else { - if (isset($msg)) { - $this->assertEquals($msg, $var->getMessage()); - } - } - } - - protected function fetchByCn($server, $cn) - { - $cn_result = $server->uidForCn($cn); - $this->assertNoError($cn_result); - - $object = $server->fetch($cn_result); - $this->assertNoError($object); - - return $object; - } - - /** - * Assert that creating a new object operation yields some predictable - * attribute results. - * - * @param Horde_Kolab_Server $server The server the object resides on. - * @param array $store The information to save. - * @param array $fetch The expected results. - * - * @return NULL. - */ - protected function assertAdd(Horde_Kolab_Server &$server, - array $store, array $fetch) - { - $object = $server->add($store); - $this->assertNoError($object); - - $this->added[] = array(&$server, $object->getUid()); - $object = $server->fetch($object->getUid()); - - foreach ($fetch as $attribute => $expect) { - $this->assertEquals($expect, $object->get($attribute)); - } - return $object; - } - - /** - * Test simple attributes. - * - * @dataProvider provideServers - * - * @return NULL - */ - public function assertSimpleAttributes(Horde_Kolab_Server_Object $object, - Horde_Kolab_Server $server, array $list) - { - foreach ($list as $item) { - $this->assertSimpleSequence($object, $server, - $item, - array($item, 'öäü/)(="§%$&§§$\'*', '', array('a', 'b'), '0'), - true); - } - } - - /** - * Test easy attributes. - * - * @dataProvider provideServers - * - * @return NULL - */ - public function assertEasyAttributes(Horde_Kolab_Server_Object $object, - Horde_Kolab_Server $server, array $list) - { - foreach ($list as $key => $items) { - $this->assertSimpleSequence($object, $server, - $key, - $items, - true); - } - } - - /** - * Assert that a save() operation yields some predictable attribute results. - * - * @param Horde_Kolab_Server_Object $object The object to work on. - * @param Horde_Kolab_Server $server The server the object resides on. - * @param string $attribute The attribute to work on. - * @param array $sequence The sequence of values to set and expect. - * - * @return NULL. - */ - protected function assertSimpleSequence(Horde_Kolab_Server_Object &$object, - Horde_Kolab_Server &$server, - $attribute, array $sequence, - $pop_arrays = false) - { - foreach ($sequence as $value) { - $this->assertStoreFetch($object, $server, - array($attribute => $value), - array($attribute => $value), - $pop_arrays); - } - } - - /** - * Assert that a save() operation yields some predictable attribute results. - * - * @param Horde_Kolab_Server_Object $object The object to work on. - * @param Horde_Kolab_Server $server The server the object resides on. - * @param array $store The information to save. - * @param array $fetch The expected results. - * - * @return NULL. - */ - protected function assertStoreFetch(Horde_Kolab_Server_Object &$object, - Horde_Kolab_Server &$server, - array $store, array $fetch, - $pop_arrays = false) - { - $result = $object->save($store); - $this->assertNoError($result); - - $object = $server->fetch($object->getUid()); - - foreach ($fetch as $attribute => $expect) { - $actual = $object->get($attribute, false); - if ($pop_arrays && is_array($actual) && count($actual) == 1) { - $actual = array_pop($actual); - } - $this->assertEquals($expect, - $actual); - } - } - - /** - * Cleanup function. - * - * @return NULL. - */ - public function tearDown() - { - if (isset($this->added)) { - $added = array_reverse($this->added); - foreach ($added as $add) { - $result = $add[0]->delete($add[1]); - $this->assertNoError($result); - } - } - } -} diff --git a/framework/Kolab_Server/package.xml b/framework/Kolab_Server/package.xml index bd754e0cc..9798b2515 100644 --- a/framework/Kolab_Server/package.xml +++ b/framework/Kolab_Server/package.xml @@ -62,6 +62,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -87,16 +88,13 @@ http://pear.php.net/dtd/package-2.0.xsd"> + - - - - @@ -174,8 +172,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> - + @@ -197,6 +195,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/AddingObjectsTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/AddingObjectsTest.php index 718a922b8..d4f1544a4 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/AddingObjectsTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/AddingObjectsTest.php @@ -30,7 +30,7 @@ require_once 'Horde/Autoloader.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_AddingObjectsTest extends Horde_Kolab_Test_Server +class Horde_Kolab_Server_AddingObjectsTest extends Horde_Kolab_Server_Scenario { /** * Test adding valid users. @@ -44,8 +44,11 @@ class Horde_Kolab_Server_AddingObjectsTest extends Horde_Kolab_Test_Server */ public function addingValidUser($user) { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a Kolab server object', $user) - ->then('the result should be an object of type', 'Horde_Kolab_Server_Object_Kolab_User'); + ->then( + 'the result should be an object of type', + 'Horde_Kolab_Server_Object_Kolab_User' + ); } } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/AdminTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/AdminTest.php index 1943c763e..87c9fdca0 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/AdminTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/AdminTest.php @@ -30,7 +30,7 @@ require_once 'Horde/Autoloader.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_AdminTest extends Horde_Kolab_Test_Server +class Horde_Kolab_Server_AdminTest extends Horde_Kolab_Server_Scenario { /** @@ -40,7 +40,7 @@ class Horde_Kolab_Server_AdminTest extends Horde_Kolab_Test_Server */ protected function setUp() { - $this->ldap = $this->prepareEmptyKolabServer(); + $this->server = $this->getKolabMockServer(); } /** @@ -50,9 +50,7 @@ class Horde_Kolab_Server_AdminTest extends Horde_Kolab_Test_Server */ private function _addValidAdmin() { - $admin = $this->provideBasicAdmin(); - $result = $this->ldap->add($admin); - $this->assertNoError($result); + $this->addToServers($this->provideBasicAdmin()); } /** @@ -63,10 +61,12 @@ class Horde_Kolab_Server_AdminTest extends Horde_Kolab_Test_Server public function testGenerateId() { $admin = $this->provideBasicAdmin(); - $this->assertNoError($admin); - $user = new Horde_Kolab_Server_Object_Kolab_Administrator($this->ldap, null, $admin); - $this->assertNoError($user); - $this->assertEquals('cn=The Administrator,dc=example,dc=org', $user->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID)); + $user = new Horde_Kolab_Server_Object_Kolab_Administrator($this->server, + null, $admin); + $this->assertEquals( + 'cn=The Administrator,dc=example,dc=org', + $user->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID) + ); } /** @@ -79,20 +79,25 @@ class Horde_Kolab_Server_AdminTest extends Horde_Kolab_Test_Server $this->_addValidAdmin(); $this->assertEquals(2, count($GLOBALS['KOLAB_SERVER_TEST_DATA'])); - $this->assertContains('cn=admin,cn=internal,dc=example,dc=org', - array_keys($GLOBALS['KOLAB_SERVER_TEST_DATA'])); + $this->assertContains( + 'cn=admin,cn=internal,dc=example,dc=org', + array_keys($GLOBALS['KOLAB_SERVER_TEST_DATA']) + ); + + $administrators = $this->server->getGroups( + 'cn=The Administrator,dc=example,dc=org' + ); + $admin_group = $this->server->fetch( + 'cn=admin,cn=internal,dc=example,dc=org' + ); - $administrators = $this->ldap->getGroups('cn=The Administrator,dc=example,dc=org'); - $this->assertNoError($administrators); - - $admin_group = $this->ldap->fetch('cn=admin,cn=internal,dc=example,dc=org'); - $this->assertNoError($admin_group); $this->assertTrue($admin_group->exists()); - $admin = $this->ldap->fetch('cn=The Administrator,dc=example,dc=org'); - $this->assertNoError($admin); - $this->assertEquals('Horde_Kolab_Server_Object_Kolab_Administrator', - get_class($admin)); + $admin = $this->server->fetch('cn=The Administrator,dc=example,dc=org'); + $this->assertEquals( + 'Horde_Kolab_Server_Object_Kolab_Administrator', + get_class($admin) + ); } /** @@ -104,11 +109,9 @@ class Horde_Kolab_Server_AdminTest extends Horde_Kolab_Test_Server { $this->_addValidAdmin(); - $admin = $this->ldap->fetch('cn=The Administrator,dc=example,dc=org'); - $this->assertNoError($admin); - - $hash = $admin->toHash(); - $this->assertNoError($hash); + $hash = $this->server->fetch( + 'cn=The Administrator,dc=example,dc=org' + )->toHash(); $this->assertContains('uid', array_keys($hash)); $this->assertContains('lnfn', array_keys($hash)); $this->assertEquals('admin', $hash['uid']); @@ -123,12 +126,14 @@ class Horde_Kolab_Server_AdminTest extends Horde_Kolab_Test_Server { $this->_addValidAdmin(); - $entries = $this->ldap->search('(&(cn=*)(objectClass=inetOrgPerson)(!(uid=manager))(sn=*))'); - $this->assertNoError($entries); + $entries = $this->server->search( + '(&(cn=*)(objectClass=inetOrgPerson)(!(uid=manager))(sn=*))' + ); $this->assertEquals(1, count($entries)); - $list = $this->ldap->listObjects('Horde_Kolab_Server_Object_Kolab_Administrator'); - $this->assertNoError($list); + $list = $this->server->listObjects( + 'Horde_Kolab_Server_Object_Kolab_Administrator' + ); $this->assertEquals(1, count($list)); } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/DistListHandlingTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/DistListHandlingTest.php index 0b114eec0..b7dc64503 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/DistListHandlingTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/DistListHandlingTest.php @@ -12,11 +12,9 @@ */ /** - * We need the base class + * The Autoloader allows us to omit "require/include" statements. */ -require_once 'Horde/Kolab/Test/Server.php'; - -require_once 'Horde/Kolab/Server.php'; +require_once 'Horde/Autoloader.php'; /** * Handling distribution lists. @@ -32,7 +30,7 @@ require_once 'Horde/Kolab/Server.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_DistListHandlingTest extends Horde_Kolab_Test_Server +class Horde_Kolab_Server_DistListHandlingTest extends Horde_Kolab_Server_Scenario { /** @@ -44,10 +42,12 @@ class Horde_Kolab_Server_DistListHandlingTest extends Horde_Kolab_Test_Server */ public function creatingDistributionList() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a distribution list') - ->then('the result should be an object of type', - 'Horde_Kolab_Server_Object_Kolab_Distlist'); + ->then( + 'the result should be an object of type', + 'Horde_Kolab_Server_Object_Kolab_Distlist' + ); } } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/GroupHandlingTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/GroupHandlingTest.php index fe926f77c..c67b36503 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/GroupHandlingTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/GroupHandlingTest.php @@ -12,11 +12,9 @@ */ /** - * We need the base class + * The Autoloader allows us to omit "require/include" statements. */ -require_once 'Horde/Kolab/Test/Server.php'; - -require_once 'Horde/Kolab/Server.php'; +require_once 'Horde/Autoloader.php'; /** * Handling groups. @@ -32,7 +30,7 @@ require_once 'Horde/Kolab/Server.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server +class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Server_Scenario { /** * Test listing groups if there are no groups. @@ -43,9 +41,11 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function listingGroupsOnEmptyServer() { - $this->given('an empty Kolab server') - ->when('retrieving a hash list with all objects of type', - 'Horde_Kolab_Server_Object_Kolabgroupofnames') + $this->given('several Kolab servers') + ->when( + 'retrieving a hash list with all objects of type', + 'Horde_Kolab_Server_Object_Kolabgroupofnames' + ) ->then('the list is an empty array'); } @@ -61,13 +61,17 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function listingGroups($group_list) { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding an object list', $group_list) - ->and('retrieving a hash list with all objects of type', - 'Horde_Kolab_Server_Object_Kolabgroupofnames') + ->and( + 'retrieving a hash list with all objects of type', + 'Horde_Kolab_Server_Object_Kolabgroupofnames' + ) ->then('the result indicates success.') - ->and('the list has a number of entries equal to', - count($group_list)); + ->and( + 'the list has a number of entries equal to', + count($group_list) + ); } /** @@ -82,12 +86,16 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function listingGroupsHasAttributeId($group_list) { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding an object list', $group_list) - ->and('retrieving a hash list with all objects of type', - 'Horde_Kolab_Server_Object_Kolabgroupofnames') - ->then('the provided list and the result list match with regard to these attributes', - 'mail', 'cn', $group_list); + ->and( + 'retrieving a hash list with all objects of type', + 'Horde_Kolab_Server_Object_Kolabgroupofnames' + ) + ->then( + 'the provided list and the result list match with regard to these attributes', + 'mail', 'cn', $group_list + ); } /** @@ -102,12 +110,16 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function listingGroupsHasAttributeMail($group_list) { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding an object list', $group_list) - ->and('retrieving a hash list with all objects of type', - 'Horde_Kolab_Server_Object_Kolabgroupofnames') - ->then('the provided list and the result list match with regard to these attributes', - 'mail', 'mail', $group_list); + ->and( + 'retrieving a hash list with all objects of type', + 'Horde_Kolab_Server_Object_Kolabgroupofnames' + ) + ->then( + 'the provided list and the result list match with regard to these attributes', + 'mail', 'mail', $group_list + ); } /** @@ -122,12 +134,16 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function listingGroupsHasAttributeVisibility($group_list) { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding an object list', $group_list) - ->and('retrieving a hash list with all objects of type', - 'Horde_Kolab_Server_Object_Kolabgroupofnames') - ->then('each element in the result list has an attribute', - 'visible'); + ->and( + 'retrieving a hash list with all objects of type', + 'Horde_Kolab_Server_Object_Kolabgroupofnames' + ) + ->then( + 'each element in the result list has an attribute', + 'visible' + ); } /** @@ -139,10 +155,12 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function creatingGroupsWithoutMailAddressFails() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a group without a mail address') - ->then('the result should indicate an error with', - 'Adding object failed: The value for "mail" is missing!'); + ->then( + 'the result should indicate an error with', + 'Adding object failed: The value for "mail" is missing!' + ); } /** @@ -154,12 +172,16 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function creatingGroupWithoutVisibilityCreatesVisibleGroup() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding an object', $this->provideGroupWithoutMembers()) - ->and('retrieving a hash list with all objects of type', - 'Horde_Kolab_Server_Object_Kolabgroupofnames') - ->then('each element in the result list has an attribute set to a given value', - 'visible', true); + ->and( + 'retrieving a hash list with all objects of type', + 'Horde_Kolab_Server_Object_Kolabgroupofnames' + ) + ->then( + 'each element in the result list has an attribute set to a given value', + 'visible', true + ); } /** @@ -171,11 +193,13 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function modifyingGroupMailAddressIsNotAllowed() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a group with the mail address "test@example.org"') ->and('modifying the mail address to "new@example.org"') - ->then('the result should indicate an error with', - 'The group cannot be modified: Changing the mail address from "test@example.org" to "new@example.org" is not allowed!'); + ->then( + 'the result should indicate an error with', + 'The group cannot be modified: Changing the mail address from "test@example.org" to "new@example.org" is not allowed!' + ); } /** @@ -187,25 +211,30 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function conflictBetweenGroupMailAndUserMailIsNotAllowed() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a group with the mail address "test@example.org"') ->and('adding a user "Test Test" with the mail address "test@example.org"') - ->then('the result should indicate an error with', - 'The user cannot be added: Mail address "test@example.org" is already the mail address for the group "test@example.org"!'); + ->then( + 'the result should indicate an error with', + 'The user cannot be added: Mail address "test@example.org" is already the mail address for the group "test@example.org"!' + ); } /** + * * @scenario * * @return NULL */ public function conflictBetweenUserMailAndGroupMailIsNotAllowed() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user "Test Test" with the mail address "test@example.org"') ->and('adding a group with the mail address "test@example.org"') - ->then('the result should indicate an error with', - 'The group cannot be added: Mail address "test@example.org" is already the mail address of the user "Test Test"!'); + ->then( + 'the result should indicate an error with', + 'The group cannot be added: Mail address "test@example.org" is already the mail address of the user "Test Test"!' + ); } /** @@ -213,11 +242,13 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function conflictBetweenGroupMailAndUserAliasIsNotAllowed() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a group with the mail address "test@example.org"') ->and('adding a user with the alias address "test@example.org"') - ->then('the result should indicate an error with', - 'The user cannot be added: Alias address "test@example.org" is already the mail address of the group "test@example.org"!'); + ->then( + 'the result should indicate an error with', + 'The user cannot be added: Alias address "test@example.org" is already the mail address of the group "test@example.org"!' + ); } /** @@ -225,11 +256,13 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function conflictBetweenUserAliasAndGroupMailIsNotAllowed() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user "Test Test" with the alias address "test@example.org"') ->and('adding a group with the mail address "test@example.org"') - ->then('the result should indicate an error with', - 'The group cannot be added: Mail address "test@example.org" is already the alias address of the user "Test Test"!'); + ->then( + 'the result should indicate an error with', + 'The group cannot be added: Mail address "test@example.org" is already the alias address of the user "Test Test"!' + ); } /** @@ -239,7 +272,7 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function showGroupsWhenFetchingTheUser() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user "cn=Test Test" with the mail address "test@example.org"') ->and('adding a group with the mail address "testgroup@example.org" and the member "cn=Test Test"') ->and('fetching the user "test@example.org"') @@ -252,7 +285,7 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function allowAddingUserToGroup() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a group with the mail address "testgroup@example.org"') ->and('adding a user "cn=Test Test" with the mail address "test@example.org"') ->and('modifying group with the mail address "testgroup@example.org" to contain the member "cn=Test Test".') @@ -266,7 +299,7 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function allowAddingUserToGroupWhenCreatingUser() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a group with the mail address "testgroup@example.org"') ->and('adding a user "cn=Test Test" with the mail address "test@example.org" and member of "testgroup@example.org"') ->and('fetching the groups "group@example.org"') @@ -279,7 +312,7 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function allowRemovingUserFromGroup() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user "cn=Test Test" with the mail address "test@example.org"') ->and('adding a group with the mail address "testgroup@example.org" and the member "cn=Test Test"') ->and('modifying group with the mail address "testgroup@example.org" to contain no members.') @@ -293,7 +326,7 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function deletingUserRemovesUserFromAllDistributionLists() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user "cn=Test Test" with the mail address "test@example.org"') ->and('adding a group with the mail address "testgroup@example.org" and the member "cn=Test Test"') ->and('adding a group with the mail address "testgroup2@example.org" and the member "cn=Test Test"') @@ -309,7 +342,7 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function modifyingUserIDDoesNotChangeGroupMembership() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user "cn=Test Test" with the mail address "test@example.org"') ->and('adding a group with the mail address "testgroup@example.org" and the member "cn=Test Test"') ->and('modifying user "cn=Test Test" to ID "cn=Test2 Test"') @@ -322,10 +355,13 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function addingGroupInUndefinedDomainIsNotAllowed() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('the only served mail domain is "example.org"') ->when('adding a group with the mail address "test@doesnotexist.org"') - ->then('the result should indicate an error with', 'The group cannot be added: Domain "doesnotexist.org" is not being handled by this server!'); + ->then( + 'the result should indicate an error with', + 'The group cannot be added: Domain "doesnotexist.org" is not being handled by this server!' + ); } /** @@ -336,9 +372,12 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function disallowInvalidMailAddresses($address) { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a group with an invalid mail address', $address) - ->then('the result should indicate an error with', "The group cannot be added: Address \"$address\" is not a valid mail address!"); + ->then( + 'the result should indicate an error with', + "The group cannot be added: Address \"$address\" is not a valid mail address!" + ); } /** @@ -346,7 +385,7 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function objectAttributeDescriptionsCanBeRetrieved() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('retrieving the supported attributes by the object type "group"') ->then('the result is an array of Horde attribute descriptions') ->and('contains the description of "members"'); @@ -357,10 +396,13 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function removingGroupFailsIfGroupDoesNotExist() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a group with the mail address "group@example.org"') ->and('deleting the group with the mail address "group@example.org"') - ->then('the result should indicate an error with', 'The group cannot be deleted: Group "group@example.org" does not exist!'); + ->then( + 'the result should indicate an error with', + 'The group cannot be deleted: Group "group@example.org" does not exist!' + ); } /** @@ -368,7 +410,7 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function removingGroupByMailSucceeds() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a group with the mail address "test@example.org"') ->and('deleting the group with mail address "test@example.org"') ->then('the result indicates success') @@ -382,10 +424,13 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function userUidsShouldNotResembleTheLocalPartOfMailAddresses() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a group with the mail address "test@example.org"') ->and('adding a user with the uid "test"') - ->then('the result should indicate an error with', 'The user cannot be added: The uid "test" matches the local part of the mail address "test@example.org" assigned to group "test@example.org"!'); + ->then( + 'the result should indicate an error with', + 'The user cannot be added: The uid "test" matches the local part of the mail address "test@example.org" assigned to group "test@example.org"!' + ); } /** @@ -395,7 +440,7 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function addedUserCanLoginIfInAllowedGroup() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('Horde uses the Kolab auth driver') ->and('only members of group "testgroup@example.org" are allowed') ->when('adding a user "cn=Test Test" with the mail address "test@example.org" and password "test"') @@ -412,7 +457,7 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function addedUserCannotLoginIfInNotInAllowedGroup() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('Horde uses the Kolab auth driver') ->and('only members of group "testgroup@example.org" are allowed') ->when('adding a user "cn=Test Test" with the mail address "test@example.org" and password "test"') @@ -428,7 +473,7 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function addedUserCanLoginIfInNotInDisallowedGroup() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('Horde uses the Kolab auth driver') ->and('members of group "testgroup@example.org" may not login') ->when('adding a user "cn=Test Test" with the mail address "test@example.org" and password "test"') @@ -445,7 +490,7 @@ class Horde_Kolab_Server_GroupHandlingTest extends Horde_Kolab_Test_Server */ public function addedUserCannotLoginIfInDisallowedGroup() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('Horde uses the Kolab auth driver') ->and('members of group "testgroup@example.org" may not login') ->when('adding a user "cn=Test Test" with the mail address "test@example.org" and password "test"') diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/GroupTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/GroupTest.php index 6cbc3d096..619cf5a12 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/GroupTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/GroupTest.php @@ -30,7 +30,7 @@ require_once 'Horde/Autoloader.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_GroupTest extends Horde_Kolab_Test_Server +class Horde_Kolab_Server_GroupTest extends Horde_Kolab_Server_Scenario { /** @@ -40,7 +40,7 @@ class Horde_Kolab_Server_GroupTest extends Horde_Kolab_Test_Server */ protected function setUp() { - $this->ldap = $this->prepareEmptyKolabServer(); + $this->ldap = $this->getKolabMockServer(); } /** @@ -65,9 +65,14 @@ class Horde_Kolab_Server_GroupTest extends Horde_Kolab_Test_Server public function testGenerateId() { $groups = $this->validGroups(); - $user = new Horde_Kolab_Server_Object_Kolabgroupofnames($this->ldap, null, $groups[0][0]); + $user = new Horde_Kolab_Server_Object_Kolabgroupofnames($this->ldap, + null, + $groups[0][0]); $this->assertNoError($user); - $this->assertEquals('cn=empty.group@example.org,dc=example,dc=org', $user->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID)); + $this->assertEquals( + 'cn=empty.group@example.org,dc=example,dc=org', + $user->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID) + ); } /** @@ -81,7 +86,10 @@ class Horde_Kolab_Server_GroupTest extends Horde_Kolab_Test_Server $group = $this->ldap->fetch('cn=empty.group@example.org,dc=example,dc=org'); $this->assertNoError($group); - $this->assertEquals('Horde_Kolab_Server_Object_Kolabgroupofnames', get_class($group)); + $this->assertEquals( + 'Horde_Kolab_Server_Object_Kolabgroupofnames', + get_class($group) + ); } /** @@ -115,20 +123,26 @@ class Horde_Kolab_Server_GroupTest extends Horde_Kolab_Test_Server { $this->assertEquals(0, count($GLOBALS['KOLAB_SERVER_TEST_DATA'])); - $result = $this->ldap->search('(&(!(cn=domains))(objectClass=kolabGroupOfNames))', - array(), - $this->ldap->getBaseUid()); + $result = $this->ldap->search( + '(&(!(cn=domains))(objectClass=kolabGroupOfNames))', + array(), + $this->ldap->getBaseUid() + ); $this->assertEquals(0, count($result)); $this->_addValidGroups(); $this->assertEquals(3, count($GLOBALS['KOLAB_SERVER_TEST_DATA'])); - $result = $this->ldap->search('(&(!(cn=domains))(objectClass=kolabGroupOfNames))', - array(), - $this->ldap->getBaseUid()); + $result = $this->ldap->search( + '(&(!(cn=domains))(objectClass=kolabGroupOfNames))', + array(), + $this->ldap->getBaseUid() + ); $this->assertEquals(3, count($result)); - $list = $this->ldap->listObjects('Horde_Kolab_Server_Object_Kolabgroupofnames'); + $list = $this->ldap->listObjects( + 'Horde_Kolab_Server_Object_Kolabgroupofnames' + ); $this->assertNoError($list); $this->assertEquals(3, count($list)); } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/InetorgpersonTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/InetorgpersonTest.php index 4797c75db..1b9cf2193 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/InetorgpersonTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/InetorgpersonTest.php @@ -30,7 +30,7 @@ require_once 'Horde/Autoloader.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_InetorgpersonTest extends Horde_Kolab_Test_Server +class Horde_Kolab_Server_InetorgpersonTest extends Horde_Kolab_Server_Scenario { /** * Objects used within this test @@ -62,146 +62,133 @@ class Horde_Kolab_Server_InetorgpersonTest extends Horde_Kolab_Test_Server ); /** - * Provide different server types. + * Set up testing. * - * @return array The different server types. + * @return NULL */ - public function &provideServers() + protected function setUp() { - $servers = array(); - /** - * We always use the test server - */ - $servers[] = array($this->prepareEmptyKolabServer()); - if (false) { - $real = $this->prepareLdapKolabServer(); - if (!empty($real)) { - $servers[] = array($real); - } - } - return $servers; + $this->initializeEnvironments(); + $this->servers = $this->getKolabServers(); } /** * Test ID generation for a person. * - * @dataProvider provideServers - * * @return NULL */ - public function testGenerateId($server) + public function testGenerateId() { - $a = new Horde_Kolab_Server_Object_Inetorgperson($server, null, $this->objects[0]); - $this->assertContains('Frank Mustermann', - $a->get(Horde_Kolab_Server_Object_Person::ATTRIBUTE_UID)); + foreach ($this->servers as $server) { + $a = new Horde_Kolab_Server_Object_Inetorgperson($server, null, $this->objects[0]); + $this->assertContains('Frank Mustermann', + $a->get(Horde_Kolab_Server_Object_Person::ATTRIBUTE_UID)); + } } /** * Test adding an invalid person. * - * @dataProvider provideServers * @expectedException Horde_Kolab_Server_Exception * * @return NULL */ - public function testAddInvalidPerson($server) + public function testAddInvalidPerson() { - $result = $server->add($this->objects[1]); + $this->addToServers($this->objects[1]); } /** * Test a person with middle names. * - * @dataProvider provideServers - * * @return NULL */ - public function testHandlePersonWithMiddleNames($server) + public function testHandlePersonWithMiddleNames() { - $person = $this->assertAdd($server, $this->objects[2], - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => $this->objects[2][Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME], - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => $this->objects[2][Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES])); - - $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Kolab_Server_InetorgpersonTest_123$123', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => 'Kolab_Server_InetorgpersonTest_123$123'), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Kolab_Server_InetorgpersonTest_123$123', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => 'Kolab_Server_InetorgpersonTest_123$123')); - - $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Kolab_Server_InetorgpersonTest_123$456', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => ''), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Kolab_Server_InetorgpersonTest_123$456', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => '')); - - $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => 'Kolab_Server_InetorgpersonTest_789'), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Kolab_Server_InetorgpersonTest_123$456', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => 'Kolab_Server_InetorgpersonTest_789')); - - $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => '', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => ''), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => '', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => '')); - - $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => 'Kolab_Server_InetorgpersonTest_789'), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => '', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => 'Kolab_Server_InetorgpersonTest_789')); - - $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Frank', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => ''), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Frank', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => '')); + foreach ($this->servers as $server) { + $person = $this->assertAdd($server, $this->objects[2], + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => $this->objects[2][Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME], + Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => $this->objects[2][Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES])); + + $this->assertStoreFetch($person, $server, + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Kolab_Server_InetorgpersonTest_123$123', + Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => 'Kolab_Server_InetorgpersonTest_123$123'), + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Kolab_Server_InetorgpersonTest_123$123', + Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => 'Kolab_Server_InetorgpersonTest_123$123')); + + $this->assertStoreFetch($person, $server, + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Kolab_Server_InetorgpersonTest_123$456', + Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => ''), + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Kolab_Server_InetorgpersonTest_123$456', + Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => '')); + + $this->assertStoreFetch($person, $server, + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => 'Kolab_Server_InetorgpersonTest_789'), + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Kolab_Server_InetorgpersonTest_123$456', + Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => 'Kolab_Server_InetorgpersonTest_789')); + + $this->assertStoreFetch($person, $server, + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => '', + Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => ''), + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => '', + Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => '')); + + $this->assertStoreFetch($person, $server, + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => 'Kolab_Server_InetorgpersonTest_789'), + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => '', + Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => 'Kolab_Server_InetorgpersonTest_789')); + + $this->assertStoreFetch($person, $server, + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Frank', + Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => ''), + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Frank', + Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => '')); + } } /** * Test handling labeled URIs. * - * @dataProvider provideServers - * * @return NULL */ - public function testHandleLabeledUris($server) + public function testHandleLabeledUris() { - $person = $this->assertAdd($server, $this->objects[0], - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => $this->objects[0][Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME], - Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array())); - - $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array('a' => 'http://a.example.com', - 'b' => 'http://b.example.com')), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array('a' => array('http://a.example.com'), - 'b' => array('http://b.example.com')))); - - $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array('a' => 'http://a.example.com', - 'b' => 'http://b.example.com', - 'c' => 'http://c.example.com')), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array('a' => array('http://a.example.com'), - 'b' => array('http://b.example.com'), - 'c' => array('http://c.example.com')))); - - $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array()), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array())); - - $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array('a' => 'http://a.example.com')), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array('a' => array('http://a.example.com')))); + foreach ($this->servers as $server) { + $person = $this->assertAdd($server, $this->objects[0], + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => $this->objects[0][Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME], + Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array())); + + $this->assertStoreFetch($person, $server, + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array('a' => 'http://a.example.com', + 'b' => 'http://b.example.com')), + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array('a' => array('http://a.example.com'), + 'b' => array('http://b.example.com')))); + + $this->assertStoreFetch($person, $server, + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array('a' => 'http://a.example.com', + 'b' => 'http://b.example.com', + 'c' => 'http://c.example.com')), + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array('a' => array('http://a.example.com'), + 'b' => array('http://b.example.com'), + 'c' => array('http://c.example.com')))); + + $this->assertStoreFetch($person, $server, + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array()), + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array())); + + $this->assertStoreFetch($person, $server, + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array('a' => 'http://a.example.com')), + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array('a' => array('http://a.example.com')))); + } } /** * Test handling the home postal address. * - * @dataProvider provideServers - * * @return NULL */ - public function testHandlingHomePostalAddress($server) + public function testHandlingHomePostalAddress() { //FIXME } @@ -209,55 +196,55 @@ class Horde_Kolab_Server_InetorgpersonTest extends Horde_Kolab_Test_Server /** * Test handling easy attributes. * - * @dataProvider provideServers - * * @return NULL */ - public function testEasyAttributes($server) + public function testEasyAttributes() { - $person = $this->assertAdd($server, $this->objects[0], - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_SID => '')); - $this->assertEasyAttributes($person, $server, - array( - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_SID => array( - 'user', - '0', - 'somebody', - null, - '', - array('he', 'she'), - ), - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_ORGANIZATION => array( - 'them', - '0', - 'somebody', - null, - '', - array('they', 'we'), - ), - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_BUSINESSCATEGORY => array( - 'them', - '0', - 'somebody', - null, - '', - array('they', 'we'), - ), - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_HOMEPHONE => array( - '123456789', - '+1234567890', - array('1', '2'), - null, - '0' - ), - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MOBILE => array( - '123456789', - '+1234567890', - array('1', '2'), - null, - '0' - ), - ) - ); + foreach ($this->servers as $server) { + $person = $this->assertAdd($server, $this->objects[0], + array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_SID => '')); + $this->assertEasyAttributes($person, $server, + array( + Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_SID => array( + 'user', + '0', + 'somebody', + null, + '', + array('he', 'she'), + ), + Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_ORGANIZATION => array( + 'them', + '0', + 'somebody', + null, + '', + array('they', 'we'), + ), + Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_BUSINESSCATEGORY => array( + 'them', + '0', + 'somebody', + null, + '', + array('they', 'we'), + ), + Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_HOMEPHONE => array( + '123456789', + '+1234567890', + array('1', '2'), + null, + '0' + ), + Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MOBILE => array( + '123456789', + '+1234567890', + array('1', '2'), + null, + '0' + ), + ) + ); + } } } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/KolabgermanbankarrangementTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/KolabgermanbankarrangementTest.php index e987854c8..1a20167b8 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/KolabgermanbankarrangementTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/KolabgermanbankarrangementTest.php @@ -30,7 +30,7 @@ require_once 'Horde/Autoloader.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_KolabgermanbankarrangementTest extends Horde_Kolab_Test_Server +class Horde_Kolab_Server_KolabgermanbankarrangementTest extends Horde_Kolab_Server_Scenario { /** * Objects used within this test @@ -54,132 +54,121 @@ class Horde_Kolab_Server_KolabgermanbankarrangementTest extends Horde_Kolab_Test ); /** - * Provide different server types. + * Set up testing. * - * @return array The different server types. + * @return NULL */ - public function &provideServers() + protected function setUp() { - $servers = array(); - /** - * We always use the test server - */ - $servers[] = array($this->prepareEmptyKolabServer()); - if (false) { - $real = $this->prepareLdapKolabServer(); - if (!empty($real)) { - $servers[] = array($real); - } - } - return $servers; + $this->initializeEnvironments(); + $this->servers = $this->getKolabServers(); } /** * Test ID generation for a person. * - * @dataProvider provideServers - * * @return NULL */ - public function testGenerateId($server) + public function testGenerateId() { - $person = $this->assertAdd($server, $this->objects[0], - array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); - $account_data = $this->objects[1]; - $account_data[Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_OWNERUID] = $person->getUid(); - $a = new Horde_Kolab_Server_Object_Kolabgermanbankarrangement($server, null, $account_data); - $this->assertContains(Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_NUMBER . '=' . $this->objects[1][Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_NUMBER], - $a->get(Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_UID)); + foreach ($this->servers as $server) { + $person = $this->assertAdd($server, $this->objects[0], + array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); + $account_data = $this->objects[1]; + $account_data[Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_OWNERUID] = $person->getUid(); + $a = new Horde_Kolab_Server_Object_Kolabgermanbankarrangement($server, null, $account_data); + $this->assertContains(Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_NUMBER . '=' . $this->objects[1][Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_NUMBER], + $a->get(Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_UID)); + } } /** * Test adding an invalid Account. * - * @dataProvider provideServers * @expectedException Horde_Kolab_Server_Exception * * @return NULL */ - public function testAddInvalidAccount($server) + public function testAddInvalidAccount() { - $result = $server->add($this->objects[1]); + $this->addToServers($this->objects[1]); } /** * Test handling easy attributes. * - * @dataProvider provideServers - * * @return NULL */ - public function testEasyAttributes($server) + public function testEasyAttributes() { - $person = $this->assertAdd($server, $this->objects[0], - array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); - $account_data = $this->objects[1]; - $account_data[Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_OWNERUID] = $person->getUid(); - $account = $this->assertAdd($server, $account_data, - array(Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_OWNERUID => $person->getUid())); - $this->assertEasyAttributes($account, $server, - array( - Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_HOLDER => array( - 'something', - 'somewhere', - null, - array('a', 'b'), - '', - ), - Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_BANKNAME => array( - 'something', - 'somewhere', - null, - array('a', 'b'), - '', - ), - Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_INFO => array( - 'something', - 'somewhere', - null, - array('a', 'b'), - '', - ), - ) - ); + foreach ($this->servers as $server) { + $person = $this->assertAdd($server, $this->objects[0], + array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); + $account_data = $this->objects[1]; + $account_data[Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_OWNERUID] = $person->getUid(); + $account = $this->assertAdd($server, $account_data, + array(Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_OWNERUID => $person->getUid())); + $this->assertEasyAttributes($account, $server, + array( + Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_HOLDER => array( + 'something', + 'somewhere', + null, + array('a', 'b'), + '', + ), + Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_BANKNAME => array( + 'something', + 'somewhere', + null, + array('a', 'b'), + '', + ), + Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_INFO => array( + 'something', + 'somewhere', + null, + array('a', 'b'), + '', + ), + ) + ); + } } /** * Test modifying the account number of an account. This should have an * effect on the UID of the object and needs to rename the object. * - * @dataProvider provideServers - * * @return NULL */ - public function testModifyAccountNumber($server) + public function testModifyAccountNumber() { - $person = $this->assertAdd($server, $this->objects[0], - array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); - $account_data = $this->objects[1]; - $account_data[Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_OWNERUID] = $person->getUid(); - $account = $server->add($account_data); - $this->assertNoError($account); + foreach ($this->servers as $server) { + $person = $this->assertAdd($server, $this->objects[0], + array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); + $account_data = $this->objects[1]; + $account_data[Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_OWNERUID] = $person->getUid(); + $account = $server->add($account_data); + $this->assertNoError($account); - $account = $server->fetch($account->getUid()); - $this->assertNoError($account); + $account = $server->fetch($account->getUid()); + $this->assertNoError($account); - $this->assertEquals($this->objects[1][Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_NUMBER], - $account->get(Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_NUMBER)); + $this->assertEquals($this->objects[1][Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_NUMBER], + $account->get(Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_NUMBER)); - $result = $account->save(array(Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_NUMBER => '66666666')); - $this->assertNoError($result); + $result = $account->save(array(Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_NUMBER => '66666666')); + $this->assertNoError($result); - $account = $server->fetch($account->getUid()); - $this->assertNoError($account); + $account = $server->fetch($account->getUid()); + $this->assertNoError($account); - $this->assertEquals($account->get(Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_NUMBER), - '66666666'); + $this->assertEquals($account->get(Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_NUMBER), + '66666666'); - $result = $server->delete($account->getUid()); - $this->assertNoError($result); + $result = $server->delete($account->getUid()); + $this->assertNoError($result); + } } } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/KolabinetorgpersonTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/KolabinetorgpersonTest.php index 2f3aba98d..cada6395e 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/KolabinetorgpersonTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/KolabinetorgpersonTest.php @@ -30,7 +30,7 @@ require_once 'Horde/Autoloader.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_KolabinetorgpersonTest extends Horde_Kolab_Test_Server +class Horde_Kolab_Server_KolabinetorgpersonTest extends Horde_Kolab_Server_Scenario { /** * Objects used within this test @@ -54,251 +54,240 @@ class Horde_Kolab_Server_KolabinetorgpersonTest extends Horde_Kolab_Test_Server ); /** - * Provide different server types. + * Set up testing. * - * @return array The different server types. + * @return NULL */ - public function &provideServers() + protected function setUp() { - $servers = array(); - /** - * We always use the test server - */ - $servers[] = array($this->prepareEmptyKolabServer()); - if (false) { - $real = $this->prepareLdapKolabServer(); - if (!empty($real)) { - $servers[] = array($real); - } - } - return $servers; + $this->initializeEnvironments(); + $this->servers = $this->getKolabServers(); } /** * Test ID generation for a person. * - * @dataProvider provideServers - * * @return NULL */ - public function testGenerateId($server) + public function testGenerateId() { - $a = new Horde_Kolab_Server_Object_Kolabinetorgperson($server, null, $this->objects[0]); - $this->assertContains('Frank Mustermann', - $a->get(Horde_Kolab_Server_Object_Person::ATTRIBUTE_UID)); + foreach ($this->servers as $server) { + $a = new Horde_Kolab_Server_Object_Kolabinetorgperson($server, null, $this->objects[0]); + $this->assertContains('Frank Mustermann', + $a->get(Horde_Kolab_Server_Object_Person::ATTRIBUTE_UID)); + } } /** * Test adding an invalid person. * - * @dataProvider provideServers * @expectedException Horde_Kolab_Server_Exception * * @return NULL */ - public function testAddInvalidPerson($server) + public function testAddInvalidPerson() { - $result = $server->add($this->objects[1]); + $this->addToServers($this->objects[1]); } /** * Test handling easy attributes. * - * @dataProvider provideServers - * * @return NULL */ - public function testEasyAttributes($server) + public function testEasyAttributes() { - $person = $this->assertAdd($server, $this->objects[0], - array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); - $this->assertEasyAttributes($person, $server, - array( - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_GERMANTAXID => array( - '01234567890123456789', - '0', - '101', - null, - 'DE', - array('101', '202'), - ), - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_HOMESERVER => array( - 'a.b.c', - '', - 'jodeldodel', - null, - array('a.example.com', 'b.example.com'), - ), - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_QUOTA => array( - '100', - null, - array('0', '1000'), - ), - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_ALLOWEDRECIPIENTS => array( - '-a@example.com', - '', - array('a', 'b'), - null, - '0' - ), - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_ALLOWEDFROM => array( - '-a@example.com', - '', - array('a', 'b'), - null, - '0' - ), - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SALUTATION => array( - 'Herr', - 'Mrs.', - null, - array('Herr', 'Mrs.'), - '0' - ), - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_GENDER => array( - '1', - null, - '0', - '2', - ), - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_BIRTHNAME => array( - 'Adam', - null, - '', - '0', - ), - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_PLACEOFBIRTH => array( - 'Jotwede', - null, - '', - ), - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_COUNTRY => array( - 'DE', - 'SE', - null, - 'DE', - ), - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_COUNTRYCITIZENSHIP => array( - 'DE', - 'SE', - //FIXME: "null" does not work. Why? - //null, - 'DE', - ), - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_LEGALFORM => array( - 'GmbH', - 'Freelancer', - null, - 'Freelancer', - ), -// FIXME: Undefined in object class -/* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_REGISTEREDCAPITAL => array( */ -/* '1212121211', */ -/* '0', */ -/* null, */ -/* '' */ -/* ), */ + foreach ($this->servers as $server) { + $person = $this->assertAdd($server, $this->objects[0], + array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); + $this->assertEasyAttributes($person, $server, + array( + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_GERMANTAXID => array( + '01234567890123456789', + '0', + '101', + null, + 'DE', + array('101', '202'), + ), + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_HOMESERVER => array( + 'a.b.c', + '', + 'jodeldodel', + null, + array('a.example.com', 'b.example.com'), + ), + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_QUOTA => array( + '100', + null, + array('0', '1000'), + ), + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_ALLOWEDRECIPIENTS => array( + '-a@example.com', + '', + array('a', 'b'), + null, + '0' + ), + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_ALLOWEDFROM => array( + '-a@example.com', + '', + array('a', 'b'), + null, + '0' + ), + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SALUTATION => array( + 'Herr', + 'Mrs.', + null, + array('Herr', 'Mrs.'), + '0' + ), + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_GENDER => array( + '1', + null, + '0', + '2', + ), + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_BIRTHNAME => array( + 'Adam', + null, + '', + '0', + ), + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_PLACEOFBIRTH => array( + 'Jotwede', + null, + '', + ), + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_COUNTRY => array( + 'DE', + 'SE', + null, + 'DE', + ), + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_COUNTRYCITIZENSHIP => array( + 'DE', + 'SE', + //FIXME: "null" does not work. Why? + //null, + 'DE', + ), + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_LEGALFORM => array( + 'GmbH', + 'Freelancer', + null, + 'Freelancer', + ), + // FIXME: Undefined in object class + /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_REGISTEREDCAPITAL => array( */ + /* '1212121211', */ + /* '0', */ + /* null, */ + /* '' */ + /* ), */ -// FIXME: Undefined in object class -/* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_BYLAWURI => array( */ -/* 'something', */ -/* 'somewhere', */ -/* null, */ -/* array('a', 'b'), */ -/* '', */ -/* ), */ + // FIXME: Undefined in object class + /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_BYLAWURI => array( */ + /* 'something', */ + /* 'somewhere', */ + /* null, */ + /* array('a', 'b'), */ + /* '', */ + /* ), */ -//FIXME: Alias support -/* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_DATEOFINCORPORATION => array( */ -/* '199911220707Z', */ -/* ), */ + //FIXME: Alias support + /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_DATEOFINCORPORATION => array( */ + /* '199911220707Z', */ + /* ), */ -// FIXME: Undefined in object class -/* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_LEGALREPRESENTATIONPOLICY => array( */ -/* 'something', */ -/* 'somewhere', */ -/* null, */ -/* array('a', 'b'), */ -/* '', */ -/* ), */ + // FIXME: Undefined in object class + /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_LEGALREPRESENTATIONPOLICY => array( */ + /* 'something', */ + /* 'somewhere', */ + /* null, */ + /* array('a', 'b'), */ + /* '', */ + /* ), */ - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_VATNUMBER => array( - 'something', - 'somewhere', - null, - array('a', 'b'), - ), + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_VATNUMBER => array( + 'something', + 'somewhere', + null, + array('a', 'b'), + ), -//FIXME: Undefined -/* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_OTHERLEGAL => array( */ -/* 'something', */ -/* 'somewhere', */ -/* null, */ -/* array('a', 'b'), */ -/* ), */ + //FIXME: Undefined + /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_OTHERLEGAL => array( */ + /* 'something', */ + /* 'somewhere', */ + /* null, */ + /* array('a', 'b'), */ + /* ), */ -// FIXME: Undefined in object class -/* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_INLIQUIDATION => array( */ -/* 'TRUE', */ -/* 'FALSE', */ -/* null, */ -/* array('TRUE', 'FALSE'), */ -/* ), */ + // FIXME: Undefined in object class + /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_INLIQUIDATION => array( */ + /* 'TRUE', */ + /* 'FALSE', */ + /* null, */ + /* array('TRUE', 'FALSE'), */ + /* ), */ -// FIXME: Undefined in object class -/* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_TRTYPE => array( */ -/* 'something', */ -/* 'somewhere', */ -/* null, */ -/* array('a', 'b'), */ -/* ), */ + // FIXME: Undefined in object class + /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_TRTYPE => array( */ + /* 'something', */ + /* 'somewhere', */ + /* null, */ + /* array('a', 'b'), */ + /* ), */ - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_TRLOCATION => array( - 'something', - 'somewhere', - null, - 'somewhere', - ), + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_TRLOCATION => array( + 'something', + 'somewhere', + null, + 'somewhere', + ), - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_TRIDENTIFIER => array( - 'something', - 'somewhere', - null, - 'somewhere', - ), + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_TRIDENTIFIER => array( + 'something', + 'somewhere', + null, + 'somewhere', + ), -// FIXME: Undefined in object class -/* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_TRURI => array( */ -/* 'something', */ -/* 'somewhere', */ -/* null, */ -/* array('a', 'b'), */ -/* ), */ + // FIXME: Undefined in object class + /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_TRURI => array( */ + /* 'something', */ + /* 'somewhere', */ + /* null, */ + /* array('a', 'b'), */ + /* ), */ -// FIXME: Undefined in object class -/* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_TRLASTCHANGED => array( */ -/* 'something', */ -/* 'somewhere', */ -/* null, */ -/* array('a', 'b'), */ -/* ), */ + // FIXME: Undefined in object class + /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_TRLASTCHANGED => array( */ + /* 'something', */ + /* 'somewhere', */ + /* null, */ + /* array('a', 'b'), */ + /* ), */ -// FIXME: Undefined in object class -/* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_DC => array( */ -/* 'something', */ -/* 'somewhere', */ -/* null, */ -/* array('a', 'b'), */ -/* ), */ + // FIXME: Undefined in object class + /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_DC => array( */ + /* 'something', */ + /* 'somewhere', */ + /* null, */ + /* array('a', 'b'), */ + /* ), */ - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_ALIAS => array( - 'something', - 'somewhere', - null, - array('a', 'b'), - ), + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_ALIAS => array( + 'something', + 'somewhere', + null, + array('a', 'b'), + ), - ) - ); + ) + ); + } } } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Kolabpop3accountTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Kolabpop3accountTest.php index 2a3718537..da596047f 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Kolabpop3accountTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Kolabpop3accountTest.php @@ -30,7 +30,7 @@ require_once 'Horde/Autoloader.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Kolabpop3accountTest extends Horde_Kolab_Test_Server +class Horde_Kolab_Server_Kolabpop3accountTest extends Horde_Kolab_Server_Scenario { /** * Objects used within this test @@ -56,165 +56,154 @@ class Horde_Kolab_Server_Kolabpop3accountTest extends Horde_Kolab_Test_Server ); /** - * Provide different server types. + * Set up testing. * - * @return array The different server types. + * @return NULL */ - public function &provideServers() + protected function setUp() { - $servers = array(); - /** - * We always use the test server - */ - $servers[] = array($this->prepareEmptyKolabServer()); - if (false) { - $real = $this->prepareLdapKolabServer(); - if (!empty($real)) { - $servers[] = array($real); - } - } - return $servers; + $this->initializeEnvironments(); + $this->servers = $this->getKolabServers(); } /** * Test ID generation for a person. * - * @dataProvider provideServers - * * @return NULL */ - public function testGenerateId($server) + public function testGenerateId() { - $person = $this->assertAdd($server, $this->objects[0], - array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); - $account_data = $this->objects[1]; - $account_data[Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_OWNERUID] = $person->getUid(); - $a = new Horde_Kolab_Server_Object_Kolabpop3account($server, null, $account_data); - $this->assertContains(Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_MAIL . '=' . $this->objects[1][Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_MAIL], - $a->get(Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_UID)); + foreach ($this->servers as $server) { + $person = $this->assertAdd($server, $this->objects[0], + array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); + $account_data = $this->objects[1]; + $account_data[Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_OWNERUID] = $person->getUid(); + $a = new Horde_Kolab_Server_Object_Kolabpop3account($server, null, $account_data); + $this->assertContains(Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_MAIL . '=' . $this->objects[1][Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_MAIL], + $a->get(Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_UID)); + } } /** * Test adding an invalid Account. * - * @dataProvider provideServers * @expectedException Horde_Kolab_Server_Exception * * @return NULL */ - public function testAddInvalidAccount($server) + public function testAddInvalidAccount() { - $result = $server->add($this->objects[1]); + $this->addToServers($this->objects[1]); } /** * Test handling easy attributes. * - * @dataProvider provideServers - * * @return NULL */ - public function testEasyAttributes($server) + public function testEasyAttributes() { - $person = $this->assertAdd($server, $this->objects[0], - array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); - $account_data = $this->objects[1]; - $account_data[Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_OWNERUID] = $person->getUid(); - $account = $this->assertAdd($server, $account_data, - array(Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_OWNERUID => $person->getUid())); - $this->assertEasyAttributes($account, $server, - array( - Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_PASSWORD => array( - 'something', - 'somewhere', - ), - Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_DESCRIPTION => array( - 'something', - 'somewhere', - null, - '', - ), - Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_SERVER => array( - 'something', - 'somewhere', - array('a', 'b'), - ), - Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_PORT => array( - '110', - '111', - null, - '', - ), - Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_USESSL => array( - 'TRUE', - 'FALSE', - null, - '', - ), - Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_USETLS => array( - 'TRUE', - 'FALSE', - null, - '', - ), - Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_LOGINMETHOD => array( - 'something', - 'somewhere', - null, - array('a', 'b'), - '', - ), - Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_CHECKCERTIFICATE => array( - 'TRUE', - 'FALSE', - null, - '', - ), - Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_KEEPMAILONSERVER => array( - 'TRUE', - 'FALSE', - null, - '', - ), - ) - ); + foreach ($this->servers as $server) { + $person = $this->assertAdd($server, $this->objects[0], + array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); + $account_data = $this->objects[1]; + $account_data[Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_OWNERUID] = $person->getUid(); + $account = $this->assertAdd($server, $account_data, + array(Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_OWNERUID => $person->getUid())); + $this->assertEasyAttributes($account, $server, + array( + Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_PASSWORD => array( + 'something', + 'somewhere', + ), + Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_DESCRIPTION => array( + 'something', + 'somewhere', + null, + '', + ), + Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_SERVER => array( + 'something', + 'somewhere', + array('a', 'b'), + ), + Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_PORT => array( + '110', + '111', + null, + '', + ), + Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_USESSL => array( + 'TRUE', + 'FALSE', + null, + '', + ), + Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_USETLS => array( + 'TRUE', + 'FALSE', + null, + '', + ), + Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_LOGINMETHOD => array( + 'something', + 'somewhere', + null, + array('a', 'b'), + '', + ), + Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_CHECKCERTIFICATE => array( + 'TRUE', + 'FALSE', + null, + '', + ), + Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_KEEPMAILONSERVER => array( + 'TRUE', + 'FALSE', + null, + '', + ), + ) + ); + } } /** * Test modifying the attributes required for the UID of the account. This * should lead to renaming object. * - * @dataProvider provideServers - * * @return NULL */ - public function testModifyUidElements($server) + public function testModifyUidElements() { - $person = $this->assertAdd($server, $this->objects[0], - array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); - $account_data = $this->objects[1]; - $account_data[Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_OWNERUID] = $person->getUid(); - $account = $server->add($account_data); - $this->assertNoError($account); + foreach ($this->servers as $server) { + $person = $this->assertAdd($server, $this->objects[0], + array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); + $account_data = $this->objects[1]; + $account_data[Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_OWNERUID] = $person->getUid(); + $account = $server->add($account_data); + $this->assertNoError($account); - $account = $server->fetch($account->getUid()); - $this->assertNoError($account); + $account = $server->fetch($account->getUid()); + $this->assertNoError($account); - $this->assertEquals($this->objects[1][Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_SERVER], - $account->get(Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_SERVER)); + $this->assertEquals($this->objects[1][Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_SERVER], + $account->get(Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_SERVER)); - $result = $account->save(array(Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_SERVER => 'pop3s.example.com')); - $this->assertNoError($result); + $result = $account->save(array(Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_SERVER => 'pop3s.example.com')); + $this->assertNoError($result); - $account = $server->fetch($account->getUid()); - $this->assertNoError($account); + $account = $server->fetch($account->getUid()); + $this->assertNoError($account); - $this->assertEquals($account->get(Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_SERVER), - 'pop3s.example.com'); + $this->assertEquals($account->get(Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_SERVER), + 'pop3s.example.com'); - $this->assertContains('frank@example.com', $account->getUid()); + $this->assertContains('frank@example.com', $account->getUid()); - $result = $server->delete($account->getUid()); - $this->assertNoError($result); + $result = $server->delete($account->getUid()); + $this->assertNoError($result); + } } } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/LdapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/LdapTest.php index 086e3b1ba..8ad44a463 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/LdapTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/LdapTest.php @@ -1,3 +1,4 @@ + prepareEmptyKolabServer()); - if (false) { - $real = $this->prepareLdapKolabServer(); - if (!empty($real)) { - $servers[] = array($real); - } - } - return $servers; + $this->initializeEnvironments(); + $this->servers = $this->getKolabServers(); } /** * Test ID generation for a person. * - * @dataProvider provideServers - * * @return NULL */ - public function testGenerateId($server) + public function testGenerateId() { - $a = new Horde_Kolab_Server_Object_Organizationalperson($server, null, $this->objects[0]); - $this->assertContains(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN . '=' . $this->objects[0][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN], - $a->get(Horde_Kolab_Server_Object_Person::ATTRIBUTE_UID)); + foreach ($this->servers as $server) { + $a = new Horde_Kolab_Server_Object_Organizationalperson($server, null, $this->objects[0]); + $this->assertContains(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN . '=' . $this->objects[0][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN], + $a->get(Horde_Kolab_Server_Object_Person::ATTRIBUTE_UID)); + } } /** * Test adding an invalid person. * - * @dataProvider provideServers * @expectedException Horde_Kolab_Server_Exception * * @return NULL */ - public function testAddInvalidPerson($server) + public function testAddInvalidPerson() { - $result = $server->add($this->objects[1]); + $this->addToServers($this->objects[1]); } /** * Test handling simple attributes. * - * @dataProvider provideServers - * * @return NULL */ - public function testSimpleAttributes($server) + public function testSimpleAttributes() { - $person = $this->assertAdd($server, $this->objects[0], - array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_JOBTITLE => '')); - $this->assertSimpleAttributes($person, $server, - array( - )); + foreach ($this->servers as $server) { + $person = $this->assertAdd($server, $this->objects[0], + array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_JOBTITLE => '')); + $this->assertSimpleAttributes($person, $server, + array( + )); + } } /** * Test handling the postal address. * - * @dataProvider provideServers - * * @return NULL */ - public function testHandlingAPostalAddress($server) + public function testHandlingAPostalAddress() { - $person = $this->assertAdd($server, $this->objects[0], - array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALADDRESS => 'Kolab_Server_OrgPersonTest_123$$ ')); + foreach ($this->servers as $server) { + $person = $this->assertAdd($server, $this->objects[0], + array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALADDRESS => 'Kolab_Server_OrgPersonTest_123$$ ')); - $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_SN => 'Kolab_Server_OrgPersonTest_456'), - array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALADDRESS => array('Kolab_Server_OrgPersonTest_456$$ '))); + $this->assertStoreFetch($person, $server, + array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_SN => 'Kolab_Server_OrgPersonTest_456'), + array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALADDRESS => array('Kolab_Server_OrgPersonTest_456$$ '))); - $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_SN => 'Kolab_Server_OrgPersonTest_123', - Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_STREET => 'Street 1', - Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALCODE => '12345', - Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_CITY => 'Nowhere'), - array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALADDRESS => array('Kolab_Server_OrgPersonTest_123$Street 1$12345 Nowhere'))); - $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTOFFICEBOX => 'öäü/)(="§%$&§§$\'*', - Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_STREET => null), - array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALADDRESS => array('Kolab_Server_OrgPersonTest_123$öäü/)(="§%\24&§§\24\'*$12345 Nowhere'))); + $this->assertStoreFetch($person, $server, + array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_SN => 'Kolab_Server_OrgPersonTest_123', + Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_STREET => 'Street 1', + Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALCODE => '12345', + Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_CITY => 'Nowhere'), + array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALADDRESS => array('Kolab_Server_OrgPersonTest_123$Street 1$12345 Nowhere'))); + $this->assertStoreFetch($person, $server, + array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTOFFICEBOX => 'öäü/)(="§%$&§§$\'*', + Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_STREET => null), + array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALADDRESS => array('Kolab_Server_OrgPersonTest_123$öäü/)(="§%\24&§§\24\'*$12345 Nowhere'))); - $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_STREET => null, - Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALCODE => null, - //FIXME: Why does this need a string? - Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALADDRESS => '', - Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTOFFICEBOX => null, - Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_CITY => null), - array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALADDRESS => array('Kolab_Server_OrgPersonTest_123$$ '))); + $this->assertStoreFetch($person, $server, + array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_STREET => null, + Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALCODE => null, + //FIXME: Why does this need a string? + Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALADDRESS => '', + Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTOFFICEBOX => null, + Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_CITY => null), + array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALADDRESS => array('Kolab_Server_OrgPersonTest_123$$ '))); + } } /** * Test handling easy attributes. * - * @dataProvider provideServers - * * @return NULL */ - public function testEasyAttributes($server) + public function testEasyAttributes() { - $person = $this->assertAdd($server, $this->objects[0], - array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_JOBTITLE => '')); - $this->assertEasyAttributes($person, $server, - array( - Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_JOBTITLE => array( - 'Teacher', - '0', - 'Something', - null, - '', - array('This', 'That'), - ), - Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_FAX => array( - '123456789', - '+1234567890', - array('1', '2'), - '0', - //FIXME: How to delete? - //null + foreach ($this->servers as $server) { + $person = $this->assertAdd($server, $this->objects[0], + array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_JOBTITLE => '')); + $this->assertEasyAttributes($person, $server, + array( + Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_JOBTITLE => array( + 'Teacher', + '0', + 'Something', + null, + '', + array('This', 'That'), + ), + Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_FAX => array( + '123456789', + '+1234567890', + array('1', '2'), + '0', + //FIXME: How to delete? + //null + ) ) - ) - ); + ); + } } } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/PersonTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/PersonTest.php index 70ddc5959..dd4ad6a75 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/PersonTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/PersonTest.php @@ -30,7 +30,7 @@ require_once 'Horde/Autoloader.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_PersonTest extends Horde_Kolab_Test_Server +class Horde_Kolab_Server_PersonTest extends Horde_Kolab_Server_Scenario { public $cn = 'Kolab_Server_PersonTest'; @@ -108,181 +108,170 @@ class Horde_Kolab_Server_PersonTest extends Horde_Kolab_Test_Server ); /** - * Provide different server types. + * Set up testing. * - * @return array The different server types. + * @return NULL */ - public function &provideServers() + protected function setUp() { - $servers = array(); - /** - * We always use the test server - */ - $servers[] = array($this->prepareEmptyKolabServer()); - if (false) { - $real = $this->prepareLdapKolabServer(); - if (!empty($real)) { - $servers[] = array($real); - } - } - return $servers; + $this->initializeEnvironments(); + $this->servers = $this->getKolabServers(); } /** * Test ID generation for a person. * - * @dataProvider provideServers - * * @return NULL */ - public function testGenerateId($server) + public function testGenerateId() { - $a = new Horde_Kolab_Server_Object_Person($server, null, $this->objects[0]); - $this->assertContains(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN . '=' . $this->objects[0][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN], - $a->get(Horde_Kolab_Server_Object_Person::ATTRIBUTE_UID)); + foreach ($this->servers as $server) { + $a = new Horde_Kolab_Server_Object_Person($server, null, $this->objects[0]); + $this->assertContains(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN . '=' . $this->objects[0][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN], + $a->get(Horde_Kolab_Server_Object_Person::ATTRIBUTE_UID)); + } } /** * Test adding an invalid person. * - * @dataProvider provideServers * @expectedException Horde_Kolab_Server_Exception * * @return NULL */ - public function testAddInvalidPerson($server) + public function testAddInvalidPerson() { - $result = $server->add($this->objects[1]); + $this->addToServers($this->objects[1]); } /** * Test adding a person. * - * @dataProvider provideServers - * * @return NULL */ - public function testAddPerson($server) + public function testAddPerson() { - $adds = array(0, 2, 3, 4); - foreach ($adds as $add) { - $result = $server->add($this->objects[$add]); - $this->assertNoError($result); - $cn_result = $server->uidForCn($this->objects[$add][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN]); - $this->assertNoError($cn_result); - $dn_parts = Net_LDAP2_Util::ldap_explode_dn($cn_result, array('casefold' => 'lower')); - $dnpart = Net_LDAP2_Util::unescape_dn_value($dn_parts[0]); - /** - * FIXME: I currently do not really understand why the forward slash - * is not correctly converted back but I lack the time to analyse it - * in detail. The server entry looks okay. - */ - $dnpart = str_replace('\/', '/', $dnpart); - $this->assertContains(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN . '=' . $this->objects[$add][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN], - $dnpart[0]); - $result = $server->delete($cn_result); - $this->assertNoError($result); - $cn_result = $server->uidForCn($this->objects[$add][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN]); - $this->assertNoError($cn_result); - $this->assertFalse($server->uidForCn($this->objects[$add][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN])); + foreach ($this->servers as $server) { + $adds = array(0, 2, 3, 4); + foreach ($adds as $add) { + $result = $server->add($this->objects[$add]); + $this->assertNoError($result); + $cn_result = $server->uidForCn($this->objects[$add][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN]); + $this->assertNoError($cn_result); + $dn_parts = Net_LDAP2_Util::ldap_explode_dn($cn_result, array('casefold' => 'lower')); + $dnpart = Net_LDAP2_Util::unescape_dn_value($dn_parts[0]); + /** + * FIXME: I currently do not really understand why the forward slash + * is not correctly converted back but I lack the time to analyse it + * in detail. The server entry looks okay. + */ + $dnpart = str_replace('\/', '/', $dnpart); + $this->assertContains(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN . '=' . $this->objects[$add][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN], + $dnpart[0]); + $result = $server->delete($cn_result); + $this->assertNoError($result); + $cn_result = $server->uidForCn($this->objects[$add][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN]); + $this->assertNoError($cn_result); + $this->assertFalse($server->uidForCn($this->objects[$add][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN])); + } } } /** * Test modifying the surname of a person. * - * @dataProvider provideServers - * * @return NULL */ - public function testModifyPersonSn($server) + public function testModifyPersonSn() { - $person = $this->assertAdd($server, $this->objects[2], - array(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN => $this->objects[2][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN])); - $this->assertSimpleSequence($person, $server, - Horde_Kolab_Server_Object_Person::ATTRIBUTE_SN, - array('modified', 'modified_again'), true); + foreach ($this->servers as $server) { + $person = $this->assertAdd($server, $this->objects[2], + array(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN => $this->objects[2][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN])); + $this->assertSimpleSequence($person, $server, + Horde_Kolab_Server_Object_Person::ATTRIBUTE_SN, + array('modified', 'modified_again'), true); + } } /** * Test modifying the cn of a person. This should have an effect on the UID * of the object and needs to rename the object. * - * @dataProvider provideServers - * * @return NULL */ - public function testModifyPersonCn($server) + public function testModifyPersonCn() { - $person = $server->add($this->objects[2]); - $this->assertNoError($person); + foreach ($this->servers as $server) { + $person = $server->add($this->objects[2]); + $this->assertNoError($person); - $person = $server->fetch($person->getUid()); + $person = $server->fetch($person->getUid()); - $this->assertEquals($this->objects[2][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN], - $person->get(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN)); + $this->assertEquals($this->objects[2][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN], + $person->get(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN)); - $result = $person->save(array(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN => 'Kolab_Server_PersonTest_äö')); - $cn_result = $server->uidForCn('Kolab_Server_PersonTest_äö'); - $person = $server->fetch($cn_result); - $this->assertEquals($person->get(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN), - 'Kolab_Server_PersonTest_äö'); - $result = $server->delete($cn_result); - $this->assertNoError($result); - $cn_result = $server->uidForCn('Kolab_Server_PersonTest_äö'); - $this->assertNoError($cn_result); - $this->assertFalse($cn_result); + $result = $person->save(array(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN => 'Kolab_Server_PersonTest_äö')); + $cn_result = $server->uidForCn('Kolab_Server_PersonTest_äö'); + $person = $server->fetch($cn_result); + $this->assertEquals($person->get(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN), + 'Kolab_Server_PersonTest_äö'); + $result = $server->delete($cn_result); + $this->assertNoError($result); + $cn_result = $server->uidForCn('Kolab_Server_PersonTest_äö'); + $this->assertNoError($cn_result); + $this->assertFalse($cn_result); + } } /** * Test adding a person with two common names. * - * @dataProvider provideServers - * * @return NULL */ - public function testAddDoubleCnPerson($server) + public function testAddDoubleCnPerson() { - $person = $this->assertAdd($server, $this->objects[5], - array()); + foreach ($this->servers as $server) { + $person = $this->assertAdd($server, $this->objects[5], + array()); - $cn_result = $server->uidForCn($this->objects[5][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN][0]); - $this->assertNoError($cn_result); - $dn_parts = Net_LDAP2_Util::ldap_explode_dn($cn_result, array('casefold' => 'lower')); - $dnpart = Net_LDAP2_Util::unescape_dn_value($dn_parts[0]); - $this->assertContains(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN . '=' . $this->objects[5][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN][0], - $dnpart[0]); + $cn_result = $server->uidForCn($this->objects[5][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN][0]); + $this->assertNoError($cn_result); + $dn_parts = Net_LDAP2_Util::ldap_explode_dn($cn_result, array('casefold' => 'lower')); + $dnpart = Net_LDAP2_Util::unescape_dn_value($dn_parts[0]); + $this->assertContains(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN . '=' . $this->objects[5][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN][0], + $dnpart[0]); + } } /** * Test handling a phone number. * - * @dataProvider provideServers - * * @return NULL */ - public function testHandlingAPhoneNumaber($server) + public function testHandlingAPhoneNumaber() { - $person = $this->assertAdd($server, $this->objects[7], - array(Horde_Kolab_Server_Object_Person::ATTRIBUTE_TELNO => '')); - $this->assertSimpleSequence($person, $server, - Horde_Kolab_Server_Object_Person::ATTRIBUTE_TELNO, - array('123456789', '+1234567890', array('1', '2'), null, '0'), true); + foreach ($this->servers as $server) { + $person = $this->assertAdd($server, $this->objects[7], + array(Horde_Kolab_Server_Object_Person::ATTRIBUTE_TELNO => '')); + $this->assertSimpleSequence($person, $server, + Horde_Kolab_Server_Object_Person::ATTRIBUTE_TELNO, + array('123456789', '+1234567890', array('1', '2'), null, '0'), true); + } } /** * Test retrrieving a date. * - * @dataProvider provideServers - * * @return NULL */ - public function testGetDate($server) + public function testGetDate() { - $person = $this->assertAdd($server, $this->objects[8], - array(Horde_Kolab_Server_Object_Person::ATTRIBUTE_TELNO => '')); - $cdate = $person->get(Horde_Kolab_Server_Object_Person::ATTRDATE_CREATIONDATE); - $this->assertEquals('Horde_Date', get_class($cdate)); - $this->assertEquals('1910-08-03 01:00:00', (string) $cdate); + foreach ($this->servers as $server) { + $person = $this->assertAdd($server, $this->objects[8], + array(Horde_Kolab_Server_Object_Person::ATTRIBUTE_TELNO => '')); + $cdate = $person->get(Horde_Kolab_Server_Object_Person::ATTRDATE_CREATIONDATE); + $this->assertEquals('Horde_Date', get_class($cdate)); + $this->assertEquals('1910-08-03 01:00:00', (string) $cdate); + } } } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/ServerTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/ServerTest.php index 231d3345c..429dde54e 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/ServerTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/ServerTest.php @@ -33,16 +33,33 @@ require_once 'Horde/Autoloader.php'; class Horde_Kolab_Server_ServerTest extends PHPUnit_Framework_TestCase { /** + * Provide a mock server. + * + * @return Horde_Kolab_Server The mock server. + */ + protected function getMockServer() + { + $injector = new Horde_Injector(new Horde_Injector_TopLevel()); + $config = new stdClass; + $config->driver = 'none'; + $injector->setInstance('Horde_Kolab_Server_Config', $config); + $injector->bindFactory('Horde_Kolab_Server_Structure', + 'Horde_Kolab_Server_Factory', + 'getStructure'); + $injector->bindFactory('Horde_Kolab_Server', + 'Horde_Kolab_Server_Factory', + 'getServer'); + return $injector->getInstance('Horde_Kolab_Server'); + } + + /** * The generating a uid for an object. * * @return NULL */ public function testGenerateUid() { - $provider = new stdClass; - $provider->kolab_server_driver = 'none'; - $provider->kolab_server_structure = new Horde_Kolab_Server_Structure_Ldap(); - $ks = &Horde_Kolab_Server::factory($provider); + $ks = $this->getMockServer(); $user = new Horde_Kolab_Server_Object($ks, null, null); $this->assertEquals(preg_replace('/[0-9a-f]*/', '', $user->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID)), ''); } @@ -55,10 +72,17 @@ class Horde_Kolab_Server_ServerTest extends PHPUnit_Framework_TestCase public function testCreation() { try { - $provider = new stdClass; - $provider->kolab_server_driver = 'dummy'; - $provider->kolab_server_structure = new Horde_Kolab_Server_Structure_Ldap(); - Horde_Kolab_Server::factory($provider); + $injector = new Horde_Injector(new Horde_Injector_TopLevel()); + $config = new stdClass; + $config->driver = 'dummy'; + $injector->setInstance('Horde_Kolab_Server_Config', $config); + $injector->bindFactory('Horde_Kolab_Server_Structure', + 'Horde_Kolab_Server_Factory', + 'getStructure'); + $injector->bindFactory('Horde_Kolab_Server', + 'Horde_Kolab_Server_Factory', + 'getServer'); + Horde_Kolab_Server_Factory::getServer($injector); $this->assertFail('No error!'); } catch (Horde_Kolab_Server_Exception $e) { $this->assertEquals('Server type definition "Horde_Kolab_Server_Dummy" missing.', @@ -75,17 +99,11 @@ class Horde_Kolab_Server_ServerTest extends PHPUnit_Framework_TestCase */ public function testFetch() { - $provider = new stdClass; - $provider->kolab_server_driver = 'none'; - $provider->kolab_server_structure = new Horde_Kolab_Server_Structure_Ldap(); - $ks = &Horde_Kolab_Server::factory($provider); + $ks = $this->getMockServer(); $user = $ks->fetch('test'); $this->assertEquals('Horde_Kolab_Server_Object_Kolab_User', get_class($user)); - $provider = new stdClass; - $provider->kolab_server_driver = 'none'; - $provider->kolab_server_structure = new Horde_Kolab_Server_Structure_Ldap(); - $ks = &Horde_Kolab_Server::factory($provider); + $ks = $this->getMockServer(); $user = $ks->fetch(); $this->assertEquals('Horde_Kolab_Server_Object_Kolab_User', get_class($user)); } @@ -97,18 +115,11 @@ class Horde_Kolab_Server_ServerTest extends PHPUnit_Framework_TestCase */ public function testList() { - $provider = new stdClass; - $provider->kolab_server_driver = 'none'; - $provider->kolab_server_structure = new Horde_Kolab_Server_Structure_Ldap(); - $ks = &Horde_Kolab_Server::factory($provider); + $ks = $this->getMockServer(); $hash = $ks->listHash('Horde_Kolab_Server_Object'); $this->assertEquals($hash, array()); - $provider = new stdClass; - $provider->kolab_server_driver = 'none'; - $provider->kolab_server_params = array('whatever'); - $provider->kolab_server_structure = new Horde_Kolab_Server_Structure_Ldap(); - $ks = &Horde_Kolab_Server::factory($provider); + $ks = $this->getMockServer(); $hash = $ks->listHash('Horde_Kolab_Server_Object'); $this->assertEquals($hash, array()); } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/TestTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/TestTest.php index 9744217f7..867db4e8c 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/TestTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/TestTest.php @@ -30,48 +30,95 @@ require_once 'Horde/Autoloader.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_testTest extends Horde_Kolab_Test_Server +class Horde_Kolab_Server_testTest extends Horde_Kolab_Server_Scenario { + /** The file based mock environment */ + const ENVIRONMENT_FILE = 'file'; + /** - * Test search base. + * The environments we provide to the test. + * + * @var array + */ + protected $_environments = array( + self::ENVIRONMENT_MOCK, + self::ENVIRONMENT_FILE + ); + + /** + * Prepare the server configuration for the given environment. * - * @dataProvider provideServerTypes + * @param string $environment The name of the environment. * * @return NULL */ - public function testSearchBase($type) + public function prepareKolabServerConfiguration($environment) { - $server = &$this->prepareBasicServer($type); + switch ($environment) { + case self::ENVIRONMENT_FILE: + /** Prepare a Kolab test server */ + $config = new stdClass; + $config->driver = 'file'; + $config->params = array( + 'file' => Horde::getTempFile('fileTest'), + 'basedn' => 'dc=example,dc=org', + 'hashtype' => 'plain' + ); + $this->world['injector'][$environment]->setInstance('Horde_Kolab_Server_Config', $config); + break; + default: + return parent::prepareKolabServerConfiguration($environment); + } + } - $result = $server->search( - '(' . Horde_Kolab_Server_Object::ATTRIBUTE_OC - . '=' . Horde_Kolab_Server_Object::OBJECTCLASS_TOP . ')', - array(Horde_Kolab_Server_Object::ATTRIBUTE_OC)); - $this->assertEquals(13, count($result)); + /** + * Set up testing. + * + * @return NULL + */ + protected function setUp() + { + $this->initializeEnvironments(); + $this->servers = $this->getKolabServers(); + foreach ($this->servers as $server) { + $this->addBasicUsersToServer($server); + } + } + + /** + * Test search base. + * + * @return NULL + */ + public function testSearchBase() + { + foreach ($this->servers as $server) { + $result = $server->search( + '(' . Horde_Kolab_Server_Object::ATTRIBUTE_OC + . '=' . Horde_Kolab_Server_Object::OBJECTCLASS_TOP . ')', + array(Horde_Kolab_Server_Object::ATTRIBUTE_OC)); + $this->assertEquals(13, count($result)); - $result = $server->search( - '(' . Horde_Kolab_Server_Object::ATTRIBUTE_OC - . '=' . Horde_Kolab_Server_Object::OBJECTCLASS_TOP . ')', - array(Horde_Kolab_Server_Object::ATTRIBUTE_OC), - 'cn=internal,dc=example,dc=org'); - $this->assertNoError($result); - $this->assertEquals(4, count($result)); + $result = $server->search( + '(' . Horde_Kolab_Server_Object::ATTRIBUTE_OC + . '=' . Horde_Kolab_Server_Object::OBJECTCLASS_TOP . ')', + array(Horde_Kolab_Server_Object::ATTRIBUTE_OC), + 'cn=internal,dc=example,dc=org'); + $this->assertEquals(4, count($result)); + } } /** * Test sorting. * - * @dataProvider provideServerTypes - * * @return NULL */ - public function testSorting($type) + public function testSorting() { - $server = &$this->prepareBasicServer($type); + foreach ($this->servers as $server) { /* $result = $server->search('(mail=*)', array('mail')); */ -/* $this->assertNoError($result); */ /* $this->assertEquals(5, count($result)); */ /* $server->sort($result, 'mail'); */ /* foreach ($result as $object) { */ @@ -86,351 +133,284 @@ class Horde_Kolab_Server_testTest extends Horde_Kolab_Test_Server /* } */ /* } */ /* } */ + } } /** * Test listing objects. * - * @dataProvider provideServerTypes - * * @return NULL */ - public function testListObjects($type) + public function testListObjects() { - $server = &$this->prepareBasicServer($type); - - $filter = '(&(objectClass=kolabInetOrgPerson)(uid=*)(mail=*)(sn=*))'; - $attributes = array( - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SN, - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_CN, - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_UID, - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_MAIL, - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_DELETED, - ); - - $sort = Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SN; - $result = $server->search($filter); - $this->assertNoError($result); - $this->assertEquals(2, count($result)); - - $result = $server->listObjects('Horde_Kolab_Server_Object_Kolab_User'); - $this->assertNoError($result); - $this->assertEquals(2, count($result)); - $this->assertEquals('Horde_Kolab_Server_Object_Kolab_User', get_class(array_shift($result))); - - $result = $server->listObjects('Horde_Kolab_Server_Object_Kolabsharedfolder'); - $this->assertNoError($result); - $this->assertEquals(1, count($result)); - $this->assertEquals('Horde_Kolab_Server_Object_Kolabsharedfolder', get_class(array_shift($result))); + foreach ($this->servers as $server) { + $filter = '(&(objectClass=kolabInetOrgPerson)(uid=*)(mail=*)(sn=*))'; + $attributes = array( + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SN, + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_CN, + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_UID, + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_MAIL, + Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_DELETED, + ); + + $sort = Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SN; + $result = $server->search($filter); + $this->assertEquals(2, count($result)); + + $result = $server->listObjects('Horde_Kolab_Server_Object_Kolab_User'); + $this->assertEquals('Horde_Kolab_Server_Object_Kolab_User', get_class(array_shift($result))); + + $result = $server->listObjects('Horde_Kolab_Server_Object_Kolabsharedfolder'); + $this->assertEquals(1, count($result)); + $this->assertEquals('Horde_Kolab_Server_Object_Kolabsharedfolder', get_class(array_shift($result))); + } } /** * Test handling of object classes. * - * @dataProvider provideServerTypes - * * @return NULL */ - public function testGetObjectClasses($type) + public function testGetObjectClasses() { - $server = &$this->prepareBasicServer($type); - - $classes = $server->getObjectClasses('cn=Gunnar Wrobel,dc=example,dc=org'); - $this->assertNoError($classes); - $this->assertContains('top', $classes); - $this->assertContains('kolabinetorgperson', $classes); - - try { - $classes = $server->getObjectClasses('cn=DOES NOT EXIST,dc=example,dc=org'); - } catch (Horde_Kolab_Server_Exception $classes) { + foreach ($this->servers as $server) { + $classes = $server->getObjectClasses('cn=Gunnar Wrobel,dc=example,dc=org'); + $this->assertContains('top', $classes); + $this->assertContains('kolabinetorgperson', $classes); + + try { + $classes = $server->getObjectClasses('cn=DOES NOT EXIST,dc=example,dc=org'); + } catch (Horde_Kolab_Server_Exception $classes) { + } + $this->assertError($classes, + 'No such object: cn=DOES NOT EXIST,dc=example,dc=org'); + + $classes = $server->getObjectClasses('cn=The Administrator,dc=example,dc=org'); + $this->assertContains('kolabinetorgperson', $classes); } - $this->assertError($classes, - 'No such object: cn=DOES NOT EXIST,dc=example,dc=org'); - - $classes = $server->getObjectClasses('cn=The Administrator,dc=example,dc=org'); - $this->assertNoError($classes); - $this->assertContains('kolabinetorgperson', $classes); } /** * Test handling of object types. * - * @dataProvider provideServerTypes - * * @return NULL */ - public function testDetermineType($type) + public function testDetermineType() { - $server = &$this->prepareBasicServer($type); - - $type = $server->determineType('cn=empty.group@example.org,dc=example,dc=org'); - $this->assertNoError($type); - $this->assertEquals('Horde_Kolab_Server_Object_Kolabgroupofnames', $type); + foreach ($this->servers as $server) { + $type = $server->determineType('cn=empty.group@example.org,dc=example,dc=org'); + $this->assertEquals('Horde_Kolab_Server_Object_Kolabgroupofnames', $type); - $type = $server->determineType('cn=shared@example.org,dc=example,dc=org'); - $this->assertNoError($type); - $this->assertEquals('Horde_Kolab_Server_Object_Kolabsharedfolder', $type); + $type = $server->determineType('cn=shared@example.org,dc=example,dc=org'); + $this->assertEquals('Horde_Kolab_Server_Object_Kolabsharedfolder', $type); - $type = $server->determineType('cn=The Administrator,dc=example,dc=org'); - $this->assertNoError($type); - $this->assertEquals('Horde_Kolab_Server_Object_Kolab_Administrator', $type); + $type = $server->determineType('cn=The Administrator,dc=example,dc=org'); + $this->assertEquals('Horde_Kolab_Server_Object_Kolab_Administrator', $type); - $type = $server->determineType('cn=Main Tainer,dc=example,dc=org'); - $this->assertNoError($type); - $this->assertEquals('Horde_Kolab_Server_Object_Kolab_Maintainer', $type); + $type = $server->determineType('cn=Main Tainer,dc=example,dc=org'); + $this->assertEquals('Horde_Kolab_Server_Object_Kolab_Maintainer', $type); - $type = $server->determineType('cn=Domain Maintainer,dc=example,dc=org'); - $this->assertNoError($type); - $this->assertEquals('Horde_Kolab_Server_Object_Kolab_Domainmaintainer', $type); + $type = $server->determineType('cn=Domain Maintainer,dc=example,dc=org'); + $this->assertEquals('Horde_Kolab_Server_Object_Kolab_Domainmaintainer', $type); - $type = $server->determineType('cn=Test Address,cn=external,dc=example,dc=org'); - $this->assertNoError($type); - $this->assertEquals('Horde_Kolab_Server_Object_Kolab_Address', $type); + $type = $server->determineType('cn=Test Address,cn=external,dc=example,dc=org'); + $this->assertEquals('Horde_Kolab_Server_Object_Kolab_Address', $type); - $type = $server->determineType('cn=Gunnar Wrobel,dc=example,dc=org'); - $this->assertNoError($type); - $this->assertEquals('Horde_Kolab_Server_Object_Kolab_User', $type); + $type = $server->determineType('cn=Gunnar Wrobel,dc=example,dc=org'); + $this->assertEquals('Horde_Kolab_Server_Object_Kolab_User', $type); + } } /** * Test retrieving a primary mail for a mail or id. * - * @dataProvider provideServerTypes - * * @return NULL */ - public function testMailForIdOrMail($type) + public function testMailForIdOrMail() { - $server = &$this->prepareBasicServer($type); - - $mail = $server->mailForIdOrMail('wrobel'); - $this->assertEquals('wrobel@example.org', $mail); + foreach ($this->servers as $server) { + $mail = $server->mailForIdOrMail('wrobel'); + $this->assertEquals('wrobel@example.org', $mail); - $mail = $server->mailForIdOrMail('wrobel@example.org'); - $this->assertNoError($mail); - $this->assertEquals('wrobel@example.org', $mail); + $mail = $server->mailForIdOrMail('wrobel@example.org'); + $this->assertEquals('wrobel@example.org', $mail); - $mail = $server->mailForIdOrMail('DOES NOT EXIST'); - $this->assertNoError($mail); - $this->assertSame(false, $mail); + $mail = $server->mailForIdOrMail('DOES NOT EXIST'); + $this->assertSame(false, $mail); + } } /** * Test retrieving a UID for a mail or id. * - * @dataProvider provideServerTypes - * * @return NULL */ - public function testUidForIdOrMail($type) + public function testUidForIdOrMail() { - $server = &$this->prepareBasicServer($type); + foreach ($this->servers as $server) { + $uid = $server->uidForIdOrMail('wrobel'); + $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); - $uid = $server->uidForIdOrMail('wrobel'); - $this->assertNoError($uid); - $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); + $uid = $server->uidForIdOrMail('wrobel@example.org'); + $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); - $uid = $server->uidForIdOrMail('wrobel@example.org'); - $this->assertNoError($uid); - $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); - - $uid = $server->uidForIdOrMail('DOES NOT EXIST'); - $this->assertNoError($uid); - $this->assertSame(false, $uid); + $uid = $server->uidForIdOrMail('DOES NOT EXIST'); + $this->assertSame(false, $uid); + } } /** * Test retrieving a UID for a mail or id. * - * @dataProvider provideServerTypes - * * @return NULL */ - public function testUidForMailOrIdOrAlias($type) + public function testUidForMailOrIdOrAlias() { - $server = &$this->prepareBasicServer($type); + foreach ($this->servers as $server) { + $uid = $server->uidForIdOrMailOrAlias('g.wrobel@example.org'); + $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); - $uid = $server->uidForIdOrMailOrAlias('g.wrobel@example.org'); - $this->assertNoError($uid); - $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); + $uid = $server->uidForIdOrMailOrAlias('wrobel@example.org'); + $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); - $uid = $server->uidForIdOrMailOrAlias('wrobel@example.org'); - $this->assertNoError($uid); - $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); + $uid = $server->uidForIdOrMailOrAlias('wrobel'); + $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); - $uid = $server->uidForIdOrMailOrAlias('wrobel'); - $this->assertNoError($uid); - $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); - - $uid = $server->uidForIdOrMailOrAlias('DOES NOT EXIST'); - $this->assertNoError($uid); - $this->assertSame(false, $uid); + $uid = $server->uidForIdOrMailOrAlias('DOES NOT EXIST'); + $this->assertSame(false, $uid); + } } /** * Test retrieving all addresses for a mail or id. * - * @dataProvider provideServerTypes - * * @return NULL */ - public function testAddrsForIdOrMail($type) + public function testAddrsForIdOrMail() { - $server = &$this->prepareBasicServer($type); - - $addrs = $server->addrsForIdOrMail('wrobel'); - - $testuser = $server->fetch('cn=Test Test,dc=example,dc=org'); - $this->assertNoError($testuser); - $this->assertContains('wrobel@example.org', - $testuser->get(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_DELEGATE, false)); - - $this->assertNoError($addrs); - $this->assertContains('wrobel@example.org', $addrs); - $this->assertContains('test@example.org', $addrs); - $this->assertContains('t.test@example.org', $addrs); - $this->assertContains('g.wrobel@example.org', $addrs); - $this->assertContains('gunnar@example.org', $addrs); - - $addrs = $server->addrsForIdOrMail('test@example.org'); - $this->assertNoError($addrs); - $this->assertContains('test@example.org', $addrs); - $this->assertContains('t.test@example.org', $addrs); + foreach ($this->servers as $server) { + $addrs = $server->addrsForIdOrMail('wrobel'); + + $testuser = $server->fetch('cn=Test Test,dc=example,dc=org'); + $this->assertContains('wrobel@example.org', + $testuser->get(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_DELEGATE, false)); + + $this->assertContains('wrobel@example.org', $addrs); + $this->assertContains('test@example.org', $addrs); + $this->assertContains('t.test@example.org', $addrs); + $this->assertContains('g.wrobel@example.org', $addrs); + $this->assertContains('gunnar@example.org', $addrs); + + $addrs = $server->addrsForIdOrMail('test@example.org'); + $this->assertContains('test@example.org', $addrs); + $this->assertContains('t.test@example.org', $addrs); + } } /** * Test retrieving a UID for a primary mail. * - * @dataProvider provideServerTypes - * * @return NULL */ - public function testUidForMailAddress($type) + public function testUidForMailAddress() { - $server = &$this->prepareBasicServer($type); + foreach ($this->servers as $server) { + $uid = $server->uidForIdOrMailOrAlias('wrobel@example.org'); + $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); - $uid = $server->uidForIdOrMailOrAlias('wrobel@example.org'); - $this->assertNoError($uid); - $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); + $uid = $server->uidForIdOrMailOrAlias('test@example.org'); + $this->assertEquals('cn=Test Test,dc=example,dc=org', $uid); - $uid = $server->uidForIdOrMailOrAlias('test@example.org'); - $this->assertNoError($uid); - $this->assertEquals('cn=Test Test,dc=example,dc=org', $uid); + $uid = $server->uidForIdOrMailOrAlias('gunnar@example.org'); + $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); - $uid = $server->uidForIdOrMailOrAlias('gunnar@example.org'); - $this->assertNoError($uid); - $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); - - $uid = $server->uidForIdOrMailOrAlias('wrobel'); - $this->assertNoError($uid); - $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); + $uid = $server->uidForIdOrMailOrAlias('wrobel'); + $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); + } } /** * Test retrieving a UID for an attribute. * - * @dataProvider provideServerTypes - * * @return NULL */ - public function testUidForAttr($type) + public function testUidForAttr() { - $server = &$this->prepareBasicServer($type); - - $uid = $server->uidForSearch(array('AND' => array(array('field' => 'alias', + foreach ($this->servers as $server) { + $uid = $server->uidForSearch(array('AND' => array(array('field' => 'alias', 'op' => '=', 'test' => 'g.wrobel@example.org')))); - $this->assertNoError($uid); - $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); + $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); + } } /** * Test group membership testing. * - * @dataProvider provideServerTypes - * * @return NULL */ - public function testMemberOfGroupAddress($type) + public function testMemberOfGroupAddress() { - $server = &$this->prepareBasicServer($type); - - $uid = $server->uidForIdOrMailOrAlias('g.wrobel@example.org'); - $this->assertNoError($uid); - $member = $server->memberOfGroupAddress($uid, 'group@example.org'); - $this->assertNoError($member); - $this->assertTrue($member); - - $member = $server->memberOfGroupAddress( - $server->uidForIdOrMailOrAlias('test@example.org'), - 'group@example.org'); - $this->assertNoError($member); - $this->assertTrue($member); - - $member = $server->memberOfGroupAddress( - $server->uidForIdOrMailOrAlias('somebody@example.org'), - 'group@example.org'); - $this->assertNoError($member); - $this->assertFalse($member); + foreach ($this->servers as $server) { + $uid = $server->uidForIdOrMailOrAlias('g.wrobel@example.org'); + $member = $server->memberOfGroupAddress($uid, 'group@example.org'); + $this->assertTrue($member); + + $member = $server->memberOfGroupAddress( + $server->uidForIdOrMailOrAlias('test@example.org'), + 'group@example.org'); + $this->assertTrue($member); + + $member = $server->memberOfGroupAddress( + $server->uidForIdOrMailOrAlias('somebody@example.org'), + 'group@example.org'); + $this->assertFalse($member); + } } /** * Test group fetching. * - * @dataProvider provideServerTypes - * * @return NULL */ - public function testGetGroups($type) + public function testGetGroups() { - $server = &$this->prepareBasicServer($type); - - $filter = '(&(objectClass=kolabGroupOfNames)(member=' - . Horde_LDAP::quote('cn=The Administrator,dc=example,dc=org') . '))'; - $result = $server->search($filter, array()); - $this->assertNoError($result); - $this->assertTrue(!empty($result)); + foreach ($this->servers as $server) { + $filter = '(&(objectClass=kolabGroupOfNames)(member=' + . Horde_LDAP::quote('cn=The Administrator,dc=example,dc=org') . '))'; + $result = $server->search($filter, array()); + $this->assertTrue(!empty($result)); -/* $entry = $server->_firstEntry($result); */ -/* $this->assertNoError($entry); */ -/* $this->assertTrue(!empty($entry)); */ + /* $entry = $server->_firstEntry($result); */ + /* $this->assertTrue(!empty($entry)); */ -/* $uid = $server->_getDn($entry); */ -/* $this->assertNoError($uid); */ -/* $this->assertTrue(!empty($uid)); */ + /* $uid = $server->_getDn($entry); */ + /* $this->assertTrue(!empty($uid)); */ -/* $entry = $server->_nextEntry($entry); */ -/* $this->assertNoError($entry); */ -/* $this->assertTrue(empty($entry)); */ + /* $entry = $server->_nextEntry($entry); */ + /* $this->assertTrue(empty($entry)); */ -/* $entries = $server->_getDns($result); */ -/* $this->assertNoError($entries); */ -/* $this->assertTrue(!empty($entries)); */ + /* $entries = $server->_getDns($result); */ + /* $this->assertTrue(!empty($entries)); */ - $groups = $server->getGroups('cn=The Administrator,dc=example,dc=org'); - $this->assertNoError($groups); - $this->assertTrue(!empty($groups)); + $groups = $server->getGroups('cn=The Administrator,dc=example,dc=org'); + $this->assertTrue(!empty($groups)); - $groups = $server->getGroups($server->uidForIdOrMailOrAlias('g.wrobel@example.org')); - $this->assertNoError($groups); - $this->assertContains('cn=group@example.org,dc=example,dc=org', $groups); + $groups = $server->getGroups($server->uidForIdOrMailOrAlias('g.wrobel@example.org')); + $this->assertContains('cn=group@example.org,dc=example,dc=org', $groups); - $groups = $server->getGroupAddresses($server->uidForIdOrMailOrAlias('g.wrobel@example.org')); - $this->assertNoError($groups); - $this->assertContains('group@example.org', $groups); + $groups = $server->getGroupAddresses($server->uidForIdOrMailOrAlias('g.wrobel@example.org')); + $this->assertContains('group@example.org', $groups); - $groups = $server->getGroups($server->uidForIdOrMailOrAlias('test@example.org')); - $this->assertNoError($groups); - $this->assertContains('cn=group@example.org,dc=example,dc=org', $groups); + $groups = $server->getGroups($server->uidForIdOrMailOrAlias('test@example.org')); + $this->assertContains('cn=group@example.org,dc=example,dc=org', $groups); - $groups = $server->getGroupAddresses($server->uidForIdOrMailOrAlias('test@example.org')); - $this->assertNoError($groups); - $this->assertContains('group@example.org', $groups); - - $groups = $server->getGroups('nobody'); - $this->assertNoError($groups); - $this->assertTrue(empty($groups)); + $groups = $server->getGroupAddresses($server->uidForIdOrMailOrAlias('test@example.org')); + $this->assertContains('group@example.org', $groups); + $groups = $server->getGroups('nobody'); + $this->assertTrue(empty($groups)); + } } /** @@ -440,26 +420,19 @@ class Horde_Kolab_Server_testTest extends Horde_Kolab_Test_Server */ public function testFilterParse() { - $provider = new stdClass; - $provider->kolab_server_driver = 'test'; - $provider->kolab_server_params = array(); - $provider->kolab_server_structure = new Horde_Kolab_Server_Structure_Ldap(); - $db = &Horde_Kolab_Server::factory($provider); + $db = $this->getKolabMockServer(); $a = $db->parse('(a=b)'); - $this->assertNoError($a); $this->assertEquals(array('att' => 'a', 'log' => '=', 'val' => 'b'), $a); $a = $db->parse('(&(a=b)(c=d))'); - $this->assertNoError($a); $this->assertEquals(array('op' => '&', 'sub' => array( array('att' => 'a', 'log' => '=', 'val' => 'b'), array('att' => 'c', 'log' => '=', 'val' => 'd'), )), $a); $a = $db->parse('(&(a=1)(|(b=2)(c=3)))'); - $this->assertNoError($a); $this->assertEquals(array('op' => '&', 'sub' => array( array('att' => 'a', 'log' => '=', 'val' => '1'), array('op' => '|', 'sub' => @@ -469,7 +442,6 @@ class Horde_Kolab_Server_testTest extends Horde_Kolab_Test_Server )))), $a); $a = $db->parseSub('(!(x=2))(b=1)'); - $this->assertNoError($a); $this->assertEquals(array(array('op' => '!', 'sub' => array( array('att' => 'x', 'log' => '=', 'val' => '2'), @@ -479,7 +451,6 @@ class Horde_Kolab_Server_testTest extends Horde_Kolab_Test_Server ), $a); $a = $db->parse('(&(!(x=2))(b=1))'); - $this->assertNoError($a); $this->assertEquals(array('op' => '&', 'sub' => array( array('op' => '!', 'sub' => array( @@ -498,49 +469,56 @@ class Horde_Kolab_Server_testTest extends Horde_Kolab_Test_Server */ public function testSearch() { - $provider = new stdClass; - $provider->kolab_server_driver = 'test'; - $provider->kolab_server_structure = new Horde_Kolab_Server_Structure_Ldap(); - $provider->kolab_server_params = array('data' => - array( - 'cn=a' => array( - 'dn' => 'cn=a', - 'data' => array( - 'a' => '1', - 'b' => '1', - 'c' => '1', - ) - ), - 'cn=b' => array( - 'dn' => 'cn=b', - 'data' => array( - 'a' => '1', - 'b' => '2', - 'c' => '2', - ) - ), - 'cn=c' => array( - 'dn' => 'cn=c', - 'data' => array( - 'a' => '1', - 'b' => '2', - 'c' => '3', - ) - ), - 'cn=d' => array( - 'dn' => 'cn=d', - 'data' => array( - 'a' => '2', - 'b' => '2', - 'c' => '1', - ) - ), - ) + $injector = new Horde_Injector(new Horde_Injector_TopLevel()); + $config = new stdClass; + $config->driver = 'test'; + $config->params = array( + 'data' => + array( + 'cn=a' => array( + 'dn' => 'cn=a', + 'data' => array( + 'a' => '1', + 'b' => '1', + 'c' => '1', + ) + ), + 'cn=b' => array( + 'dn' => 'cn=b', + 'data' => array( + 'a' => '1', + 'b' => '2', + 'c' => '2', + ) + ), + 'cn=c' => array( + 'dn' => 'cn=c', + 'data' => array( + 'a' => '1', + 'b' => '2', + 'c' => '3', + ) + ), + 'cn=d' => array( + 'dn' => 'cn=d', + 'data' => array( + 'a' => '2', + 'b' => '2', + 'c' => '1', + ) + ), + ) ); - $db = &Horde_Kolab_Server::factory($provider); + $injector->setInstance('Horde_Kolab_Server_Config', $config); + $injector->bindFactory('Horde_Kolab_Server_Structure', + 'Horde_Kolab_Server_Factory', + 'getStructure'); + $injector->bindFactory('Horde_Kolab_Server', + 'Horde_Kolab_Server_Factory', + 'getServer'); + $db = $injector->getInstance('Horde_Kolab_Server'); $a = $db->search('(c=1)'); - $this->assertNoError($a); $this->assertEquals( array( 'cn=a' => array( @@ -560,7 +538,6 @@ class Horde_Kolab_Server_testTest extends Horde_Kolab_Test_Server ); $a = $db->search('(c=3)'); - $this->assertNoError($a); $this->assertEquals( array( 'cn=c' => array( @@ -574,7 +551,6 @@ class Horde_Kolab_Server_testTest extends Horde_Kolab_Test_Server ); $a = $db->search('(c=3)', array('attributes' => array('a'))); - $this->assertNoError($a); $this->assertEquals( array( 'cn=c' => array( @@ -586,7 +562,6 @@ class Horde_Kolab_Server_testTest extends Horde_Kolab_Test_Server ); $a = $db->search('(&(a=1)(b=2))', array('attributes' => array('a', 'b'))); - $this->assertNoError($a); $this->assertEquals( array( 'cn=b' => array( @@ -604,7 +579,6 @@ class Horde_Kolab_Server_testTest extends Horde_Kolab_Test_Server ); $a = $db->search('(&(b=2))', array('attributes' => array('b'))); - $this->assertNoError($a); $this->assertEquals( array( 'cn=b' => array( @@ -624,7 +598,6 @@ class Horde_Kolab_Server_testTest extends Horde_Kolab_Test_Server ); $a = $db->search('(!(b=2))', array('attributes' => array('a', 'b'))); - $this->assertNoError($a); $this->assertEquals( array( 'cn=a' => array( @@ -637,7 +610,6 @@ class Horde_Kolab_Server_testTest extends Horde_Kolab_Test_Server ); $a = $db->search('(&(!(x=2))(b=1))', array('attributes' => array('b'))); - $this->assertNoError($a); $this->assertEquals( array( 'cn=a' => array( diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/UserHandlingTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/UserHandlingTest.php index c28744f71..d2612d7fe 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/UserHandlingTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/UserHandlingTest.php @@ -30,7 +30,7 @@ require_once 'Horde/Autoloader.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server +class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Server_Scenario { /** @@ -42,7 +42,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function listingUsersOnEmptyServer() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('listing all users') ->then('the list is an empty array'); } @@ -59,7 +59,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function listingUsersAfterAddingUsers($user_list) { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding an object list', $user_list) ->and('listing all users') ->then('the list has a number of entries equal to', count($user_list)); @@ -77,7 +77,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function listingUserCount($user_list) { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding an object list', $user_list) ->and('retriving the result count') ->then('the count equals to', count($user_list)); @@ -95,7 +95,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function listingUsersHasAttributeId($user_list) { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user list', $user_list) ->then('the user list contains the unique ID for each user') ->and('the user list contains the user type for each user'); @@ -113,7 +113,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function listingUsersHasAttributeType($user_list) { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user list', $user_list) ->then('the user list contains the user type for each user'); } @@ -130,7 +130,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function listingUsersHasAttributeFullName($user_list) { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user list', $user_list) ->then('the user list contains the full name for each user'); } @@ -147,7 +147,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function listingUsersHasAttributeEmail($user_list) { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user list', $user_list) ->then('the user list contains the email for each user'); } @@ -164,7 +164,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function listingUsersHasAttributeUid($user_list) { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user list', $user_list) ->then('the list contains the uid for each user'); } @@ -175,7 +175,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function listingUsersCanBeRestrictedByStartLetterOfTheLastName($letter, $count) { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding user list', $this->largeList()) ->and('retrieving the result count of a list restricted by the start letter of the last name', $letter) ->then('the list contains a correct amount of results', $count); @@ -187,7 +187,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function countingUsersCanBeRestrictedByStartLetterOfTheLastName($letter, $count) { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding user list', $this->largeList()) ->and('retrieving the result count of a list restricted by the start letter of the last name', $letter) ->then('the count contains a correct number', $count); @@ -199,7 +199,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function countingUsersCanBeRestrictedByContentsInAnAttribute($attribute, $content, $count) { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding user list', $this->largeList()) ->and('retrieving the result count of a list restricted by content in an attribute', $attribute, $content) ->then('the count contains a correct number', $count); @@ -210,7 +210,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function creatingUserWithoutTypeCreatesStandardUser() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user without user type') ->then('a standard user has been created'); } @@ -220,7 +220,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function creatingUserWithoutInvitationPolicySetsManualPolicy() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user without an invitation policy') ->then('the added user has a manual policy'); } @@ -230,7 +230,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function creatingUserWithoutHomeServerFails() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user without a home server') ->then('the result should indicate an error with', 'The user cannot be added: The home Kolab server (or network) has not been specified!'); } @@ -240,7 +240,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function creatingUserForDistributedKolabWithoutImapServerFails() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('distributed Kolab') ->when('adding a user without an imap server') ->then('the result should indicate an error with', 'The user cannot be added: The home imap server has not been specified!'); @@ -251,7 +251,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function creatingUserWithImapServerFailsOnNonDistributedKolab() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('monolithic Kolab') ->when('adding a user with an imap server') ->then('the result should indicate an error with', 'The user cannot be added: A home imap server is only supported with a distributed Kolab setup!'); @@ -262,7 +262,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function creatingUserWithFreeBusyServerFailsOnNonDistributedKolab() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('monolithic Kolab') ->when('adding a user with a free/busy server') ->then('the result should indicate an error with', 'The user cannot be added: A seperate free/busy server is only supported with a distributed Kolab setup!'); @@ -273,7 +273,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function modifyingUserMailAddressIsNotAllowed() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user with the mail address "test@example.org"') ->and('modifying the mail address to "new@example.org"') ->then('the result should indicate an error with', 'The user cannot be modified: Changing the mail address from "test@example.org" to "new@example.org" is not allowed!'); @@ -284,7 +284,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function modifyingUserHomeServerIsNotAllowd() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user with the home server "test.example.org"') ->and('modifying the home server to "new.example.org"') ->then('the result should indicate an error with', 'The user cannot be modified: Changing the home server from "test.example.org" to "new.example.org" is not allowed!'); @@ -295,7 +295,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function modifyingUserImapServerIsNotAllowd() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('distributed Kolab') ->when('adding a user with the imap server "test.example.org"') ->and('modifying the imap server to "new.example.org"') @@ -307,7 +307,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function conflictBetweenMailAndMailIsNotAllowed() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user "Test Test" with the mail address "test@example.org"') ->and('adding a user "Test2 Test2" with the mail address "test@example.org"') ->then('the result should indicate an error with', 'The user cannot be added: Mail address "test@example.org" is already the mail address of user "Test Test"!'); @@ -318,7 +318,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function conflictBetweenMailAndAliasIsNotAllowed() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user "Test Test" with the mail address "test@example.org"') ->and('adding a user with the alias address "test@example.org"') ->then('the result should indicate an error with', 'The user cannot be added: Alias address "test@example.org" is already the mail address of user "Test Test"!'); @@ -329,7 +329,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function conflictBetweenAliasAndAliasIsNotAllowed() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user "Test Test" with the alias address "test@example.org"') ->and('adding a user with the alias address "test@example.org"') ->then('the result should indicate an error with', 'The user cannot be added: Alias address "test@example.org" is already the alias address of user "Test Test"!'); @@ -340,7 +340,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function conflictBetweenMailAndUidIsNotAllowed() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user "Test Test" with the mail address "test@example.org"') ->and('adding a user with the uid "test@example.org"') ->then('the result should indicate an error with', 'The user cannot be added: Uid "test@example.org" is already the mail address of user "Test Test"!'); @@ -351,7 +351,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function conflictBetweenUidAndUidIsNotAllowed() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user "Test Test" with the uid "test"') ->and('adding a user with the uid "test"') ->then('the result should indicate an error with', 'The user cannot be added: Uid "test" is already the uid of user "Test Test"!'); @@ -362,7 +362,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function nonExistingDelegateIsNotAllowed() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user with the delegate address "test@example.org"') ->then('the result should indicate an error with', 'The user cannot be added: Delegate address "test@example.org" does not exist!'); } @@ -372,7 +372,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function addingUserInUndefinedDomainIsNotAllowed() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('the only served mail domain is "example.org"') ->when('adding a user with the mail address "test@doesnotexist.org"') ->then('the result should indicate an error with', 'The user cannot be added: Domain "doesnotexist.org" is not being handled by this server!'); @@ -385,7 +385,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function addingUserWithDelegateInUndefinedDomainIsNotAllowed() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('the only served mail domain is "example.org"') ->when('adding a user with the delegate mail address "test@doesnotexist.org"') ->then('the result should indicate an error with', 'The user cannot be added: Domain "doesnotexist.org" is not being handled by this server!'); @@ -399,7 +399,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function disallowInvalidMailAddresses($address) { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user with an invalid mail address', $address) ->then('the result should indicate an error with', "The user cannot be added: Address \"$address\" is not a valid mail address!"); } @@ -409,7 +409,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function addingUserOnUndefinedHomeServer() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('the only home server in the network is "example.org"') ->when('adding a user with the home server "doesnotexist.org"') ->then('the result should indicate an error with', 'The user cannot be added: Host "doesnotexist.org" is not part of the Kolab network!'); @@ -420,7 +420,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function addingUserOnUndefinedImapServer() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('distributed Kolab') ->and('the only imap server in the network is "example.org"') ->when('adding a user with the imap server "doesnotexist.org"') @@ -432,7 +432,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function userAttributesCanBeExtended() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('an extended attribute "test" has been defined') ->when('adding a user with the attribute "test" set to "FIND ME"') ->then('the result indicates success') @@ -444,7 +444,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function extendedObjectAttributeDescriptionsCanBeRetrieved() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('an extended attribute "test" has been defined') ->when('retrieving the supported attributes by the object type "user"') ->then('the result is an array of Horde attribute descriptions') @@ -456,7 +456,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function removingUserFailsIfUserDoesNotExist() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user with the ID "cn=Test Test"') ->and('deleting the user with the ID "cn=Dummy Dummy"') ->then('the result should indicate an error with', 'The user cannot be deleted: User "cn=Dummy Dummy" does not exist!'); @@ -467,7 +467,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function removingUserByMailSucceeds() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user with the mail address "test@example.org"') ->and('deleting the user with mail address "test@example.org"') ->then('the result indicates success') @@ -479,7 +479,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function removingUserByIdSucceeds() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user with the ID "cn=Test Test"') ->and('deleting the user with the ID "cn=Test Test"') ->then('the result indicates success') @@ -491,7 +491,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function addedUserCanLogin() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('Horde uses the Kolab auth driver') ->when('adding a user with the mail address "test@example.org" and password "test"') ->and('trying to login to Horde with "test@example.org" and passowrd "test"') @@ -504,7 +504,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function allowUserWithExtendedObjectClasses() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('an extended set of objectclasses') ->when('adding a user with the mail address "test@example.org"') ->and('fetching user "test@example.org"') @@ -516,7 +516,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function allowToCheckUserPasswords() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('password check enabled') ->when('adding a user with the mail address "test@example.org" and password "tosimple"') ->then('the result should indicate an error with', 'The user cannot be added: The chosen password is not complex enough!'); @@ -527,7 +527,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function allowToSetAttributeDefaults() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('an extended attribute "test" with the default value "test" has been defined') ->when('adding a user with the mail address "test@example.org" and an empty attribute "test"') ->and('fetching user "test@example.org"') @@ -541,7 +541,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function allowToSetDomainSpecificAttributeDefaults() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('domain "example.org" is served by the Kolab server') ->and('domain "example2.org" is served by the Kolab server') ->and('an extended attribute "test" with the default value "test" has been defined') @@ -561,7 +561,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function addedUserHasPreferencesInitialized() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('Horde uses the Kolab auth driver') ->when('adding a user', $user) ->and('trying to login to Horde with "test@example.org" and passowrd "test"') @@ -575,7 +575,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function userUidsShouldNotResembleTheLocalPartOfMailAddresses() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user "cn=Test Test" with the mail address "test@example.org"') ->and('adding a user with the uid "test"') ->then('the result should indicate an error with', 'The user cannot be added: The uid "test" matches the local part of the mail address "test@example.org" assigned to user "cn=Test Test"!'); @@ -588,7 +588,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function allowToSetTheMiddleName() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('an extended attribute "middleName" has been defined') ->when('adding a user with the mail address "test@example.org" and the middle name "Middle"') ->and('fetching user "test@example.org"') @@ -602,7 +602,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function correctlyEscapeApostrophesInNames() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user with the mail address "test@example.org" and the last name "O\'Donnell"') ->and('fetching user "test@example.org"') ->then('the user name has the attribute "sn" set to "O\'Donnell"'); @@ -615,7 +615,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function allowUserToUseExternalAddressAsSender() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->when('adding a user with the mail address "test@example.org" and the external address "other@doesnotexist.org"') ->and('fetching user "test@example.org"') ->then('the user has the attribute external address "other@doesnotexist.org"'); @@ -628,7 +628,7 @@ class Horde_Kolab_Server_UserHandlingTest extends Horde_Kolab_Test_Server */ public function allowCustomFullnameHandling() { - $this->given('an empty Kolab server') + $this->given('several Kolab servers') ->and('an extended attribute "middleName" has been defined') ->and('custom full name handling has been set to "lastname, firstname middlename"') ->when('adding a user with the mail address "test@example.org", the last name "Test", the first name "Test", and the middle name "Middle"') diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/UserTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/UserTest.php index 21735f69b..c91410e75 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/UserTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/UserTest.php @@ -30,7 +30,7 @@ require_once 'Horde/Autoloader.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_UserTest extends Horde_Kolab_Test_Server +class Horde_Kolab_Server_UserTest extends Horde_Kolab_Server_Scenario { /** @@ -40,7 +40,7 @@ class Horde_Kolab_Server_UserTest extends Horde_Kolab_Test_Server */ protected function setUp() { - $this->server = $this->prepareEmptyKolabServer(); + $this->server = $this->getKolabMockServer(); $users = $this->validUsers(); foreach ($users as $user) { $result = $this->server->add($user[0]);