Remove the use of Horde_Session and access the session directly. Simplify the factory.
authorGunnar Wrobel <p@rdus.de>
Wed, 1 Dec 2010 13:56:19 +0000 (14:56 +0100)
committerGunnar Wrobel <p@rdus.de>
Wed, 1 Dec 2010 13:56:19 +0000 (14:56 +0100)
39 files changed:
framework/Core/lib/Horde/Core/Factory/KolabSession.php
framework/Kolab_Session/lib/Horde/Kolab/Session.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Base.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Logged.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Stored.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Storage.php [new file with mode: 0644]
framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Interface.php [deleted file]
framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Mock.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Session.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
framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Decorator/Logged.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Interface.php [deleted file]
framework/Kolab_Session/package.xml
framework/Kolab_Session/test/Horde/Kolab/Session/Autoload.php
framework/Kolab_Session/test/Horde/Kolab/Session/Class/BaseTest.php [deleted file]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/AnonymousTest.php [deleted file]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/BaseTest.php [deleted file]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/LoggedTest.php [deleted file]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/StoredTest.php [deleted file]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Storage/MockTest.php [deleted file]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Storage/SessionTest.php [deleted file]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Valid/BaseTest.php [deleted file]
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Valid/Decorator/LoggedTest.php [deleted file]
framework/Kolab_Session/test/Horde/Kolab/Session/Integration/AnonymousTest.php
framework/Kolab_Session/test/Horde/Kolab/Session/Integration/SessionTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Integration/ValidTest.php
framework/Kolab_Session/test/Horde/Kolab/Session/SessionTestCase.php [deleted file]
framework/Kolab_Session/test/Horde/Kolab/Session/TestCase.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Unit/BaseTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/AnonymousTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/BaseTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/LoggedTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/StoredTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Storage/MockTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Storage/SessionTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Valid/BaseTest.php [new file with mode: 0644]
framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Valid/Decorator/LoggedTest.php [new file with mode: 0644]

index 5b58d8a..81c338f 100644 (file)
@@ -42,74 +42,10 @@ class Horde_Core_Factory_KolabSession
     public function __construct(
         Horde_Injector $injector
     ) {
-        $this->_injector      = $injector;
-        $this->_setup();
-    }
-
-    /**
-     * Setup the machinery to create Horde_Kolab_Session objects.
-     *
-     * @return NULL
-     */
-    private function _setup()
-    {
-        $this->_setupConfiguration();
-        $this->_setupAuth();
-        $this->_setupStorage();
-    }
-
-    /**
-     * Provide configuration settings for Horde_Kolab_Session.
-     *
-     * @return NULL
-     */
-    private function _setupConfiguration()
-    {
-        $configuration = array();
-        if (!empty($GLOBALS['conf']['kolab']['session'])) {
-            $configuration = $GLOBALS['conf']['kolab']['session'];
-        }
-        $this->_injector->setInstance(
-            'Horde_Kolab_Session_Configuration', $configuration
-        );
-    }
-
-    /**
-     * Setup the machinery to create a Horde_Kolab_Session_Auth handler.
-     *
-     * @return NULL
-     */
-    private function _setupAuth()
-    {
+        $this->_injector = $injector;
         $this->_injector->bindImplementation(
-            'Horde_Kolab_Session_Auth_Interface',
-            'Horde_Kolab_Session_Auth_Horde'
-        );
-    }
-
-    /**
-     * Setup the machinery to create a Horde_Kolab_Session_Storage handlers.
-     *
-     * @return NULL
-     */
-    private function _setupStorage()
-    {
-        $this->_injector->bindFactory(
-            'Horde_Kolab_Session_Storage_Interface',
-            'Horde_Core_Factory_KolabSession',
-            'getStorage'
-        );
-    }
-
-    /**
-     * Return the session storage driver.
-     *
-     * @return Horde_Kolab_Session_Storage The driver for storing sessions.
-     */
-    public function getStorage()
-    {
-        return new Horde_Kolab_Session_Storage_Session(
-            $GLOBALS['session']
+            'Horde_Kolab_Session_Storage',
+            'Horde_Kolab_Session_Storage_Session'
         );
     }
 
@@ -123,17 +59,15 @@ class Horde_Core_Factory_KolabSession
      * @return Horde_Kolab_Session_Valid_Interface The driver for validating
      *                                             sessions.
      */
