Refactoring and testing of Kolab_Session largely complete. The connection with Kolab_...
authorGunnar Wrobel <p@rdus.de>
Mon, 26 Oct 2009 17:55:05 +0000 (18:55 +0100)
committerGunnar Wrobel <p@rdus.de>
Mon, 26 Oct 2009 17:55:05 +0000 (18:55 +0100)
50 files changed:
framework/Kolab_Session/lib/Horde/Kolab/Session.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Anonymous.php [new file with mode: 0644]
framework/Kolab_Session/lib/Horde/Kolab/Session/Auth/Mock.php [new file with mode: 0644]
framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Factory.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Anonymous.php [new file with mode: 0644]
framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Base.php [new file with mode: 0644]
framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Configuration.php [new file with mode: 0644]
framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Constructor.php [new file with mode: 0644]
framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Default.php [new file with mode: 0644]
framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Injector.php [new file with mode: 0644]
framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Logged.php [new file with mode: 0644]
framework/Kolab_Session/lib/Horde/Kolab/Session/Logged.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Singleton.php [new file with mode: 0644]
framework/Kolab_Session/lib/Horde/Kolab/Session/Storage.php [new file with mode: 0644]
framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Mock.php [new file with mode: 0644]
framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Sessionobjects.php [new file with mode: 0644]
framework/Kolab_Session/lib/Horde/Kolab/Session/Store.php [deleted file]
framework/Kolab_Session/lib/Horde/Kolab/Session/Store/Mock.php [deleted file]
framework/Kolab_Session/lib/Horde/Kolab/Session/Store/Sessionobjects.php [deleted file]
framework/Kolab_Session/lib/Horde/Kolab/Session/Stored.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Valid.php [new file with mode: 0644]
framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Base.php [new file with mode: 0644]
framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Logged.php [new file with mode: 0644]
framework/Kolab_Session/package.xml
framework/Kolab_Session/test/Horde/Kolab/Session/AllTests.php
framework/Kolab_Session/test/Horde/Kolab/Session/Autoload.php
framework/Kolab_Session/test/Horde/Kolab/Session/Class/AnonymousTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Auth/HordeTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Auth/MockTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/BaseTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/AnonymousTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/BaseTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/ConfigurationTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/ConstructorTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/DefaultTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/InjectorTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/LoggedTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/LoggedTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/SingletonTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Storage/MockTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Storage/SessionobjectsTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/StoredTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Valid/BaseTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Valid/LoggedTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Integration/AnonymousTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Integration/ValidTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/SessionTest.php
framework/Kolab_Session/test/Horde/Kolab/Session/SessionTestCase.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/phpunit.xml [new file with mode: 0644]

index 9d415f2..f36a04a 100644 (file)
@@ -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 (file)
index 0000000..9c046a6
--- /dev/null
@@ -0,0 +1,182 @@
+<?php
+/**
+ * The Horde_Kolab_Session_Anonymous class allows anonymous access to the Kolab
+ * system.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <code>Auth::getAuth()</code> respectively
+ * <code>Auth::getCredential('password')</code>. 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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..bf08936
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/**
+ * Mock authentication for the Kolab session information.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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;
+    }
+}
index ead5483..c0e2c62 100644 (file)
@@ -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!');
     }
 }
index aec6aea..5a8df03 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 /**
- * Revives an old Horde_Kolab_Session handler or generates a new one if
- * required.
+ * Interface for Horde_Kolab_Session factories.
  *
  * PHP version 5
  *
  * @link     http://pear.horde.org/index.php?package=Kolab_Session
  */
 
-/** We need the Auth library */
-require_once 'Horde/Auth.php';
-
 /**
- * Revives an old Horde_Kolab_Session handler or generates a new one if
- * required.
+ * Interface for Horde_Kolab_Session factories.
  *
- * Copyright 2008-2009 The Horde Project (http://www.horde.org/)
+ * 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.
@@ -30,223 +25,75 @@ require_once 'Horde/Auth.php';
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
  * @link     http://pear.horde.org/index.php?package=Kolab_Session
  */
