--- /dev/null
+<?php
+/**
+ * Setup autoloading for the tests.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package Kolab_Server
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @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';
+
+if (!defined('HORE_KOLAB_SERVER_TESTS')) {
+ $test_dir = '@test_dir@/Kolab_Server';
+
+ if (substr($test_dir, 0, 1) == '@') {
+ /**
+ * Assume we are working in development mode and this package resides in
+ * 'framework'.
+ */
+ define('HORE_KOLAB_SERVER_TESTS', dirname(__FILE__) . '/../../../../../Kolab_Server/test');
+ } else {
+ define('HORE_KOLAB_SERVER_TESTS', $test_dir);
+ }
+
+ Horde_Autoloader::addClassPath(HORE_KOLAB_SERVER_TESTS);
+}
+
+if (!defined('HORE_KOLAB_AUTH_TESTS')) {
+ $test_dir = '@test_dir@/Auth';
+
+ if (substr($test_dir, 0, 1) == '@') {
+ /**
+ * Assume we are working in development mode and this package resides in
+ * 'framework'.
+ */
+ define('HORE_KOLAB_AUTH_TESTS', dirname(__FILE__) . '/../../..');
+ } else {
+ define('HORE_KOLAB_AUTH_TESTS', $test_dir);
+ }
+
+ Horde_Autoloader::addClassPath(HORE_KOLAB_AUTH_TESTS);
+}
\ No newline at end of file
--- /dev/null
+<?php
+/**
+ * Kolab authentication scenarios.
+ *
+ * $Horde: framework/Auth/tests/Horde/Auth/KolabScenarioTest.php,v 1.3 2009/03/20 23:38:13 wrobel Exp $
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Auth
+ * @subpackage UnitTests
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Auth
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once 'Autoload.php';
+
+/**
+ * Kolab authentication scenarios.
+ *
+ * $Horde: framework/Auth/tests/Horde/Auth/KolabScenarioTest.php,v 1.3 2009/03/20 23:38:13 wrobel Exp $
+ *
+ * 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 <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Server
+ */
+
+class Horde_Auth_Kolab_KolabScenarioTest extends Horde_Kolab_Server_Scenario
+{
+ /**
+ * Test loggin in after a user has been added.
+ *
+ * @scenario
+ *
+ * @return NULL
+ */
+ public function login()
+ {
+ $test_user = $this->provideBasicUserOne();
+
+ $this->given('a populated Kolab setup')
+ ->and('the Kolab auth driver has been selected')
+ ->when('logging in as a user with a password', $test_user['mail'],
+ $test_user['userPassword'])
+ ->then('the login was successful');
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+/**
+ * Kolab authentication tests.
+ *
+ * $Horde: framework/Auth/tests/Horde/Auth/KolabTest.php,v 1.4 2009/04/01 07:59:47 wrobel Exp $
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Auth
+ * @subpackage UnitTests
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Auth
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once 'Autoload.php';
+
+/**
+ * Kolab authentication tests.
+ *
+ * $Horde: framework/Auth/tests/Horde/Auth/KolabTest.php,v 1.4 2009/04/01 07:59:47 wrobel Exp $
+ *
+ * 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 <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Server
+ */
+class Horde_Auth_Kolab_KolabTest extends Horde_Kolab_Server_Scenario
+{
+ /**
+ * Test loggin in after a user has been added.
+ *
+ * @return NULL
+ */
+ public function testLogin()
+ {
+ /** Create the test base */
+ $world = &$this->prepareBasicSetup();
+ $server = $world['server'];
+ $auth = $world['auth'];
+
+ /** Ensure we always use the test server */
+ $GLOBALS['conf']['kolab']['server']['driver'] = 'test';
+
+ $uid = $server->uidForIdOrMail('wrobel@example.org');
+ $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid);
+
+ $result = $auth->authenticate('wrobel@example.org',
+ array('password' => 'none'));
+ $this->assertNoError($result);
+ $this->assertTrue($result);
+
+ $session = Horde_Kolab_Session::singleton();
+ $this->assertNoError($session->user_mail);
+ $this->assertEquals('wrobel@example.org', $session->user_mail);
+
+ $result = $auth->authenticate('wrobel@example.org',
+ array('password' => 'invalid'));
+ $this->assertFalse($result);
+
+ /** Ensure we don't use a connection from older tests */
+ $server->unbind();
+
+ $result = $auth->authenticate('wrobel',
+ array('password' => 'invalid'));
+ $this->assertNoError($result);
+ $this->assertFalse($result);
+
+ /** Ensure we don't use a connection from older tests */
+ $server->unbind();
+ $result = $auth->authenticate('wrobel',
+ array('password' => 'none'));
+ $this->assertNoError($result);
+ $this->assertTrue($result);
+
+ $session = Horde_Kolab_Session::singleton();
+ $this->assertNoError($session->user_mail);
+ $this->assertEquals('wrobel@example.org', $session->user_mail);
+
+ $this->assertEquals('wrobel@example.org', Horde_Auth::getAuth());
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+/**
+ * A base for scenario test of the Kolab authentication driver.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Auth
+ * @subpackage UnitTests
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Auth
+ */
+
+/**
+ * The Autoloader allows us to omit "require/include" statements.
+ */
+require_once 'Horde/Autoloader.php';
+
+/**
+ * Supports scenario based testing of the Kolab auth driver.
+ *
+ * Copyright 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 Horde
+ * @package Auth
+ * @subpackage UnitTests
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Auth
+ */
+class Horde_Auth_Kolab_Scenario extends Horde_Kolab_Server_Scenario
+{
+ /**
+ * 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 'a provider':
+ $world['provider'] = new Horde_Provider_Base();
+ break;
+ case 'a registered element':
+ $world['provider']->{$arguments[0]} = $arguments[1];
+ 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 'retrieving the element':
+ try {
+ $world['result'] = $world['provider']->{$arguments[0]};
+ } catch (Exception $e) {
+ $world['result'] = $e;
+ }
+ break;
+ case 'deleting the element':
+ try {
+ unset($world['provider']->{$arguments[0]});
+ } catch (Exception $e) {
+ $world['result'] = $e;
+ }
+ 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 is':
+ $this->assertEquals($arguments[0], $world['result']);
+ break;
+ case 'the result is an error':
+ $this->assertTrue($world['result'] instanceOf Exception);
+ break;
+ case 'the result is an error with the message':
+ $this->assertTrue($world['result'] instanceOf Exception);
+ $this->assertEquals($arguments[0], $world['result']->getMessage());
+ break;
+ case 'the element exists':
+ $this->assertTrue(isset($world['provider']->{$arguments[0]}));
+ break;
+ default:
+ return $this->notImplemented($action);
+ }
+ }
+}
+++ /dev/null
-<?php
-/**
- * Kolab authentication scenarios.
- *
- * $Horde: framework/Auth/tests/Horde/Auth/KolabScenarioTest.php,v 1.3 2009/03/20 23:38:13 wrobel Exp $
- *
- * PHP version 5
- *
- * @category Horde
- * @package Auth
- * @subpackage UnitTests
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Auth
- */
-
-/**
- * We need the base class
- */
-require_once 'Horde/Kolab/Test/Storage.php';
-
-/**
- * Kolab authentication scenarios.
- *
- * $Horde: framework/Auth/tests/Horde/Auth/KolabScenarioTest.php,v 1.3 2009/03/20 23:38:13 wrobel Exp $
- *
- * 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 <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Kolab_Server
- */
-class Horde_Auth_KolabScenarioTest extends Horde_Kolab_Test_Storage
-{
- /**
- * Test loggin in after a user has been added.
- *
- * @scenario
- *
- * @return NULL
- */
- public function login()
- {
- $test_user = $this->provideBasicUserOne();
-
- $this->given('a populated Kolab setup')
- ->and('the Kolab auth driver has been selected')
- ->when('logging in as a user with a password', $test_user['mail'],
- $test_user['userPassword'])
- ->then('the login was successful');
- }
-}
\ No newline at end of file
+++ /dev/null
-<?php
-/**
- * Kolab authentication tests.
- *
- * $Horde: framework/Auth/tests/Horde/Auth/KolabTest.php,v 1.4 2009/04/01 07:59:47 wrobel Exp $
- *
- * PHP version 5
- *
- * @category Horde
- * @package Auth
- * @subpackage UnitTests
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Auth
- */
-
-/**
- * We need the base class
- */
-require_once 'Horde/Kolab/Test/Storage.php';
-
-/**
- * Kolab authentication tests.
- *
- * $Horde: framework/Auth/tests/Horde/Auth/KolabTest.php,v 1.4 2009/04/01 07:59:47 wrobel Exp $
- *
- * 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 <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Kolab_Server
- */
-class Horde_Auth_KolabTest extends Horde_Kolab_Test_Storage
-{
- /**
- * Test loggin in after a user has been added.
- *
- * @return NULL
- */
- public function testLogin()
- {
- /** Create the test base */
- $world = &$this->prepareBasicSetup();
- $server = $world['server'];
- $auth = $world['auth'];
-
- /** Ensure we always use the test server */
- $GLOBALS['conf']['kolab']['server']['driver'] = 'test';
-
- $uid = $server->uidForIdOrMail('wrobel@example.org');
- $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid);
-
- $result = $auth->authenticate('wrobel@example.org',
- array('password' => 'none'));
- $this->assertNoError($result);
- $this->assertTrue($result);
-
- $session = Horde_Kolab_Session::singleton();
- $this->assertNoError($session->user_mail);
- $this->assertEquals('wrobel@example.org', $session->user_mail);
-
- $result = $auth->authenticate('wrobel@example.org',
- array('password' => 'invalid'));
- $this->assertFalse($result);
-
- /** Ensure we don't use a connection from older tests */
- $server->unbind();
-
- $result = $auth->authenticate('wrobel',
- array('password' => 'invalid'));
- $this->assertNoError($result);
- $this->assertFalse($result);
-
- /** Ensure we don't use a connection from older tests */
- $server->unbind();
- $result = $auth->authenticate('wrobel',
- array('password' => 'none'));
- $this->assertNoError($result);
- $this->assertTrue($result);
-
- $session = Horde_Kolab_Session::singleton();
- $this->assertNoError($session->user_mail);
- $this->assertEquals('wrobel@example.org', $session->user_mail);
-
- $this->assertEquals('wrobel@example.org', Horde_Auth::getAuth());
- }
-}
\ No newline at end of file
$baseregexp = preg_quote($basedir . DIRECTORY_SEPARATOR, '/');
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($basedir)) as $file) {
+ //@TODO: Fix testing. Working on it...
+ continue;
if ($file->isFile() && preg_match('/Test.php$/', $file->getFilename())) {
$pathname = $file->getPathname();
require $pathname;
+++ /dev/null
-<?php
-/**
- * Base for PHPUnit scenarios.
- *
- * PHP version 5
- *
- * @category Kolab
- * @package Kolab_Test
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @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 <wrobel@pardus.de>
- * @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);
- }
- }
- }
-}
<file name="User.php" role="php" />
</dir> <!-- /lib/Horde/Kolab/Server/Object/Kolab -->
</dir> <!-- /lib/Horde/Kolab/Server/Object -->
- <file name="Scenario.php" role="php" />
<file name="Structure.php" role="php" />
<dir name="Structure">
<file name="Kolab.php" role="php" />
<file name="AddingObjectsTest.php" role="test" />
<file name="AdminTest.php" role="test" />
<file name="AllTests.php" role="test" />
+ <file name="Autoload.php" role="test" />
<file name="DistListHandlingTest.php" role="test" />
<file name="GroupHandlingTest.php" role="test" />
<file name="GroupTest.php" role="test" />
<file name="ObjectTest.php" role="test" />
<file name="OrgPersonTest.php" role="test" />
<file name="PersonTest.php" role="test" />
+ <file name="Scenario.php" role="test" />
<file name="ServerTest.php" role="test" />
<file name="TestTest.php" role="test" />
<file name="UserHandlingTest.php" role="test" />
<install name="lib/Horde/Kolab/Server/Object/Kolab/User.php" as="Horde/Kolab/Server/Object/Kolab/User.php" />
<install name="lib/Horde/Kolab/Server/Object/Organizationalperson.php" as="Horde/Kolab/Server/Object/Organizationalperson.php" />
<install name="lib/Horde/Kolab/Server/Object/Person.php" as="Horde/Kolab/Server/Object/Person.php" />
- <install name="lib/Horde/Kolab/Server/Scenario.php" as="Horde/Kolab/Server/Scenario.php" />
<install name="lib/Horde/Kolab/Server/Structure.php" as="Horde/Kolab/Server/Structure.php" />
<install name="lib/Horde/Kolab/Server/Structure/Kolab.php" as="Horde/Kolab/Server/Structure/Kolab.php" />
<install name="lib/Horde/Kolab/Server/Structure/Ldap.php" as="Horde/Kolab/Server/Structure/Ldap.php" />
<install name="test/Horde/Kolab/Server/AddingObjectsTest.php" as="Horde/Kolab/Server/AddingObjectsTest.php" />
<install name="test/Horde/Kolab/Server/AdminTest.php" as="Horde/Kolab/Server/AdminTest.php" />
<install name="test/Horde/Kolab/Server/AllTests.php" as="Horde/Kolab/Server/AllTests.php" />
+ <install name="test/Horde/Kolab/Server/Autoload.php" as="Horde/Kolab/Server/Autoload.php" />
<install name="test/Horde/Kolab/Server/DistListHandlingTest.php" as="Horde/Kolab/Server/DistListHandlingTest.php" />
<install name="test/Horde/Kolab/Server/GroupHandlingTest.php" as="Horde/Kolab/Server/GroupHandlingTest.php" />
<install name="test/Horde/Kolab/Server/GroupTest.php" as="Horde/Kolab/Server/GroupTest.php" />
<install name="test/Horde/Kolab/Server/ObjectTest.php" as="Horde/Kolab/Server/ObjectTest.php" />
<install name="test/Horde/Kolab/Server/OrgPersonTest.php" as="Horde/Kolab/Server/OrgPersonTest.php" />
<install name="test/Horde/Kolab/Server/PersonTest.php" as="Horde/Kolab/Server/PersonTest.php" />
+ <install name="test/Horde/Kolab/Server/Scenario.php" as="Horde/Kolab/Server/Scenario.php" />
<install name="test/Horde/Kolab/Server/ServerTest.php" as="Horde/Kolab/Server/ServerTest.php" />
<install name="test/Horde/Kolab/Server/TestTest.php" as="Horde/Kolab/Server/TestTest.php" />
<install name="test/Horde/Kolab/Server/UserHandlingTest.php" as="Horde/Kolab/Server/UserHandlingTest.php" />
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Adding objects to the server.
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Test the admin object.
--- /dev/null
+<?php
+/**
+ * Setup autoloading for the tests.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package Kolab_Server
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Server
+ */
+
+if (!defined('HORE_KOLAB_SERVER_TESTS')) {
+ /**
+ * The Autoloader allows us to omit "require/include" statements.
+ */
+ require_once 'Horde/Autoloader.php';
+
+ $test_dir = '@test_dir@/Kolab_Server';
+
+ if (substr($test_dir, 0, 1) == '@') {
+ /**
+ * Assume we are working in development mode and this package resides in
+ * 'framework'.
+ */
+ define('HORE_KOLAB_SERVER_TESTS', dirname(__FILE__) . '/../../..');
+ } else {
+ define('HORE_KOLAB_SERVER_TESTS', $test_dir);
+ }
+
+ Horde_Autoloader::addClassPath(HORE_KOLAB_SERVER_TESTS);
+}
\ No newline at end of file
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Handling distribution lists.
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Handling groups.
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Test the group object.
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Test the inetOrgPerson object.
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Test the kolabGermanBankArrangement object.
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Test the kolabInetOrgPerson object.
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Test the kolabExternalPop3Account object.
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Test the LDAP backend.
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* The the handling of objects.
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Test the organizationalPerson object.
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Test the person object.
--- /dev/null
+<?php
+/**
+ * Base for PHPUnit scenarios.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package Kolab_Test
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Share
+ */
+
+/**
+ * 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 <wrobel@pardus.de>
+ * @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 wish to support.
+ *
+ * @param array $environments The selected environments.
+ *
+ * @return NULL
+ */
+ public function setEnvironments($environments)
+ {
+ $this->_environments = $environments;
+ }
+
+ /**
+ * Initialize the environments.
+ *
+ * @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 a server and remember it for the tear down method.
+ *
+ * @param Horde_Kolab_Server &$server The server to add the object to.
+ * @param array $object The object data to store.
+ *
+ * @return Horde_Kolab_Server_Object The resulting object.
+ */
+ public function &addToServer(Horde_Kolab_Server &$server, array $object)
+ {
+ $object = $server->add($object);
+ $this->added[] = array($server, $object->getUid());
+ return $object;
+ }
+
+ /**
+ * Add an object to the registered servers.
+ *
+ * @param array $object The object data to store.
+ *
+ * @return array An array of objects.
+ */
+ public function addToServers(array $object)
+ {
+ $result = array();
+ foreach ($this->world['injector'] as $injector) {
+ $server = $injector->getInstance('Horde_Kolab_Server');
+ $result[] = $this->addToServer($server, $object);
+ }
+ 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 = $this->addToServer($server, $this->provideBasicUserOne());
+ $this->assertNoError($result);
+ $result = $this->addToServer($server, $this->provideBasicUserTwo());
+ $this->assertNoError($result);
+ $result = $this->addToServer($server, $this->provideBasicAddress());
+ $this->assertNoError($result);
+ $result = $this->addToServer($server, $this->provideBasicAdmin());
+ $this->assertNoError($result);
+ $result = $this->addToServer($server, $this->provideBasicDomainMaintainer());
+ $this->assertNoError($result);
+ $result = $this->addToServer($server, $this->provideGroupWithoutMembers());
+ $this->assertNoError($result);
+ $result = $this->addToServer($server, $this->provideBasicGroupOne());
+ $this->assertNoError($result);
+ $result = $this->addToServer($server, $this->provideBasicMaintainer());
+ $this->assertNoError($result);
+ $result = $this->addToServer($server, $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);
+ }
+ }
+ }
+}
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Tests for the main server class.
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Test the test backend.
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Handling users.
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Test the user object.
--- /dev/null
+<?php
+/**
+ * Setup autoloading for the tests.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package Kolab_Server
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @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';
+
+if (!defined('HORE_KOLAB_SERVER_TESTS')) {
+ $test_dir = '@test_dir@/Kolab_Server';
+
+ if (substr($test_dir, 0, 1) == '@') {
+ /**
+ * Assume we are working in development mode and this package resides in
+ * 'framework'.
+ */
+ define('HORE_KOLAB_SERVER_TESTS', dirname(__FILE__) . '/../../../../../Kolab_Server/test');
+ } else {
+ define('HORE_KOLAB_SERVER_TESTS', $test_dir);
+ }
+
+ Horde_Autoloader::addClassPath(HORE_KOLAB_SERVER_TESTS);
+}
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
-
-require_once 'Horde/Util.php';
+require_once 'Autoload.php';
/**
* Test the Kolab session handler.
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @link http://pear.horde.org/index.php?package=Kolab_Session
*/
-class Horde_Kolab_Session_SessionTest extends Horde_Kolab_Test_Server
+class Horde_Kolab_Session_SessionTest extends Horde_Kolab_Server_Scenario
{
/**
* Test class construction.
+++ /dev/null
-<?php
-/**
- * Base for PHPUnit scenarios.
- *
- * $Horde: framework/Kolab_Storage/lib/Horde/Kolab/Test/Storage.php,v 1.9 2009/06/24 23:39:23 slusarz Exp $
- *
- * PHP version 5
- *
- * @category Kolab
- * @package Kolab_Test
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Kolab_Storage
- */
-
-/**
- * The Autoloader allows us to omit "require/include" statements.
- */
-require_once 'Horde/Autoloader.php';
-
-/**
- * Base for PHPUnit scenarios.
- *
- * $Horde: framework/Kolab_Storage/lib/Horde/Kolab/Test/Storage.php,v 1.9 2009/06/24 23:39:23 slusarz Exp $
- *
- * 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 <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Kolab_Storage
- */
-class Horde_Kolab_Test_Storage extends Horde_Kolab_Test_Server
-{
- /**
- * 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 storage':
- $world['storage'] = &$this->prepareEmptyKolabStorage();
- break;
- case 'a Kolab setup':
- $result = $this->prepareKolabSetup();
-
- $world['server'] = &$result['server'];
- $world['storage'] = &$result['storage'];
- $world['auth'] = &$result['auth'];
- break;
- case 'a populated Kolab setup':
- $result = $this->prepareBasicSetup();
-
- $world['server'] = &$result['server'];
- $world['storage'] = &$result['storage'];
- $world['auth'] = &$result['auth'];
- break;
- default:
- return parent::runGiven($world, $action, $arguments);
- }
- }
-
- /**
- * 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 'create a Kolab default calendar with name':
- $folder = $world['storage']->getNewFolder();
- $folder->setName($arguments[0]);
- $world['folder_creation'] = $folder->save(array('type' => 'event',
- 'default' => true));
- $folder->setACL(Auth::getAuth(), 'alrid');
- break;
- case 'allow a group full access to a folder':
- $folder = $world['storage']->getFolder($arguments[1]);
- $folder->setACL($arguments[0], 'alrid');
- break;
- case 'retrieving the list of shares for the application':
- $shares = Horde_Share::singleton($arguments[0], 'kolab');
-
- $world['list'] = $shares->listShares(Auth::getAuth());
- break;
- case 'logging in as a user with a password':
- $world['login'] = $world['auth']->authenticate($arguments[0],
- array('password' => $arguments[1]));
- $world['storage'] = &$this->prepareEmptyKolabStorage();
- return parent::runWhen($world, $action, $arguments);
- default:
- return parent::runWhen($world, $action, $arguments);
- }
- }
-
- /**
- * 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 creation of the folder was successful':
- $this->assertNoError($world['folder_creation']);
- break;
- case 'the list contains a share named':
- $this->assertNoError($world['list']);
- $this->assertContains($arguments[0],
- array_keys($world['list']));
- break;
- default:
- return parent::runThen($world, $action, $arguments);
- }
- }
-
- /**
- * Prepare a Kolab server with some basic entries.
- *
- * @return Horde_Kolab_Server The empty server.
- */
- public function &prepareBasicSetup()
- {
- $world = &$this->prepareKolabSetup();
- $this->prepareUsers($world['server']);
- return $world;
- }
-
- /**
- * Prepare an empty Kolab storage.
- *
- * @return Horde_Kolab_Storage_List The empty storage.
- */
- public function &prepareEmptyKolabStorage($params = null)
- {
- /** Prepare a Kolab test storage */
- if(empty($params)) {
- $params = array('driver' => 'Mock',
- 'username' => 'test',
- 'password' => 'test');
- }
- $storage = Horde_Kolab_Storage::singleton('imap', $params);
- return $storage;
- }
-
- /**
- * Prepare the browser setup.
- *
- * @return NULL
- */
- public function prepareBrowser()
- {
- /** Provide a browser setup */
- $GLOBALS['browser'] = new Horde_Browser();
- }
-
- protected function getConfiguration()
- {
- $data = <<<EOD
-\$conf['use_ssl'] = 2;
-\$conf['server']['name'] = \$_SERVER['SERVER_NAME'];
-\$conf['server']['port'] = \$_SERVER['SERVER_PORT'];
-\$conf['debug_level'] = E_ALL;
-\$conf['umask'] = 077;
-\$conf['compress_pages'] = true;
-\$conf['menu']['always'] = false;
-\$conf['portal']['fixed_blocks'] = array();
-\$conf['imsp']['enabled'] = false;
-
-/** Additional config variables required for a clean Horde setup */
-\$conf['session']['use_only_cookies'] = false;
-\$conf['session']['timeout'] = 0;
-\$conf['cookie']['path'] = '/';
-\$conf['cookie']['domain'] = \$_SERVER['SERVER_NAME'];
-\$conf['use_ssl'] = false;
-\$conf['session']['cache_limiter'] = null;
-\$conf['session']['name'] = 'Horde';
-\$conf['log']['enabled'] = false;
-\$conf['prefs']['driver'] = 'session';
-\$conf['auth']['driver'] = 'kolab';
-\$conf['share']['driver'] = 'kolab';
-\$conf['debug_level'] = E_ALL;
-
-/** Make the share driver happy */
-\$conf['kolab']['enabled'] = true;
-
-/** Ensure we still use the LDAP test driver */
-\$conf['kolab']['server']['driver'] = 'test';
-\$conf['kolab']['server']['params']['hashtype'] = 'plain';
-
-/** Ensure that we do not trigger on folder update */
-\$conf['kolab']['no_triggering'] = true;
-
-/** Storage location for the free/busy system */
-\$conf['fb']['cache_dir'] = '/tmp';
-\$conf['kolab']['freebusy']['server'] = 'https://fb.example.org/freebusy';
-
-/** Setup the virtual file system for Kolab */
-\$conf['vfs']['params']['all_folders'] = true;
-\$conf['vfs']['type'] = 'kolab';
-EOD;
- return $data;
- }
-
- /**
- * Prepare the configuration.
- *
- * @return NULL
- */
- public function prepareConfiguration()
- {
- $fh = fopen(HORDE_BASE . '/config/conf.php', 'w');
- $data = $this->getConfiguration();
- fwrite($fh, "<?php\n" . $data);
- fclose($fh);
- }
-
- /**
- * Prepare the registry.
- *
- * @return NULL
- */
- public function prepareRegistry()
- {
- $fh = fopen(HORDE_BASE . '/config/registry.php', 'w');
- $data = <<<EOD
-\$this->applications['horde'] = array(
- 'fileroot' => dirname(__FILE__) . '/..',
- 'webroot' => '/',
- 'initial_page' => 'login.php',
- 'name' => _("Horde"),
- 'status' => 'active',
- 'templates' => dirname(__FILE__) . '/../templates',
- 'provides' => 'horde',
-);
-EOD;
- fwrite($fh, "<?php\n" . $data);
- fclose($fh);
- if (!file_exists(HORDE_BASE . '/config/registry.d')) {
- mkdir(HORDE_BASE . '/config/registry.d');
- }
- }
-
- /**
- * Prepare the notification setup.
- *
- * @return NULL
- */
- public function prepareNotification()
- {
-
- $fh = fopen(HORDE_BASE . '/config/nls.php', 'w');
- $data = <<<EOD
-\$nls['defaults']['language'] = '';
-\$nls['languages']['en_US'] = '‭English (American)';
-\$nls['aliases']['en'] = 'en_US';
-\$nls['spelling']['en_US'] = '-d american';
-\$GLOBALS['nls'] = &\$nls;
-EOD;
- fwrite($fh, "<?php\n" . $data);
- fclose($fh);
- }
-
- /**
- * Prepare a Kolab setup.
- *
- * @return NULL
- */
- public function &prepareKolabSetup($username = 'test', $password = 'test')
- {
- /**
- * Ensure we have a session array. Otherwise the Auth handler will try
- * to unset the session and issue a notice.
- */
- $_SESSION = array();
-
- $world = array();
-
- $params = array('driver' => 'Mock',
- 'username' => $username,
- 'password' => $password);
-
- $world['server'] = &$this->prepareEmptyKolabServer();
- $world['storage'] = &$this->prepareEmptyKolabStorage($params);
- $world['auth'] = &$this->prepareKolabAuthDriver();
-
- $this->prepareBasicConfiguration();
-
- if (!defined('HORDE_BASE')) {
- define('HORDE_BASE', $this->provideHordeBase());
- }
-
- if (!file_exists(HORDE_BASE . '/config')) {
- $result = mkdir(HORDE_BASE . '/config', 0755, true);
- }
-
- /* Ensure that we send no heders when the session is started */
- ini_set('session.use_cookies', 0);
- ini_set('session.use_only_cookies', 0);
-
- $this->prepareConfiguration();
- $this->prepareRegistry();
- $this->prepareNotification();
-
- if (!isset($GLOBALS['perms'])) {
- include_once 'Horde/Perms.php';
- $GLOBALS['perms'] = &Perms::singleton();
- }
-
- /** Provide the horde registry */
- $GLOBALS['registry'] = &Horde_Registry::singleton();
- $GLOBALS['notification'] = &Horde_Notification::singleton();
-
- $this->prepareFixedConfiguration();
-
- $this->prepareBrowser();
-
- /* Make sure the configuration is correct after initializing the registry */
- $this->prepareBasicConfiguration();
-
- return $world;
- }
-
- /**
- * Fix the read configuration.
- *
- * @return NULL
- */
- public function prepareFixedConfiguration()
- {
- $GLOBALS['registry']->importConfig('horde');
- }
-
- /**
- * Prepare a basic Kolab configuration.
- *
- * @return NULL
- */
- public function prepareBasicConfiguration()
- {
- /** We need a server name for MIME processing */
- $_SERVER['SERVER_NAME'] = $this->provideServerName();
- $_SERVER['SERVER_PORT'] = 80;
-
- $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
- }
-
- /**
- * Create a new folder.
- *
- * @param string $name Name of the new folder.
- * @param string $type Type of the new folder.
- * @param boolean $default Should the new folder be a default folder?
- *
- * @return Kolab_Folder The new folder.
- */
- public function &prepareNewFolder(&$storage, $name, $type, $default = false)
- {
- $folder = $storage->getNewFolder();
- $folder->setName($name);
- $this->assertNoError($folder->save(array('type' => $type,
- 'default' => $default)));
- return $folder;
- }
-
- function provideServerName() {
- return 'localhost';
- }
-
- function provideHordeBase() {
- return Horde::getTempDir() . '/test_config';
- }
-
- public function &authenticate(Horde_Auth_Base $auth, $username = 'test', $password = 'test')
- {
- $this->assertTrue($auth->authenticate($username,
- array('password' => $password)));
-
- $params = array('driver' => 'Mock',
- 'username' => $username,
- 'password' => $password);
-
- return $this->prepareEmptyKolabStorage($params);
- }
-}
<file name="Folder.php" role="php" />
<file name="Permission.php" role="php" />
</dir> <!-- /lib/Horde/Kolab/Storage -->
- <dir name="Test">
- <file name="Storage.php" role="php" />
- </dir> <!-- /lib/Horde/Kolab/Test -->
</dir> <!-- /lib/Horde/Kolab -->
</dir> <!-- /lib/Horde -->
</dir> <!-- /lib -->
<dir name="Kolab">
<dir name="Storage">
<file name="AllTests.php" role="test" />
+ <file name="Autoload.php" role="php" />
<file name="CacheTest.php" role="test" />
<file name="DataTest.php" role="test" />
<file name="FolderTest.php" role="test" />
+ <file name="Scenario.php" role="php" />
<file name="StorageTest.php" role="test" />
<file name="PermissionTest.php" role="test" />
</dir> <!-- /test/Horde/Kolab/Storage -->
<install name="lib/Horde/Kolab/Storage/Exception.php" as="Horde/Kolab/Storage/Exception.php" />
<install name="lib/Horde/Kolab/Storage/Folder.php" as="Horde/Kolab/Storage/Folder.php" />
<install name="lib/Horde/Kolab/Storage/Permission.php" as="Horde/Kolab/Storage/Permission.php" />
- <install name="lib/Horde/Kolab/Test/Storage.php" as="Horde/Kolab/Test/Storage.php" />
<install name="test/Horde/Kolab/Storage/AllTests.php" as="Horde/Kolab/Storage/AllTests.php" />
+ <install name="test/Horde/Kolab/Storage/Autoload.php" as="Horde/Kolab/Storage/Autoload.php" />
<install name="test/Horde/Kolab/Storage/CacheTest.php" as="Horde/Kolab/Storage/CacheTest.php" />
<install name="test/Horde/Kolab/Storage/DataTest.php" as="Horde/Kolab/Storage/DataTest.php" />
<install name="test/Horde/Kolab/Storage/FolderTest.php" as="Horde/Kolab/Storage/FolderTest.php" />
+ <install name="test/Horde/Kolab/Storage/Scenario.php" as="Horde/Kolab/Storage/Scenario.php" />
<install name="test/Horde/Kolab/Storage/StorageTest.php" as="Horde/Kolab/Storage/StorageTest.php" />
<install name="test/Horde/Kolab/Storage/PermissionTest.php" as="Horde/Kolab/Storage/PermissionTest.php" />
</filelist>
*/
/**
- * We need the base class
+ * Prepare the test setup.
*/
-require_once 'Horde/Kolab/Test/Storage.php';
-
-require_once 'Horde.php';
-require_once 'Horde/Kolab/Storage/Data.php';
-require_once 'Horde/Kolab/IMAP.php';
-require_once 'Horde/Kolab/IMAP/test.php';
+require_once 'Autoload.php';
/**
* Test the handling of attachments.
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @link http://pear.horde.org/index.php?package=Kolab_Storage
*/
-class Horde_Kolab_Storage_AttachmentTest extends Horde_Kolab_Test_Storage
+class Horde_Kolab_Storage_AttachmentTest extends Horde_Kolab_Storage_Scenario
{
/**
--- /dev/null
+<?php
+/**
+ * Setup autoloading for the tests.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package Kolab_Server
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @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';
+
+if (!defined('HORE_KOLAB_SERVER_TESTS')) {
+ $test_dir = '@test_dir@/Kolab_Server';
+
+ if (substr($test_dir, 0, 1) == '@') {
+ /**
+ * Assume we are working in development mode and this package resides in
+ * 'framework'.
+ */
+ define('HORE_KOLAB_SERVER_TESTS', dirname(__FILE__) . '/../../../../../Kolab_Server/test');
+ } else {
+ define('HORE_KOLAB_SERVER_TESTS', $test_dir);
+ }
+
+ Horde_Autoloader::addClassPath(HORE_KOLAB_SERVER_TESTS);
+}
+
+if (!defined('HORE_KOLAB_STORAGE_TESTS')) {
+ $test_dir = '@test_dir@/Kolab_Storage';
+
+ if (substr($test_dir, 0, 1) == '@') {
+ /**
+ * Assume we are working in development mode and this package resides in
+ * 'framework'.
+ */
+ define('HORE_KOLAB_STORAGE_TESTS', dirname(__FILE__) . '/../../..');
+ } else {
+ define('HORE_KOLAB_STORAGE_TESTS', $test_dir);
+ }
+
+ Horde_Autoloader::addClassPath(HORE_KOLAB_STORAGE_TESTS);
+}
\ No newline at end of file
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Test the Kolab cache.
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Test the Kolab data handler.
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @link http://pear.horde.org/index.php?package=Kolab_Storage
*/
-class Horde_Kolab_Storage_DataTest extends Horde_Kolab_Test_Storage
+class Horde_Kolab_Storage_DataTest extends Horde_Kolab_Storage_Scenario
{
/**
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Test the Kolab folder handler.
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @link http://pear.horde.org/index.php?package=Kolab_Storage
*/
-class Horde_Kolab_Storage_FolderTest extends Horde_Kolab_Test_Storage
+class Horde_Kolab_Storage_FolderTest extends Horde_Kolab_Storage_Scenario
{
/**
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Test the Kolab permission handler.
--- /dev/null
+<?php
+/**
+ * Base for PHPUnit scenarios.
+ *
+ * $Horde: framework/Kolab_Storage/lib/Horde/Kolab/Test/Storage.php,v 1.9 2009/06/24 23:39:23 slusarz Exp $
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package Kolab_Test
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Base for PHPUnit scenarios.
+ *
+ * $Horde: framework/Kolab_Storage/lib/Horde/Kolab/Test/Storage.php,v 1.9 2009/06/24 23:39:23 slusarz Exp $
+ *
+ * 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 <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Scenario extends Horde_Kolab_Server_Scenario
+{
+ /**
+ * 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 storage':
+ $world['storage'] = &$this->prepareEmptyKolabStorage();
+ break;
+ case 'a Kolab setup':
+ $result = $this->prepareKolabSetup();
+
+ $world['server'] = &$result['server'];
+ $world['storage'] = &$result['storage'];
+ $world['auth'] = &$result['auth'];
+ break;
+ case 'a populated Kolab setup':
+ $result = $this->prepareBasicSetup();
+
+ $world['server'] = &$result['server'];
+ $world['storage'] = &$result['storage'];
+ $world['auth'] = &$result['auth'];
+ break;
+ default:
+ return parent::runGiven($world, $action, $arguments);
+ }
+ }
+
+ /**
+ * 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 'create a Kolab default calendar with name':
+ $folder = $world['storage']->getNewFolder();
+ $folder->setName($arguments[0]);
+ $world['folder_creation'] = $folder->save(array('type' => 'event',
+ 'default' => true));
+ $folder->setACL(Auth::getAuth(), 'alrid');
+ break;
+ case 'allow a group full access to a folder':
+ $folder = $world['storage']->getFolder($arguments[1]);
+ $folder->setACL($arguments[0], 'alrid');
+ break;
+ case 'retrieving the list of shares for the application':
+ $shares = Horde_Share::singleton($arguments[0], 'kolab');
+
+ $world['list'] = $shares->listShares(Auth::getAuth());
+ break;
+ case 'logging in as a user with a password':
+ $world['login'] = $world['auth']->authenticate($arguments[0],
+ array('password' => $arguments[1]));
+ $world['storage'] = &$this->prepareEmptyKolabStorage();
+ return parent::runWhen($world, $action, $arguments);
+ default:
+ return parent::runWhen($world, $action, $arguments);
+ }
+ }
+
+ /**
+ * 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 creation of the folder was successful':
+ $this->assertNoError($world['folder_creation']);
+ break;
+ case 'the list contains a share named':
+ $this->assertNoError($world['list']);
+ $this->assertContains($arguments[0],
+ array_keys($world['list']));
+ break;
+ default:
+ return parent::runThen($world, $action, $arguments);
+ }
+ }
+
+ /**
+ * Prepare a Kolab server with some basic entries.
+ *
+ * @return Horde_Kolab_Server The empty server.
+ */
+ public function &prepareBasicSetup()
+ {
+ $world = &$this->prepareKolabSetup();
+ $this->addBasicUsersToServer($world['server']);
+ return $world;
+ }
+
+ /**
+ * Prepare an empty Kolab storage.
+ *
+ * @return Horde_Kolab_Storage_List The empty storage.
+ */
+ public function &prepareEmptyKolabStorage($params = null)
+ {
+ /** Prepare a Kolab test storage */
+ if(empty($params)) {
+ $params = array('driver' => 'Mock',
+ 'username' => 'test',
+ 'password' => 'test');
+ }
+ $storage = Horde_Kolab_Storage::singleton('imap', $params);
+ return $storage;
+ }
+
+ /**
+ * Prepare the browser setup.
+ *
+ * @return NULL
+ */
+ public function prepareBrowser()
+ {
+ /** Provide a browser setup */
+ $GLOBALS['browser'] = new Horde_Browser();
+ }
+
+ protected function getConfiguration()
+ {
+ $data = <<<EOD
+\$conf['use_ssl'] = 2;
+\$conf['server']['name'] = \$_SERVER['SERVER_NAME'];
+\$conf['server']['port'] = \$_SERVER['SERVER_PORT'];
+\$conf['debug_level'] = E_ALL;
+\$conf['umask'] = 077;
+\$conf['compress_pages'] = true;
+\$conf['menu']['always'] = false;
+\$conf['portal']['fixed_blocks'] = array();
+\$conf['imsp']['enabled'] = false;
+
+/** Additional config variables required for a clean Horde setup */
+\$conf['session']['use_only_cookies'] = false;
+\$conf['session']['timeout'] = 0;
+\$conf['cookie']['path'] = '/';
+\$conf['cookie']['domain'] = \$_SERVER['SERVER_NAME'];
+\$conf['use_ssl'] = false;
+\$conf['session']['cache_limiter'] = null;
+\$conf['session']['name'] = 'Horde';
+\$conf['log']['enabled'] = false;
+\$conf['prefs']['driver'] = 'session';
+\$conf['auth']['driver'] = 'kolab';
+\$conf['share']['driver'] = 'kolab';
+\$conf['debug_level'] = E_ALL;
+
+/** Make the share driver happy */
+\$conf['kolab']['enabled'] = true;
+
+/** Ensure we still use the LDAP test driver */
+\$conf['kolab']['server']['driver'] = 'test';
+\$conf['kolab']['server']['params']['hashtype'] = 'plain';
+
+/** Ensure that we do not trigger on folder update */
+\$conf['kolab']['no_triggering'] = true;
+
+/** Storage location for the free/busy system */
+\$conf['fb']['cache_dir'] = '/tmp';
+\$conf['kolab']['freebusy']['server'] = 'https://fb.example.org/freebusy';
+
+/** Setup the virtual file system for Kolab */
+\$conf['vfs']['params']['all_folders'] = true;
+\$conf['vfs']['type'] = 'kolab';
+EOD;
+ return $data;
+ }
+
+ /**
+ * Prepare the configuration.
+ *
+ * @return NULL
+ */
+ public function prepareConfiguration()
+ {
+ $fh = fopen(HORDE_BASE . '/config/conf.php', 'w');
+ $data = $this->getConfiguration();
+ fwrite($fh, "<?php\n" . $data);
+ fclose($fh);
+ }
+
+ /**
+ * Prepare the registry.
+ *
+ * @return NULL
+ */
+ public function prepareRegistry()
+ {
+ $fh = fopen(HORDE_BASE . '/config/registry.php', 'w');
+ $data = <<<EOD
+\$this->applications['horde'] = array(
+ 'fileroot' => dirname(__FILE__) . '/..',
+ 'webroot' => '/',
+ 'initial_page' => 'login.php',
+ 'name' => _("Horde"),
+ 'status' => 'active',
+ 'templates' => dirname(__FILE__) . '/../templates',
+ 'provides' => 'horde',
+);
+EOD;
+ fwrite($fh, "<?php\n" . $data);
+ fclose($fh);
+ if (!file_exists(HORDE_BASE . '/config/registry.d')) {
+ mkdir(HORDE_BASE . '/config/registry.d');
+ }
+ }
+
+ /**
+ * Prepare the notification setup.
+ *
+ * @return NULL
+ */
+ public function prepareNotification()
+ {
+
+ $fh = fopen(HORDE_BASE . '/config/nls.php', 'w');
+ $data = <<<EOD
+\$nls['defaults']['language'] = '';
+\$nls['languages']['en_US'] = '‭English (American)';
+\$nls['aliases']['en'] = 'en_US';
+\$nls['spelling']['en_US'] = '-d american';
+\$GLOBALS['nls'] = &\$nls;
+EOD;
+ fwrite($fh, "<?php\n" . $data);
+ fclose($fh);
+ }
+
+ /**
+ * Prepare a Kolab setup.
+ *
+ * @return NULL
+ */
+ public function &prepareKolabSetup($username = 'test', $password = 'test')
+ {
+ /**
+ * Ensure we have a session array. Otherwise the Auth handler will try
+ * to unset the session and issue a notice.
+ */
+ $_SESSION = array();
+
+ $world = array();
+
+ $params = array('driver' => 'Mock',
+ 'username' => $username,
+ 'password' => $password);
+
+ $world['server'] = &$this->getKolabMockServer();
+ $world['storage'] = &$this->prepareEmptyKolabStorage($params);
+ //$world['auth'] = &$this->prepareKolabAuthDriver();
+
+ $this->prepareBasicConfiguration();
+
+ if (!defined('HORDE_BASE')) {
+ define('HORDE_BASE', $this->provideHordeBase());
+ }
+
+ if (!file_exists(HORDE_BASE . '/config')) {
+ $result = mkdir(HORDE_BASE . '/config', 0755, true);
+ }
+
+ /* Ensure that we send no heders when the session is started */
+ ini_set('session.use_cookies', 0);
+ ini_set('session.use_only_cookies', 0);
+
+ $this->prepareConfiguration();
+ $this->prepareRegistry();
+ $this->prepareNotification();
+
+ if (!isset($GLOBALS['perms'])) {
+ include_once 'Horde/Perms.php';
+ $GLOBALS['perms'] = &Perms::singleton();
+ }
+
+ /** Provide the horde registry */
+ $GLOBALS['registry'] = &Horde_Registry::singleton();
+ $GLOBALS['notification'] = &Horde_Notification::singleton();
+
+ $this->prepareFixedConfiguration();
+
+ $this->prepareBrowser();
+
+ /* Make sure the configuration is correct after initializing the registry */
+ $this->prepareBasicConfiguration();
+
+ return $world;
+ }
+
+ /**
+ * Fix the read configuration.
+ *
+ * @return NULL
+ */
+ public function prepareFixedConfiguration()
+ {
+ $GLOBALS['registry']->importConfig('horde');
+ }
+
+ /**
+ * Prepare a basic Kolab configuration.
+ *
+ * @return NULL
+ */
+ public function prepareBasicConfiguration()
+ {
+ /** We need a server name for MIME processing */
+ $_SERVER['SERVER_NAME'] = $this->provideServerName();
+ $_SERVER['SERVER_PORT'] = 80;
+
+ $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
+ }
+
+ /**
+ * Create a new folder.
+ *
+ * @param string $name Name of the new folder.
+ * @param string $type Type of the new folder.
+ * @param boolean $default Should the new folder be a default folder?
+ *
+ * @return Kolab_Folder The new folder.
+ */
+ public function &prepareNewFolder(&$storage, $name, $type, $default = false)
+ {
+ $folder = $storage->getNewFolder();
+ $folder->setName($name);
+ $this->assertNoError($folder->save(array('type' => $type,
+ 'default' => $default)));
+ return $folder;
+ }
+
+ function provideServerName() {
+ return 'localhost';
+ }
+
+ function provideHordeBase() {
+ return Horde::getTempDir() . '/test_config';
+ }
+
+ public function &authenticate(Horde_Auth_Base $auth, $username = 'test', $password = 'test')
+ {
+ $this->assertTrue($auth->authenticate($username,
+ array('password' => $password)));
+
+ $params = array('driver' => 'Mock',
+ 'username' => $username,
+ 'password' => $password);
+
+ return $this->prepareEmptyKolabStorage($params);
+ }
+}
*/
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once 'Autoload.php';
/**
* Test the Kolab storage handler.
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @link http://pear.horde.org/index.php?package=Kolab_Storage
*/
-class Horde_Kolab_Storage_StorageTest extends Horde_Kolab_Test_Storage
+class Horde_Kolab_Storage_StorageTest extends Horde_Kolab_Storage_Scenario
{
/**