-    public function getSessionValidator(
+    public function createSessionValidator(
         Horde_Kolab_Session $session,
         $auth
     ) {
-        $configuration = $this->_injector->getInstance('Horde_Kolab_Session_Configuration');
-
         $validator = new Horde_Kolab_Session_Valid_Base(
             $session, $auth
         );
 
-        if (isset($configuration['debug']) || isset($configuration['log'])) {
+        if (isset($GLOBALS['conf']['kolab']['session']['debug'])) {
             $validator = new Horde_Kolab_Session_Valid_Decorator_Logged(
                 $validator, $this->_injector->getInstance('Horde_Log_Logger')
             );
@@ -143,22 +77,6 @@ class Horde_Core_Factory_KolabSession
     }
 
     /**
-     * Validate the given session.
-     *
-     * @param Horde_Kolab_Session $session The session to validate.
-     *
-     * @return boolean True if the given session is valid.
-     */
-    public function validate(
-        Horde_Kolab_Session $session
-    ) {
-        return $this->getSessionValidator(
-            $session,
-            $this->_injector->getInstance('Horde_Registry')->getAuth()
-        )->isValid();
-    }
-
-    /**
      * Returns a new session handler.
      *
      * @return Horde_Kolab_Session The concrete Kolab session reference.
@@ -167,15 +85,20 @@ class Horde_Core_Factory_KolabSession
     {
         $session = new Horde_Kolab_Session_Base(
             $this->_injector->getInstance('Horde_Kolab_Server_Composite'),
-            $this->_injector->getInstance('Horde_Kolab_Session_Configuration')
+            $GLOBALS['conf']['kolab']['session']
         );
 
-        //@todo: Fix validation
-        /** If we created a new session handler it needs to be stored once */
+        if (isset($GLOBALS['conf']['kolab']['session']['debug'])) {
+            $session = new Horde_Kolab_Session_Decorator_Logged(
+                $session, $this->_injector->getInstance('Horde_Log_Logger')
+            );
+        }
+
         $session = new Horde_Kolab_Session_Decorator_Stored(
             $session,
-            $this->_injector->getInstance('Horde_Kolab_Session_Storage_Interface')
+            $this->_injector->getInstance('Horde_Kolab_Session_Storage')
         );
+
         return $session;
     }
 
@@ -186,29 +109,20 @@ class Horde_Core_Factory_KolabSession
      */
     public function create()
     {
-        $storage = $this->_injector->getInstance('Horde_Kolab_Session_Storage_Interface');
-        $session = $storage->load();
-
-        if (empty($session) || !$this->validate($session)) {
-            $session = $this->createSession();
-        }
-
-        $configuration = $this->_injector->getInstance('Horde_Kolab_Session_Configuration');
+        $session = $this->createSession();
 
+        $this->createSessionValidator(
+            $session,
+            $this->_injector->getInstance('Horde_Registry')->getAuth()
+        )->validate();
 
-        if (isset($configuration['debug']) || isset($configuration['log'])) {
-            $session = new Horde_Kolab_Session_Decorator_Logged(
-                $session, $this->_injector->getInstance('Horde_Log_Logger')
-            );
-        }
-
-        if (isset($configuration['anonymous']['user'])
-            && isset($configuration['anonymous']['pass'])
+        if (isset($GLOBALS['conf']['kolab']['session']['anonymous']['user'])
+            && isset($GLOBALS['conf']['kolab']['session']['anonymous']['pass'])
         ) {
             $session = new Horde_Kolab_Session_Decorator_Anonymous(
                 $session,
-                $configuration['anonymous']['user'],
-                $configuration['anonymous']['pass']
+                $GLOBALS['conf']['kolab']['session']['anonymous']['user'],
+                $GLOBALS['conf']['kolab']['session']['anonymous']['pass']
             );
         }
 
index 70c3f9c..271458c 100644 (file)
@@ -89,4 +89,27 @@ interface Horde_Kolab_Session
      * @return string The freebusy host for the current user.
      */
     public function getFreebusyServer();
+
+    /**
+     * Import the session data from an array.
+     *
+     * @param array The session data.
+     *
+     * @return NULL
+     */
+    public function import(array $session_data);
+
+    /**
+     * Export the session data as array.
+     *
+     * @return array The session data.
+     */
+    public function export();
+
+    /**
+     * Clear the session data.
+     *
+     * @return NULL
+     */
+    public function purge();
 }
index 83b17e6..85c32a6 100644 (file)
@@ -35,6 +35,13 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
     private $_params;
 
     /**
+     * The session data.
+     *
+     * @var array
+     */
+    private $_data;
+
+    /**
      * User ID.
      *
      * @var string
@@ -84,13 +91,6 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
     private $_server;
 
     /**
-     * Mark the session as connected.
-     *
-     * @var true
-     */
-    private $_connected = false;
-
-    /**
      * Constructor.
      *
      * @param Horde_Kolab_Server $server  The connection to the Kolab user
@@ -118,7 +118,7 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
      */
     public function connect($user_id = null, array $credentials = null)
     {
-        $this->_user_id = $user_id;
+        $this->_data['user']['id'] = $user_id;
         if (isset($credentials['password'])) {
             $password = $credentials['password'];
         } else {
@@ -126,7 +126,7 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
         }
 
         try {
-            $this->_server->connect($this->_user_id, $password);
+            $this->_server->connect($this->_data['user']['id'], $password);
             $user_object = $this->_server->objects->fetch();
         } catch (Horde_Kolab_Server_Exception_Bindfailed $e) {
             throw new Horde_Kolab_Session_Exception_Badlogin('Invalid credentials!', 0, $e);
@@ -139,8 +139,6 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
         $this->_initName($user_object);
         $this->_initImapServer($user_object);
         $this->_initFreebusyServer($user_object);
-
-        $this->_connected = true;
     }
 
     /**
@@ -154,9 +152,9 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
         Horde_Kolab_Server_Object_Hash $user
     ) {
         try {
-            $this->_user_mail = $user->getSingle('mail');;
+            $this->_data['user']['mail'] = $user->getSingle('mail');;
         } catch (Horde_Kolab_Server_Exception_Novalue $e) {
-            $this->_user_mail = $this->_user_id;
+            $this->_data['user']['mail'] = $this->_data['user']['id'];
         }
     }
 
@@ -171,9 +169,9 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
         Horde_Kolab_Server_Object_Hash $user
     ) {
         try {
-            $this->_user_uid = $user->getSingle('uid');
+            $this->_data['user']['uid'] = $user->getSingle('uid');
         } catch (Horde_Kolab_Server_Exception_Novalue $e) {
-            $this->_user_uid = $this->_user_id;
+            $this->_data['user']['uid'] = $this->_data['user']['id'];
         }
     }
 
@@ -188,9 +186,9 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
         Horde_Kolab_Server_Object_Hash $user
     ) {
         try {
-            $this->_user_name = $user->getSingle('Firstnamelastname');
+            $this->_data['user']['name'] = $user->getSingle('Firstnamelastname');
         } catch (Horde_Kolab_Server_Exception_Novalue $e) {
-            $this->_user_name = $this->_user_id;
+            $this->_data['user']['name'] = $this->_data['user']['id'];
         }
     }
 
@@ -205,12 +203,12 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
         Horde_Kolab_Server_Object_Hash $user
     ) {
         try {
-            $this->_imap_server = $user->getSingle('kolabHomeServer');
+            $this->_data['imap']['server'] = $user->getSingle('kolabHomeServer');
         } catch (Horde_Kolab_Server_Exception_Novalue $e) {
             if (isset($this->_params['imap']['server'])) {
-                $this->_imap_server = $this->_params['imap']['server'];
+                $this->_data['imap']['server'] = $this->_params['imap']['server'];
             } else {
-                $this->_imap_server = 'localhost';
+                $this->_data['imap']['server'] = 'localhost';
             }
         }
     }
@@ -229,10 +227,10 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
             $fb_server = $user->getSingle('kolabFreebusyHost');
         } catch (Horde_Kolab_Server_Exception_Novalue $e) {
             if (isset($this->_params['freebusy']['url'])) {
-                $this->_freebusy_server = $this->_params['freebusy']['url'];
+                $this->_data['fb']['server'] = $this->_params['freebusy']['url'];
                 return;
             } else {
-                $fb_server = $this->_imap_server;
+                $fb_server = $this->_data['imap']['server'];
             }
         }
 
@@ -242,20 +240,7 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
             $fb_format = 'http://%s/freebusy';
         }
 
-        $this->_freebusy_server = sprintf($fb_format, $fb_server);
-    }
-
-    /**
-     * Returns the properties that need to be serialized.
-     *
-     * @return array  List of serializable properties.
-     */
-    public function __sleep()
-    {
-        $properties = get_object_vars($this);
-        unset($properties['_server']);
-        $properties = array_keys($properties);
-        return $properties;
+        $this->_data['fb']['server'] = sprintf($fb_format, $fb_server);
     }
 
     /**
@@ -265,7 +250,9 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
      */
     public function getId()
     {
-        return $this->_user_id;
+        if (isset($this->_data['user']['id'])) {
+            return $this->_data['user']['id'];
+        }
     }
 
     /**
@@ -275,7 +262,9 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
      */
     public function getMail()
     {
-        return $this->_user_mail;
+        if (isset($this->_data['user']['mail'])) {
+            return $this->_data['user']['mail'];
+        }
     }
 
     /**
@@ -285,7 +274,9 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
      */
     public function getUid()
     {
-        return $this->_user_uid;
+        if (isset($this->_data['user']['uid'])) {
+            return $this->_data['user']['uid'];
+        }
     }
 
     /**
@@ -295,7 +286,9 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
      */
     public function getName()
     {
-        return $this->_user_name;
+        if (isset($this->_data['user']['name'])) {
+            return $this->_data['user']['name'];
+        }
     }
 
     /**
@@ -305,7 +298,9 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
      */
     public function getImapServer()
     {
-        return $this->_imap_server;
+        if (isset($this->_data['imap']['server'])) {
+            return $this->_data['imap']['server'];
+        }
     }
 
     /**
@@ -315,6 +310,40 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
      */
     public function getFreebusyServer()
     {
-        return $this->_freebusy_server;
+        if (isset($this->_data['fb']['server'])) {
+            return $this->_data['fb']['server'];
+        }
+    }
+
+    /**
+     * Import the session data from an array.
+     *
+     * @param array The session data.
+     *
+     * @return NULL
+     */
+    public function import(array $session_data)
+    {
+        $this->_data = $session_data;
+    }
+
+    /**
+     * Export the session data as array.
+     *
+     * @return array The session data.
+     */
+    public function export()
+    {
+        return $this->_data;
+    }
+
+    /**
+     * Clear the session data.
+     *
+     * @return NULL
+     */
+    public function purge()
+    {
+        $this->_data = array();
     }
 }
index 4570e33..7632816 100644 (file)
@@ -46,7 +46,7 @@ implements Horde_Kolab_Session
     public function __construct(
         Horde_Kolab_Session $session
     ) {
-        $this->_session        = $session;
+        $this->_session = $session;
     }
 
     /**
@@ -124,4 +124,36 @@ implements Horde_Kolab_Session
     {
         return $this->_session->getFreebusyServer();
     }
+
+    /**
+     * Import the session data from an array.
+     *
+     * @param array The session data.
+     *
+     * @return NULL
+     */
+    public function import(array $session_data)
+    {
+        $this->_session->import($session_data);
+    }
+
+    /**
+     * Export the session data as array.
+     *
+     * @return array The session data.
+     */
+    public function export()
+    {
+        return $this->_session->export();
+    }
+
+    /**
+     * Clear the session data.
+     *
+     * @return NULL
+     */
+    public function purge()
+    {
+        $this->_session->purge();
+    }
 }
index 0ba31d6..1c81d96 100644 (file)
@@ -77,10 +77,61 @@ extends Horde_Kolab_Session_Decorator_Base
             $this->_logger->err(
                 sprintf(
                     "Failed to connect Kolab session for \"%s\". Error was: %s",
-                    $this->_session->getId(), $e->getMessage()
+                    $this->_session->getMail(), $e->getMessage()
                 )
             );
             throw $e;
         }
     }
+
+    /**
+     * Export the session data as array.
+     *
+     * @return array The session data.
+     */
+    public function export()
+    {
+        $session_data = $this->_session->export();
+        $this->_logger->info(
+            sprintf(
+                "Exported session data for \"%s\" (%s). [%s]",
+                $this->_session->getMail(), serialize($session_data), new Horde_Support_Backtrace()
+            )
+        );
+        return $session_data;
+    }
+
+    /**
+     * Import the session data from an array.
+     *
+     * @param array The session data.
+     *
+     * @return NULL
+     */
+    public function import(array $session_data)
+    {
+        $this->_session->import($session_data);
+        $this->_logger->info(
+            sprintf(
+                "Imported session data for \"%s\" (%s). [%s]",
+                $this->_session->getMail(), serialize($session_data), new Horde_Support_Backtrace()
+            )
+        );
+    }
+
+    /**
+     * Clear the session data.
+     *
+     * @return NULL
+     */
+    public function purge()
+    {
+        $this->_logger->warn(
+            sprintf(
+                "Purged session data for \"%s\". [%s]",
+                $this->_session->getMail(), new Horde_Support_Backtrace()
+            )
+        );
+        $this->_session->purge();
+    }
 }
index ee6e656..be049c5 100644 (file)
@@ -36,11 +36,11 @@ extends Horde_Kolab_Session_Decorator_Base
     private $_storage;
 
     /**
-     * Has the storage been connected successfully?
+     * Has the session information changed?
      *
      * @var boolean
      */
