From: Gunnar Wrobel
Date: Mon, 26 Oct 2009 17:55:05 +0000 (+0100)
Subject: Refactoring and testing of Kolab_Session largely complete. The connection with Kolab_...
X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=f695fe922bbb55247fb0aa3a5364c0d7adb02303;p=horde.git
Refactoring and testing of Kolab_Session largely complete. The connection with Kolab_Server still needs some fixes on the side of Kolab_Server.
---
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session.php b/framework/Kolab_Session/lib/Horde/Kolab/Session.php
index 9d415f200..f36a04ade 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session.php
@@ -47,7 +47,7 @@ interface Horde_Kolab_Session
*
* @throws Horde_Kolab_Session_Exception If the connection failed.
*/
- public function connect(array $credentials);
+ public function connect(array $credentials = null);
/**
* Return the user id used for connecting the session.
@@ -57,6 +57,15 @@ interface Horde_Kolab_Session
public function getId();
/**
+ * Set the user id used for connecting the session.
+ *
+ * @param string $id The user id.
+ *
+ * @return NULL
+ */
+ public function setId($id);
+
+ /**
* Return the users mail address.
*
* @return string The users mail address.
@@ -78,37 +87,23 @@ interface Horde_Kolab_Session
public function getName();
/**
- * Return a connection to the Kolab storage system.
+ * Return the imap server.
*
- * @return Horde_Kolab_Storage The storage connection.
+ * @return string The imap host for the current user.
*/
- public function getStorage();
+ public function getImapServer();
/**
- * Set the handler that provides getCurrentUser() for this instance.
- *
- * @param Horde_Kolab_Session_Auth $auth The authentication handler.
+ * Return the freebusy server.
*
- * @return NULL
- */
- public function setAuth(Horde_Kolab_Session_Auth $auth);
-
- /**
- * Get the handler that provides getCurrentUser() for this instance.
- *
- * @return Horde_Kolab_Session_Auth The authentication handler.
+ * @return string The freebusy host for the current user.
*/
- public function getAuth();
+ public function getFreebusyServer();
/**
- * Does the current session still match the authentication information?
- *
- * @param string $user The user the session information is being requested
- * for. This is usually empty, indicating the current
- * user.
- * @param string $auth The user the current session belongs to.
+ * Return a connection to the Kolab storage system.
*
- * @return boolean True if the session is still valid.
+ * @return Horde_Kolab_Storage The storage connection.
*/
- public function isValid($user, $auth);
+ public function getStorage();
}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Anonymous.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Anonymous.php
new file mode 100644
index 000000000..9c046a6b2
--- /dev/null
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Anonymous.php
@@ -0,0 +1,182 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * The Horde_Kolab_Session_Anonymous class allows anonymous access to the Kolab
+ * system.
+ *
+ * The core user credentials (login, pass) are kept within the Auth module and
+ * can be retrieved using Auth::getAuth() respectively
+ * Auth::getCredential('password'). Any additional Kolab user data
+ * relevant for the user session should be accessed via the Horde_Kolab_Session
+ * class.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Anonymous implements Horde_Kolab_Session
+{
+ /**
+ * The session handler this instance provides with anonymous access.
+ *
+ * @var Horde_Kolab_Session
+ */
+ private $_session;
+
+ /**
+ * Anonymous user ID.
+ *
+ * @var string
+ */
+ private $_anonymous_id;
+
+ /**
+ * Anonymous password.
+ *
+ * @var string
+ */
+ private $_anonymous_pass;
+
+ /**
+ * Constructor.
+ *
+ * @param Horde_Kolab_Session $session The this instance should provide
+ * anonymous access for.
+ * @param string $user ID of the anonymous user.
+ * @param string $pass Password of the anonymous user.
+ */
+ public function __construct(Horde_Kolab_Session $session, $user, $pass)
+ {
+ $this->_session = $session;
+ $this->_anonymous_id = $user;
+ $this->_anonymous_pass = $pass;
+ }
+
+ /**
+ * Try to connect the session handler.
+ *
+ * @param array $credentials An array of login credentials. For Kolab,
+ * this must contain a "password" entry.
+ *
+ * @return NULL
+ *
+ * @throws Horde_Kolab_Session_Exception If the connection failed.
+ */
+ public function connect(array $credentials = null)
+ {
+ $id = $this->_session->getId();
+ if (empty($id) && $credentials === null) {
+ $this->_session->setId($this->_anonymous_id);
+ $this->_session->connect(array('password' => $this->_anonymous_pass));
+ } else {
+ $this->_session->connect($credentials);
+ }
+ }
+
+ /**
+ * Return the user id used for connecting the session.
+ *
+ * @return string The user id.
+ */
+ public function getId()
+ {
+ $id = $this->_session->getId();
+ if ($id == $this->_anonymous_id) {
+ return null;
+ }
+ return $id;
+ }
+
+ /**
+ * Set the user id used for connecting the session.
+ *
+ * @param string $id The user id.
+ *
+ * @return NULL
+ */
+ public function setId($id)
+ {
+ $this->_session->setId($id);
+ }
+
+ /**
+ * Return the users mail address.
+ *
+ * @return string The users mail address.
+ */
+ public function getMail()
+ {
+ return $this->_session->getMail();
+ }
+
+ /**
+ * Return the users uid.
+ *
+ * @return string The users uid.
+ */
+ public function getUid()
+ {
+ return $this->_session->getUid();
+ }
+
+ /**
+ * Return the users name.
+ *
+ * @return string The users name.
+ */
+ public function getName()
+ {
+ return $this->_session->getName();
+ }
+
+ /**
+ * Return the imap server.
+ *
+ * @return string The imap host for the current user.
+ */
+ public function getImapServer()
+ {
+ return $this->_session->getImapServer();
+ }
+
+ /**
+ * Return the freebusy server.
+ *
+ * @return string The freebusy host for the current user.
+ */
+ public function getFreebusyServer()
+ {
+ return $this->_session->getFreebusyServer();
+ }
+
+ /**
+ * Return a connection to the Kolab storage system.
+ *
+ * @return Horde_Kolab_Storage The storage connection.
+ *
+ * @todo Adapt to new structure of this class.
+ */
+ public function getStorage()
+ {
+ return $this->_session->getStorage();
+ }
+}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Auth/Mock.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Auth/Mock.php
new file mode 100644
index 000000000..bf0893652
--- /dev/null
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Auth/Mock.php
@@ -0,0 +1,56 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Mock authentication for the Kolab session information.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Auth_Mock implements Horde_Kolab_Session_Auth
+{
+ /**
+ * The user this instance will report.
+ *
+ * @var string
+ */
+ private $_user;
+
+ /**
+ * Constructor
+ *
+ * @param string $user The user this instance should report.
+ */
+ public function __construct($user)
+ {
+ $this->_user = $user;
+ }
+
+ /**
+ * Get the current user ID.
+ *
+ * @return string The ID of the current user.
+ */
+ public function getCurrentUser()
+ {
+ return $this->_user;
+ }
+}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php
index ead548310..c0e2c62b1 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php
@@ -11,9 +11,6 @@
* @link http://pear.horde.org/index.php?package=Kolab_Session
*/
-/** We need the Auth library */
-require_once 'Horde/Auth.php';
-
/**
* The Horde_Kolab_Session class holds user details in the current session.
*
@@ -37,18 +34,18 @@ require_once 'Horde/Auth.php';
class Horde_Kolab_Session_Base implements Horde_Kolab_Session
{
/**
- * User ID.
+ * Kolab configuration parameters.
*
- * @var string
+ * @var array
*/
- private $_user_id;
+ private $_params;
/**
- * User GUID in the kolab user database.
+ * User ID.
*
* @var string
*/
- private $_user_guid;
+ private $_user_id;
/**
* Kolab UID of the user.
@@ -72,25 +69,25 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
private $_user_name;
/**
- * The connection parameters for the Kolab storage system.
+ * The imap server for the current user.
*
- * @var array
+ * @var string
*/
- private $_storage_params;
+ private $_imap_server;
/**
* The free/busy server for the current user.
*
- * @var array|PEAR_Error
+ * @var string
*/
private $_freebusy_server;
/**
- * Kolab configuration parameters.
+ * The connection parameters for the Kolab storage system.
*
* @var array
*/
- private $_params;
+ private $_storage_params;
/**
* The kolab user database connection.
@@ -107,64 +104,22 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
private $_storage;
/**
- * Provides authentication information for this object.
- *
- * @var Horde_Kolab_Session_Auth
- */
- private $_auth;
-
- /**
* Constructor.
*
* @param string $user The session will be setup for the user
* with this ID.
* @param Horde_Kolab_Server $server The connection to the Kolab user
* database.
- * @param array $params Kolb configuration settings.
+ * @param array $params Kolab configuration settings.
*/
public function __construct(
- $user,
- Horde_Kolab_Server $server,
+ $user_id,
+ Horde_Kolab_Server_Composite $server,
array $params
) {
+ $this->_user_id = $user_id;
$this->_server = $server;
$this->_params = $params;
-
- if (empty($user)) {
- $user = $this->getAnonymousUser();
- }
-
- $this->_user_id = $user;
- }
-
- /**
- * Return the name of the anonymous user if set.
- *
- * @return string The name of the anonymous user.
- */
- public function getAnonymousUser()
- {
- if (isset($this->_params['anonymous']['user'])) {
- return $this->_params['anonymous']['user'];
- }
- return '';
- }
-
- /**
- * Return the password of the anonymous user if set.
- *
- * @return string The password of the anonymous user.
- *
- * @throws Horde_Kolab_Session_Exception If the password is not set.
- */
- public function getAnonymousPass()
- {
- if (isset($this->_params['anonymous']['pass'])) {
- return $this->_params['anonymous']['pass'];
- }
- throw new Horde_Kolab_Session_Exception(
- 'No password for the anonymous user!'
- );
}
/**
@@ -177,11 +132,9 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
*
* @throws Horde_Kolab_Session_Exception If the connection failed.
*/
- public function connect(array $credentials)
+ public function connect(array $credentials = null)
{
- if (empty($credentials)) {
- $password = $this->getAnonymousPass();
- } else if (isset($credentials['password'])) {
+ if (isset($credentials['password'])) {
$password = $credentials['password'];
} else {
throw new Horde_Kolab_Session_Exception('Missing password!');
@@ -189,7 +142,6 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
try {
$this->_server->connect($this->_user_id, $password);
- $this->user_guid = $this->_server->server->getGuid();
$user_object = $this->_server->objects->fetch();
} catch (Horde_Kolab_Server_Exception $e) {
throw new Horde_Kolab_Session_Exception($e);
@@ -198,7 +150,8 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
$this->_initMail($user_object);
$this->_initUid($user_object);
$this->_initName($user_object);
- $this->_initHosts($user_object);
+ $this->_initImapServer($user_object);
+ $this->_initFreebusyServer($user_object);
}
/**
@@ -227,7 +180,7 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
private function _initUid(Horde_Kolab_Server_Object $user)
{
try {
- $this->_user_uid = $user_object->getExternal('Uid');
+ $this->_user_uid = $user->getExternal('Uid');
} catch (Horde_Kolab_Server_Exception_Novalue $e) {
$this->_user_uid = $this->_user_id;
}
@@ -243,56 +196,59 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
private function _initName(Horde_Kolab_Server_Object $user)
{
try {
- $this->_user_name = $user_object->getExternal('Fnln');
+ $this->_user_name = $user->getExternal('Fnln');
} catch (Horde_Kolab_Server_Exception_Novalue $e) {
$this->_user_name = $this->_user_id;
}
}
/**
- * Initialize the user host settings.
+ * Initialize the users imap server FQDN.
*
* @param Horde_Kolab_Server_Object $user The user object.
*
* @return NULL
- *
- * @todo Adapt to new structure of this class.
*/
- private function _initHosts(Horde_Kolab_Server_Object $user)
+ private function _initImapServer(Horde_Kolab_Server_Object $user)
{
- $result = $user_object->getServer('imap');
- if (!empty($result) && !is_a($result, 'PEAR_Error')) {
- $server = explode(':', $result, 2);
- if (!empty($server[0])) {
- $this->_imap_params['hostspec'] = $server[0];
- }
- if (!empty($server[1])) {
- $this->_imap_params['port'] = $server[1];
+ try {
+ $this->_imap_server = $user->getExternal('KolabHomeserver');
+ } catch (Horde_Kolab_Server_Exception_Novalue $e) {
+ if (isset($this->_params['imap']['server'])) {
+ $this->_imap_server = $this->_params['imap']['server'];
+ } else {
+ $this->_imap_server = 'localhost';
}
}
+ }
- $result = $user_object->getServer('freebusy');
- if (!empty($result) && !is_a($result, 'PEAR_Error')) {
- $this->freebusy_server = $result;
- }
-
- if (!isset($this->_imap_params['hostspec'])) {
- if (isset($conf['kolab']['imap']['server'])) {
- $this->_imap_params['hostspec'] = $conf['kolab']['imap']['server'];
+ /**
+ * Initialize the users free/busy URL.
+ *
+ * @param Horde_Kolab_Server_Object $user The user object.
+ *
+ * @return NULL
+ */
+ private function _initFreebusyServer(Horde_Kolab_Server_Object $user)
+ {
+ try {
+ $fb_server = $user->getExternal('KolabFreebusyHost');
+ } catch (Horde_Kolab_Server_Exception_Novalue $e) {
+ if (isset($this->_params['freebusy']['url'])) {
+ $this->_freebusy_server = $this->_params['freebusy']['url'];
+ return;
} else {
- $this->_imap_params['hostspec'] = 'localhost';
+ $fb_server = $this->_imap_server;
}
}
- if (!isset($this->_imap_params['port'])) {
- if (isset($conf['kolab']['imap']['port'])) {
- $this->_imap_params['port'] = $conf['kolab']['imap']['port'];
- } else {
- $this->_imap_params['port'] = 143;
- }
+ if (isset($this->_params['freebusy']['url_format'])) {
+ $fb_format = $this->_params['freebusy']['url_format'];
+ } else {
+ $fb_format = 'http://%s/freebusy';
}
- $this->_imap_params['protocol'] = 'imap/notls/novalidate-cert';
+ $this->_freebusy_server = sprintf($fb_format, $fb_server);
}
/**
@@ -321,6 +277,18 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
}
/**
+ * Set the user id used for connecting the session.
+ *
+ * @param string $id The user id.
+ *
+ * @return NULL
+ */
+ public function setId($id)
+ {
+ $this->_user_id = $id;
+ }
+
+ /**
* Return the users mail address.
*
* @return string The users mail address.
@@ -351,92 +319,34 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
}
/**
- * Return a connection to the Kolab storage system.
+ * Return the imap server.
*
- * @return Horde_Kolab_Storage The storage connection.
- *
- * @todo Adapt to new structure of this class.
+ * @return string The imap host for the current user.
*/
- public function getStorage()
+ public function getImapServer()
{
- if (!isset($this->_imap)) {
- $params = $this->getImapParams();
- if (is_a($params, 'PEAR_Error')) {
- return $params;
- }
-
- $imap = Horde_Kolab_IMAP::singleton(
- $params['hostspec'],
- $params['port'], true, false
- );
- if (is_a($imap, 'PEAR_Error')) {
- return $imap;
- }
-
- $result = $imap->connect(
- Horde_Auth::getAuth(),
- Horde_Auth::getCredential('password')
- );
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
- $this->_imap = $imap;
- }
- return $this->_imap;
+ return $this->_imap_server;
}
/**
- * Set the handler that provides getCurrentUser() for this instance.
+ * Return the freebusy server.
*
- * @param Horde_Kolab_Session_Auth $auth The authentication handler.
- *
- * @return NULL
+ * @return string The freebusy host for the current user.
*/
- public function setAuth(Horde_Kolab_Session_Auth $auth)
+ public function getFreebusyServer()
{
- $this->_auth = $auth;
+ return $this->_freebusy_server;
}
/**
- * Get the handler that provides getCurrentUser() for this instance.
- *
- * @return Horde_Kolab_Session_Auth The authentication handler.
- */
- public function getAuth()
- {
- if (empty($this->_auth)) {
- throw new Horde_Kolab_Session_Exception('Undefined auth handler!');
- }
- return $this->_auth;
- }
-
- /**
- * Does the current session still match the authentication information?
+ * Return a connection to the Kolab storage system.
*
- * @param string $user The user the session information is being requested
- * for. This is usually empty, indicating the current
- * user.
+ * @return Horde_Kolab_Storage The storage connection.
*
- * @return boolean True if the session is still valid.
+ * @todo Implement
*/
- public function isValid($user = null)
+ public function getStorage()
{
- if (empty($this->_auth)) {
- return false;
- }
- $current = $this->_auth->getCurrentUser();
- if (empty($current)) {
- $current = $this->getAnonymousUser();
- }
- if ($current != $this->user_mail) {
- return false;
- }
- if (empty($user)) {
- return true;
- }
- if ($user != $this->user_mail && $user != $this->user_uid) {
- return false;
- }
- return true;
+ throw new Horde_Kolab_Session_Exception('Not implemented!');
}
}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory.php
index aec6aea2f..5a8df0363 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory.php
@@ -1,7 +1,6 @@
bindImplementation(
- 'Horde_Kolab_Session_Auth',
- 'Horde_Kolab_Session_Auth_Horde'
- );
- }
+ public function getSessionConfiguration();
/**
- * Setup the machinery to create a Horde_Kolab_Sesssion_Store handler.
- *
- * @param Horde_Injector $injector The object providing our dependencies.
+ * Return the session storage driver.
*
- * @return NULL
+ * @return Horde_Kolab_Session_Storage The driver for storing sessions.
*/
- static protected function setupStore(Horde_Injector $injector)
- {
- $injector->bindImplementation(
- 'Horde_Kolab_Session_Store',
- 'Horde_Kolab_Session_Store_Sessionobjects'
- );
- }
+ public function getSessionStorage();
/**
- * Provide a log handler for Horde_Kolab_Session.
+ * Return the session validation driver.
*
- * @param Horde_Injector $injector The object providing our dependencies.
- * @param mixed $instance The log handler or empty if it
- * should be created.
+ * @param Horde_Kolab_Session $session The session to validate.
+ * @param Horde_Kolab_Session_Auth $auth The auth handler.
*
- * @return NULL
+ * @return Horde_Kolab_Session_Valid The driver for validating sessions.
*/
- static protected function setupLogger(
- Horde_Injector $injector,
- $instance = null
- ) {
- if (empty($instance)) {
- $instance = new Horde_Log_Logger(new Horde_Log_Handler_Null());
- }
- $injector->setInstance('Horde_Kolab_Session_Logger', $instance);
- }
+ public function getSessionValidator(
+ Horde_Kolab_Session $session,
+ Horde_Kolab_Session_Auth $auth
+ );
/**
- * Provide configuration settings for Horde_Kolab_Session.
+ * Validate the given session.
*
- * @param Horde_Injector $injector The object providing our
- * dependencies.
- * @param stdClass $configuration The configuration parameters.
+ * @param string $user The session will be validated for this user ID.
*
- * @return NULL
+ * @return boolean True if the given session is valid.
*/
- static protected function setupConfiguration(
- Horde_Injector $injector,
- stdClass $configuration
- ) {
- $injector->setInstance(
- 'Horde_Kolab_Session_Configuration', $configuration
- );
- }
+ public function validate(Horde_Kolab_Session $session, $user = null);
/**
- * Setup the machinery to create a Horde_Kolab_Sesssion handler.
+ * Returns a new session handler.
*
- * @param Horde_Injector $injector The object providing our dependencies.
+ * @param string $user The session will be setup for the user with this ID.
*
- * @return NULL
+ * @return Horde_Kolab_Session The concrete Kolab session reference.
*/
- static protected function setupSession(Horde_Injector $injector)
- {
- $injector->bindFactory(
- 'Horde_Kolab_Session',
- 'Horde_Kolab_Session_Factory',
- 'getSession'
- );
- }
+ public function createSession($user = null);
/**
- * Attempts to return a reference to a concrete Horde_Kolab_Session instance.
- *
- * It will only create a new instance if no Horde_Kolab_Session instance
- * currently exists or if a user ID has been specified that does not match the
- * user ID/user mail of the current session.
+ * Returns either a reference to a session handler with data retrieved from
+ * the session or a new session handler.
*
- * @param string $user The session will be setup for the user with
- * this ID.
- * @param array $credentials An array of login credentials. For Kolab,
- * this must contain a "password" entry.
+ * @param string $user The session will be setup for the user
+ * with this ID.
*
- * @return Horde_Kolab_Session The concrete Session reference.
- *
- * @throws Horde_Kolab_Session_Exception If the connection failed.
+ * @return Horde_Kolab_Session The concrete Kolab session reference.
*/
- static public function getSession(Horde_Injector $injector)
- {
- $config = $injector->getInstance('Horde_Kolab_Session_Config');
- $logger = $injector->getInstance('Horde_Kolab_Session_Logger');
- $store = $injector->getInstance('Horde_Kolab_Session_Store');
- $auth = $injector->getInstance('Horde_Kolab_Session_Auth');
-
- $session = $store->load();
-
- if (!empty($session)) {
- $session->setAuth($auth);
- $logged_session = new Horde_Kolab_Session_Logged($session, $logger);
- if ($logged_session->isValid($config->user)) {
- /**
- * Return only the core session handler as this is only about
- * data access and that needs no decorators.
- */
- return $session;
- }
- }
-
- $server = $injector->getInstance('Horde_Kolab_Server');
-
- $session = new Horde_Kolab_Session_Base($config->user, $server, $config->params);
- $session->setAuth($auth);
- /** If we created a new session handler it needs to be stored once */
- $session = new Horde_Kolab_Session_Stored($session, $store);
- $session = new Horde_Kolab_Session_Logged($session, $logger);
- $session->connect($config->credentials);
- return $session;
- }
-
- /**
- * Attempts to return a reference to a concrete Horde_Kolab_Session instance.
- *
- * It will only create a new instance if no Horde_Kolab_Session instance
- * currently exists
- *
- * @param string $user The session will be setup for the user with
- * this ID. For Kolab this must either contain
- * the user id or the primary user mail address.
- *
- * @param array $credentials An array of login credentials. For Kolab,
- * this must contain a "password" entry.
- *
- * @return Horde_Kolab_Session The concrete Session reference.
- *
- * @throws Horde_Kolab_Session_Exception If the connection failed.
- */
- static public function singleton($user = null, $credentials = null)
- {
- global $conf;
-
- if (!isset(self::$_instance)) {
- $config['logger'] = Horde::getLogger();
- $config['server'] = $conf['kolab']['server'];
- $config['session']['user'] = $user;
- $config['session']['credentials'] = $credentials;
- //@todo
- $config['session']['params'] = array();
- $injector = new Horde_Injector(new Horde_Injector_TopLevel());
- self::setup($config, $injector);
- self::$_instance = $injector->getInstance('Horde_Kolab_Session');
- /**
- * Once we are not building our own provider here we need to take
- * care that the resulting session is checked for validity. Invalid
- * sessions need to be discarded an recreated with createInstance().
- *
- * if (!self::$_instance->isValid()) {
- * self::$_instance = $injector->createInstance('Horde_Kolab_Session');
- * $injector->setInstance('Horde_Kolab_Session', self::$_instance);
- * }
- */
- }
- return self::$_instance;
- }
+ public function getSession($user = null);
}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Anonymous.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Anonymous.php
new file mode 100644
index 000000000..109e914b3
--- /dev/null
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Anonymous.php
@@ -0,0 +1,165 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * A factory decorator that adds an anonymous user to the generated instances.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Factory_Anonymous
+implements Horde_Kolab_Session_Factory
+{
+ /**
+ * The factory setup resulting from the configuration.
+ *
+ * @var Horde_Kolab_Session_Factory
+ */
+ private $_factory;
+
+ /**
+ * Anonymous user ID.
+ *
+ * @var string
+ */
+ private $_anonymous_id;
+
+ /**
+ * Anonymous password.
+ *
+ * @var string
+ */
+ private $_anonymous_pass;
+
+ /**
+ * Constructor.
+ *
+ * @param Horde_Kolab_Session_Factory $factory The base factory.
+ * @param string $user ID of the anonymous user.
+ * @param string $pass Password of the anonymous
+ * user.
+ */
+ public function __construct(
+ Horde_Kolab_Session_Factory $factory,
+ $user,
+ $pass
+ ) {
+ $this->_factory = $factory;
+ $this->_anonymous_id = $user;
+ $this->_anonymous_pass = $pass;
+ }
+
+ /**
+ * Return the kolab user db connection.
+ *
+ * @return Horde_Kolab_Server The server connection.
+ */
+ public function getServer()
+ {
+ return $this->_factory->getServer();
+ }
+
+ /**
+ * Return the auth handler for sessions.
+ *
+ * @return Horde_Kolab_Session_Auth The authentication handler.
+ */
+ public function getSessionAuth()
+ {
+ return $this->_factory->getSessionAuth();
+ }
+
+ /**
+ * Return the configuration parameters for the session.
+ *
+ * @return array The configuration values.
+ */
+ public function getSessionConfiguration()
+ {
+ return $this->_factory->getSessionConfiguration();
+ }
+
+ /**
+ * Return the session storage driver.
+ *
+ * @return Horde_Kolab_Session_Storage The driver for storing sessions.
+ */
+ public function getSessionStorage()
+ {
+ return $this->_factory->getSessionStorage();
+ }
+
+ /**
+ * Return the session validation driver.
+ *
+ * @return Horde_Kolab_Session_Valid The driver for validating sessions.
+ */
+ public function getSessionValidator(
+ Horde_Kolab_Session $session,
+ Horde_Kolab_Session_Auth $auth
+ ) {
+ return $this->_factory->getSessionValidator($session, $auth);
+ }
+
+ /**
+ * Validate the given session.
+ *
+ * @param string $user The session will be validated for this user ID.
+ *
+ * @return boolean True if thxe given session is valid.
+ */
+ public function validate(Horde_Kolab_Session $session, $user = null)
+ {
+ return $this->_factory->validate($session, $user);
+ }
+
+ /**
+ * Returns a new session handler.
+ *
+ * @param string $user The session will be setup for the user with this ID.
+ *
+ * @return Horde_Kolab_Session The concrete Kolab session reference.
+ */
+ public function createSession($user = null)
+ {
+ $session = $this->_factory->createSession($user);
+ $session = new Horde_Kolab_Session_Anonymous(
+ $session,
+ $this->_anonymous_id,
+ $this->_anonymous_pass
+ );
+ return $session;
+ }
+
+ /**
+ * Returns either a reference to a session handler with data retrieved from
+ * the session or a new session handler.
+ *
+ * @param string $user The session will be setup for the user
+ * with this ID.
+ *
+ * @return Horde_Kolab_Session The concrete Kolab session reference.
+ */
+ public function getSession($user = null)
+ {
+ return $this->_factory->getSession($user);
+ }
+}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Base.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Base.php
new file mode 100644
index 000000000..b9f9ea8fc
--- /dev/null
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Base.php
@@ -0,0 +1,105 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Revives an old Horde_Kolab_Session handler or generates a new one if
+ * required.
+ *
+ * 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_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+abstract class Horde_Kolab_Session_Factory_Base
+implements Horde_Kolab_Session_Factory
+{
+ /**
+ * Return the session validation driver.
+ *
+ * @return Horde_Kolab_Session_Valid The driver for validating sessions.
+ */
+ public function getSessionValidator(
+ Horde_Kolab_Session $session,
+ Horde_Kolab_Session_Auth $auth
+ ) {
+ $validator = new Horde_Kolab_Session_Valid_Base(
+ $session, $auth
+ );
+ return $validator;
+ }
+
+ /**
+ * Validate the given session.
+ *
+ * @param Horde_Kolab_Session $session The session to validate.
+ * @param string $user The session will be validated for
+ * this user ID.
+ *
+ * @return boolean True if the given session is valid.
+ */
+ public function validate(Horde_Kolab_Session $session, $user = null)
+ {
+ return $this->getSessionValidator(
+ $session,
+ $this->getSessionAuth()
+ )->isValid($user);
+ }
+
+ /**
+ * Returns a new session handler.
+ *
+ * @param string $user The session will be setup for the user with this ID.
+ *
+ * @return Horde_Kolab_Session The concrete Kolab session reference.
+ */
+ public function createSession($user = null)
+ {
+ $session = new Horde_Kolab_Session_Base(
+ $user,
+ $this->getServer(),
+ $this->getSessionConfiguration()
+ );
+ /** If we created a new session handler it needs to be stored once */
+ $session = new Horde_Kolab_Session_Stored(
+ $session,
+ $this->getSessionStorage()
+ );
+ return $session;
+ }
+
+ /**
+ * Returns either a reference to a session handler with data retrieved from
+ * the session or a new session handler.
+ *
+ * @param string $user The session will be setup for the user with this ID.
+ *
+ * @return Horde_Kolab_Session The concrete Kolab session reference.
+ */
+ public function getSession($user = null)
+ {
+ $storage = $this->getSessionStorage();
+ $session = $storage->load();
+
+ if (!empty($session) && $this->validate($session, $user)) {
+ return $session;
+ }
+ return $this->createSession($user);
+ }
+}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Configuration.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Configuration.php
new file mode 100644
index 000000000..cc48b83ed
--- /dev/null
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Configuration.php
@@ -0,0 +1,163 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * A factory that receives all required details via configuration parameters.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Factory_Configuration
+implements Horde_Kolab_Session_Factory
+{
+ /**
+ * Configuration parameters for the session.
+ *
+ * @var array
+ */
+ private $_configuration;
+
+ /**
+ * The factory setup resulting from the configuration.
+ *
+ * @var Horde_Kolab_Session_Factory
+ */
+ private $_factory;
+
+ /**
+ * Constructor.
+ *
+ * @param array $config Configuration parameters for the session.
+ */
+ public function __construct(
+ Horde_Kolab_Session_Factory $factory,
+ array $config
+ ) {
+ $this->_configuration = $config;
+
+ if (isset($config['logger'])) {
+ $factory = new Horde_Kolab_Session_Factory_Logged(
+ $factory, $config['logger']
+ );
+ }
+
+ if (isset($config['session']['anonymous']['user'])
+ && isset($config['session']['anonymous']['pass'])) {
+ $factory = new Horde_Kolab_Session_Factory_Anonymous(
+ $factory,
+ $config['session']['anonymous']['user'],
+ $config['session']['anonymous']['pass']
+ );
+ }
+
+ $this->_factory = $factory;
+ }
+
+ /**
+ * Return the kolab user db connection.
+ *
+ * @return Horde_Kolab_Server The server connection.
+ */
+ public function getServer()
+ {
+ return $this->_factory->getServer();
+ }
+
+ /**
+ * Return the auth handler for sessions.
+ *
+ * @return Horde_Kolab_Session_Auth The authentication handler.
+ */
+ public function getSessionAuth()
+ {
+ return $this->_factory->getSessionAuth();
+ }
+
+ /**
+ * Return the configuration parameters for the session.
+ *
+ * @return array The configuration values.
+ */
+ public function getSessionConfiguration()
+ {
+ return $this->_factory->getSessionConfiguration();
+ }
+
+ /**
+ * Return the session storage driver.
+ *
+ * @return Horde_Kolab_Session_Storage The driver for storing sessions.
+ */
+ public function getSessionStorage()
+ {
+ return $this->_factory->getSessionStorage();
+ }
+
+ /**
+ * Return the session validation driver.
+ *
+ * @return Horde_Kolab_Session_Valid The driver for validating sessions.
+ */
+ public function getSessionValidator(
+ Horde_Kolab_Session $session,
+ Horde_Kolab_Session_Auth $auth
+ ) {
+ return $this->_factory->getSessionValidator($session, $auth);
+ }
+
+ /**
+ * Validate the given session.
+ *
+ * @param string $user The session will be validated for this user ID.
+ *
+ * @return boolean True if the given session is valid.
+ */
+ public function validate(Horde_Kolab_Session $session, $user = null)
+ {
+ return $this->_factory->validate($session, $user);
+ }
+
+ /**
+ * Returns a new session handler.
+ *
+ * @param string $user The session will be setup for the user with this ID.
+ *
+ * @return Horde_Kolab_Session The concrete Kolab session reference.
+ */
+ public function createSession($user = null)
+ {
+ return $this->_factory->createSession($user);
+ }
+
+ /**
+ * Returns either a reference to a session handler with data retrieved from
+ * the session or a new session handler.
+ *
+ * @param string $user The session will be setup for the user
+ * with this ID.
+ *
+ * @return Horde_Kolab_Session The concrete Kolab session reference.
+ */
+ public function getSession($user = null)
+ {
+ return $this->_factory->getSession($user);
+ }
+}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Constructor.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Constructor.php
new file mode 100644
index 000000000..cda221e63
--- /dev/null
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Constructor.php
@@ -0,0 +1,122 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * A factory that receives all required details via the factory constructor.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Factory_Constructor
+extends Horde_Kolab_Session_Factory_Base
+{
+ /**
+ * The connection to the Kolab user db.
+ *
+ * @var Horde_Kolab_Server_Composite
+ */
+ private $_server;
+
+ /**
+ * The auth handler for the session.
+ *
+ * @var Horde_Kolab_Session_Auth
+ */
+ private $_auth;
+
+ /**
+ * Configuration parameters for the session.
+ *
+ * @var array
+ */
+ private $_configuration;
+
+ /**
+ * The storage handler for the session.
+ *
+ * @var Horde_Kolab_Session_Storage
+ */
+ private $_storage;
+
+ /**
+ * Constructor.
+ *
+ * @param Horde_Kolab_Server_Composite $server The connection to the Kolab
+ * user db.
+ * @param Horde_Kolab_Session_Auth $auth The auth handler for the
+ * session.
+ * @param array $config Configuration parameters for
+ * the session.
+ * @param Horde_Kolab_Session_Storage $storage The storage handler for the
+ * session.
+ */
+ public function __construct(
+ Horde_Kolab_Server_Composite $server,
+ Horde_Kolab_Session_Auth $auth,
+ array $config,
+ Horde_Kolab_Session_Storage $storage
+ ) {
+ $this->_server = $server;
+ $this->_auth = $auth;
+ $this->_configuration = $config;
+ $this->_storage = $storage;
+ }
+
+ /**
+ * Return the kolab user db connection.
+ *
+ * @return Horde_Kolab_Server The server connection.
+ */
+ public function getServer()
+ {
+ return $this->_server;
+ }
+
+ /**
+ * Return the auth handler for sessions.
+ *
+ * @return Horde_Kolab_Session_Auth The authentication handler.
+ */
+ public function getSessionAuth()
+ {
+ return $this->_auth;
+ }
+
+ /**
+ * Return the configuration parameters for the session.
+ *
+ * @return array The configuration values.
+ */
+ public function getSessionConfiguration()
+ {
+ return $this->_configuration;
+ }
+
+ /**
+ * Return the session storage driver.
+ *
+ * @return Horde_Kolab_Session_Storage The driver for storing sessions.
+ */
+ public function getSessionStorage()
+ {
+ return $this->_storage;
+ }
+}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Default.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Default.php
new file mode 100644
index 000000000..4150c4f8d
--- /dev/null
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Default.php
@@ -0,0 +1,104 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * A factory implementing the default policy.
+ *
+ * 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_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Factory_Default
+extends Horde_Kolab_Session_Factory_Base
+{
+ /**
+ * Configuration parameters for the session.
+ *
+ * @var array
+ */
+ private $_configuration;
+
+ /**
+ * The server factory used by this instance.
+ *
+ * @var array
+ */
+ private $_server_factory;
+
+ /**
+ * Constructor.
+ *
+ * @param array $config Configuration parameters for
+ * the session.
+ * @param Horde_Kolab_Server_Factory $factory The factory for the Kolab user
+ * db connection.
+ */
+ public function __construct(
+ array $config,
+ Horde_Kolab_Server_Factory $factory
+ ) {
+ $this->_configuration = $config;
+ $this->_server_factory = $factory;
+ }
+
+ /**
+ * Return the kolab user db connection.
+ *
+ * @return Horde_Kolab_Server The server connection.
+ */
+ public function getServer()
+ {
+ return $this->_server_factory->getServer();
+ }
+
+ /**
+ * Return the auth handler for sessions.
+ *
+ * @return Horde_Kolab_Session_Auth The authentication handler.
+ */
+ public function getSessionAuth()
+ {
+ $auth = new Horde_Kolab_Session_Auth_Horde();
+ return $auth;
+ }
+
+ /**
+ * Return the configuration parameters for the session.
+ *
+ * @return array The configuration values.
+ */
+ public function getSessionConfiguration()
+ {
+ return $this->_configuration;
+ }
+
+ /**
+ * Return the session storage driver.
+ *
+ * @return Horde_Kolab_Session_Storage The driver for storing sessions.
+ */
+ public function getSessionStorage()
+ {
+ $storage = new Horde_Kolab_Session_Storage_Sessionobjects(
+ Horde_SessionObjects::singleton()
+ );
+ return $storage;
+ }
+}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Injector.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Injector.php
new file mode 100644
index 000000000..1472e635e
--- /dev/null
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Injector.php
@@ -0,0 +1,163 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * A factory using a Horde_Injector instance.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Factory_Injector
+extends Horde_Kolab_Session_Factory_Base
+{
+ /**
+ * Configuration parameters for the session.
+ *
+ * @var array
+ */
+ private $_configuration;
+
+ /**
+ * The injector.
+ *
+ * @var Horde_Injector
+ */
+ private $_injector;
+
+ /**
+ * Constructor.
+ *
+ * @param array $config Configuration parameters for the session.
+ * @param Horde_Injector $injector The injector to use.
+ */
+ public function __construct(
+ array $config,
+ Horde_Injector $injector
+ ) {
+ $this->_configuration = $config;
+ $this->_injector = $injector;
+ $this->_setup();
+ }
+
+ /**
+ * Setup the machinery to create Horde_Kolab_Session objects.
+ *
+ * @return NULL
+ */
+ private function _setup()
+ {
+ $this->_setupAuth();
+ $this->_setupStorage();
+ $this->_setupConfiguration();
+ $this->_setupSession();
+ }
+
+ /**
+ * Setup the machinery to create a Horde_Kolab_Session_Auth handler.
+ *
+ * @return NULL
+ */
+ private function _setupAuth()
+ {
+ $this->_injector->bindImplementation(
+ 'Horde_Kolab_Session_Auth',
+ 'Horde_Kolab_Session_Auth_Horde'
+ );
+ }
+
+ /**
+ * Setup the machinery to create a Horde_Kolab_Session_Storage handlers.
+ *
+ * @return NULL
+ */
+ private function _setupStorage()
+ {
+ $this->_injector->bindImplementation(
+ 'Horde_Kolab_Session_Storage',
+ 'Horde_Kolab_Session_Storage_Sessionobjects'
+ );
+ }
+
+ /**
+ * Provide configuration settings for Horde_Kolab_Session.
+ *
+ * @return NULL
+ */
+ private function _setupConfiguration() {
+ $this->_injector->setInstance(
+ 'Horde_Kolab_Session_Configuration', $this->_configuration
+ );
+ }
+
+ /**
+ * Setup the machinery to create a Horde_Kolab_Session handler.
+ *
+ * @return NULL
+ */
+ private function _setupSession()
+ {
+ $this->_injector->bindFactory(
+ 'Horde_Kolab_Session',
+ 'Horde_Kolab_Session_Factory_Injector',
+ 'getSession'
+ );
+ }
+
+ /**
+ * Return the kolab user db connection.
+ *
+ * @return Horde_Kolab_Server The server connection.
+ */
+ public function getServer()
+ {
+ return $this->_injector->getInstance('Horde_Kolab_Server');
+ }
+
+ /**
+ * Return the auth handler for sessions.
+ *
+ * @return Horde_Kolab_Session_Auth The authentication handler.
+ */
+ public function getSessionAuth()
+ {
+ return $this->_injector->getInstance('Horde_Kolab_Session_Auth');
+ }
+
+ /**
+ * Return the configuration parameters for the session.
+ *
+ * @return array The configuration values.
+ */
+ public function getSessionConfiguration()
+ {
+ return $this->_injector->getInstance('Horde_Kolab_Session_Configuration');
+ }
+
+ /**
+ * Return the session storage driver.
+ *
+ * @return Horde_Kolab_Session_Storage The driver for storing sessions.
+ */
+ public function getSessionStorage()
+ {
+ return $this->_injector->getInstance('Horde_Kolab_Session_Storage');
+ }
+}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Logged.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Logged.php
new file mode 100644
index 000000000..e69087bb2
--- /dev/null
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Logged.php
@@ -0,0 +1,150 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * A factory decorator that adds logging to the generated instances.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Factory_Logged
+implements Horde_Kolab_Session_Factory
+{
+ /**
+ * The factory setup resulting from the configuration.
+ *
+ * @var Horde_Kolab_Session_Factory
+ */
+ private $_factory;
+
+ /**
+ * The logger.
+ *
+ * @var mixed
+ */
+ private $_logger;
+
+ /**
+ * Constructor.
+ *
+ * @param Horde_Kolab_Session_Factory $factory The base factory.
+ * @param mixed $logger The logger isntance.
+ */
+ public function __construct(Horde_Kolab_Session_Factory $factory, $logger)
+ {
+ $this->_factory = $factory;
+ $this->_logger = $logger;
+ }
+
+ /**
+ * Return the kolab user db connection.
+ *
+ * @return Horde_Kolab_Server The server connection.
+ */
+ public function getServer()
+ {
+ return $this->_factory->getServer();
+ }
+
+ /**
+ * Return the auth handler for sessions.
+ *
+ * @return Horde_Kolab_Session_Auth The authentication handler.
+ */
+ public function getSessionAuth()
+ {
+ return $this->_factory->getSessionAuth();
+ }
+
+ /**
+ * Return the configuration parameters for the session.
+ *
+ * @return array The configuration values.
+ */
+ public function getSessionConfiguration()
+ {
+ return $this->_factory->getSessionConfiguration();
+ }
+
+ /**
+ * Return the session storage driver.
+ *
+ * @return Horde_Kolab_Session_Storage The driver for storing sessions.
+ */
+ public function getSessionStorage()
+ {
+ return $this->_factory->getSessionStorage();
+ }
+
+ /**
+ * Return the session validation driver.
+ *
+ * @return Horde_Kolab_Session_Valid The driver for validating sessions.
+ */
+ public function getSessionValidator(
+ Horde_Kolab_Session $session,
+ Horde_Kolab_Session_Auth $auth
+ ) {
+ $valid = $this->_factory->getSessionValidator($session, $auth);
+ $valid = new Horde_Kolab_Session_Valid_Logged($valid, $this->_logger);
+ return $valid;
+ }
+
+ /**
+ * Validate the given session.
+ *
+ * @param string $user The session will be validated for this user ID.
+ *
+ * @return boolean True if thxe given session is valid.
+ */
+ public function validate(Horde_Kolab_Session $session, $user = null)
+ {
+ return $this->_factory->validate($session, $user);
+ }
+
+ /**
+ * Returns a new session handler.
+ *
+ * @param string $user The session will be setup for the user with this ID.
+ *
+ * @return Horde_Kolab_Session The concrete Kolab session reference.
+ */
+ public function createSession($user = null)
+ {
+ $session = $this->_factory->createSession($user);
+ $session = new Horde_Kolab_Session_Logged($session, $this->_logger);
+ return $session;
+ }
+
+ /**
+ * Returns either a reference to a session handler with data retrieved from
+ * the session or a new session handler.
+ *
+ * @param string $user The session will be setup for the user
+ * with this ID.
+ *
+ * @return Horde_Kolab_Session The concrete Kolab session reference.
+ */
+ public function getSession($user = null)
+ {
+ return $this->_factory->getSession($user);
+ }
+}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Logged.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Logged.php
index 4d41472a0..bba8424bd 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Logged.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Logged.php
@@ -66,20 +66,20 @@ class Horde_Kolab_Session_Logged implements Horde_Kolab_Session
*
* @throws Horde_Kolab_Session_Exception If the connection failed.
*/
- public function connect(array $credentials)
+ public function connect(array $credentials = null)
{
try {
$this->_session->connect($credentials);
$this->_logger->info(
sprintf(
- 'Connected Kolab session for user %s.',
+ "Connected Kolab session for \"%s\".",
$this->_session->getId()
)
);
} catch (Horde_Kolab_Session_Exception $e) {
$this->_logger->err(
sprintf(
- 'Failed to connect Kolab session for user %s: Error was: %s',
+ "Failed to connect Kolab session for \"%s\". Error was: %s",
$this->_session->getId(), $e->getMessage()
)
);
@@ -98,6 +98,18 @@ class Horde_Kolab_Session_Logged implements Horde_Kolab_Session
}
/**
+ * Set the user id used for connecting the session.
+ *
+ * @param string $id The user id.
+ *
+ * @return NULL
+ */
+ public function setId($id)
+ {
+ $this->_session->setId($id);
+ }
+
+ /**
* Return the users mail address.
*
* @return string The users mail address.
@@ -128,59 +140,32 @@ class Horde_Kolab_Session_Logged implements Horde_Kolab_Session
}
/**
- * Return a connection to the Kolab storage system.
+ * Return the imap server.
*
- * @return Horde_Kolab_Storage The storage connection.
+ * @return string The imap host for the current user.
*/
- public function getStorage()
+ public function getImapServer()
{
- return $this->_session->getStorage();
+ return $this->_session->getImapServer();
}
/**
- * Set the handler that provides getCurrentUser() for this instance.
+ * Return the freebusy server.
*
- * @param Horde_Kolab_Session_Auth $auth The authentication handler.
- *
- * @return NULL
+ * @return string The freebusy host for the current user.
*/
- public function setAuth(Horde_Kolab_Session_Auth $auth)
+ public function getFreebusyServer()
{
- $this->_session->setAuth($auth);
+ return $this->_session->getFreebusyServer();
}
/**
- * Get the handler that provides getCurrentUser() for this instance.
- *
- * @return Horde_Kolab_Session_Auth The authentication handler.
- */
- public function getAuth()
- {
- return $this->_session->getAuth();
- }
-
- /**
- * Does the current session still match the authentication information?
- *
- * @param string $user The user the session information is being requested
- * for. This is usually empty, indicating the current
- * user.
+ * Return a connection to the Kolab storage system.
*
- * @return boolean True if the session is still valid.
+ * @return Horde_Kolab_Storage The storage connection.
*/
- public function isValid($user = null)
+ public function getStorage()
{
- $result = $this->_session->isValid($user);
- if ($result === false) {
- $this->_logger->info(
- sprintf(
- 'Invalid Kolab session for current user %s, requested user %s and stored user %s.',
- $this->getAuth()->getCurrentUser(),
- $user,
- $this->_session->getMail()
- )
- );
-
- }
+ return $this->_session->getStorage();
}
}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Singleton.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Singleton.php
new file mode 100644
index 000000000..edef55c12
--- /dev/null
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Singleton.php
@@ -0,0 +1,70 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * A singleton pattern providing Horde_Kolab_Session instances.
+ *
+ * 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_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Singleton
+{
+ /**
+ * Horde_Kolab_Session instance.
+ *
+ * @var Horde_Kolab_Session
+ */
+ static private $_instance;
+
+ /**
+ * Attempts to return a reference to a concrete Horde_Kolab_Session instance.
+ *
+ * It will only create a new instance if no Horde_Kolab_Session instance
+ * currently exists
+ *
+ * @param string $user The session will be setup for the user with
+ * this ID. For Kolab this must either contain
+ * the user id or the primary user mail address.
+ *
+ * @param array $credentials An array of login credentials. For Kolab,
+ * this must contain a "password" entry.
+ *
+ * @return Horde_Kolab_Session The concrete Session reference.
+ *
+ * @throws Horde_Kolab_Session_Exception If the connection failed.
+ */
+ static public function singleton($user = null, array $credentials = null)
+ {
+ global $conf;
+
+ if (!isset(self::$_instance)) {
+ $config['logger'] = Horde::getLogger();
+ $config['server'] = $conf['kolab']['server'];
+ $server_factory = new Horde_Kolab_Server_Factory_Default($config);
+ $server_factory = new Horde_Kolab_Server_Factory_Configuration($server_factory, $config);
+ $factory = new Horde_Kolab_Session_Factory_Default($config, $server_factory);
+ $factory = new Horde_Kolab_Session_Factory_Configuration($factory, $config);
+ self::$_instance = $factory->getSession($user);
+ self::$_instance->connect($credentials);
+ }
+ return self::$_instance;
+ }
+}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage.php
new file mode 100644
index 000000000..5eab9a754
--- /dev/null
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage.php
@@ -0,0 +1,46 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Defines storage containers for the Kolab session information.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+interface Horde_Kolab_Session_Storage
+{
+ /**
+ * Load the session information.
+ *
+ * @return Horde_Kolab_Session|boolean The session information or false if
+ * it could not be loaded.
+ */
+ public function load();
+
+ /**
+ * Lave the session information.
+ *
+ * @param Horde_Kolab_Session $session The session information.
+ *
+ * @return NULL
+ */
+ public function save(Horde_Kolab_Session $session);
+}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Mock.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Mock.php
new file mode 100644
index 000000000..4d3a4155c
--- /dev/null
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Mock.php
@@ -0,0 +1,58 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * A mock container for the Kolab session information.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Storage_Mock
+implements Horde_Kolab_Session_Storage
+{
+ /**
+ * The session information.
+ */
+ public $session;
+
+ /**
+ * Load the session information.
+ *
+ * @return Horde_Kolab_Session|boolean The session information or false if
+ * it could not be loaded.
+ */
+ public function load()
+ {
+ return false;
+ }
+
+ /**
+ * Save the session information.
+ *
+ * @param Horde_Kolab_Session $session The session information.
+ *
+ * @return NULL
+ */
+ public function save(Horde_Kolab_Session $session)
+ {
+ $this->session = $session;
+ }
+}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Sessionobjects.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Sessionobjects.php
new file mode 100644
index 000000000..c7163fe80
--- /dev/null
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Sessionobjects.php
@@ -0,0 +1,70 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Defines storage containers for the Kolab session information.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Storage_Sessionobjects
+implements Horde_Kolab_Session_Storage
+{
+ /**
+ * The handler for session objects.
+ *
+ * @var Horde_SessionObjects
+ */
+ private $_session_objects;
+
+ /**
+ * Constructor
+ *
+ * @param Horde_SessionObjects $session_objects The session objects handler.
+ */
+ public function __construct(Horde_SessionObjects $session_objects)
+ {
+ $this->_session_objects = $session_objects;
+ }
+
+ /**
+ * Load the session information.
+ *
+ * @return Horde_Kolab_Session|boolean The session information or false if
+ * it could not be loaded.
+ */
+ public function load()
+ {
+ return $this->_session_objects->query('kolab_session');
+ }
+
+ /**
+ * Save the session information.
+ *
+ * @param Horde_Kolab_Session $session The session information.
+ *
+ * @return NULL
+ */
+ public function save(Horde_Kolab_Session $session)
+ {
+ $this->_session_objects->overwrite('kolab_session', $session);
+ }
+}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Store.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Store.php
deleted file mode 100644
index d59950d1c..000000000
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Store.php
+++ /dev/null
@@ -1,46 +0,0 @@
-
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Kolab_Session
- */
-
-/**
- * Defines storage containers for the Kolab session information.
- *
- * 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 Kolab
- * @package Kolab_Session
- * @author Gunnar Wrobel
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Kolab_Session
- */
-interface Horde_Kolab_Session_Store
-{
- /**
- * Load the session information.
- *
- * @return Horde_Kolab_Session|boolean The session information or false if
- * it could not be loaded.
- */
- public function load();
-
- /**
- * Lave the session information.
- *
- * @param Horde_Kolab_Session $session The session information.
- *
- * @return NULL
- */
- public function save(Horde_Kolab_Session $session);
-}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Store/Mock.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Store/Mock.php
deleted file mode 100644
index 0ee124622..000000000
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Store/Mock.php
+++ /dev/null
@@ -1,61 +0,0 @@
-
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Kolab_Session
- */
-
-/** We need the Auth library */
-require_once 'Horde/Auth.php';
-
-/**
- * A mock container for the Kolab session information.
- *
- * 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 Kolab
- * @package Kolab_Session
- * @author Gunnar Wrobel
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Kolab_Session
- */
-class Horde_Kolab_Session_Store_Mock
-implements Horde_Kolab_Session_Store
-{
- /**
- * The session information.
- */
- public $session;
-
- /**
- * Load the session information.
- *
- * @return Horde_Kolab_Session|boolean The session information or false if
- * it could not be loaded.
- */
- public function load()
- {
- return false;
- }
-
- /**
- * Save the session information.
- *
- * @param Horde_Kolab_Session $session The session information.
- *
- * @return NULL
- */
- public function save(Horde_Kolab_Session $session)
- {
- $this->$session = $session;
- }
-}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Store/Sessionobjects.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Store/Sessionobjects.php
deleted file mode 100644
index ab238fcbf..000000000
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Store/Sessionobjects.php
+++ /dev/null
@@ -1,66 +0,0 @@
-
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Kolab_Session
- */
-
-/** We need the Auth library */
-require_once 'Horde/Auth.php';
-
-/**
- * Defines storage containers for the Kolab session information.
- *
- * 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 Kolab
- * @package Kolab_Session
- * @author Gunnar Wrobel
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Kolab_Session
- */
-class Horde_Kolab_Session_Store_Sessionobjects
-implements Horde_Kolab_Session_Store
-{
- /**
- * Load the session information.
- *
- * @return Horde_Kolab_Session|boolean The session information or false if
- * it could not be loaded.
- */
- public function load()
- {
- return $this->getSessionObjects()->query('kolab_session');
- }
-
- /**
- * Save the session information.
- *
- * @param Horde_Kolab_Session $session The session information.
- *
- * @return NULL
- */
- public function save(Horde_Kolab_Session $session)
- {
- $this->getSessionObjects()->overwrite('kolab_session', $session, false);
- }
-
- /**
- * Fetch the handler for session objects.
- *
- * @return Horde_SessionObjects The session objects.
- */
- private function _getSessionObjects()
- {
- return Horde_SessionObjects::singleton();
- }
-}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Stored.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Stored.php
index d91d414ea..c1455908f 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Stored.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Stored.php
@@ -37,9 +37,9 @@ class Horde_Kolab_Session_Stored implements Horde_Kolab_Session
/**
* The storage.
*
- * @var Horde_Kolab_Session_Store
+ * @var Horde_Kolab_Session_Storage
*/
- private $_store;
+ private $_storage;
/**
* Has the storage been connected successfully?
@@ -51,15 +51,15 @@ class Horde_Kolab_Session_Stored implements Horde_Kolab_Session
/**
* Constructor.
*
- * @param Horde_Kolab_Session $session The session handler.
- * @param Horde_Kolab_Session_Store $store Store the session here.
+ * @param Horde_Kolab_Session $session The session handler.
+ * @param Horde_Kolab_Session_Storage $storage Store the session here.
*/
public function __construct(
Horde_Kolab_Session $session,
- Horde_Kolab_Session_Store $store
+ Horde_Kolab_Session_Storage $storage
) {
$this->_session = $session;
- $this->_store = $store;
+ $this->_storage = $storage;
}
/**
@@ -69,7 +69,7 @@ class Horde_Kolab_Session_Stored implements Horde_Kolab_Session
*/
public function __destruct()
{
- $this->_store->save($this->_session);
+ $this->_storage->save($this->_session);
}
/**
@@ -80,7 +80,7 @@ class Horde_Kolab_Session_Stored implements Horde_Kolab_Session
*
* @return NULL
*/
- public function connect(array $credentials)
+ public function connect(array $credentials = null)
{
$this->_session->connect($credentials);
$this->_connected = true;
@@ -97,6 +97,18 @@ class Horde_Kolab_Session_Stored implements Horde_Kolab_Session
}
/**
+ * Set the user id used for connecting the session.
+ *
+ * @param string $id The user id.
+ *
+ * @return NULL
+ */
+ public function setId($id)
+ {
+ $this->_session->setId($id);
+ }
+
+ /**
* Return the users mail address.
*
* @return string The users mail address.
@@ -127,49 +139,32 @@ class Horde_Kolab_Session_Stored implements Horde_Kolab_Session
}
/**
- * Return a connection to the Kolab storage system.
+ * Return the imap server.
*
- * @return Horde_Kolab_Storage The storage connection.
+ * @return string The imap host for the current user.
*/
- public function getStorage()
+ public function getImapServer()
{
- return $this->_session->getStorage();
+ return $this->_session->getImapServer();
}
/**
- * Set the handler that provides getCurrentUser() for this instance.
- *
- * @param Horde_Kolab_Session_Auth $auth The authentication handler.
+ * Return the freebusy server.
*
- * @return NULL
- */
- public function setAuth(Horde_Kolab_Session_Auth $auth)
- {
- $this->_session->setAuth($auth);
- }
-
- /**
- * Get the handler that provides getCurrentUser() for this instance.
- *
- * @return Horde_Kolab_Session_Auth The authentication handler.
+ * @return string The freebusy host for the current user.
*/
- public function getAuth()
+ public function getFreebusyServer()
{
- return $this->_session->getAuth();
+ return $this->_session->getFreebusyServer();
}
/**
- * Does the current session still match the authentication information?
- *
- * @param string $user The user the session information is being requested
- * for. This is usually empty, indicating the current
- * user.
+ * Return a connection to the Kolab storage system.
*
- * @return boolean True if the session is still valid.
+ * @return Horde_Kolab_Storage The storage connection.
*/
- public function isValid($user = null)
+ public function getStorage()
{
- $this->_connected = $this->_session->isValid($user);
- return $this->_connected;
+ return $this->_session->getStorage();
}
}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid.php
new file mode 100644
index 000000000..a1c2fe8b5
--- /dev/null
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid.php
@@ -0,0 +1,60 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Interface for session validators.
+ *
+ * The core user credentials (login, pass) are kept within the Auth module and
+ * can be retrieved using Auth::getAuth() respectively
+ * Auth::getCredential('password'). Any additional Kolab user data
+ * relevant for the user session should be accessed via the Horde_Kolab_Session
+ * class.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+interface Horde_Kolab_Session_Valid
+{
+ /**
+ * Does the current session still match the authentication information?
+ *
+ * @param string $user The user the session information is being requested
+ * for. This is usually empty, indicating the current
+ * user.
+ *
+ * @return boolean True if the session is still valid.
+ */
+ public function isValid($user = null);
+
+ /**
+ * Return the session this validator checks.
+ *
+ * @return Horde_Kolab_Session The session checked by this validator.
+ */
+ public function getSession();
+
+ /**
+ * Return the auth driver of this validator.
+ *
+ * @return Horde_Kolab_Session_Auth The auth driver set for this validator.
+ */
+ public function getAuth();
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Base.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Base.php
new file mode 100644
index 000000000..1e6be37b8
--- /dev/null
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Base.php
@@ -0,0 +1,108 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * A class to check if the given session is valid.
+ *
+ * The core user credentials (login, pass) are kept within the Auth module and
+ * can be retrieved using Auth::getAuth() respectively
+ * Auth::getCredential('password'). Any additional Kolab user data
+ * relevant for the user session should be accessed via the Horde_Kolab_Session
+ * class.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Valid_Base implements Horde_Kolab_Session_Valid
+{
+ /**
+ * The session handler this instance provides with anonymous access.
+ *
+ * @var Horde_Kolab_Session
+ */
+ private $_session;
+
+ /**
+ * Provides authentication information for this object.
+ *
+ * @var Horde_Kolab_Session_Auth
+ */
+ private $_auth;
+
+ /**
+ * Constructor.
+ *
+ * @param Horde_Kolab_Session $session The session that should be
+ * validated.
+ * @param Horde_Kolab_Session_Auth $auth The authentication handler.
+ */
+ public function __construct(
+ Horde_Kolab_Session $session,
+ Horde_Kolab_Session_Auth $auth
+ ) {
+ $this->_session = $session;
+ $this->_auth = $auth;
+ }
+
+ /**
+ * Does the current session still match the authentication information?
+ *
+ * @param string $user The user the session information is being requested
+ * for. This is usually empty, indicating the current
+ * user.
+ *
+ * @return boolean True if the session is still valid.
+ */
+ public function isValid($user = null)
+ {
+ $mail = $this->_session->getMail();
+ if ($this->_auth->getCurrentUser() != $mail) {
+ return false;
+ }
+ if (empty($user)) {
+ return true;
+ }
+ if ($user != $mail && $user != $this->_session->getUid()) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Return the session this validator checks.
+ *
+ * @return Horde_Kolab_Session The session checked by this validator.
+ */
+ public function getSession()
+ {
+ return $this->_session;
+ }
+
+ /**
+ * Return the auth driver of this validator.
+ *
+ * @return Horde_Kolab_Session_Auth The auth driver set for this validator.
+ */
+ public function getAuth()
+ {
+ return $this->_auth;
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Logged.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Logged.php
new file mode 100644
index 000000000..a21b88af6
--- /dev/null
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Logged.php
@@ -0,0 +1,103 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * A logger for Horde_Kolab_Session_Valid validators.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Valid_Logged implements Horde_Kolab_Session_Valid
+{
+ /**
+ * The valid handler.
+ *
+ * @var Horde_Kolab_Session_Valid
+ */
+ private $_valid;
+
+ /**
+ * The logger.
+ *
+ * @var mixed
+ */
+ private $_logger;
+
+ /**
+ * Constructor.
+ *
+ * The provided logger class needs to implement the methods info() and
+ * err().
+ *
+ * @param Horde_Kolab_Session_Valid $valid The validator.
+ * @param mixed $logger The logger instance.
+ */
+ public function __construct(Horde_Kolab_Session_Valid $valid, $logger)
+ {
+ $this->_valid = $valid;
+ $this->_logger = $logger;
+ }
+
+ /**
+ * Does the current session still match the authentication information?
+ *
+ * @param string $user The user the session information is being requested
+ * for. This is usually empty, indicating the current
+ * user.
+ *
+ * @return boolean True if the session is still valid.
+ */
+ public function isValid($user = null)
+ {
+ $result = $this->_valid->isValid($user);
+ if ($result === false) {
+ $this->_logger->info(
+ sprintf(
+ "Invalid Kolab session for current user \"%s\", requested user \"%s\" and stored user \"%s\".",
+ $this->_valid->getAuth()->getCurrentUser(),
+ $user,
+ $this->_valid->getSession()->getMail()
+ )
+ );
+ }
+ return $result;
+ }
+
+ /**
+ * Return the session this validator checks.
+ *
+ * @return Horde_Kolab_Session The session checked by this validator.
+ */
+ public function getSession()
+ {
+ return $this->_valid->getSession();
+ }
+
+ /**
+ * Return the auth driver of this validator.
+ *
+ * @return Horde_Kolab_Session_Auth The auth driver set for this validator.
+ */
+ public function getAuth()
+ {
+ return $this->_valid->getAuth();
+ }
+}
diff --git a/framework/Kolab_Session/package.xml b/framework/Kolab_Session/package.xml
index c62ce5052..610c6b1a4 100644
--- a/framework/Kolab_Session/package.xml
+++ b/framework/Kolab_Session/package.xml
@@ -46,6 +46,39 @@ http://pear.php.net/dtd/package-2.0.xsd">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -70,31 +103,59 @@ http://pear.php.net/dtd/package-2.0.xsd">
1.4.0b1
- Auth
+ Kolab_Server
+ pear.horde.org
+
+
+ Kolab_Storage
pear.horde.org
- Kolab_Server
+ Auth
pear.horde.org
- SessionObjects
+ Injector
pear.horde.org
- PHPUnit
- pear.phpunit.de
+ Log
+ pear.horde.org
+
+
+ SessionObjects
+ pear.horde.org
-
- ldap
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/AllTests.php b/framework/Kolab_Session/test/Horde/Kolab/Session/AllTests.php
index 7eebe26b1..84267a5e1 100644
--- a/framework/Kolab_Session/test/Horde/Kolab/Session/AllTests.php
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/AllTests.php
@@ -2,7 +2,6 @@
/**
* All tests for the Horde_Kolab_Session:: package.
*
- *
* PHP version 5
*
* @category Kolab
@@ -20,14 +19,13 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
}
/**
- * The Autoloader allows us to omit "require/include" statements.
+ * Prepare the test setup.
*/
-require_once 'Horde/Autoloader.php';
+require_once dirname(__FILE__) . '/Autoload.php';
/**
* Combine the tests for this package.
*
- *
* Copyright 2007-2009 The Horde Project (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
@@ -69,8 +67,10 @@ class Horde_Kolab_Session_AllTests
$pathname = $file->getPathname();
require $pathname;
- $class = str_replace(DIRECTORY_SEPARATOR, '_',
- preg_replace("/^$baseregexp(.*)\.php/", '\\1', $pathname));
+ $class = str_replace(
+ DIRECTORY_SEPARATOR, '_',
+ preg_replace("/^$baseregexp(.*)\.php/", '\\1', $pathname)
+ );
$suite->addTestSuite('Horde_Kolab_Session_' . $class);
}
}
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Autoload.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Autoload.php
index 609861518..3048c4ae5 100644
--- a/framework/Kolab_Session/test/Horde/Kolab/Session/Autoload.php
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Autoload.php
@@ -5,29 +5,27 @@
* PHP version 5
*
* @category Kolab
- * @package Kolab_Server
+ * @package Kolab_Session
* @author Gunnar Wrobel
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Kolab_Server
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
*/
-/**
- * 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 (!spl_autoload_functions()) {
+ spl_autoload_register(
+ create_function(
+ '$class',
+ '$filename = str_replace(array(\'::\', \'_\'), \'/\', $class);'
+ . '$err_mask = E_ALL ^ E_WARNING;'
+ . '$oldErrorReporting = error_reporting($err_mask);'
+ . 'include "$filename.php";'
+ . 'error_reporting($oldErrorReporting);'
+ )
+ );
+}
- 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);
- }
+/** Catch strict standards */
+error_reporting(E_ALL | E_STRICT);
- Horde_Autoloader::addClassPath(HORE_KOLAB_SERVER_TESTS);
-}
+/** Load the basic test definition */
+require_once dirname(__FILE__) . '/SessionTestCase.php';
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/AnonymousTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/AnonymousTest.php
new file mode 100644
index 000000000..05b0f2b24
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/AnonymousTest.php
@@ -0,0 +1,174 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../Autoload.php';
+
+/**
+ * Test the anonymous decorator.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Class_AnonymousTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function testMethodConnectHasPostconditionThatTheConnectionHasBeenEstablishedAsAnonymousUserIfRequired()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue(null));
+ $session->expects($this->once())
+ ->method('setId')
+ ->with('anonymous');
+ $session->expects($this->once())
+ ->method('connect')
+ ->with(array('password' => 'pass'));
+ $anonymous = new Horde_Kolab_Session_Anonymous(
+ $session, 'anonymous', 'pass'
+ );
+ $anonymous->connect();
+ }
+
+ public function testMethodGetidReturnsNullIfConnectedUserIsAnonymousUser()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue('anonymous'));
+ $anonymous = new Horde_Kolab_Session_Anonymous(
+ $session, 'anonymous', 'pass'
+ );
+ $this->assertNull($anonymous->getId());
+ }
+
+ public function testMethodConnectGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('connect')
+ ->with(array('password' => 'pass'));
+ $anonymous = new Horde_Kolab_Session_Anonymous(
+ $session, 'anonymous', 'pass'
+ );
+ $anonymous->connect(array('password' => 'pass'));
+ }
+
+ public function testMethodGetidGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue('1'));
+ $anonymous = new Horde_Kolab_Session_Anonymous(
+ $session, 'anonymous', 'pass'
+ );
+ $anonymous->getId();
+ }
+
+ public function testMethodSetidGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('setId')
+ ->with('1');
+ $anonymous = new Horde_Kolab_Session_Anonymous(
+ $session, 'anonymous', 'pass'
+ );
+ $anonymous->setId('1');
+ }
+
+ public function testMethodGetmailGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getMail')
+ ->will($this->returnValue('1'));
+ $anonymous = new Horde_Kolab_Session_Anonymous(
+ $session, 'anonymous', 'pass'
+ );
+ $anonymous->getMail();
+ }
+
+ public function testMethodGetuidGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getUid')
+ ->will($this->returnValue('1'));
+ $anonymous = new Horde_Kolab_Session_Anonymous(
+ $session, 'anonymous', 'pass'
+ );
+ $anonymous->getUid();
+ }
+
+ public function testMethodGetnameGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getName')
+ ->will($this->returnValue('1'));
+ $anonymous = new Horde_Kolab_Session_Anonymous(
+ $session, 'anonymous', 'pass'
+ );
+ $anonymous->getName();
+ }
+
+ public function testMethodGetimapserverGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getImapServer')
+ ->will($this->returnValue('1'));
+ $anonymous = new Horde_Kolab_Session_Anonymous(
+ $session, 'anonymous', 'pass'
+ );
+ $anonymous->getImapServer();
+ }
+
+ public function testMethodGetfreebusyserverGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getFreebusyServer')
+ ->will($this->returnValue('1'));
+ $anonymous = new Horde_Kolab_Session_Anonymous(
+ $session, 'anonymous', 'pass'
+ );
+ $anonymous->getFreebusyServer();
+ }
+
+ public function testMethodGetstorageGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getStorage')
+ ->will($this->returnValue('1'));
+ $anonymous = new Horde_Kolab_Session_Anonymous(
+ $session, 'anonymous', 'pass'
+ );
+ $anonymous->getStorage();
+ }
+
+
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Auth/HordeTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Auth/HordeTest.php
new file mode 100644
index 000000000..3b328de33
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Auth/HordeTest.php
@@ -0,0 +1,41 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the horde 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Class_Auth_HordeTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function testMethodGetcurrentuserHasResultStringTheCurrentUser()
+ {
+ $_SESSION['horde_auth']['userId'] = 'test';
+ $auth = new Horde_Kolab_Session_Auth_Horde();
+ $this->assertEquals('test', $auth->getCurrentUser());
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Auth/MockTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Auth/MockTest.php
new file mode 100644
index 000000000..73388e13c
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Auth/MockTest.php
@@ -0,0 +1,40 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the mock 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Class_Auth_MockTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function testMethodGetcurrentuserHasResultStringTheCurrentUser()
+ {
+ $auth = new Horde_Kolab_Session_Auth_Mock('test');
+ $this->assertEquals('test', $auth->getCurrentUser());
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/BaseTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/BaseTest.php
new file mode 100644
index 000000000..e7c81a16b
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/BaseTest.php
@@ -0,0 +1,440 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../Autoload.php';
+
+/**
+ * Test the Kolab session handler base implementation.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Class_BaseTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function testMethodConstructHasParameterStringUserid()
+ {
+ $session = new Horde_Kolab_Session_Base(
+ 'userid', $this->_getComposite(), array()
+ );
+ }
+
+ public function testMethodConstructHasParameterServercompositeServer()
+ {
+ $session = new Horde_Kolab_Session_Base(
+ '', $this->_getComposite(), array()
+ );
+ }
+
+ public function testMethodConstructHasParameterArrayParams()
+ {
+ $session = new Horde_Kolab_Session_Base(
+ '', $this->_getComposite(), array('params' => 'params')
+ );
+ }
+
+ public function testMethodConnectHasParameterArrayCredentials()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ '', $composite, array()
+ );
+ $session->connect(array('password' => ''));
+ }
+
+ public function testMethodConnectHasPostconditionThatTheUserMailAddressIsKnown()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->returnValue('mail@example.org'));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ '', $composite, array()
+ );
+ $session->connect(array('password' => ''));
+ $this->assertEquals('mail@example.org', $session->getMail());
+ }
+
+ public function testMethodConnectHasPostconditionThatTheUserUidIsKnown()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->returnValue('uid'));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ '', $composite, array()
+ );
+ $session->connect(array('password' => ''));
+ $this->assertEquals('uid', $session->getUid());
+ }
+
+ public function testMethodConnectHasPostconditionThatTheUserNameIsKnown()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->returnValue('name'));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ '', $composite, array()
+ );
+ $session->connect(array('password' => ''));
+ $this->assertEquals('name', $session->getName());
+ }
+
+ public function testMethodConnectHasPostconditionThatTheUsersImapHostIsKnown()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->returnValue('home.example.org'));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ 'userid', $composite, array()
+ );
+ $session->connect(array('password' => ''));
+ $this->assertEquals('home.example.org', $session->getImapServer());
+ }
+
+ public function testMethodConnectHasPostconditionThatTheUsersFreebusyHostIsKnown()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->returnValue('freebusy.example.org'));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ 'userid', $composite,
+ array('freebusy' => array('url_format' => 'https://%s/fb'))
+ );
+ $session->connect(array('password' => ''));
+ $this->assertEquals('https://freebusy.example.org/fb', $session->getFreebusyServer());
+ }
+
+ public function testMethodConnectThrowsExceptionIfTheCredentialsHaveNoPasswordEntry()
+ {
+ $session = new Horde_Kolab_Session_Base(
+ 'user', $this->_getComposite(), array()
+ );
+ try {
+ $session->connect(array());
+ } catch (Horde_Kolab_Session_Exception $e) {
+ $this->assertEquals('Missing password!', $e->getMessage());
+ }
+ }
+
+ public function testMethodConnectThrowsExceptionIfTheConnectionFailed()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $composite = $this->_getMockedComposite();
+ $composite->server->expects($this->exactly(1))
+ ->method('connectGuid')
+ ->will($this->throwException(new Horde_Kolab_Server_Exception('Error')));
+ $session = new Horde_Kolab_Session_Base(
+ 'user', $composite, array()
+ );
+ try {
+ $session->connect(array('password' => 'pass'));
+ } catch (Horde_Kolab_Session_Exception $e) {
+ $this->assertEquals('Error', $e->getMessage());
+ }
+ }
+
+ public function testMethodSleepHasResultArrayThePropertiesToSerialize()
+ {
+ $session = new Horde_Kolab_Session_Base(
+ 'user', $this->_getComposite(), array()
+ );
+ $this->assertEquals(
+ array(
+ '_params',
+ '_user_id',
+ '_user_uid',
+ '_user_mail',
+ '_user_name',
+ '_imap_server',
+ '_freebusy_server',
+ '_storage_params',
+ ), $session->__sleep());
+ }
+
+ public function testMethodGetidHasResultStringTheIdOfTheUserUserUsedForConnecting()
+ {
+ $session = new Horde_Kolab_Session_Base(
+ 'userid', $this->_getComposite(), array()
+ );
+ $this->assertEquals('userid', $session->getId());
+ }
+
+ public function testMethodGetmailHasResultStringTheMailOfTheConnectedUser()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ 'userid', $composite, array()
+ );
+ $session->connect(array('password' => ''));
+ $this->assertEquals('userid', $session->getMail());
+ }
+
+ public function testMethodGetuidHasResultStringTheUidOfTheConnectedUser()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ 'userid', $composite, array()
+ );
+ $session->connect(array('password' => ''));
+ $this->assertEquals('userid', $session->getUid());
+ }
+
+ public function testMethodGetnameHasResultStringTheNameOfTheConnectedUser()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ 'userid', $composite, array()
+ );
+ $session->connect(array('password' => ''));
+ $this->assertEquals('userid', $session->getName());
+ }
+
+ public function testMethodGetfreebusyserverHasResultStringTheUsersFreebusyServerConverterdToACompleteUrlUsingParametersIfAvailable()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->returnValue('freebusy.example.org'));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ 'userid', $composite,
+ array('freebusy' => array('url_format' => 'https://%s/fb'))
+ );
+ $session->connect(array('password' => ''));
+ $this->assertEquals('https://freebusy.example.org/fb', $session->getFreebusyServer());
+ }
+
+ public function testMethodGetfreebusyserverHasResultStringTheUsersFreebusyServerConverterdToACompleteUrlUsingFreebusyIfAvailable()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->returnValue('freebusy.example.org'));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ 'userid', $composite, array()
+ );
+ $session->connect(array('password' => ''));
+ $this->assertEquals('http://freebusy.example.org/freebusy', $session->getFreebusyServer());
+ }
+
+ public function testMethodGetfreebusyserverHasResultStringTheConfiguredServerIfAvailable()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ 'userid', $composite,
+ array('freebusy' => array('url' => 'https://freebusy2.example.org/fb'))
+ );
+ $session->connect(array('password' => ''));
+ $this->assertEquals('https://freebusy2.example.org/fb', $session->getFreebusyServer());
+ }
+
+ public function testMethodGetfreebusyserverHasResultStringTheUsersHomeServerConverterdToACompleteUrlUsingParametersIfAvailable()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ 'userid', $composite,
+ array('freebusy' => array('url_format' => 'https://%s/fb'))
+ );
+ $session->connect(array('password' => ''));
+ $this->assertEquals('https://localhost/fb', $session->getFreebusyServer());
+ }
+
+ public function testMethodGetfreebusyserverHasResultStringTheUsersHomeServerConverterdToACompleteUrlUsingFreebusyIfAvailable()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ 'userid', $composite, array()
+ );
+ $session->connect(array('password' => ''));
+ $this->assertEquals('http://localhost/freebusy', $session->getFreebusyServer());
+ }
+
+ public function testMethodGetfreebusyserverHasResultStringLocalhostConvertedToACompleteUrlUsingParametersIfAvailable()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ 'userid', $composite,
+ array('freebusy' => array('url_format' => 'https://%s/fb'))
+ );
+ $session->connect(array('password' => ''));
+ $this->assertEquals('https://localhost/fb', $session->getFreebusyServer());
+ }
+
+ public function testMethodGetfreebusyserverHasResultStringLocalhostConvertedToACompleteUrlUsingFreebusy()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ 'userid', $composite, array()
+ );
+ $session->connect(array('password' => ''));
+ $this->assertEquals('http://localhost/freebusy', $session->getFreebusyServer());
+ }
+
+ public function testMethodGetimapserverHasResultStringTheUsersHomeServerIfAvailable()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->returnValue('home.example.org'));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ 'userid', $composite, array()
+ );
+ $session->connect(array('password' => ''));
+ $this->assertEquals('home.example.org', $session->getImapServer());
+ }
+
+ public function testMethodGetimapserverHasResultStringTheConfiguredServerIfAvailable()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ 'userid', $composite,
+ array('imap' => array('server' => 'imap.example.org'))
+ );
+ $session->connect(array('password' => ''));
+ $this->assertEquals('imap.example.org', $session->getImapServer());
+ }
+
+ public function testMethodGetimapserverHasResultStringLocalhostIfNoAlternative()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ 'userid', $composite, array()
+ );
+ $session->connect(array('password' => ''));
+ $this->assertEquals('localhost', $session->getImapServer());
+ }
+
+ public function testMethodGetstorageHasResultKolabstorageConnectionForTheCurrentUser()
+ {
+ $this->markTestIncomplete('Not implemented');
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/AnonymousTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/AnonymousTest.php
new file mode 100644
index 000000000..6209ea7eb
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/AnonymousTest.php
@@ -0,0 +1,164 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the anonymous decorator factory.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Class_Factory_AnonymousTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function testMethodCreatesessionHasResultHordekolabsessionanonymous()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('createSession')
+ ->will($this->returnValue($session));
+ $factory = new Horde_Kolab_Session_Factory_Anonymous(
+ $factory, 'anonymous', ''
+ );
+ $this->assertType(
+ 'Horde_Kolab_Session_Anonymous',
+ $factory->createSession()
+ );
+ }
+
+ public function testMethodGetserverGetsDelegated()
+ {
+ $server = $this->getMock('Horde_Kolab_Server');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getServer')
+ ->will($this->returnValue($server));
+ $factory = new Horde_Kolab_Session_Factory_Anonymous(
+ $factory, 'anonymous', ''
+ );
+ $this->assertType('Horde_Kolab_Server', $factory->getServer());
+ }
+
+ public function testMethodGetsessionauthGetsDelegated()
+ {
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getSessionAuth')
+ ->will($this->returnValue($auth));
+ $factory = new Horde_Kolab_Session_Factory_Anonymous(
+ $factory, 'anonymous', ''
+ );
+ $this->assertType(
+ 'Horde_Kolab_Session_Auth',
+ $factory->getSessionAuth()
+ );
+ }
+
+ public function testMethodGetsessionconfigurationGetsDelegated()
+ {
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getSessionConfiguration')
+ ->will($this->returnValue(array()));
+ $factory = new Horde_Kolab_Session_Factory_Anonymous(
+ $factory, 'anonymous', ''
+ );
+ $this->assertType('array', $factory->getSessionConfiguration());
+ }
+
+ public function testMethodGetsessionstorageGetsDelegated()
+ {
+ $storage = $this->getMock('Horde_Kolab_Session_Storage');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getSessionStorage')
+ ->will($this->returnValue($storage));
+ $factory = new Horde_Kolab_Session_Factory_Anonymous(
+ $factory, 'anonymous', ''
+ );
+ $this->assertType(
+ 'Horde_Kolab_Session_Storage',
+ $factory->getSessionStorage()
+ );
+ }
+
+ public function testMethodGetsessionvalidatorGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $validator = $this->getMock('Horde_Kolab_Session_Valid');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getSessionValidator')
+ ->will($this->returnValue($validator));
+ $factory = new Horde_Kolab_Session_Factory_Anonymous(
+ $factory, 'anonymous', ''
+ );
+ $this->assertType(
+ 'Horde_Kolab_Session_Valid',
+ $factory->getSessionValidator($session, $auth)
+ );
+ }
+
+ public function testMethodValidateGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('validate')
+ ->will($this->returnValue(true));
+ $factory = new Horde_Kolab_Session_Factory_Anonymous(
+ $factory, 'anonymous', ''
+ );
+ $this->assertTrue($factory->validate($session, 'test'));
+ }
+
+ public function testMethodCreatesessionGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('createSession')
+ ->will($this->returnValue($session));
+ $factory = new Horde_Kolab_Session_Factory_Anonymous(
+ $factory, 'anonymous', ''
+ );
+ $this->assertType('Horde_Kolab_Session', $factory->createSession());
+ }
+
+ public function testMethodGetsessionGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getSession')
+ ->will($this->returnValue($session));
+ $factory = new Horde_Kolab_Session_Factory_Anonymous(
+ $factory, 'anonymous', ''
+ );
+ $this->assertType('Horde_Kolab_Session', $factory->getSession());
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/BaseTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/BaseTest.php
new file mode 100644
index 000000000..5379d5cfe
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/BaseTest.php
@@ -0,0 +1,122 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the base factory definition via the constructor based factory.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Class_Factory_BaseTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function setUp()
+ {
+ parent::setUp();
+ $this->setupFactoryMocks();
+ }
+
+ public function testMethodGetvalidatorHasResultHordekolabsesessionvalid()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $factory = new Horde_Kolab_Session_Factory_Constructor(
+ $this->server, $this->session_auth, array(), $this->session_storage
+ );
+ $this->assertType(
+ 'Horde_Kolab_Session_Valid',
+ $factory->getSessionValidator($session, $this->session_auth)
+ );
+ }
+
+ public function testMethodValidateHasResultTrueIfTheSessionIsStillValid()
+ {
+ $this->session_auth->expects($this->once())
+ ->method('getCurrentUser')
+ ->will($this->returnValue('mail@example.org'));
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getMail')
+ ->will($this->returnValue('mail@example.org'));
+ $factory = new Horde_Kolab_Session_Factory_Constructor(
+ $this->server, $this->session_auth, array(), $this->session_storage
+ );
+ $this->assertTrue($factory->validate($session));
+ }
+
+ public function testMethodCreatesessionHasResultHordekolabsessionstored()
+ {
+ $factory = new Horde_Kolab_Session_Factory_Constructor(
+ $this->server, $this->session_auth, array(), $this->session_storage
+ );
+ $this->assertType('Horde_Kolab_Session_Stored', $factory->createSession());
+ }
+
+ public function testMethodGetsessionHasResultHordekolabsessionTheOldSessionIfAnOldSessionWasStoredAndValid()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getMail')
+ ->will($this->returnValue('mail@example.org'));
+ $this->session_storage->expects($this->once())
+ ->method('load')
+ ->will($this->returnValue($session));
+ $this->session_auth->expects($this->once())
+ ->method('getCurrentUser')
+ ->will($this->returnValue('mail@example.org'));
+ $factory = new Horde_Kolab_Session_Factory_Constructor(
+ $this->server, $this->session_auth, array(), $this->session_storage
+ );
+ $this->assertSame($session, $factory->getSession());
+ }
+
+ public function testMethodGetsessionHasResultHordekolabsessionANewSessionIfAnOldSessionWasStoredAndInvalid()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getMail')
+ ->will($this->returnValue('mail@example.org'));
+ $this->session_storage->expects($this->once())
+ ->method('load')
+ ->will($this->returnValue($session));
+ $this->session_auth->expects($this->once())
+ ->method('getCurrentUser')
+ ->will($this->returnValue('new@example.org'));
+ $factory = new Horde_Kolab_Session_Factory_Constructor(
+ $this->server, $this->session_auth, array(), $this->session_storage
+ );
+ $this->assertTrue($session !== $factory->getSession());
+ }
+
+ public function testMethodGetsessionHasResultHordekolabsessionANewSessionIfNoOldSessionExisted()
+ {
+ $this->session_storage->expects($this->once())
+ ->method('load')
+ ->will($this->returnValue(false));
+ $factory = new Horde_Kolab_Session_Factory_Constructor(
+ $this->server, $this->session_auth, array(), $this->session_storage
+ );
+ $this->assertType('Horde_Kolab_Session', $factory->getSession());
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/ConfigurationTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/ConfigurationTest.php
new file mode 100644
index 000000000..69a2aeade
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/ConfigurationTest.php
@@ -0,0 +1,212 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the configuration based factory.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Class_Factory_ConfigurationTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function setUp()
+ {
+ parent::setUp();
+ $this->setupLogger();
+ }
+
+ public function testMethodCreatesessionHasResultHordekolabsessionanonymousIfConfiguredThatWay()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('createSession')
+ ->will($this->returnValue($session));
+ $factory = new Horde_Kolab_Session_Factory_Configuration(
+ $factory,
+ array(
+ 'session' => array(
+ 'anonymous' => array(
+ 'user' => 'anonymous',
+ 'pass' => ''
+ )
+ )
+ )
+ );
+ $this->assertType(
+ 'Horde_Kolab_Session_Anonymous',
+ $factory->createSession()
+ );
+ }
+
+ public function testMethodCreatesessionHasResultHordekolabsessionloggedIfConfiguredThatWay()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('createSession')
+ ->will($this->returnValue($session));
+ $factory = new Horde_Kolab_Session_Factory_Configuration(
+ $factory, array('logger' => $this->logger)
+ );
+ $this->assertType(
+ 'Horde_Kolab_Session_Logged',
+ $factory->createSession()
+ );
+ }
+
+ public function testMethodGetsessionvalidatorHasResultHordekolabsessionvalidloggedIfConfiguredThatWay()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $validator = $this->getMock('Horde_Kolab_Session_Valid');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getSessionValidator')
+ ->will($this->returnValue($validator));
+ $factory = new Horde_Kolab_Session_Factory_Configuration(
+ $factory, array('logger' => $this->logger)
+ );
+ $this->assertType(
+ 'Horde_Kolab_Session_Valid_Logged',
+ $factory->getSessionValidator($session, $auth)
+ );
+ }
+
+ public function testMethodGetserverGetsDelegated()
+ {
+ $server = $this->getMock('Horde_Kolab_Server');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getServer')
+ ->will($this->returnValue($server));
+ $factory = new Horde_Kolab_Session_Factory_Configuration(
+ $factory, array()
+ );
+ $this->assertType('Horde_Kolab_Server', $factory->getServer());
+ }
+
+ public function testMethodGetsessionauthGetsDelegated()
+ {
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getSessionAuth')
+ ->will($this->returnValue($auth));
+ $factory = new Horde_Kolab_Session_Factory_Configuration(
+ $factory, array()
+ );
+ $this->assertType(
+ 'Horde_Kolab_Session_Auth',
+ $factory->getSessionAuth()
+ );
+ }
+
+ public function testMethodGetsessionconfigurationGetsDelegated()
+ {
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getSessionConfiguration')
+ ->will($this->returnValue(array()));
+ $factory = new Horde_Kolab_Session_Factory_Configuration(
+ $factory, array()
+ );
+ $this->assertType('array', $factory->getSessionConfiguration());
+ }
+
+ public function testMethodGetsessionstorageGetsDelegated()
+ {
+ $storage = $this->getMock('Horde_Kolab_Session_Storage');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getSessionStorage')
+ ->will($this->returnValue($storage));
+ $factory = new Horde_Kolab_Session_Factory_Configuration(
+ $factory, array()
+ );
+ $this->assertType(
+ 'Horde_Kolab_Session_Storage',
+ $factory->getSessionStorage()
+ );
+ }
+
+ public function testMethodGetsessionvalidatorGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $validator = $this->getMock('Horde_Kolab_Session_Valid');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getSessionValidator')
+ ->will($this->returnValue($validator));
+ $factory = new Horde_Kolab_Session_Factory_Configuration(
+ $factory, array()
+ );
+ $this->assertType(
+ 'Horde_Kolab_Session_Valid',
+ $factory->getSessionValidator($session, $auth)
+ );
+ }
+
+ public function testMethodValidateGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('validate')
+ ->will($this->returnValue(true));
+ $factory = new Horde_Kolab_Session_Factory_Configuration(
+ $factory, array()
+ );
+ $this->assertTrue($factory->validate($session, 'test'));
+ }
+
+ public function testMethodCreatesessionGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('createSession')
+ ->will($this->returnValue($session));
+ $factory = new Horde_Kolab_Session_Factory_Configuration(
+ $factory, array()
+ );
+ $this->assertType('Horde_Kolab_Session', $factory->createSession());
+ }
+
+ public function testMethodGetsessionGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getSession')
+ ->will($this->returnValue($session));
+ $factory = new Horde_Kolab_Session_Factory_Configuration(
+ $factory, array()
+ );
+ $this->assertType('Horde_Kolab_Session', $factory->getSession());
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/ConstructorTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/ConstructorTest.php
new file mode 100644
index 000000000..f7ff42906
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/ConstructorTest.php
@@ -0,0 +1,72 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the constructor based factory.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Class_Factory_ConstructorTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function setUp()
+ {
+ parent::setUp();
+ $this->setupFactoryMocks();
+ }
+
+ public function testMethodGetserverHasResultHordekolabserver()
+ {
+ $factory = new Horde_Kolab_Session_Factory_Constructor(
+ $this->server, $this->session_auth, array(), $this->session_storage
+ );
+ $this->assertType('Horde_Kolab_Server_Composite', $factory->getServer());
+ }
+
+ public function testMethodGetsessionauthHasResultHordekolabsessionauth()
+ {
+ $factory = new Horde_Kolab_Session_Factory_Constructor(
+ $this->server, $this->session_auth, array(), $this->session_storage
+ );
+ $this->assertType('Horde_Kolab_Session_Auth', $factory->getSessionAuth());
+ }
+
+ public function testMethodGetsessionconfigurationHasResultArray()
+ {
+ $factory = new Horde_Kolab_Session_Factory_Constructor(
+ $this->server, $this->session_auth, array(), $this->session_storage
+ );
+ $this->assertType('array', $factory->getSessionConfiguration());
+ }
+
+ public function testMethodGetsessionstorageHasResultHordekolabsessionstorage()
+ {
+ $factory = new Horde_Kolab_Session_Factory_Constructor(
+ $this->server, $this->session_auth, array(), $this->session_storage
+ );
+ $this->assertType('Horde_Kolab_Session_Storage', $factory->getSessionStorage());
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/DefaultTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/DefaultTest.php
new file mode 100644
index 000000000..d6c856c77
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/DefaultTest.php
@@ -0,0 +1,76 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the default factory.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Class_Factory_DefaultTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function testMethodGetserverHasResultHordekolabserver()
+ {
+ $this->markTestIncomplete('The factory in the Kolab_Server package needs to be fixed.');
+ $server = $this->getMock('Horde_Kolab_Server');
+ $server_factory = $this->getMock('Horde_Kolab_Server_Factory');
+ $server_factory->expects($this->once())
+ ->method('getServer')
+ ->will($this->returnValue($server));
+ $factory = new Horde_Kolab_Session_Factory_Default(
+ array('server' => array()),
+ $server_factory
+ );
+ $this->assertType('Horde_Kolab_Server', $factory->getServer());
+ }
+
+ public function testMethodGetsessionauthHasResultHordekolabsessionauth()
+ {
+ $factory = new Horde_Kolab_Session_Factory_Default(
+ array('server' => array()),
+ $this->getMock('Horde_Kolab_Server_Factory')
+ );
+ $this->assertType('Horde_Kolab_Session_Auth', $factory->getSessionAuth());
+ }
+
+ public function testMethodGetsessionconfigurationHasResultArray()
+ {
+ $factory = new Horde_Kolab_Session_Factory_Default(
+ array('server' => array()),
+ $this->getMock('Horde_Kolab_Server_Factory')
+ );
+ $this->assertType('array', $factory->getSessionConfiguration());
+ }
+
+ public function testMethodGetsessionstorageHasResultHordekolabsessionstorage()
+ {
+ $factory = new Horde_Kolab_Session_Factory_Default(
+ array('server' => array()),
+ $this->getMock('Horde_Kolab_Server_Factory')
+ );
+ $this->assertType('Horde_Kolab_Session_Storage', $factory->getSessionStorage());
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/InjectorTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/InjectorTest.php
new file mode 100644
index 000000000..a6ec495b3
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/InjectorTest.php
@@ -0,0 +1,72 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the injector based factory.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Class_Factory_InjectorTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function setUp()
+ {
+ $this->injector = new Horde_Injector(new Horde_Injector_TopLevel());
+ $this->markTestIncomplete('This needs an injector factory in the Kolab_Server package.');
+ }
+
+ public function testMethodGetserverHasResultHordekolabserver()
+ {
+ $factory = new Horde_Kolab_Session_Factory_Injector(
+ array('server' => array()), $this->injector
+ );
+ $this->assertType('Horde_Kolab_Server', $factory->getServer());
+ }
+
+ public function testMethodGetsessionauthHasResultHordekolabsessionauth()
+ {
+ $factory = new Horde_Kolab_Session_Factory_Injector(
+ array('server' => array()), $this->injector
+ );
+ $this->assertType('Horde_Kolab_Session_Auth', $factory->getSessionAuth());
+ }
+
+ public function testMethodGetsessionconfigurationHasResultArray()
+ {
+ $factory = new Horde_Kolab_Session_Factory_Injector(
+ array('server' => array()), $this->injector
+ );
+ $this->assertType('array', $factory->getSessionConfiguration());
+ }
+
+ public function testMethodGetsessionstorageHasResultHordekolabsessionstorage()
+ {
+ $factory = new Horde_Kolab_Session_Factory_Injector(
+ array('server' => array()), $this->injector
+ );
+ $this->assertType('Horde_Kolab_Session_Storage', $factory->getSessionStorage());
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/LoggedTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/LoggedTest.php
new file mode 100644
index 000000000..367b134b0
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/LoggedTest.php
@@ -0,0 +1,188 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the log decorator factory.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Class_Factory_LoggedTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function setUp()
+ {
+ parent::setUp();
+ $this->setupLogger();
+ }
+
+ public function testMethodCreatesessionHasResultHordekolabsessionlogged()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('createSession')
+ ->will($this->returnValue($session));
+ $factory = new Horde_Kolab_Session_Factory_Logged(
+ $factory, $this->logger
+ );
+ $this->assertType(
+ 'Horde_Kolab_Session_Logged',
+ $factory->createSession()
+ );
+ }
+
+ public function testMethodGetsessionvalidatorHasResultHordekolabsessionvalidlogged()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $validator = $this->getMock('Horde_Kolab_Session_Valid');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getSessionValidator')
+ ->will($this->returnValue($validator));
+ $factory = new Horde_Kolab_Session_Factory_Logged(
+ $factory, $this->logger
+ );
+ $this->assertType(
+ 'Horde_Kolab_Session_Valid_Logged',
+ $factory->getSessionValidator($session, $auth)
+ );
+ }
+
+ public function testMethodGetserverGetsDelegated()
+ {
+ $server = $this->getMock('Horde_Kolab_Server');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getServer')
+ ->will($this->returnValue($server));
+ $factory = new Horde_Kolab_Session_Factory_Logged(
+ $factory, $this->logger
+ );
+ $this->assertType('Horde_Kolab_Server', $factory->getServer());
+ }
+
+ public function testMethodGetsessionauthGetsDelegated()
+ {
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getSessionAuth')
+ ->will($this->returnValue($auth));
+ $factory = new Horde_Kolab_Session_Factory_Logged(
+ $factory, $this->logger
+ );
+ $this->assertType(
+ 'Horde_Kolab_Session_Auth',
+ $factory->getSessionAuth()
+ );
+ }
+
+ public function testMethodGetsessionconfigurationGetsDelegated()
+ {
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getSessionConfiguration')
+ ->will($this->returnValue(array()));
+ $factory = new Horde_Kolab_Session_Factory_Logged(
+ $factory, $this->logger
+ );
+ $this->assertType('array', $factory->getSessionConfiguration());
+ }
+
+ public function testMethodGetsessionstorageGetsDelegated()
+ {
+ $storage = $this->getMock('Horde_Kolab_Session_Storage');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getSessionStorage')
+ ->will($this->returnValue($storage));
+ $factory = new Horde_Kolab_Session_Factory_Logged(
+ $factory, $this->logger
+ );
+ $this->assertType(
+ 'Horde_Kolab_Session_Storage',
+ $factory->getSessionStorage()
+ );
+ }
+
+ public function testMethodGetsessionvalidatorGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $validator = $this->getMock('Horde_Kolab_Session_Valid');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getSessionValidator')
+ ->will($this->returnValue($validator));
+ $factory = new Horde_Kolab_Session_Factory_Logged(
+ $factory, $this->logger
+ );
+ $this->assertType(
+ 'Horde_Kolab_Session_Valid',
+ $factory->getSessionValidator($session, $auth)
+ );
+ }
+
+ public function testMethodValidateGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('validate')
+ ->will($this->returnValue(true));
+ $factory = new Horde_Kolab_Session_Factory_Logged(
+ $factory, $this->logger
+ );
+ $this->assertTrue($factory->validate($session, 'test'));
+ }
+
+ public function testMethodCreatesessionGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('createSession')
+ ->will($this->returnValue($session));
+ $factory = new Horde_Kolab_Session_Factory_Logged(
+ $factory, $this->logger
+ );
+ $this->assertType('Horde_Kolab_Session', $factory->createSession());
+ }
+
+ public function testMethodGetsessionGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $factory = $this->getMock('Horde_Kolab_Session_Factory');
+ $factory->expects($this->once())
+ ->method('getSession')
+ ->will($this->returnValue($session));
+ $factory = new Horde_Kolab_Session_Factory_Logged(
+ $factory, $this->logger
+ );
+ $this->assertType('Horde_Kolab_Session', $factory->getSession());
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/LoggedTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/LoggedTest.php
new file mode 100644
index 000000000..f8be5455e
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/LoggedTest.php
@@ -0,0 +1,175 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../Autoload.php';
+
+/**
+ * Test the log decorator.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Class_LoggedTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->setupLogger();
+ }
+
+ public function testMethodConnectHasPostconditionThatASuccessfulConnectionGetsLogged()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('connect')
+ ->with(array('password' => 'pass'));
+ $session->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue('somebody@example.org'));
+ $this->logger->expects($this->once())
+ ->method('__call')
+ ->with(
+ 'info',
+ array('Connected Kolab session for "somebody@example.org".')
+ );
+ $logged = new Horde_Kolab_Session_Logged($session, $this->logger);
+ $logged->connect(array('password' => 'pass'));
+ }
+
+ public function testMethodConnectHasPostconditionThatAnUnsuccessfulConnectionGetsLogged()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('connect')
+ ->will($this->throwException(new Horde_Kolab_Session_Exception('Error.')));
+ $session->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue('somebody@example.org'));
+ $this->logger->expects($this->once())
+ ->method('__call')
+ ->with(
+ 'err',
+ array('Failed to connect Kolab session for "somebody@example.org". Error was: Error.')
+ );
+ $logged = new Horde_Kolab_Session_Logged($session, $this->logger);
+ try {
+ $logged->connect(array('password' => 'pass'));
+ $this->fail('No Exception!');
+ } catch (Horde_Kolab_Session_Exception $e) {
+ }
+ }
+
+ public function testMethodConnectGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('connect')
+ ->with(array('password' => 'pass'));
+ $logged = new Horde_Kolab_Session_Logged($session, $this->logger);
+ $logged->connect(array('password' => 'pass'));
+ }
+
+ public function testMethodGetidGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue('1'));
+ $logged = new Horde_Kolab_Session_Logged($session, $this->logger);
+ $logged->getId();
+ }
+
+ public function testMethodSetidGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('setId')
+ ->with('1');
+ $logged = new Horde_Kolab_Session_Logged($session, $this->logger);
+ $logged->setId('1');
+ }
+
+ public function testMethodGetmailGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getMail')
+ ->will($this->returnValue('1'));
+ $logged = new Horde_Kolab_Session_Logged($session, $this->logger);
+ $logged->getMail();
+ }
+
+ public function testMethodGetuidGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getUid')
+ ->will($this->returnValue('1'));
+ $logged = new Horde_Kolab_Session_Logged($session, $this->logger);
+ $logged->getUid();
+ }
+
+ public function testMethodGetnameGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getName')
+ ->will($this->returnValue('1'));
+ $logged = new Horde_Kolab_Session_Logged($session, $this->logger);
+ $logged->getName();
+ }
+
+ public function testMethodGetimapserverGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getImapServer')
+ ->will($this->returnValue('1'));
+ $logged = new Horde_Kolab_Session_Logged($session, $this->logger);
+ $logged->getImapServer();
+ }
+
+ public function testMethodGetfreebusyserverGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getFreebusyServer')
+ ->will($this->returnValue('1'));
+ $logged = new Horde_Kolab_Session_Logged($session, $this->logger);
+ $logged->getFreebusyServer();
+ }
+
+ public function testMethodGetstorageGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getStorage')
+ ->will($this->returnValue('1'));
+ $logged = new Horde_Kolab_Session_Logged($session, $this->logger);
+ $logged->getStorage();
+ }
+
+
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/SingletonTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/SingletonTest.php
new file mode 100644
index 000000000..f9969cbd3
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/SingletonTest.php
@@ -0,0 +1,57 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../Autoload.php';
+
+/**
+ * Test the Kolab session singleton pattern.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Class_SingletonTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function testMethodSingletonHasResultHordekolabsession()
+ {
+ $this->markTestIncomplete('The factory in the Kolab_Server package needs to be fixed.');
+ $this->assertType(
+ 'Horde_Kolab_Session',
+ Horde_Kolab_Session_Singleton::singleton(
+ 'user', array('password' => 'pass')
+ )
+ );
+ }
+
+ public function testMethodSingletonHasResultHordekolabsessionAlwaysTheSameIfTheSessionIsValid()
+ {
+ $this->markTestIncomplete('The factory in the Kolab_Server package needs to be fixed.');
+ $session1 = Horde_Kolab_Session_Singleton::singleton(
+ 'user', array('password' => 'pass')
+ );
+ $session2 = Horde_Kolab_Session_Singleton::singleton(
+ 'user', array('password' => 'pass')
+ );
+ $this->assertSame($session1, $session2);
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Storage/MockTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Storage/MockTest.php
new file mode 100644
index 000000000..b18725984
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Storage/MockTest.php
@@ -0,0 +1,48 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the mock storage 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Class_Storage_MockTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function testMethodLoadHasResultBooleanFalse()
+ {
+ $storage = new Horde_Kolab_Session_Storage_Mock('test');
+ $this->assertFalse($storage->load());
+ }
+
+ public function testMethodSaveHasPostconditionThatTheSessionDataWasSaved()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $storage = new Horde_Kolab_Session_Storage_Mock('test');
+ $storage->save($session);
+ $this->assertSame($session, $storage->session);
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Storage/SessionobjectsTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Storage/SessionobjectsTest.php
new file mode 100644
index 000000000..ec620a6a8
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Storage/SessionobjectsTest.php
@@ -0,0 +1,55 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the sessionobjects storage 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Class_Storage_SessionobjectsTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function testMethodLoadHasResultQueriedObject()
+ {
+ $session_objects = $this->getMock('Horde_SessionObjects', array(), array(), '', false, false);
+ $session_objects->expects($this->once())
+ ->method('query')
+ ->with('kolab_session');
+ $storage = new Horde_Kolab_Session_Storage_Sessionobjects($session_objects);
+ $storage->load();
+ }
+
+ public function testMethodSaveHasPostconditionThatTheSessionDataWasSaved()
+ {
+ $session_objects = $this->getMock('Horde_SessionObjects', array(), array(), '', false, false);
+ $session_objects->expects($this->once())
+ ->method('overwrite')
+ ->with('kolab_session', $this->isInstanceOf('Horde_Kolab_Session'));
+ $session = $this->getMock('Horde_Kolab_Session');
+ $storage = new Horde_Kolab_Session_Storage_Sessionobjects($session_objects);
+ $storage->save($session);
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/StoredTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/StoredTest.php
new file mode 100644
index 000000000..767da7be5
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/StoredTest.php
@@ -0,0 +1,143 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../Autoload.php';
+
+/**
+ * Test the storing decorator.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Class_StoredTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->setupStorage();
+ }
+
+ public function testMethodDestructHasPostconditionThatTheSessionWasSaved()
+ {
+ $this->storage->expects($this->once())
+ ->method('save')
+ ->with($this->isInstanceOf('Horde_Kolab_Session'));
+ $session = $this->getMock('Horde_Kolab_Session');
+ $stored = new Horde_Kolab_Session_Stored($session, $this->storage);
+ $stored = null;
+ }
+
+ public function testMethodConnectGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('connect')
+ ->with(array('password' => 'pass'));
+ $stored = new Horde_Kolab_Session_Stored($session, $this->storage);
+ $stored->connect(array('password' => 'pass'));
+ }
+
+ public function testMethodGetidGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue('1'));
+ $stored = new Horde_Kolab_Session_Stored($session, $this->storage);
+ $stored->getId();
+ }
+
+ public function testMethodSetidGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('setId')
+ ->with('1');
+ $stored = new Horde_Kolab_Session_Stored($session, $this->storage);
+ $stored->setId('1');
+ }
+
+ public function testMethodGetmailGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getMail')
+ ->will($this->returnValue('1'));
+ $stored = new Horde_Kolab_Session_Stored($session, $this->storage);
+ $stored->getMail();
+ }
+
+ public function testMethodGetuidGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getUid')
+ ->will($this->returnValue('1'));
+ $stored = new Horde_Kolab_Session_Stored($session, $this->storage);
+ $stored->getUid();
+ }
+
+ public function testMethodGetnameGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getName')
+ ->will($this->returnValue('1'));
+ $stored = new Horde_Kolab_Session_Stored($session, $this->storage);
+ $stored->getName();
+ }
+
+ public function testMethodGetimapserverGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getImapServer')
+ ->will($this->returnValue('1'));
+ $stored = new Horde_Kolab_Session_Stored($session, $this->storage);
+ $stored->getImapServer();
+ }
+
+ public function testMethodGetfreebusyserverGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getFreebusyServer')
+ ->will($this->returnValue('1'));
+ $stored = new Horde_Kolab_Session_Stored($session, $this->storage);
+ $stored->getFreebusyServer();
+ }
+
+ public function testMethodGetstorageGetsDelegated()
+ {
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getStorage')
+ ->will($this->returnValue('1'));
+ $stored = new Horde_Kolab_Session_Stored($session, $this->storage);
+ $stored->getStorage();
+ }
+
+
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Valid/BaseTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Valid/BaseTest.php
new file mode 100644
index 000000000..7f9b700df
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Valid/BaseTest.php
@@ -0,0 +1,118 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the valid check.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Class_Valid_BaseTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function testMethodIsvalidHasResultBooleanTrueIfTheSessionIsNotConnectedAndTheCurrentUserIsAnonymous()
+ {
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $auth->expects($this->once())
+ ->method('getCurrentUser')
+ ->will($this->returnValue(''));
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getMail')
+ ->will($this->returnValue(''));
+ $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
+ $this->assertTrue($valid->isValid());
+ }
+
+ public function testMethodIsvalidHasResultBooleanFalseIfTheSessionIsNotConnected()
+ {
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $auth->expects($this->once())
+ ->method('getCurrentUser')
+ ->will($this->returnValue('mail@example.org'));
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getMail')
+ ->will($this->returnValue(''));
+ $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
+ $this->assertFalse($valid->isValid());
+ }
+
+ public function testMethodIsvalidHasResultBooleanFalseIfTheMailOfTheCurrentUserDoesNotMatchTheCurrentUserOfTheSession()
+ {
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $auth->expects($this->once())
+ ->method('getCurrentUser')
+ ->will($this->returnValue('somebody@example.org'));
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getMail')
+ ->will($this->returnValue('mail@example.org'));
+ $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
+ $this->assertFalse($valid->isValid());
+ }
+
+ public function testMethodIsvalidHasResultBooleanTrueIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndNoNewUserWasSet()
+ {
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $auth->expects($this->once())
+ ->method('getCurrentUser')
+ ->will($this->returnValue('mail@example.org'));
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getMail')
+ ->will($this->returnValue('mail@example.org'));
+ $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
+ $this->assertTrue($valid->isValid());
+ }
+
+ public function testMethodIsvalidHasResultBooleanFalseIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndTheNewUserMatchesNeitherTheCurrentUserMailAndUid()
+ {
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $auth->expects($this->once())
+ ->method('getCurrentUser')
+ ->will($this->returnValue('mail@example.org'));
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getMail')
+ ->will($this->returnValue('mail@example.org'));
+ $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
+ $this->assertFalse($valid->isValid('somebody@example.org'));
+ }
+
+ public function testMethodIsvalidHasResultBooleanTrueIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndTheNewUserMatchesEitherTheCurrentUserMailAndUid()
+ {
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $auth->expects($this->once())
+ ->method('getCurrentUser')
+ ->will($this->returnValue('mail@example.org'));
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->once())
+ ->method('getMail')
+ ->will($this->returnValue('mail@example.org'));
+ $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
+ $this->assertTrue($valid->isValid('mail@example.org'));
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Valid/LoggedTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Valid/LoggedTest.php
new file mode 100644
index 000000000..bd51d0432
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Valid/LoggedTest.php
@@ -0,0 +1,91 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the log decorator for validators.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Class_Valid_LoggedTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->setupLogger();
+ }
+
+ public function testMethodIsvalidHasPostconditionThatAnInvalidSessionGetsLogged()
+ {
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $auth->expects($this->exactly(2))
+ ->method('getCurrentUser')
+ ->will($this->returnValue('auth@example.org'));
+ $session = $this->getMock('Horde_Kolab_Session');
+ $session->expects($this->exactly(2))
+ ->method('getMail')
+ ->will($this->returnValue('somebody@example.org'));
+ $this->logger->expects($this->once())
+ ->method('__call')
+ ->with(
+ 'info',
+ array('Invalid Kolab session for current user "auth@example.org", requested user "nobody@example.org" and stored user "somebody@example.org".')
+ );
+ $logged = new Horde_Kolab_Session_Logged($session, $this->logger);
+ $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
+ $logged = new Horde_Kolab_Session_Valid_Logged($valid, $this->logger);
+ $this->assertFalse($logged->isValid('nobody@example.org'));
+ }
+
+ public function testMethodIsvalidGetsDelegated()
+ {
+ $valid = $this->getMock('Horde_Kolab_Session_Valid');
+ $valid->expects($this->once())
+ ->method('isValid')
+ ->will($this->returnValue(true));
+ $logged = new Horde_Kolab_Session_Valid_Logged($valid, $this->logger);
+ $this->assertTrue($logged->isValid());
+ }
+
+ public function testMethodGetsessionGetsDelegated()
+ {
+ $valid = $this->getMock('Horde_Kolab_Session_Valid');
+ $valid->expects($this->once())
+ ->method('getSession');
+ $logged = new Horde_Kolab_Session_Valid_Logged($valid, $this->logger);
+ $logged->getSession();
+ }
+
+ public function testMethodGetauthGetsDelegated()
+ {
+ $valid = $this->getMock('Horde_Kolab_Session_Valid');
+ $valid->expects($this->once())
+ ->method('getAuth');
+ $logged = new Horde_Kolab_Session_Valid_Logged($valid, $this->logger);
+ $logged->getAuth();
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Integration/AnonymousTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Integration/AnonymousTest.php
new file mode 100644
index 000000000..bcd0a59b8
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Integration/AnonymousTest.php
@@ -0,0 +1,56 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../Autoload.php';
+
+/**
+ * Test the anonymous decorator with the Kolab session handler base
+ * implementation.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Integration_AnonymousTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function testMethodConnectHasPostconditionThatTheConnectionHasBeenEstablishedAsAnonymousUserIfRequired()
+ {
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->returnValue('anonymous@example.org'));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ '', $composite, array()
+ );
+ $anonymous = new Horde_Kolab_Session_Anonymous(
+ $session, 'anonymous', 'pass'
+ );
+ $anonymous->connect();
+ $this->assertEquals('anonymous@example.org', $anonymous->getMail());
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Integration/ValidTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Integration/ValidTest.php
new file mode 100644
index 000000000..2b2379e28
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Integration/ValidTest.php
@@ -0,0 +1,150 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../Autoload.php';
+
+/**
+ * Test the valid check with the Kolab session handler implementation.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Integration_ValidTest extends Horde_Kolab_Session_SessionTestCase
+{
+ public function testMethodIsvalidHasResultBooleanTrueIfTheSessionIsNotConnectedAndTheCurrentUserIsAnonymous()
+ {
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $auth->expects($this->once())
+ ->method('getCurrentUser')
+ ->will($this->returnValue(''));
+ $composite = $this->_getMockedComposite();
+ $session = new Horde_Kolab_Session_Base(
+ '', $composite, array()
+ );
+ $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
+ $this->assertTrue($valid->isValid());
+ }
+
+ public function testMethodIsvalidHasResultBooleanFalseIfTheSessionIsNotConnected()
+ {
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $auth->expects($this->once())
+ ->method('getCurrentUser')
+ ->will($this->returnValue('mail@example.org'));
+ $composite = $this->_getMockedComposite();
+ $session = new Horde_Kolab_Session_Base(
+ '', $composite, array()
+ );
+ $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
+ $this->assertFalse($valid->isValid());
+ }
+
+ public function testMethodIsvalidHasResultBooleanFalseIfTheMailOfTheCurrentUserDoesNotMatchTheCurrentUserOfTheSession()
+ {
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $auth->expects($this->once())
+ ->method('getCurrentUser')
+ ->will($this->returnValue('somebody@example.org'));
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->returnValue('mail@example.org'));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ '', $composite, array()
+ );
+ $session->connect(array('password' => ''));
+ $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
+ $this->assertFalse($valid->isValid());
+ }
+
+ public function testMethodIsvalidHasResultBooleanTrueIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndNoNewUserWasSet()
+ {
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $auth->expects($this->once())
+ ->method('getCurrentUser')
+ ->will($this->returnValue('mail@example.org'));
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->returnValue('mail@example.org'));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ '', $composite, array()
+ );
+ $session->connect(array('password' => ''));
+ $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
+ $this->assertTrue($valid->isValid());
+ }
+
+ public function testMethodIsvalidHasResultBooleanFalseIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndTheNewUserMatchesNeitherTheCurrentUserMailAndUid()
+ {
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $auth->expects($this->once())
+ ->method('getCurrentUser')
+ ->will($this->returnValue('mail@example.org'));
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->returnValue('mail@example.org'));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ '', $composite, array()
+ );
+ $session->connect(array('password' => ''));
+ $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
+ $this->assertFalse($valid->isValid('somebody@example.org'));
+ }
+
+ public function testMethodIsvalidHasResultBooleanTrueIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndTheNewUserMatchesEitherTheCurrentUserMailAndUid()
+ {
+ $auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $auth->expects($this->once())
+ ->method('getCurrentUser')
+ ->will($this->returnValue('mail@example.org'));
+ $user = $this->getMock('Horde_Kolab_Server_Object');
+ $user->expects($this->exactly(5))
+ ->method('getExternal')
+ ->will($this->returnValue('mail@example.org'));
+ $composite = $this->_getMockedComposite();
+ $composite->objects->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue($user));
+ $session = new Horde_Kolab_Session_Base(
+ '', $composite, array()
+ );
+ $session->connect(array('password' => ''));
+ $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
+ $this->assertTrue($valid->isValid('mail@example.org'));
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/SessionTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/SessionTest.php
index 32b882b5e..2ec886b42 100644
--- a/framework/Kolab_Session/test/Horde/Kolab/Session/SessionTest.php
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/SessionTest.php
@@ -14,7 +14,7 @@
/**
* Prepare the test setup.
*/
-require_once 'Autoload.php';
+require_once dirname(__FILE__) . '/Autoload.php';
/**
* Test the Kolab session handler.
@@ -30,9 +30,19 @@ require_once 'Autoload.php';
* @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_Server_Integration_Scenario
+class Horde_Kolab_Session_SessionTest extends Horde_Kolab_Session_SessionTestCase
{
/**
+ * Setup function.
+ *
+ * @return NULL.
+ */
+ protected function setUp()
+ {
+ $this->markTestIncomplete('Needs to be fixed');
+ }
+
+ /**
* Test class construction.
*
* @return NULL
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/SessionTestCase.php b/framework/Kolab_Session/test/Horde/Kolab/Session/SessionTestCase.php
new file mode 100644
index 000000000..8719c3b62
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/SessionTestCase.php
@@ -0,0 +1,64 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Base for session testing.
+ *
+ * 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 Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_SessionTestCase extends PHPUnit_Framework_TestCase
+{
+ protected function _getComposite()
+ {
+ return $this->getMock(
+ 'Horde_Kolab_Server_Composite', array(), array(), '', false, false
+ );
+ }
+
+ protected function _getMockedComposite()
+ {
+ return new Horde_Kolab_Server_Composite(
+ $this->getMock('Horde_Kolab_Server'),
+ $this->getMock('Horde_Kolab_Server_Objects'),
+ $this->getMock('Horde_Kolab_Server_Structure'),
+ $this->getMock('Horde_Kolab_Server_Search'),
+ $this->getMock('Horde_Kolab_Server_Schema')
+ );
+ }
+
+ protected function setupLogger()
+ {
+ $this->logger = $this->getMock('Horde_Log_Logger');
+ }
+
+ protected function setupStorage()
+ {
+ $this->storage = $this->getMock('Horde_Kolab_Session_Storage');
+ }
+
+ protected function setupFactoryMocks()
+ {
+ $this->server = $this->_getMockedComposite();
+ $this->session_auth = $this->getMock('Horde_Kolab_Session_Auth');
+ $this->session_storage = $this->getMock('Horde_Kolab_Session_Storage');
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/phpunit.xml b/framework/Kolab_Session/test/Horde/Kolab/Session/phpunit.xml
new file mode 100644
index 000000000..0148736fe
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/phpunit.xml
@@ -0,0 +1,8 @@
+
+
+
+
+ ../../../../lib
+
+
+