-class Horde_Kolab_Session_Factory
+interface Horde_Kolab_Session_Factory
 {
     /**
-     * Horde_Kolab_Session instance.
+     * Return the kolab user db connection.
      *
-     * @var Horde_Kolab_Session
+     * @return Horde_Kolab_Server The server connection.
      */
-    static private $_instance;
+    public function getServer();
 
     /**
-     * Setup the machinery to create Horde_Kolab_Session objects.
-     *
-     * @param array          $configuration The parameters required to create
-     *                                      the desired Horde_Kolab_Server object.
-     * @param Horde_Injector $injector      The object providing our dependencies.
+     * Return the auth handler for sessions.
      *
-     * @return NULL
+     * @return Horde_Kolab_Session_Auth The authentication handler.
      */
-    static public function setup(array $configuration, Horde_Injector $injector)
-    {
-        self::setupAuth($injector);
-        self::setupStore($injector);
-
-        self::setupLogger(
-            $injector,
-            isset($configuration['logger'])
-            ? $configuration['logger'] : null
-        );
-
-        Horde_Kolab_Server_Factory::setupServer(
-            $injector,
-            isset($configuration['server'])
-            ? $configuration['server'] : array()
-        );
-
-        self::setupConfiguration(
-            $injector,
-            isset($configuration['session'])
-            ? $configuration['session'] : array()
-        );
-
-        self::setupSession($injector);
-    }
+    public function getSessionAuth();
 
     /**
-     * Setup the machinery to create a Horde_Kolab_Sesssion_Auth handler.
+     * Return the configuration parameters for the session.
      *
-     * @param Horde_Injector $injector The object providing our dependencies.
-     *
-     * @return NULL
+     * @return array The configuration values.
      */
-    static protected function setupAuth(Horde_Injector $injector)
-    {
-        $injector->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 (file)
index 0000000..109e914
--- /dev/null
@@ -0,0 +1,165 @@
+<?php
+/**
+ * A factory decorator that adds an anonymous user to the generated instances.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..b9f9ea8
--- /dev/null
@@ -0,0 +1,105 @@
+<?php
+/**
+ * Revives an old Horde_Kolab_Session handler or generates a new one if
+ * required.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..cc48b83
--- /dev/null
@@ -0,0 +1,163 @@
+<?php
+/**
+ * A factory that receives all required details via configuration parameters.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..cda221e
--- /dev/null
@@ -0,0 +1,122 @@
+<?php
+/**
+ * A factory that receives all required details via the factory constructor.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..4150c4f
--- /dev/null
@@ -0,0 +1,104 @@
+<?php
+/**
+ * A factory implementing the default policy.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..1472e63
--- /dev/null
@@ -0,0 +1,163 @@
+<?php
+/**
+ * A factory using a Horde_Injector instance.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..e69087b
--- /dev/null
@@ -0,0 +1,150 @@
+<?php
+/**
+ * A factory decorator that adds logging to the generated instances.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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);
+    }
+}
index 4d41472..bba8424 100644 (file)
@@ -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 (file)
index 0000000..edef55c
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+/**
+ * A singleton pattern providing Horde_Kolab_Session instances.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..5eab9a7
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+/**
+ * Defines storage containers for the Kolab session information.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..4d3a415
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+/**
+ * A mock container for the Kolab session information.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..c7163fe
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+/**
+ * Defines storage containers for the Kolab session information.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index d59950d..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-/**
- * Defines storage containers for the Kolab session information.
- *
- * PHP version 5
- *
- * @category Kolab
- * @package  Kolab_Session
- * @author   Gunnar Wrobel <wrobel@pardus.de>
- * @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 <wrobel@pardus.de>
- * @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 (file)
index 0ee1246..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-<?php
-/**
- * A mock container for the Kolab session information.
- *
- * PHP version 5
- *
- * @category Kolab
- * @package  Kolab_Session
- * @author   Gunnar Wrobel <wrobel@pardus.de>
- * @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 <wrobel@pardus.de>
- * @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 (file)
index ab238fc..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-<?php
-/**
- * Defines storage containers for the Kolab session information.
- *
- * PHP version 5
- *
- * @category Kolab
- * @package  Kolab_Session
- * @author   Gunnar Wrobel <wrobel@pardus.de>
- * @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 <wrobel@pardus.de>
- * @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();
-    }
-}
index d91d414..c145590 100644 (file)
@@ -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 (file)
index 0000000..a1c2fe8
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+/**
+ * Interface for session validators.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <code>Auth::getAuth()</code> respectively
+ * <code>Auth::getCredential('password')</code>. 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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..1e6be37
--- /dev/null
@@ -0,0 +1,108 @@
+<?php
+/**
+ * A class to check if the given session is valid.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <code>Auth::getAuth()</code> respectively
+ * <code>Auth::getCredential('password')</code>. 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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..a21b88a
--- /dev/null
@@ -0,0 +1,103 @@
+<?php
+/**
+ * A logger for Horde_Kolab_Session_Valid validators.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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();
+    }
+}
index c62ce50..610c6b1 100644 (file)
@@ -46,6 +46,39 @@ http://pear.php.net/dtd/package-2.0.xsd">
     <dir name="Horde">
      <dir name="Kolab">
       <file name="Session.php" role="php" />
+      <dir name="Session">
+       <file name="Anonymous.php" role="php" />
+       <file name="Auth.php" role="php" />
+       <dir name="Auth">
+        <file name="Horde.php" role="php" />
+        <file name="Mock.php" role="php" />
+       </dir> <!-- /lib/Horde/Session/Auth -->
+       <file name="Base.php" role="php" />
+       <file name="Exception.php" role="php" />
+       <file name="Factory.php" role="php" />
+       <dir name="Factory">
+        <file name="Anonymous.php" role="php" />
+        <file name="Base.php" role="php" />
+        <file name="Configuration.php" role="php" />
+        <file name="Constructor.php" role="php" />
+        <file name="Default.php" role="php" />
+        <file name="Injector.php" role="php" />
+        <file name="Logged.php" role="php" />
+       </dir> <!-- /lib/Horde/Session/Factory -->
+       <file name="Logged.php" role="php" />
+       <file name="Singleton.php" role="php" />
+       <file name="Storage.php" role="php" />
+       <dir name="Storage">
+        <file name="Mock.php" role="php" />
+        <file name="Sessionobjects.php" role="php" />
+       </dir> <!-- /lib/Horde/Session/Storage -->
+       <file name="Stored.php" role="php" />
+       <file name="Valid.php" role="php" />
+       <dir name="Valid">
+        <file name="Base.php" role="php" />
+        <file name="Logged.php" role="php" />
+       </dir> <!-- /lib/Horde/Session/Valid -->
+      </dir> <!-- /lib/Horde/Session -->
      </dir> <!-- /lib/Horde/Kolab -->
     </dir> <!-- /lib/Horde -->
    </dir> <!-- /lib -->
@@ -70,31 +103,59 @@ http://pear.php.net/dtd/package-2.0.xsd">
     <min>1.4.0b1</min>
    </pearinstaller>
    <package>
-    <name>Auth</name>
+    <name>Kolab_Server</name>
+    <channel>pear.horde.org</channel>
+   </package>
+   <package>
+    <name>Kolab_Storage</name>
     <channel>pear.horde.org</channel>
    </package>
   </required>
   <optional>
    <package>
-    <name>Kolab_Server</name>
+    <name>Auth</name>
     <channel>pear.horde.org</channel>
    </package>
    <package>
-    <name>SessionObjects</name>
+    <name>Injector</name>
     <channel>pear.horde.org</channel>
    </package>
    <package>
-    <name>PHPUnit</name>
-    <channel>pear.phpunit.de</channel>
+    <name>Log</name>
+    <channel>pear.horde.org</channel>
+   </package>
+   <package>
+    <name>SessionObjects</name>
+    <channel>pear.horde.org</channel>
    </package>
-   <extension>
-    <name>ldap</name>
-   </extension>
   </optional>
  </dependencies>
  <phprelease>
   <filelist>
    <install name="lib/Horde/Kolab/Session.php" as="Horde/Kolab/Session.php" />
+   <install name="lib/Horde/Kolab/Session/Anonymous.php" as="Horde/Kolab/Session/Anonymous.php" />
+   <install name="lib/Horde/Kolab/Session/Auth.php" as="Horde/Kolab/Session/Auth.php" />
+   <install name="lib/Horde/Kolab/Session/Auth/Horde.php" as="Horde/Kolab/Session/Auth/Horde.php" />
+   <install name="lib/Horde/Kolab/Session/Auth/Mock.php" as="Horde/Kolab/Session/Auth/Mock.php" />
+   <install name="lib/Horde/Kolab/Session/Base.php" as="Horde/Kolab/Session/Base.php" />
+   <install name="lib/Horde/Kolab/Session/Exception.php" as="Horde/Kolab/Session/Exception.php" />
+   <install name="lib/Horde/Kolab/Session/Factory.php" as="Horde/Kolab/Session/Factory.php" />
+   <install name="lib/Horde/Kolab/Session/Factory/Anonymous.php" as="Horde/Kolab/Session/Factory/Anonymous.php" />
+   <install name="lib/Horde/Kolab/Session/Factory/Base.php" as="Horde/Kolab/Session/Factory/Base.php" />
+   <install name="lib/Horde/Kolab/Session/Factory/Configuration.php" as="Horde/Kolab/Session/Factory/Configuration.php" />
+   <install name="lib/Horde/Kolab/Session/Factory/Constructor.php" as="Horde/Kolab/Session/Factory/Constructor.php" />
+   <install name="lib/Horde/Kolab/Session/Factory/Default.php" as="Horde/Kolab/Session/Factory/Default.php" />
+   <install name="lib/Horde/Kolab/Session/Factory/Injector.php" as="Horde/Kolab/Session/Factory/Injector.php" />
+   <install name="lib/Horde/Kolab/Session/Factory/Logged.php" as="Horde/Kolab/Session/Factory/Logged.php" />
+   <install name="lib/Horde/Kolab/Session/Logged.php" as="Horde/Kolab/Session/Logged.php" />
+   <install name="lib/Horde/Kolab/Session/Singleton.php" as="Horde/Kolab/Session/Singleton.php" />
+   <install name="lib/Horde/Kolab/Session/Storage.php" as="Horde/Kolab/Session/Storage.php" />
+   <install name="lib/Horde/Kolab/Session/Storage/Mock.php" as="Horde/Kolab/Session/Storage/Mock.php" />
+   <install name="lib/Horde/Kolab/Session/Storage/Sessionobjects.php" as="Horde/Kolab/Session/Storage/Sessionobjects.php" />
+   <install name="lib/Horde/Kolab/Session/Stored.php" as="Horde/Kolab/Session/Stored.php" />
+   <install name="lib/Horde/Kolab/Session/Valid.php" as="Horde/Kolab/Session/Valid.php" />
+   <install name="lib/Horde/Kolab/Session/Valid/Base.php" as="Horde/Kolab/Session/Valid/Base.php" />
+   <install name="lib/Horde/Kolab/Session/Valid/Logged.php" as="Horde/Kolab/Session/Valid/Logged.php" />
    <install name="test/Horde/Kolab/Session/AllTests.php" as="Horde/Kolab/Session/AllTests.php" />
    <install name="test/Horde/Kolab/Session/SessionTest.php" as="Horde/Kolab/Session/SessionTest.php" />
   </filelist>
index 7eebe26..84267a5 100644 (file)
@@ -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);
             }
         }
index 6098615..3048c4a 100644 (file)
@@ -5,29 +5,27 @@
  * PHP version 5
  *
  * @category Kolab
- * @package  Kolab_Server
+ * @package  Kolab_Session
  * @author   Gunnar Wrobel <wrobel@pardus.de>
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link     http://pear.horde.org/index.php?package=Kolab_Server
+ * @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 (file)
index 0000000..05b0f2b
--- /dev/null
@@ -0,0 +1,174 @@
+<?php
+/**
+ * Test the anonymous decorator.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..3b328de
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+/**
+ * Test the horde auth driver.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..73388e1
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Test the mock auth driver.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..e7c81a1
--- /dev/null
@@ -0,0 +1,440 @@
+<?php
+/**
+ * Test the Kolab session handler base implementation.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..6209ea7
--- /dev/null
@@ -0,0 +1,164 @@
+<?php
+/**
+ * Test the anonymous decorator factory.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..5379d5c
--- /dev/null
@@ -0,0 +1,122 @@
+<?php
+/**
+ * Test the base factory definition via the constructor based factory.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..69a2aea
--- /dev/null
@@ -0,0 +1,212 @@
+<?php
+/**
+ * Test the configuration based factory.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..f7ff429
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+/**
+ * Test the constructor based factory.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..d6c856c
--- /dev/null
@@ -0,0 +1,76 @@
+<?php
+/**
+ * Test the default factory.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..a6ec495
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+/**
+ * Test the injector based factory.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..367b134
--- /dev/null
@@ -0,0 +1,188 @@
+<?php
+/**
+ * Test the log decorator factory.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..f8be545
--- /dev/null
@@ -0,0 +1,175 @@
+<?php
+/**
+ * Test the log decorator.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..f9969cb
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+/**
+ * Test the Kolab session singleton pattern.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..b187259
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+/**
+ * Test the mock storage driver.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..ec620a6
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+/**
+ * Test the sessionobjects storage driver.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..767da7b
--- /dev/null
@@ -0,0 +1,143 @@
+<?php
+/**
+ * Test the storing decorator.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..7f9b700
--- /dev/null
@@ -0,0 +1,118 @@
+<?php
+/**
+ * Test the valid check.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..bd51d04
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+/**
+ * Test the log decorator for validators.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..bcd0a59
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/**
+ * Test the anonymous decorator with the Kolab session handler base
+ * implementation.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..2b2379e
--- /dev/null
@@ -0,0 +1,150 @@
+<?php
+/**
+ * Test the valid check with the Kolab session handler implementation.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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
index 32b882b..2ec886b 100644 (file)
@@ -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 (file)
index 0000000..8719c3b
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+/**
+ * Base for session testing.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..0148736
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit>
+  <filter>
+    <whitelist>
+      <directory suffix=".php">../../../../lib</directory>
+    </whitelist>
+  </filter>
+</phpunit>