-    private $_connected = false;
+    private $_modified = false;
 
     /**
      * Constructor.
@@ -50,20 +50,12 @@ extends Horde_Kolab_Session_Decorator_Base
      */
     public function __construct(
         Horde_Kolab_Session $session,
-        Horde_Kolab_Session_Storage_Interface $storage
+        Horde_Kolab_Session_Storage $storage
     ) {
         parent::__construct($session);
         $this->_storage = $storage;
-    }
-
-    /**
-     * Destructor.
-     *
-     * Save the session in the storage on shutdown.
-     */
-    public function __destruct()
-    {
-        $this->_storage->save($this->_session);
+        $this->_session->import($this->_storage->load());
+        register_shutdown_function(array($this, 'shutdown'));
     }
 
     /**
@@ -74,10 +66,47 @@ extends Horde_Kolab_Session_Decorator_Base
      *                            this must contain a "password" entry.
      *
      * @return NULL
+     *
+     * @throws Horde_Kolab_Session_Exception If the connection failed.
      */
     public function connect($user_id = null, array $credentials = null)
     {
         $this->_session->connect($user_id, $credentials);
-        $this->_connected = true;
+        $this->_modified = $this->_session->export();
+    }
+
+    /**
+     * Import the session data from an array.
+     *
+     * @param array The session data.
+     *
+     * @return NULL
+     */
+    public function import(array $session_data)
+    {
+        throw new Horde_Kolab_Session_Exception('Data import of stored session data is handled via the session.');
+    }
+
+    /**
+     * Clear the session data.
+     *
+     * @return NULL
+     */
+    public function purge()
+    {
+        $this->_session->purge();
+        $this->_modified = array();
+    }
+
+    /**
+     * Write any modified data to the session.
+     *
+     * @return NULL
+     */
+    public function shutdown()
+    {
+        if ($this->_modified !== false) {
+            $this->_storage->save($this->_modified);
+        }
     }
 }
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..f7d6098
--- /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-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_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 array The session data or an empty array if no information was
+     *               found.
+     */
+    public function load();
+
+    /**
+     * Save the session information.
+     *
+     * @param array $session_data The session data that should be stored.
+     *
+     * @return NULL
+     */
+    public function save(array $session_data);
+}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Interface.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Interface.php
deleted file mode 100644 (file)
index e27adb0..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-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Kolab
- * @package  Kolab_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_Interface
-{
-    /**
-     * 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);
-}
index bdaea3f..a133f6b 100644 (file)
@@ -26,7 +26,7 @@
  * @link     http://pear.horde.org/index.php?package=Kolab_Session
  */
 class Horde_Kolab_Session_Storage_Mock
-implements Horde_Kolab_Session_Storage_Interface
+implements Horde_Kolab_Session_Storage
 {
     /**
      * The session information.
@@ -36,8 +36,8 @@ implements Horde_Kolab_Session_Storage_Interface
     /**
      * Load the session information.
      *
-     * @return Horde_Kolab_Session|boolean The session information or false if
-     * it could not be loaded.
+     * @return array The session data or an empty array if no information was
+     *               found.
      */
     public function load()
     {
@@ -47,12 +47,12 @@ implements Horde_Kolab_Session_Storage_Interface
     /**
      * Save the session information.
      *
-     * @param Horde_Kolab_Session $session The session information.
+     * @param array $session_data The session data that should be stored.
      *
      * @return NULL
      */
-    public function save(Horde_Kolab_Session $session)
+    public function save(array $session_data)
     {
-        $this->session = $session;
+        $this->session = $session_data;
     }
 }
index 1e2be1d..997b6d4 100644 (file)
  * @link     http://pear.horde.org/index.php?package=Kolab_Session
  */
 class Horde_Kolab_Session_Storage_Session
-implements Horde_Kolab_Session_Storage_Interface
+implements Horde_Kolab_Session_Storage
 {
     /**
-     * The handler for session objects.
-     *
-     * @var array
-     */
-    private $_session;
-
-    /**
-     * Constructor
-     *
-     * @param array $session The session handler.
-     */
-    public function __construct($session)
-    {
-        $this->_session = $session;
-    }
-
-    /**
      * Load the session information.
      *
-     * @return Horde_Kolab_Session|boolean The session information or false if
-     * it could not be loaded.
+     * @return array The session data or an empty array if no information was
+     *               found.
      */
     public function load()
     {
-        return $this->_session->get('horde', 'kolab_session');
+        if (isset($_SESSION['kolab_session'])) {
+            return $_SESSION['kolab_session'];
+        } else {
+            return array();
+        }
     }
 
     /**
      * Save the session information.
      *
-     * @param Horde_Kolab_Session $session The session information.
+     * @param array $session_data The session data that should be stored.
      *
      * @return NULL
      */
-    public function save(Horde_Kolab_Session $session)
+    public function save(array $session_data)
     {
-        $this->_session->set('horde', 'kolab_session', $session);
+        $_SESSION['kolab_session'] = $session_data;
     }
 }
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..6aef365
--- /dev/null
@@ -0,0 +1,56 @@
+<?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.
+ *
+ * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_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
+{
+    /**
+     * Reset the current session information in case it does not match the
+     * authentication information anymore.
+     *
+     * @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 validate($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 mixed The user ID or false if no user is logged in.
+     */
+    public function getAuth();
+}
\ No newline at end of file
index 10feaa0..20a9fda 100644 (file)
@@ -26,7 +26,7 @@
  * @link     http://pear.horde.org/index.php?package=Kolab_Session
  */
 class Horde_Kolab_Session_Valid_Base
-implements Horde_Kolab_Session_Valid_Interface
+implements Horde_Kolab_Session_Valid
 {
     /**
      * The session handler this instance provides with anonymous access.
@@ -58,7 +58,8 @@ implements Horde_Kolab_Session_Valid_Interface
     }
 
     /**
-     * Does the current session still match the authentication information?
+     * Reset the current session information in case it does not match the
+     * authentication information anymore.
      *
      * @param string $user The user the session information is being requested
      *                     for. This is usually empty, indicating the current
@@ -66,16 +67,18 @@ implements Horde_Kolab_Session_Valid_Interface
      *
      * @return boolean True if the session is still valid.
      */
-    public function isValid($user = null)
+    public function validate($user = null)
     {
         $mail = $this->_session->getMail();
         if ($this->_auth != $mail) {
+            $this->_session->purge();
             return false;
         }
         if (empty($user)) {
             return true;
         }
         if ($user != $mail && $user != $this->_session->getUid()) {
+            $this->_session->purge();
             return false;
         }
         return true;
index 08a1971..ea9f620 100644 (file)
@@ -26,7 +26,7 @@
  * @link     http://pear.horde.org/index.php?package=Kolab_Session
  */
 class Horde_Kolab_Session_Valid_Decorator_Logged
-implements Horde_Kolab_Session_Valid_Interface
+implements Horde_Kolab_Session_Valid
 {
     /**
      * The valid handler.
@@ -52,7 +52,7 @@ implements Horde_Kolab_Session_Valid_Interface
      * @param mixed                               $logger The logger instance.
      */
     public function __construct(
-        Horde_Kolab_Session_Valid_Interface $valid,
+        Horde_Kolab_Session_Valid $valid,
         $logger
     ) {
         $this->_valid  = $valid;
@@ -60,7 +60,8 @@ implements Horde_Kolab_Session_Valid_Interface
     }
 
     /**
-     * Does the current session still match the authentication information?
+     * Reset the current session information in case it does not match the
+     * authentication information anymore.
      *
      * @param string $user The user the session information is being requested
      *                     for. This is usually empty, indicating the current
@@ -68,17 +69,25 @@ implements Horde_Kolab_Session_Valid_Interface
      *
      * @return boolean True if the session is still valid.
      */
-    public function isValid($user = null)
+    public function validate($user = null)
     {
-        $result = $this->_valid->isValid($user);
+        $this->_logger->info(
+            sprintf(
+                "Validating Kolab session for current user \"%s\", requested"
+                . " user \"%s\", and stored user \"%s\".",
+                $this->_valid->getAuth(),
+                $user,
+                $this->_valid->getSession()->getMail()
+            )
+        );
+        $result = $this->_valid->validate($user);
         if ($result === false) {
             $this->_logger->info(
                 sprintf(
-                    "Invalid Kolab session for current user \"%s\", requested"
-                    . " user \"%s\" and stored user \"%s\".",
+                    "Invalid Kolab session for current user \"%s\" and requested"
+                    . " user \"%s\".",
                     $this->_valid->getAuth(),
-                    $user,
-                    $this->_valid->getSession()->getMail()
+                    $user
                 )
             );
         }
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Interface.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Interface.php
deleted file mode 100644 (file)
index 8c2d6d7..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-<?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.
- *
- * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Kolab
- * @package  Kolab_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_Interface
-{
-    /**
-     * 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 mixed The user ID or false if no user is logged in.
-     */
-    public function getAuth();
-}
\ No newline at end of file
index c02fceb..e11eb85 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.9.0" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
+<package packagerversion="1.9.1" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
  <name>Kolab_Session</name>
  <channel>pear.horde.org</channel>
  <summary>A package managing an active Kolab session.</summary>
@@ -23,8 +23,8 @@
   <email>jan@horde.org</email>
   <active>yes</active>
  </lead>
- <date>2010-10-26</date>
- <time>05:16:11</time>
+ <date>2010-12-01</date>
+ <time>14:54:05</time>
  <version>
   <release>0.1.0</release>
   <api>0.1.0</api>
@@ -53,7 +53,6 @@
         <file name="Badlogin.php" role="php" />
        </dir> <!-- /lib/Horde/Kolab/Session/Exception -->
        <dir name="Storage">
-        <file name="Interface.php" role="php" />
         <file name="Mock.php" role="php" />
         <file name="Session.php" role="php" />
        </dir> <!-- /lib/Horde/Kolab/Session/Storage -->
          <file name="Logged.php" role="php" />
         </dir> <!-- /lib/Horde/Kolab/Session/Valid/Decorator -->
         <file name="Base.php" role="php" />
-        <file name="Interface.php" role="php" />
        </dir> <!-- /lib/Horde/Kolab/Session/Valid -->
        <file name="Base.php" role="php" />
        <file name="Exception.php" role="php" />
+       <file name="Storage.php" role="php" />
+       <file name="Valid.php" role="php" />
       </dir> <!-- /lib/Horde/Kolab/Session -->
       <file name="Session.php" role="php" />
      </dir> <!-- /lib/Horde/Kolab -->
     <dir name="Horde">
      <dir name="Kolab">
       <dir name="Session">
-       <dir name="Class">
+       <dir name="Integration">
+        <file name="AnonymousTest.php" role="test" />
+        <file name="SessionTest.php" role="test" />
+        <file name="ValidTest.php" role="test" />
+       </dir> <!-- /test/Horde/Kolab/Session/Integration -->
+       <dir name="Unit">
         <dir name="Decorator">
          <file name="AnonymousTest.php" role="test" />
          <file name="BaseTest.php" role="test" />
          <file name="LoggedTest.php" role="test" />
          <file name="StoredTest.php" role="test" />
-        </dir> <!-- /test/Horde/Kolab/Session/Class/Decorator -->
+        </dir> <!-- /test/Horde/Kolab/Session/Unit/Decorator -->
         <dir name="Storage">
          <file name="MockTest.php" role="test" />
          <file name="SessionTest.php" role="test" />
-        </dir> <!-- /test/Horde/Kolab/Session/Class/Storage -->
+        </dir> <!-- /test/Horde/Kolab/Session/Unit/Storage -->
         <dir name="Valid">
          <dir name="Decorator">
           <file name="LoggedTest.php" role="test" />
-         </dir> <!-- /test/Horde/Kolab/Session/Class/Valid/Decorator -->
+         </dir> <!-- /test/Horde/Kolab/Session/Unit/Valid/Decorator -->
          <file name="BaseTest.php" role="test" />
-        </dir> <!-- /test/Horde/Kolab/Session/Class/Valid -->
+        </dir> <!-- /test/Horde/Kolab/Session/Unit/Valid -->
         <file name="BaseTest.php" role="test" />
-       </dir> <!-- /test/Horde/Kolab/Session/Class -->
-       <dir name="Integration">
-        <file name="AnonymousTest.php" role="test" />
-        <file name="ValidTest.php" role="test" />
-       </dir> <!-- /test/Horde/Kolab/Session/Integration -->
+       </dir> <!-- /test/Horde/Kolab/Session/Unit -->
        <file name="AllTests.php" role="test" />
        <file name="Autoload.php" role="test" />
        <file name="phpunit.xml" role="test" />
-       <file name="SessionTestCase.php" role="test" />
+       <file name="TestCase.php" role="test" />
       </dir> <!-- /test/Horde/Kolab/Session -->
      </dir> <!-- /test/Horde/Kolab -->
     </dir> <!-- /test/Horde -->
     <name>Kolab_Server</name>
     <channel>pear.horde.org</channel>
    </package>
-   <package>
-    <name>Kolab_Storage</name>
-    <channel>pear.horde.org</channel>
-   </package>
   </required>
   <optional>
    <package>
    <install as="Horde/Kolab/Session.php" name="lib/Horde/Kolab/Session.php" />
    <install as="Horde/Kolab/Session/Base.php" name="lib/Horde/Kolab/Session/Base.php" />
    <install as="Horde/Kolab/Session/Exception.php" name="lib/Horde/Kolab/Session/Exception.php" />
+   <install as="Horde/Kolab/Session/Storage.php" name="lib/Horde/Kolab/Session/Storage.php" />
+   <install as="Horde/Kolab/Session/Valid.php" name="lib/Horde/Kolab/Session/Valid.php" />
    <install as="Horde/Kolab/Session/Decorator/Anonymous.php" name="lib/Horde/Kolab/Session/Decorator/Anonymous.php" />
    <install as="Horde/Kolab/Session/Decorator/Base.php" name="lib/Horde/Kolab/Session/Decorator/Base.php" />
    <install as="Horde/Kolab/Session/Decorator/Logged.php" name="lib/Horde/Kolab/Session/Decorator/Logged.php" />
    <install as="Horde/Kolab/Session/Decorator/Stored.php" name="lib/Horde/Kolab/Session/Decorator/Stored.php" />
    <install as="Horde/Kolab/Session/Exception/Badlogin.php" name="lib/Horde/Kolab/Session/Exception/Badlogin.php" />
-   <install as="Horde/Kolab/Session/Storage/Interface.php" name="lib/Horde/Kolab/Session/Storage/Interface.php" />
    <install as="Horde/Kolab/Session/Storage/Mock.php" name="lib/Horde/Kolab/Session/Storage/Mock.php" />
    <install as="Horde/Kolab/Session/Storage/Session.php" name="lib/Horde/Kolab/Session/Storage/Session.php" />
    <install as="Horde/Kolab/Session/Valid/Base.php" name="lib/Horde/Kolab/Session/Valid/Base.php" />
-   <install as="Horde/Kolab/Session/Valid/Interface.php" name="lib/Horde/Kolab/Session/Valid/Interface.php" />
    <install as="Horde/Kolab/Session/Valid/Decorator/Logged.php" name="lib/Horde/Kolab/Session/Valid/Decorator/Logged.php" />
    <install as="Horde/Kolab/Session/AllTests.php" name="test/Horde/Kolab/Session/AllTests.php" />
    <install as="Horde/Kolab/Session/Autoload.php" name="test/Horde/Kolab/Session/Autoload.php" />
    <install as="Horde/Kolab/Session/phpunit.xml" name="test/Horde/Kolab/Session/phpunit.xml" />
-   <install as="Horde/Kolab/Session/SessionTestCase.php" name="test/Horde/Kolab/Session/SessionTestCase.php" />
-   <install as="Horde/Kolab/Session/Class/BaseTest.php" name="test/Horde/Kolab/Session/Class/BaseTest.php" />
-   <install as="Horde/Kolab/Session/Class/Decorator/AnonymousTest.php" name="test/Horde/Kolab/Session/Class/Decorator/AnonymousTest.php" />
-   <install as="Horde/Kolab/Session/Class/Decorator/BaseTest.php" name="test/Horde/Kolab/Session/Class/Decorator/BaseTest.php" />
-   <install as="Horde/Kolab/Session/Class/Decorator/LoggedTest.php" name="test/Horde/Kolab/Session/Class/Decorator/LoggedTest.php" />
-   <install as="Horde/Kolab/Session/Class/Decorator/StoredTest.php" name="test/Horde/Kolab/Session/Class/Decorator/StoredTest.php" />
-   <install as="Horde/Kolab/Session/Class/Storage/MockTest.php" name="test/Horde/Kolab/Session/Class/Storage/MockTest.php" />
-   <install as="Horde/Kolab/Session/Class/Storage/SessionTest.php" name="test/Horde/Kolab/Session/Class/Storage/SessionTest.php" />
-   <install as="Horde/Kolab/Session/Class/Valid/BaseTest.php" name="test/Horde/Kolab/Session/Class/Valid/BaseTest.php" />
-   <install as="Horde/Kolab/Session/Class/Valid/Decorator/LoggedTest.php" name="test/Horde/Kolab/Session/Class/Valid/Decorator/LoggedTest.php" />
+   <install as="Horde/Kolab/Session/TestCase.php" name="test/Horde/Kolab/Session/TestCase.php" />
    <install as="Horde/Kolab/Session/Integration/AnonymousTest.php" name="test/Horde/Kolab/Session/Integration/AnonymousTest.php" />
+   <install as="Horde/Kolab/Session/Integration/SessionTest.php" name="test/Horde/Kolab/Session/Integration/SessionTest.php" />
    <install as="Horde/Kolab/Session/Integration/ValidTest.php" name="test/Horde/Kolab/Session/Integration/ValidTest.php" />
+   <install as="Horde/Kolab/Session/Unit/BaseTest.php" name="test/Horde/Kolab/Session/Unit/BaseTest.php" />
+   <install as="Horde/Kolab/Session/Unit/Decorator/AnonymousTest.php" name="test/Horde/Kolab/Session/Unit/Decorator/AnonymousTest.php" />
+   <install as="Horde/Kolab/Session/Unit/Decorator/BaseTest.php" name="test/Horde/Kolab/Session/Unit/Decorator/BaseTest.php" />
+   <install as="Horde/Kolab/Session/Unit/Decorator/LoggedTest.php" name="test/Horde/Kolab/Session/Unit/Decorator/LoggedTest.php" />
+   <install as="Horde/Kolab/Session/Unit/Decorator/StoredTest.php" name="test/Horde/Kolab/Session/Unit/Decorator/StoredTest.php" />
+   <install as="Horde/Kolab/Session/Unit/Storage/MockTest.php" name="test/Horde/Kolab/Session/Unit/Storage/MockTest.php" />
+   <install as="Horde/Kolab/Session/Unit/Storage/SessionTest.php" name="test/Horde/Kolab/Session/Unit/Storage/SessionTest.php" />
+   <install as="Horde/Kolab/Session/Unit/Valid/BaseTest.php" name="test/Horde/Kolab/Session/Unit/Valid/BaseTest.php" />
+   <install as="Horde/Kolab/Session/Unit/Valid/Decorator/LoggedTest.php" name="test/Horde/Kolab/Session/Unit/Valid/Decorator/LoggedTest.php" />
   </filelist>
  </phprelease>
  <changelog>
     <release>alpha</release>
     <api>alpha</api>
    </stability>
-   <date>2010-10-26</date>
+   <date>2010-12-01</date>
    <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
    <notes>
 * Split package from Kolab_Server
index 3048c4a..f80069d 100644 (file)
  * @link     http://pear.horde.org/index.php?package=Kolab_Session
  */
 
-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);'
-        )
-    );
-}
+require_once 'Horde/Test/Autoload.php';
 
 /** Catch strict standards */
 error_reporting(E_ALL | E_STRICT);
 
 /** Load the basic test definition */
-require_once dirname(__FILE__) . '/SessionTestCase.php';
+require_once dirname(__FILE__) . '/TestCase.php';
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/BaseTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/BaseTest.php
deleted file mode 100644 (file)
index d19d6f4..0000000
+++ /dev/null
@@ -1,446 +0,0 @@
-<?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-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Kolab
- * @package  Kolab_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 setUp()
-    {
-        $this->user = $this->getMock(
-            'Horde_Kolab_Server_Object_Hash', array(), array(), '', false, false
-        );
-    }
-
-    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 testMethodConnectHasParameterStringUserid()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->returnValue('mail@example.org'));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite, array()
-        );
-        $session->connect('userid', array('password' => ''));
-    }
-
-    public function testMethodConnectHasParameterArrayCredentials()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->returnValue('mail@example.org'));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite, array()
-        );
-        $session->connect('', array('password' => ''));
-    }
-
-    public function testMethodConnectHasPostconditionThatTheUserMailAddressIsKnown()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->returnValue('mail@example.org'));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite, array()
-        );
-        $session->connect(array('password' => ''));
-        $this->assertEquals('mail@example.org', $session->getMail());
-    }
-
-    public function testMethodConnectHasPostconditionThatTheUserUidIsKnown()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->returnValue('uid'));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite, array()
-        );
-        $session->connect(array('password' => ''));
-        $this->assertEquals('uid', $session->getUid());
-    }
-
-    public function testMethodConnectHasPostconditionThatTheUserNameIsKnown()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->returnValue('name'));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite, array()
-        );
-        $session->connect(array('password' => ''));
-        $this->assertEquals('name', $session->getName());
-    }
-
-    public function testMethodConnectHasPostconditionThatTheUsersImapHostIsKnown()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->returnValue('home.example.org'));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite, array()
-        );
-        $session->connect('userid', array('password' => ''));
-        $this->assertEquals('home.example.org', $session->getImapServer());
-    }
-
-    public function testMethodConnectHasPostconditionThatTheUsersFreebusyHostIsKnown()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->returnValue('freebusy.example.org'));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite,
-            array('freebusy' => array('url_format' => 'https://%s/fb'))
-        );
-        $session->connect('userid', array('password' => ''));
-        $this->assertEquals('https://freebusy.example.org/fb', $session->getFreebusyServer());
-    }
-
-    public function testMethodConnectThrowsExceptionIfTheConnectionFailed()
-    {
-        $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(
-            $composite, array()
-        );
-        try {
-            $session->connect('user', array('password' => 'pass'));
-        } catch (Horde_Kolab_Session_Exception $e) {
-            $this->assertEquals('Login failed!', $e->getMessage());
-        }
-    }
-
-    public function testMethodConnectThrowsExceptionIfTheCredentialsWereInvalid()
-    {
-        $composite = $this->_getMockedComposite();
-        $composite->server->expects($this->exactly(1))
-            ->method('connectGuid')
-            ->will($this->throwException(new Horde_Kolab_Server_Exception_Bindfailed('Error')));
-        $session = new Horde_Kolab_Session_Base(
-            $composite, array()
-        );
-        try {
-            $session->connect('user', array('password' => 'pass'));
-        } catch (Horde_Kolab_Session_Exception_Badlogin $e) {
-            $this->assertEquals('Invalid credentials!', $e->getMessage());
-        }
-    }
-
-    public function testMethodSleepHasResultArrayThePropertiesToSerialize()
-    {
-        $session = new Horde_Kolab_Session_Base(
-            $this->_getComposite(), array()
-        );
-        $this->assertEquals(
-            array(
-                '_params',
-                '_user_id',
-                '_user_uid',
-                '_user_mail',
-                '_user_name',
-                '_imap_server',
-                '_freebusy_server',
-                '_connected'
-            ), $session->__sleep()
-        );
-    }
-
-    public function testMethodGetidHasResultStringTheIdOfTheUserUserUsedForConnecting()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->returnValue('mail@example.org'));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite, array()
-        );
-        $session->connect('userid', array('password' => 'pass'));
-        $this->assertEquals('userid', $session->getId());
-    }
-
-    public function testMethodGetmailHasResultStringTheMailOfTheConnectedUser()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite, array()
-        );
-        $session->connect('userid', array('password' => ''));
-        $this->assertEquals('userid', $session->getMail());
-    }
-
-    public function testMethodGetuidHasResultStringTheUidOfTheConnectedUser()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite, array()
-        );
-        $session->connect('userid', array('password' => ''));
-        $this->assertEquals('userid', $session->getUid());
-    }
-
-    public function testMethodGetnameHasResultStringTheNameOfTheConnectedUser()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite, array()
-        );
-        $session->connect('userid', array('password' => ''));
-        $this->assertEquals('userid', $session->getName());
-    }
-
-    public function testMethodGetfreebusyserverHasResultStringTheUsersFreebusyServerConverterdToACompleteUrlUsingParametersIfAvailable()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->returnValue('freebusy.example.org'));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite,
-            array('freebusy' => array('url_format' => 'https://%s/fb'))
-        );
-        $session->connect('userid', array('password' => ''));
-        $this->assertEquals('https://freebusy.example.org/fb', $session->getFreebusyServer());
-    }
-
-    public function testMethodGetfreebusyserverHasResultStringTheUsersFreebusyServerConverterdToACompleteUrlUsingFreebusyIfAvailable()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->returnValue('freebusy.example.org'));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite, array()
-        );
-        $session->connect('userid', array('password' => ''));
-        $this->assertEquals('http://freebusy.example.org/freebusy', $session->getFreebusyServer());
-    }
-
-    public function testMethodGetfreebusyserverHasResultStringTheConfiguredServerIfAvailable()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite,
-            array('freebusy' => array('url' => 'https://freebusy2.example.org/fb'))
-        );
-        $session->connect('userid', array('password' => ''));
-        $this->assertEquals('https://freebusy2.example.org/fb', $session->getFreebusyServer());
-    }
-
-    public function testMethodGetfreebusyserverHasResultStringTheUsersHomeServerConverterdToACompleteUrlUsingParametersIfAvailable()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite,
-            array('freebusy' => array('url_format' => 'https://%s/fb'))
-        );
-        $session->connect('userid', array('password' => ''));
-        $this->assertEquals('https://localhost/fb', $session->getFreebusyServer());
-    }
-
-    public function testMethodGetfreebusyserverHasResultStringTheUsersHomeServerConverterdToACompleteUrlUsingFreebusyIfAvailable()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite, array()
-        );
-        $session->connect('userid', array('password' => ''));
-        $this->assertEquals('http://localhost/freebusy', $session->getFreebusyServer());
-    }
-
-    public function testMethodGetfreebusyserverHasResultStringLocalhostConvertedToACompleteUrlUsingParametersIfAvailable()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite,
-            array('freebusy' => array('url_format' => 'https://%s/fb'))
-        );
-        $session->connect('userid', array('password' => ''));
-        $this->assertEquals('https://localhost/fb', $session->getFreebusyServer());
-    }
-
-    public function testMethodGetfreebusyserverHasResultStringLocalhostConvertedToACompleteUrlUsingFreebusy()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite, array()
-        );
-        $session->connect('userid', array('password' => ''));
-        $this->assertEquals('http://localhost/freebusy', $session->getFreebusyServer());
-    }
-
-    public function testMethodGetimapserverHasResultStringTheUsersHomeServerIfAvailable()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->returnValue('home.example.org'));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite, array()
-        );
-        $session->connect('userid', array('password' => ''));
-        $this->assertEquals('home.example.org', $session->getImapServer());
-    }
-
-    public function testMethodGetimapserverHasResultStringTheConfiguredServerIfAvailable()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite,
-            array('imap' => array('server' => 'imap.example.org'))
-        );
-        $session->connect('userid', array('password' => ''));
-        $this->assertEquals('imap.example.org', $session->getImapServer());
-    }
-
-    public function testMethodGetimapserverHasResultStringLocalhostIfNoAlternative()
-    {
-        $this->user->expects($this->exactly(5))
-            ->method('getSingle')
-            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
-        $composite = $this->_getMockedComposite();
-        $composite->objects->expects($this->once())
-            ->method('fetch')
-            ->will($this->returnValue($this->user));
-        $session = new Horde_Kolab_Session_Base(
-            $composite, array()
-        );
-        $session->connect('userid', array('password' => ''));
-        $this->assertEquals('localhost', $session->getImapServer());
-    }
-}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/AnonymousTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/AnonymousTest.php
deleted file mode 100644 (file)
index e885bc9..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-<?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-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Kolab
- * @package  Kolab_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_Decorator_AnonymousTest
-extends Horde_Kolab_Session_SessionTestCase
-{
-    public function testMethodConnectHasPostconditionThatTheConnectionHasBeenEstablishedAsAnonymousUserIfRequired()
-    {
-        $session = $this->getMock('Horde_Kolab_Session');
-        $session->expects($this->once())
-            ->method('connect')
-            ->with('anonymous', array('password' => 'pass'));
-        $anonymous = new Horde_Kolab_Session_Decorator_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_Decorator_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_Decorator_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_Decorator_Anonymous(
-            $session, 'anonymous', 'pass'
-        );
-        $anonymous->getId();
-    }
-}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/BaseTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/BaseTest.php
deleted file mode 100644 (file)
index 93b124a..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-<?php
-/**
- * Test the base 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 base decorator.
- *
- * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Kolab
- * @package  Kolab_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_Decorator_BaseTest
-extends Horde_Kolab_Session_SessionTestCase
-{
-    public function testMethodConnectGetsDelegated()
-    {
-        $session = $this->getMock('Horde_Kolab_Session');
-        $session->expects($this->once())
-            ->method('connect')
-            ->with(array('password' => 'pass'));
-        $anonymous = new Horde_Kolab_Session_Decorator_Base(
-            $session
-        );
-        $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_Decorator_Base(
-            $session
-        );
-        $anonymous->getId();
-    }
-
-    public function testMethodGetmailGetsDelegated()
-    {
-        $session = $this->getMock('Horde_Kolab_Session');
-        $session->expects($this->once())
-            ->method('getMail')
-            ->will($this->returnValue('1'));
-        $anonymous = new Horde_Kolab_Session_Decorator_Base(
-            $session
-        );
-        $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_Decorator_Base(
-            $session
-        );
-        $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_Decorator_Base(
-            $session
-        );
-        $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_Decorator_Base(
-            $session
-        );
-        $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_Decorator_Base(
-            $session
-        );
-        $anonymous->getFreebusyServer();
-    }
-}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/LoggedTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/LoggedTest.php
deleted file mode 100644 (file)
index 68ee12c..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-<?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-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Kolab
- * @package  Kolab_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_Decorator_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_Decorator_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_Decorator_Logged(
-            $session, $this->logger
-        );
-        try {
-            $logged->connect(array('password' => 'pass'));
-            $this->fail('No Exception!');
-        } catch (Horde_Kolab_Session_Exception $e) {
-        }
-    }
-}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/StoredTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/StoredTest.php
deleted file mode 100644 (file)
index 50cd9e1..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-<?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-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Kolab
- * @package  Kolab_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_Decorator_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_Decorator_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_Decorator_Stored($session, $this->storage);
-        $stored->connect(array('password' => 'pass'));
-    }
-}
\ 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
deleted file mode 100644 (file)
index ca532aa..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-<?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-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Kolab
- * @package  Kolab_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/SessionTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Storage/SessionTest.php
deleted file mode 100644 (file)
index b3226eb..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-/**
- * Test the session based 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 session based storage driver.
- *
- * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Kolab
- * @package  Kolab_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_SessionTest extends Horde_Kolab_Session_SessionTestCase
-{
-    public function testMethodLoadHasResultQueriedObject()
-    {
-        $session = $this->getMock('Horde_Session', array(), array(), '', false, false);
-        $session->expects($this->once())
-            ->method('get')
-            ->with('horde', 'kolab_session');
-        $storage = new Horde_Kolab_Session_Storage_Session($session);
-        $storage->load();
-    }
-
-    public function testMethodSaveHasPostconditionThatTheSessionDataWasSaved()
-    {
-        $session = $this->getMock('Horde_Session', array(), array(), '', false, false);
-        $session->expects($this->once())
-            ->method('set')
-            ->with('horde', 'kolab_session', $this->isInstanceOf('Horde_Kolab_Session'));
-        $kolab_session = $this->getMock('Horde_Kolab_Session');
-        $storage = new Horde_Kolab_Session_Storage_Session($session);
-        $storage->save($kolab_session);
-    }
-}
\ 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
deleted file mode 100644 (file)
index 33851f9..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-<?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-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Kolab
- * @package  Kolab_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 = false;
-        $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 = '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 = '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 = '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 = '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 = '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/Decorator/LoggedTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Valid/Decorator/LoggedTest.php
deleted file mode 100644 (file)
index 931e79b..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-<?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-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Kolab
- * @package  Kolab_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_Decorator_LoggedTest
-extends Horde_Kolab_Session_SessionTestCase
-{
-    public function setUp()
-    {
-        parent::setUp();
-
-        $this->setupLogger();
-    }
-
-    public function testMethodIsvalidHasPostconditionThatAnInvalidSessionGetsLogged()
-    {
-        $auth = '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_Decorator_Logged(
-            $session, $this->logger
-        );
-        $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
-        $logged = new Horde_Kolab_Session_Valid_Decorator_Logged(
-            $valid, $this->logger
-        );
-        $this->assertFalse($logged->isValid('nobody@example.org'));
-    }
-
-    public function testMethodIsvalidGetsDelegated()
-    {
-        $valid = $this->getMock('Horde_Kolab_Session_Valid_Interface');
-        $valid->expects($this->once())
-            ->method('isValid')
-            ->will($this->returnValue(true));
-        $logged = new Horde_Kolab_Session_Valid_Decorator_Logged(
-            $valid, $this->logger
-        );
-        $this->assertTrue($logged->isValid());
-    }
-
-    public function testMethodGetsessionGetsDelegated()
-    {
-        $valid = $this->getMock('Horde_Kolab_Session_Valid_Interface');
-        $valid->expects($this->once())
-            ->method('getSession');
-        $logged = new Horde_Kolab_Session_Valid_Decorator_Logged($valid, $this->logger);
-        $logged->getSession();
-    }
-
-    public function testMethodGetauthGetsDelegated()
-    {
-        $valid = $this->getMock('Horde_Kolab_Session_Valid_Interface');
-        $valid->expects($this->once())
-            ->method('getAuth');
-        $logged = new Horde_Kolab_Session_Valid_Decorator_Logged($valid, $this->logger);
-        $logged->getAuth();
-    }
-}
\ No newline at end of file
index a3e2c74..eeca69a 100644 (file)
@@ -32,7 +32,7 @@ require_once dirname(__FILE__) . '/../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_Integration_AnonymousTest extends Horde_Kolab_Session_SessionTestCase
+class Horde_Kolab_Session_Integration_AnonymousTest extends Horde_Kolab_Session_TestCase
 {
     public function testMethodConnectHasPostconditionThatTheConnectionHasBeenEstablishedAsAnonymousUserIfRequired()
     {
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Integration/SessionTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Integration/SessionTest.php
new file mode 100644 (file)
index 0000000..7d005fe
--- /dev/null
@@ -0,0 +1,38 @@
+<?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-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_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_SessionTest extends Horde_Kolab_Session_TestCase
+{
+    public function test()
+    {
+    }
+}
\ No newline at end of file
index 0fcbedf..79a27ba 100644 (file)
@@ -30,7 +30,7 @@ require_once dirname(__FILE__) . '/../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_Integration_ValidTest extends Horde_Kolab_Session_SessionTestCase
+class Horde_Kolab_Session_Integration_ValidTest extends Horde_Kolab_Session_TestCase
 {
     public function setUp()
     {
@@ -47,7 +47,7 @@ class Horde_Kolab_Session_Integration_ValidTest extends Horde_Kolab_Session_Sess
             $composite, array()
         );
         $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
-        $this->assertTrue($valid->isValid());
+        $this->assertTrue($valid->validate());
     }
 
     public function testMethodIsvalidHasResultBooleanFalseIfTheSessionIsNotConnected()
@@ -58,7 +58,7 @@ class Horde_Kolab_Session_Integration_ValidTest extends Horde_Kolab_Session_Sess
             $composite, array()
         );
         $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
-        $this->assertFalse($valid->isValid());
+        $this->assertFalse($valid->validate());
     }
 
     public function testMethodIsvalidHasResultBooleanFalseIfTheMailOfTheCurrentUserDoesNotMatchTheCurrentUserOfTheSession()
@@ -76,7 +76,7 @@ class Horde_Kolab_Session_Integration_ValidTest extends Horde_Kolab_Session_Sess
         );
         $session->connect('', array('password' => ''));
         $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
-        $this->assertFalse($valid->isValid());
+        $this->assertFalse($valid->validate());
     }
 
     public function testMethodIsvalidHasResultBooleanTrueIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndNoNewUserWasSet()
@@ -94,7 +94,7 @@ class Horde_Kolab_Session_Integration_ValidTest extends Horde_Kolab_Session_Sess
         );
         $session->connect('', array('password' => ''));
         $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
-        $this->assertTrue($valid->isValid());
+        $this->assertTrue($valid->validate());
     }
 
     public function testMethodIsvalidHasResultBooleanFalseIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndTheNewUserMatchesNeitherTheCurrentUserMailAndUid()
@@ -112,7 +112,7 @@ class Horde_Kolab_Session_Integration_ValidTest extends Horde_Kolab_Session_Sess
         );
         $session->connect('', array('password' => ''));
         $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
-        $this->assertFalse($valid->isValid('somebody@example.org'));
+        $this->assertFalse($valid->validate('somebody@example.org'));
     }
 
     public function testMethodIsvalidHasResultBooleanTrueIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndTheNewUserMatchesEitherTheCurrentUserMailAndUid()
@@ -130,6 +130,6 @@ class Horde_Kolab_Session_Integration_ValidTest extends Horde_Kolab_Session_Sess
         );
         $session->connect('', array('password' => ''));
         $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
-        $this->assertTrue($valid->isValid('mail@example.org'));
+        $this->assertTrue($valid->validate('mail@example.org'));
     }
 }
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/SessionTestCase.php b/framework/Kolab_Session/test/Horde/Kolab/Session/SessionTestCase.php
deleted file mode 100644 (file)
index 4449802..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-<?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-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Kolab
- * @package  Kolab_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_Interface'),
-            $this->getMock('Horde_Kolab_Server_Objects_Interface'),
-            $this->getMock('Horde_Kolab_Server_Structure_Interface'),
-            $this->getMock('Horde_Kolab_Server_Search_Interface'),
-            $this->getMock('Horde_Kolab_Server_Schema_Interface')
-        );
-    }
-
-    protected function setupLogger()
-    {
-        $this->logger = $this->getMock('Horde_Log_Logger');
-    }
-
-    protected function setupStorage()
-    {
-        $this->storage = $this->getMock('Horde_Kolab_Session_Storage_Interface');
-    }
-
-    protected function setupFactoryMocks()
-    {
-        $this->server          = $this->_getMockedComposite();
-        $this->session_auth    = $this->getMock('Horde_Kolab_Session_Auth_Interface');
-        $this->session_storage = $this->getMock('Horde_Kolab_Session_Storage_Interface');
-    }
-}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/TestCase.php b/framework/Kolab_Session/test/Horde/Kolab/Session/TestCase.php
new file mode 100644 (file)
index 0000000..cbc1be9
--- /dev/null
@@ -0,0 +1,61 @@
+<?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-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_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_TestCase 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_Interface'),
+            $this->getMock('Horde_Kolab_Server_Objects_Interface'),
+            $this->getMock('Horde_Kolab_Server_Structure_Interface'),
+            $this->getMock('Horde_Kolab_Server_Search_Interface'),
+            $this->getMock('Horde_Kolab_Server_Schema_Interface')
+        );
+    }
+
+    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_storage = $this->getMock('Horde_Kolab_Session_Storage');
+    }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/BaseTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/BaseTest.php
new file mode 100644 (file)
index 0000000..768bede
--- /dev/null
@@ -0,0 +1,427 @@
+<?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-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_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_Unit_BaseTest extends Horde_Kolab_Session_TestCase
+{
+    public function setUp()
+    {
+        $this->user = $this->getMock(
+            'Horde_Kolab_Server_Object_Hash', array(), array(), '', false, false
+        );
+    }
+
+    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 testMethodConnectHasParameterStringUserid()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->returnValue('mail@example.org'));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite, array()
+        );
+        $session->connect('userid', array('password' => ''));
+    }
+
+    public function testMethodConnectHasParameterArrayCredentials()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->returnValue('mail@example.org'));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite, array()
+        );
+        $session->connect('', array('password' => ''));
+    }
+
+    public function testMethodConnectHasPostconditionThatTheUserMailAddressIsKnown()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->returnValue('mail@example.org'));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite, array()
+        );
+        $session->connect(array('password' => ''));
+        $this->assertEquals('mail@example.org', $session->getMail());
+    }
+
+    public function testMethodConnectHasPostconditionThatTheUserUidIsKnown()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->returnValue('uid'));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite, array()
+        );
+        $session->connect(array('password' => ''));
+        $this->assertEquals('uid', $session->getUid());
+    }
+
+    public function testMethodConnectHasPostconditionThatTheUserNameIsKnown()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->returnValue('name'));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite, array()
+        );
+        $session->connect(array('password' => ''));
+        $this->assertEquals('name', $session->getName());
+    }
+
+    public function testMethodConnectHasPostconditionThatTheUsersImapHostIsKnown()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->returnValue('home.example.org'));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite, array()
+        );
+        $session->connect('userid', array('password' => ''));
+        $this->assertEquals('home.example.org', $session->getImapServer());
+    }
+
+    public function testMethodConnectHasPostconditionThatTheUsersFreebusyHostIsKnown()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->returnValue('freebusy.example.org'));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite,
+            array('freebusy' => array('url_format' => 'https://%s/fb'))
+        );
+        $session->connect('userid', array('password' => ''));
+        $this->assertEquals('https://freebusy.example.org/fb', $session->getFreebusyServer());
+    }
+
+    public function testMethodConnectThrowsExceptionIfTheConnectionFailed()
+    {
+        $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(
+            $composite, array()
+        );
+        try {
+            $session->connect('user', array('password' => 'pass'));
+        } catch (Horde_Kolab_Session_Exception $e) {
+            $this->assertEquals('Login failed!', $e->getMessage());
+        }
+    }
+
+    public function testMethodConnectThrowsExceptionIfTheCredentialsWereInvalid()
+    {
+        $composite = $this->_getMockedComposite();
+        $composite->server->expects($this->exactly(1))
+            ->method('connectGuid')
+            ->will($this->throwException(new Horde_Kolab_Server_Exception_Bindfailed('Error')));
+        $session = new Horde_Kolab_Session_Base(
+            $composite, array()
+        );
+        try {
+            $session->connect('user', array('password' => 'pass'));
+        } catch (Horde_Kolab_Session_Exception_Badlogin $e) {
+            $this->assertEquals('Invalid credentials!', $e->getMessage());
+        }
+    }
+
+    public function testMethodGetidHasResultStringTheIdOfTheUserUserUsedForConnecting()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->returnValue('mail@example.org'));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite, array()
+        );
+        $session->connect('userid', array('password' => 'pass'));
+        $this->assertEquals('userid', $session->getId());
+    }
+
+    public function testMethodGetmailHasResultStringTheMailOfTheConnectedUser()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite, array()
+        );
+        $session->connect('userid', array('password' => ''));
+        $this->assertEquals('userid', $session->getMail());
+    }
+
+    public function testMethodGetuidHasResultStringTheUidOfTheConnectedUser()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite, array()
+        );
+        $session->connect('userid', array('password' => ''));
+        $this->assertEquals('userid', $session->getUid());
+    }
+
+    public function testMethodGetnameHasResultStringTheNameOfTheConnectedUser()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite, array()
+        );
+        $session->connect('userid', array('password' => ''));
+        $this->assertEquals('userid', $session->getName());
+    }
+
+    public function testMethodGetfreebusyserverHasResultStringTheUsersFreebusyServerConverterdToACompleteUrlUsingParametersIfAvailable()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->returnValue('freebusy.example.org'));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite,
+            array('freebusy' => array('url_format' => 'https://%s/fb'))
+        );
+        $session->connect('userid', array('password' => ''));
+        $this->assertEquals('https://freebusy.example.org/fb', $session->getFreebusyServer());
+    }
+
+    public function testMethodGetfreebusyserverHasResultStringTheUsersFreebusyServerConverterdToACompleteUrlUsingFreebusyIfAvailable()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->returnValue('freebusy.example.org'));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite, array()
+        );
+        $session->connect('userid', array('password' => ''));
+        $this->assertEquals('http://freebusy.example.org/freebusy', $session->getFreebusyServer());
+    }
+
+    public function testMethodGetfreebusyserverHasResultStringTheConfiguredServerIfAvailable()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite,
+            array('freebusy' => array('url' => 'https://freebusy2.example.org/fb'))
+        );
+        $session->connect('userid', array('password' => ''));
+        $this->assertEquals('https://freebusy2.example.org/fb', $session->getFreebusyServer());
+    }
+
+    public function testMethodGetfreebusyserverHasResultStringTheUsersHomeServerConverterdToACompleteUrlUsingParametersIfAvailable()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite,
+            array('freebusy' => array('url_format' => 'https://%s/fb'))
+        );
+        $session->connect('userid', array('password' => ''));
+        $this->assertEquals('https://localhost/fb', $session->getFreebusyServer());
+    }
+
+    public function testMethodGetfreebusyserverHasResultStringTheUsersHomeServerConverterdToACompleteUrlUsingFreebusyIfAvailable()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite, array()
+        );
+        $session->connect('userid', array('password' => ''));
+        $this->assertEquals('http://localhost/freebusy', $session->getFreebusyServer());
+    }
+
+    public function testMethodGetfreebusyserverHasResultStringLocalhostConvertedToACompleteUrlUsingParametersIfAvailable()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite,
+            array('freebusy' => array('url_format' => 'https://%s/fb'))
+        );
+        $session->connect('userid', array('password' => ''));
+        $this->assertEquals('https://localhost/fb', $session->getFreebusyServer());
+    }
+
+    public function testMethodGetfreebusyserverHasResultStringLocalhostConvertedToACompleteUrlUsingFreebusy()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite, array()
+        );
+        $session->connect('userid', array('password' => ''));
+        $this->assertEquals('http://localhost/freebusy', $session->getFreebusyServer());
+    }
+
+    public function testMethodGetimapserverHasResultStringTheUsersHomeServerIfAvailable()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->returnValue('home.example.org'));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite, array()
+        );
+        $session->connect('userid', array('password' => ''));
+        $this->assertEquals('home.example.org', $session->getImapServer());
+    }
+
+    public function testMethodGetimapserverHasResultStringTheConfiguredServerIfAvailable()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite,
+            array('imap' => array('server' => 'imap.example.org'))
+        );
+        $session->connect('userid', array('password' => ''));
+        $this->assertEquals('imap.example.org', $session->getImapServer());
+    }
+
+    public function testMethodGetimapserverHasResultStringLocalhostIfNoAlternative()
+    {
+        $this->user->expects($this->exactly(5))
+            ->method('getSingle')
+            ->will($this->throwException(new Horde_Kolab_Server_Exception_Novalue()));
+        $composite = $this->_getMockedComposite();
+        $composite->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $session = new Horde_Kolab_Session_Base(
+            $composite, array()
+        );
+        $session->connect('userid', array('password' => ''));
+        $this->assertEquals('localhost', $session->getImapServer());
+    }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/AnonymousTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/AnonymousTest.php
new file mode 100644 (file)
index 0000000..842c81c
--- /dev/null
@@ -0,0 +1,83 @@
+<?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-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_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_Unit_Decorator_AnonymousTest
+extends Horde_Kolab_Session_TestCase
+{
+    public function testMethodConnectHasPostconditionThatTheConnectionHasBeenEstablishedAsAnonymousUserIfRequired()
+    {
+        $session = $this->getMock('Horde_Kolab_Session');
+        $session->expects($this->once())
+            ->method('connect')
+            ->with('anonymous', array('password' => 'pass'));
+        $anonymous = new Horde_Kolab_Session_Decorator_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_Decorator_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_Decorator_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_Decorator_Anonymous(
+            $session, 'anonymous', 'pass'
+        );
+        $anonymous->getId();
+    }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/BaseTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/BaseTest.php
new file mode 100644 (file)
index 0000000..bb7c6e1
--- /dev/null
@@ -0,0 +1,119 @@
+<?php
+/**
+ * Test the base 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 base decorator.
+ *
+ * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_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_Unit_Decorator_BaseTest
+extends Horde_Kolab_Session_TestCase
+{
+    public function testMethodConnectGetsDelegated()
+    {
+        $session = $this->getMock('Horde_Kolab_Session');
+        $session->expects($this->once())
+            ->method('connect')
+            ->with(array('password' => 'pass'));
+        $anonymous = new Horde_Kolab_Session_Decorator_Base(
+            $session
+        );
+        $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_Decorator_Base(
+            $session
+        );
+        $anonymous->getId();
+    }
+
+    public function testMethodGetmailGetsDelegated()
+    {
+        $session = $this->getMock('Horde_Kolab_Session');
+        $session->expects($this->once())
+            ->method('getMail')
+            ->will($this->returnValue('1'));
+        $anonymous = new Horde_Kolab_Session_Decorator_Base(
+            $session
+        );
+        $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_Decorator_Base(
+            $session
+        );
+        $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_Decorator_Base(
+            $session
+        );
+        $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_Decorator_Base(
+            $session
+        );
+        $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_Decorator_Base(
+            $session
+        );
+        $anonymous->getFreebusyServer();
+    }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/LoggedTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/LoggedTest.php
new file mode 100644 (file)
index 0000000..3a00298
--- /dev/null
@@ -0,0 +1,92 @@
+<?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-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_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_Unit_Decorator_LoggedTest
+extends Horde_Kolab_Session_TestCase
+{
+    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_Decorator_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('getMail')
+            ->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_Decorator_Logged(
+            $session, $this->logger
+        );
+        try {
+            $logged->connect(array('password' => 'pass'));
+            $this->fail('No Exception!');
+        } catch (Horde_Kolab_Session_Exception $e) {
+        }
+    }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/StoredTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/StoredTest.php
new file mode 100644 (file)
index 0000000..f8546b0
--- /dev/null
@@ -0,0 +1,102 @@
+<?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-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_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_Unit_Decorator_StoredTest
+extends Horde_Kolab_Session_TestCase
+{
+    public function setUp()
+    {
+        parent::setUp();
+
+        $this->setupStorage();
+    }
+
+    public function testShutdownSavesExport()
+    {
+        $this->storage->expects($this->once())
+            ->method('load')
+            ->will($this->returnValue(array()));
+        $this->storage->expects($this->once())
+            ->method('save')
+            ->with(array('export'));
+        $session = $this->getMock('Horde_Kolab_Session');
+        $session->expects($this->once())
+            ->method('export')
+            ->will($this->returnValue(array('export')));
+        $stored = new Horde_Kolab_Session_Decorator_Stored($session, $this->storage);
+        $stored->connect();
+        $stored->shutdown();
+    }
+
+    /**
+     * @expectedException Horde_Kolab_Session_Exception
+     */
+    public function testImportException()
+    {
+        $this->storage->expects($this->once())
+            ->method('load')
+            ->will($this->returnValue(array()));
+        $session = $this->getMock('Horde_Kolab_Session');
+        $stored = new Horde_Kolab_Session_Decorator_Stored($session, $this->storage);
+        $stored->import(array('import'));
+    }
+
+    public function testShutdownSavesPurged()
+    {
+        $this->storage->expects($this->once())
+            ->method('load')
+            ->will($this->returnValue(array()));
+        $this->storage->expects($this->once())
+            ->method('save')
+            ->with(array());
+        $session = $this->getMock('Horde_Kolab_Session');
+        $stored = new Horde_Kolab_Session_Decorator_Stored($session, $this->storage);
+        $stored->purge();
+        $stored->shutdown();
+    }
+
+    public function testMethodConnectGetsDelegated()
+    {
+        $this->storage->expects($this->once())
+            ->method('load')
+            ->will($this->returnValue(array()));
+        $session = $this->getMock('Horde_Kolab_Session');
+        $session->expects($this->once())
+            ->method('export')
+            ->will($this->returnValue(array()));
+        $session->expects($this->once())
+            ->method('connect')
+            ->with(array('password' => 'pass'));
+        $stored = new Horde_Kolab_Session_Decorator_Stored($session, $this->storage);
+        $stored->connect(array('password' => 'pass'));
+    }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Storage/MockTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Storage/MockTest.php
new file mode 100644 (file)
index 0000000..0f80de5
--- /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-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_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_Unit_Storage_MockTest extends Horde_Kolab_Session_TestCase
+{
+    public function testMethodLoadHasResultBooleanFalse()
+    {
+        $storage = new Horde_Kolab_Session_Storage_Mock('test');
+        $this->assertFalse($storage->load());
+    }
+
+    public function testMethodSaveHasPostconditionThatTheSessionDataWasSaved()
+    {
+        $array = array(1);
+        $storage = new Horde_Kolab_Session_Storage_Mock('test');
+        $storage->save($array);
+        $this->assertSame($array, $storage->session);
+    }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Storage/SessionTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Storage/SessionTest.php
new file mode 100644 (file)
index 0000000..5ba0914
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/**
+ * Test the session based 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 session based storage driver.
+ *
+ * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_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_Unit_Storage_SessionTest extends Horde_Kolab_Session_TestCase
+{
+    public function testLoad()
+    {
+        $_SESSION['kolab_session'] = array('data');
+        $storage = new Horde_Kolab_Session_Storage_Session($session);
+        $this->assertEquals($storage->load(), array('data'));
+        
+    }
+
+    public function testEmpty()
+    {
+        $storage = new Horde_Kolab_Session_Storage_Session($session);
+        $this->assertEquals($storage->load(), array());
+        
+    }
+
+    public function testSave()
+    {
+        $storage = new Horde_Kolab_Session_Storage_Session($session);
+        $storage->save(array('data'));
+        $this->assertEquals($_SESSION['kolab_session'], array('data'));
+    }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Valid/BaseTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Valid/BaseTest.php
new file mode 100644 (file)
index 0000000..94d9be5
--- /dev/null
@@ -0,0 +1,100 @@
+<?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-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_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_Unit_Valid_BaseTest extends Horde_Kolab_Session_TestCase
+{
+    public function testMethodIsvalidHasResultBooleanTrueIfTheSessionIsNotConnectedAndTheCurrentUserIsAnonymous()
+    {
+        $auth = false;
+        $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->validate());
+    }
+
+    public function testMethodIsvalidHasResultBooleanFalseIfTheSessionIsNotConnected()
+    {
+        $auth = '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->validate());
+    }
+
+    public function testMethodIsvalidHasResultBooleanFalseIfTheMailOfTheCurrentUserDoesNotMatchTheCurrentUserOfTheSession()
+    {
+        $auth = '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->validate());
+    }
+
+    public function testMethodIsvalidHasResultBooleanTrueIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndNoNewUserWasSet()
+    {
+        $auth = '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->validate());
+    }
+
+    public function testMethodIsvalidHasResultBooleanFalseIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndTheNewUserMatchesNeitherTheCurrentUserMailAndUid()
+    {
+        $auth = '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->validate('somebody@example.org'));
+    }
+
+    public function testMethodIsvalidHasResultBooleanTrueIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndTheNewUserMatchesEitherTheCurrentUserMailAndUid()
+    {
+        $auth = '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->validate('mail@example.org'));
+    }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Valid/Decorator/LoggedTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Valid/Decorator/LoggedTest.php
new file mode 100644 (file)
index 0000000..f5e827c
--- /dev/null
@@ -0,0 +1,101 @@
+<?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-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_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_Unit_Valid_Decorator_LoggedTest
+extends Horde_Kolab_Session_TestCase
+{
+    public function setUp()
+    {
+        parent::setUp();
+
+        $this->setupLogger();
+    }
+
+    public function testMethodValidateHasPostconditionThatAnInvalidSessionGetsLogged()
+    {
+        $auth = '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->exactly(2))
+            ->method('__call')
+            ->with(
+                'info',
+                $this->logicalOr(
+                    array('Invalid Kolab session for current user "auth@example.org" and requested user "nobody@example.org".'),
+                    array('Validating Kolab session for current user "auth@example.org", requested user "nobody@example.org", and stored user "somebody@example.org".')
+                )
+            );
+        $logged = new Horde_Kolab_Session_Decorator_Logged(
+            $session, $this->logger
+        );
+        $valid = new Horde_Kolab_Session_Valid_Base($session, $auth);
+        $logged = new Horde_Kolab_Session_Valid_Decorator_Logged(
+            $valid, $this->logger
+        );
+        $this->assertFalse($logged->validate('nobody@example.org'));
+    }
+
+    public function testMethodValidateGetsDelegated()
+    {
+        $valid = $this->getMock('Horde_Kolab_Session_Valid');
+        $valid->expects($this->once())
+            ->method('validate')
+            ->will($this->returnValue(true));
+        $valid->expects($this->once())
+            ->method('getSession')
+            ->will($this->returnValue($this->getMock('Horde_Kolab_Session')));
+        $logged = new Horde_Kolab_Session_Valid_Decorator_Logged(
+            $valid, $this->logger
+        );
+        $this->assertTrue($logged->validate());
+    }
+
+    public function testMethodGetsessionGetsDelegated()
+    {
+        $valid = $this->getMock('Horde_Kolab_Session_Valid');
+        $valid->expects($this->once())
+            ->method('getSession');
+        $logged = new Horde_Kolab_Session_Valid_Decorator_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_Decorator_Logged($valid, $this->logger);
+        $logged->getAuth();
+    }
+}
\ No newline at end of file