From 4e28face6548c76619a29e529d55313ac6db0a24 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Wed, 1 Dec 2010 14:56:19 +0100 Subject: [PATCH] Remove the use of Horde_Session and access the session directly. Simplify the factory. --- .../Core/lib/Horde/Core/Factory/KolabSession.php | 132 ++++----------------- .../Kolab_Session/lib/Horde/Kolab/Session.php | 23 ++++ .../Kolab_Session/lib/Horde/Kolab/Session/Base.php | 113 +++++++++++------- .../lib/Horde/Kolab/Session/Decorator/Base.php | 34 +++++- .../lib/Horde/Kolab/Session/Decorator/Logged.php | 53 ++++++++- .../lib/Horde/Kolab/Session/Decorator/Stored.php | 57 ++++++--- .../Session/{Storage/Interface.php => Storage.php} | 12 +- .../lib/Horde/Kolab/Session/Storage/Mock.php | 12 +- .../lib/Horde/Kolab/Session/Storage/Session.php | 35 ++---- .../Session/{Valid/Interface.php => Valid.php} | 7 +- .../lib/Horde/Kolab/Session/Valid/Base.php | 9 +- .../Horde/Kolab/Session/Valid/Decorator/Logged.php | 27 +++-- framework/Kolab_Session/package.xml | 64 +++++----- .../test/Horde/Kolab/Session/Autoload.php | 15 +-- .../Kolab/Session/Class/Decorator/StoredTest.php | 62 ---------- .../Kolab/Session/Integration/AnonymousTest.php | 2 +- .../Kolab/Session/Integration/SessionTest.php | 38 ++++++ .../Horde/Kolab/Session/Integration/ValidTest.php | 14 +-- .../Session/{SessionTestCase.php => TestCase.php} | 7 +- .../Kolab/Session/{Class => Unit}/BaseTest.php | 21 +--- .../{Class => Unit}/Decorator/AnonymousTest.php | 4 +- .../Session/{Class => Unit}/Decorator/BaseTest.php | 4 +- .../{Class => Unit}/Decorator/LoggedTest.php | 6 +- .../Kolab/Session/Unit/Decorator/StoredTest.php | 102 ++++++++++++++++ .../Session/{Class => Unit}/Storage/MockTest.php | 8 +- .../{Class => Unit}/Storage/SessionTest.php | 29 ++--- .../Session/{Class => Unit}/Valid/BaseTest.php | 14 +-- .../{Class => Unit}/Valid/Decorator/LoggedTest.php | 30 +++-- 28 files changed, 532 insertions(+), 402 deletions(-) rename framework/Kolab_Session/lib/Horde/Kolab/Session/{Storage/Interface.php => Storage.php} (75%) rename framework/Kolab_Session/lib/Horde/Kolab/Session/{Valid/Interface.php => Valid.php} (87%) delete mode 100644 framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/StoredTest.php create mode 100644 framework/Kolab_Session/test/Horde/Kolab/Session/Integration/SessionTest.php rename framework/Kolab_Session/test/Horde/Kolab/Session/{SessionTestCase.php => TestCase.php} (89%) rename framework/Kolab_Session/test/Horde/Kolab/Session/{Class => Unit}/BaseTest.php (96%) rename framework/Kolab_Session/test/Horde/Kolab/Session/{Class => Unit}/Decorator/AnonymousTest.php (96%) rename framework/Kolab_Session/test/Horde/Kolab/Session/{Class => Unit}/Decorator/BaseTest.php (97%) rename framework/Kolab_Session/test/Horde/Kolab/Session/{Class => Unit}/Decorator/LoggedTest.php (95%) create mode 100644 framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/StoredTest.php rename framework/Kolab_Session/test/Horde/Kolab/Session/{Class => Unit}/Storage/MockTest.php (83%) rename framework/Kolab_Session/test/Horde/Kolab/Session/{Class => Unit}/Storage/SessionTest.php (56%) rename framework/Kolab_Session/test/Horde/Kolab/Session/{Class => Unit}/Valid/BaseTest.php (89%) rename framework/Kolab_Session/test/Horde/Kolab/Session/{Class => Unit}/Valid/Decorator/LoggedTest.php (67%) diff --git a/framework/Core/lib/Horde/Core/Factory/KolabSession.php b/framework/Core/lib/Horde/Core/Factory/KolabSession.php index 5b58d8a0c..81c338f22 100644 --- a/framework/Core/lib/Horde/Core/Factory/KolabSession.php +++ b/framework/Core/lib/Horde/Core/Factory/KolabSession.php @@ -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'] ); } diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session.php b/framework/Kolab_Session/lib/Horde/Kolab/Session.php index 70c3f9c64..271458ce3 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session.php @@ -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(); } diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php index 83b17e69a..85c32a6f8 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php @@ -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(); } } diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Base.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Base.php index 4570e33e5..763281643 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Base.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Base.php @@ -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(); + } } diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Logged.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Logged.php index 0ba31d610..1c81d961b 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Logged.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Logged.php @@ -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(); + } } diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Stored.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Stored.php index ee6e656e1..be049c5b5 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Stored.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Stored.php @@ -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/Interface.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage.php similarity index 75% rename from framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Interface.php rename to framework/Kolab_Session/lib/Horde/Kolab/Session/Storage.php index e27adb092..f7d6098d0 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Interface.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage.php @@ -25,22 +25,22 @@ * @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 +interface Horde_Kolab_Session_Storage { /** * Load the session information. * - * @return Horde_Kolab_Session|boolean The session information or false if - * it could not be loaded. + * @return array The session data or an empty array if no information was + * found. */ public function load(); /** - * Lave the session information. + * 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); } diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Mock.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Mock.php index bdaea3f93..a133f6bfc 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Mock.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Mock.php @@ -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; } } diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Session.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Session.php index 1e2be1ddf..997b6d417 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Session.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Session.php @@ -26,45 +26,32 @@ * @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/Interface.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid.php similarity index 87% rename from framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Interface.php rename to framework/Kolab_Session/lib/Horde/Kolab/Session/Valid.php index 8c2d6d7fc..6aef36546 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Interface.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid.php @@ -25,10 +25,11 @@ * @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 +interface Horde_Kolab_Session_Valid { /** - * 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 @@ -36,7 +37,7 @@ interface Horde_Kolab_Session_Valid_Interface * * @return boolean True if the session is still valid. */ - public function isValid($user = null); + public function validate($user = null); /** * Return the session this validator checks. diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Base.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Base.php index 10feaa048..20a9fda8e 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Base.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Base.php @@ -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; diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Decorator/Logged.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Decorator/Logged.php index 08a1971af..ea9f620b3 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Decorator/Logged.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Decorator/Logged.php @@ -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/package.xml b/framework/Kolab_Session/package.xml index c02fceb36..e11eb8511 100644 --- a/framework/Kolab_Session/package.xml +++ b/framework/Kolab_Session/package.xml @@ -1,5 +1,5 @@ - + Kolab_Session pear.horde.org A package managing an active Kolab session. @@ -23,8 +23,8 @@ jan@horde.org yes - 2010-10-26 - + 2010-12-01 + 0.1.0 0.1.0 @@ -53,7 +53,6 @@ - @@ -62,10 +61,11 @@ - + + @@ -75,33 +75,34 @@ - + + + + + + - + - + - + - + - - - - - + - + @@ -120,10 +121,6 @@ Kolab_Server pear.horde.org - - Kolab_Storage - pear.horde.org - @@ -137,32 +134,33 @@ + + - - - - - - - - - - - - + + + + + + + + + + + @@ -175,7 +173,7 @@ alpha alpha - 2010-10-26 + 2010-12-01 LGPL * Split package from Kolab_Server diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Autoload.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Autoload.php index 3048c4ae5..f80069db9 100644 --- a/framework/Kolab_Session/test/Horde/Kolab/Session/Autoload.php +++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Autoload.php @@ -11,21 +11,10 @@ * @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/Decorator/StoredTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/StoredTest.php deleted file mode 100644 index 50cd9e11c..000000000 --- a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/StoredTest.php +++ /dev/null @@ -1,62 +0,0 @@ - - * @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 - * @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/Integration/AnonymousTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Integration/AnonymousTest.php index a3e2c74fc..eeca69aff 100644 --- a/framework/Kolab_Session/test/Horde/Kolab/Session/Integration/AnonymousTest.php +++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Integration/AnonymousTest.php @@ -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 index 000000000..7d005fed3 --- /dev/null +++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Integration/SessionTest.php @@ -0,0 +1,38 @@ + + * @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 + * @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 diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Integration/ValidTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Integration/ValidTest.php index 0fcbedf8a..79a27ba79 100644 --- a/framework/Kolab_Session/test/Horde/Kolab/Session/Integration/ValidTest.php +++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Integration/ValidTest.php @@ -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/TestCase.php similarity index 89% rename from framework/Kolab_Session/test/Horde/Kolab/Session/SessionTestCase.php rename to framework/Kolab_Session/test/Horde/Kolab/Session/TestCase.php index 444980299..cbc1be9af 100644 --- a/framework/Kolab_Session/test/Horde/Kolab/Session/SessionTestCase.php +++ b/framework/Kolab_Session/test/Horde/Kolab/Session/TestCase.php @@ -25,7 +25,7 @@ * @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 +class Horde_Kolab_Session_TestCase extends PHPUnit_Framework_TestCase { protected function _getComposite() { @@ -50,13 +50,12 @@ class Horde_Kolab_Session_SessionTestCase extends PHPUnit_Framework_TestCase protected function setupStorage() { - $this->storage = $this->getMock('Horde_Kolab_Session_Storage_Interface'); + $this->storage = $this->getMock('Horde_Kolab_Session_Storage'); } 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'); + $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/Class/BaseTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/BaseTest.php similarity index 96% rename from framework/Kolab_Session/test/Horde/Kolab/Session/Class/BaseTest.php rename to framework/Kolab_Session/test/Horde/Kolab/Session/Unit/BaseTest.php index d19d6f43a..768bedea6 100644 --- a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/BaseTest.php +++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/BaseTest.php @@ -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_Class_BaseTest extends Horde_Kolab_Session_SessionTestCase +class Horde_Kolab_Session_Unit_BaseTest extends Horde_Kolab_Session_TestCase { public function setUp() { @@ -196,25 +196,6 @@ class Horde_Kolab_Session_Class_BaseTest extends Horde_Kolab_Session_SessionTest } } - 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)) diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/AnonymousTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/AnonymousTest.php similarity index 96% rename from framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/AnonymousTest.php rename to framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/AnonymousTest.php index e885bc991..842c81c6c 100644 --- a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/AnonymousTest.php +++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/AnonymousTest.php @@ -30,8 +30,8 @@ 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_Class_Decorator_AnonymousTest -extends Horde_Kolab_Session_SessionTestCase +class Horde_Kolab_Session_Unit_Decorator_AnonymousTest +extends Horde_Kolab_Session_TestCase { public function testMethodConnectHasPostconditionThatTheConnectionHasBeenEstablishedAsAnonymousUserIfRequired() { diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/BaseTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/BaseTest.php similarity index 97% rename from framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/BaseTest.php rename to framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/BaseTest.php index 93b124a5e..bb7c6e1c7 100644 --- a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/BaseTest.php +++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/BaseTest.php @@ -30,8 +30,8 @@ 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_Class_Decorator_BaseTest -extends Horde_Kolab_Session_SessionTestCase +class Horde_Kolab_Session_Unit_Decorator_BaseTest +extends Horde_Kolab_Session_TestCase { public function testMethodConnectGetsDelegated() { diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/LoggedTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/LoggedTest.php similarity index 95% rename from framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/LoggedTest.php rename to framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/LoggedTest.php index 68ee12cde..3a002983f 100644 --- a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/LoggedTest.php +++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/LoggedTest.php @@ -30,8 +30,8 @@ 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_Class_Decorator_LoggedTest -extends Horde_Kolab_Session_SessionTestCase +class Horde_Kolab_Session_Unit_Decorator_LoggedTest +extends Horde_Kolab_Session_TestCase { public function setUp() { @@ -70,7 +70,7 @@ extends Horde_Kolab_Session_SessionTestCase ->method('connect') ->will($this->throwException(new Horde_Kolab_Session_Exception('Error.'))); $session->expects($this->once()) - ->method('getId') + ->method('getMail') ->will($this->returnValue('somebody@example.org')); $this->logger->expects($this->once()) ->method('__call') 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 index 000000000..f8546b00f --- /dev/null +++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/StoredTest.php @@ -0,0 +1,102 @@ + + * @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 + * @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/Class/Storage/MockTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Storage/MockTest.php similarity index 83% rename from framework/Kolab_Session/test/Horde/Kolab/Session/Class/Storage/MockTest.php rename to framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Storage/MockTest.php index ca532aa5a..0f80de582 100644 --- a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Storage/MockTest.php +++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Storage/MockTest.php @@ -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_Class_Storage_MockTest extends Horde_Kolab_Session_SessionTestCase +class Horde_Kolab_Session_Unit_Storage_MockTest extends Horde_Kolab_Session_TestCase { public function testMethodLoadHasResultBooleanFalse() { @@ -40,9 +40,9 @@ class Horde_Kolab_Session_Class_Storage_MockTest extends Horde_Kolab_Session_Ses public function testMethodSaveHasPostconditionThatTheSessionDataWasSaved() { - $session = $this->getMock('Horde_Kolab_Session'); + $array = array(1); $storage = new Horde_Kolab_Session_Storage_Mock('test'); - $storage->save($session); - $this->assertSame($session, $storage->session); + $storage->save($array); + $this->assertSame($array, $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/Unit/Storage/SessionTest.php similarity index 56% rename from framework/Kolab_Session/test/Horde/Kolab/Session/Class/Storage/SessionTest.php rename to framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Storage/SessionTest.php index b3226eb7c..5ba0914db 100644 --- a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Storage/SessionTest.php +++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Storage/SessionTest.php @@ -30,26 +30,27 @@ 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_Class_Storage_SessionTest extends Horde_Kolab_Session_SessionTestCase +class Horde_Kolab_Session_Unit_Storage_SessionTest extends Horde_Kolab_Session_TestCase { - public function testMethodLoadHasResultQueriedObject() + public function testLoad() { - $session = $this->getMock('Horde_Session', array(), array(), '', false, false); - $session->expects($this->once()) - ->method('get') - ->with('horde', 'kolab_session'); + $_SESSION['kolab_session'] = array('data'); $storage = new Horde_Kolab_Session_Storage_Session($session); - $storage->load(); + $this->assertEquals($storage->load(), array('data')); + } - public function testMethodSaveHasPostconditionThatTheSessionDataWasSaved() + public function testEmpty() { - $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); + $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/Class/Valid/BaseTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Valid/BaseTest.php similarity index 89% rename from framework/Kolab_Session/test/Horde/Kolab/Session/Class/Valid/BaseTest.php rename to framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Valid/BaseTest.php index 33851f945..94d9be579 100644 --- a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Valid/BaseTest.php +++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Valid/BaseTest.php @@ -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_Class_Valid_BaseTest extends Horde_Kolab_Session_SessionTestCase +class Horde_Kolab_Session_Unit_Valid_BaseTest extends Horde_Kolab_Session_TestCase { public function testMethodIsvalidHasResultBooleanTrueIfTheSessionIsNotConnectedAndTheCurrentUserIsAnonymous() { @@ -40,7 +40,7 @@ class Horde_Kolab_Session_Class_Valid_BaseTest extends Horde_Kolab_Session_Sessi ->method('getMail') ->will($this->returnValue('')); $valid = new Horde_Kolab_Session_Valid_Base($session, $auth); - $this->assertTrue($valid->isValid()); + $this->assertTrue($valid->validate()); } public function testMethodIsvalidHasResultBooleanFalseIfTheSessionIsNotConnected() @@ -51,7 +51,7 @@ class Horde_Kolab_Session_Class_Valid_BaseTest extends Horde_Kolab_Session_Sessi ->method('getMail') ->will($this->returnValue('')); $valid = new Horde_Kolab_Session_Valid_Base($session, $auth); - $this->assertFalse($valid->isValid()); + $this->assertFalse($valid->validate()); } public function testMethodIsvalidHasResultBooleanFalseIfTheMailOfTheCurrentUserDoesNotMatchTheCurrentUserOfTheSession() @@ -62,7 +62,7 @@ class Horde_Kolab_Session_Class_Valid_BaseTest extends Horde_Kolab_Session_Sessi ->method('getMail') ->will($this->returnValue('mail@example.org')); $valid = new Horde_Kolab_Session_Valid_Base($session, $auth); - $this->assertFalse($valid->isValid()); + $this->assertFalse($valid->validate()); } public function testMethodIsvalidHasResultBooleanTrueIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndNoNewUserWasSet() @@ -73,7 +73,7 @@ class Horde_Kolab_Session_Class_Valid_BaseTest extends Horde_Kolab_Session_Sessi ->method('getMail') ->will($this->returnValue('mail@example.org')); $valid = new Horde_Kolab_Session_Valid_Base($session, $auth); - $this->assertTrue($valid->isValid()); + $this->assertTrue($valid->validate()); } public function testMethodIsvalidHasResultBooleanFalseIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndTheNewUserMatchesNeitherTheCurrentUserMailAndUid() @@ -84,7 +84,7 @@ class Horde_Kolab_Session_Class_Valid_BaseTest extends Horde_Kolab_Session_Sessi ->method('getMail') ->will($this->returnValue('mail@example.org')); $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() @@ -95,6 +95,6 @@ class Horde_Kolab_Session_Class_Valid_BaseTest extends Horde_Kolab_Session_Sessi ->method('getMail') ->will($this->returnValue('mail@example.org')); $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/Class/Valid/Decorator/LoggedTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Valid/Decorator/LoggedTest.php similarity index 67% rename from framework/Kolab_Session/test/Horde/Kolab/Session/Class/Valid/Decorator/LoggedTest.php rename to framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Valid/Decorator/LoggedTest.php index 931e79b86..f5e827c73 100644 --- a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Valid/Decorator/LoggedTest.php +++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Valid/Decorator/LoggedTest.php @@ -30,8 +30,8 @@ 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_Class_Valid_Decorator_LoggedTest -extends Horde_Kolab_Session_SessionTestCase +class Horde_Kolab_Session_Unit_Valid_Decorator_LoggedTest +extends Horde_Kolab_Session_TestCase { public function setUp() { @@ -40,18 +40,21 @@ extends Horde_Kolab_Session_SessionTestCase $this->setupLogger(); } - public function testMethodIsvalidHasPostconditionThatAnInvalidSessionGetsLogged() + 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->once()) + $this->logger->expects($this->exactly(2)) ->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".') + $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 @@ -60,24 +63,27 @@ extends Horde_Kolab_Session_SessionTestCase $logged = new Horde_Kolab_Session_Valid_Decorator_Logged( $valid, $this->logger ); - $this->assertFalse($logged->isValid('nobody@example.org')); + $this->assertFalse($logged->validate('nobody@example.org')); } - public function testMethodIsvalidGetsDelegated() + public function testMethodValidateGetsDelegated() { - $valid = $this->getMock('Horde_Kolab_Session_Valid_Interface'); + $valid = $this->getMock('Horde_Kolab_Session_Valid'); $valid->expects($this->once()) - ->method('isValid') + ->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->isValid()); + $this->assertTrue($logged->validate()); } public function testMethodGetsessionGetsDelegated() { - $valid = $this->getMock('Horde_Kolab_Session_Valid_Interface'); + $valid = $this->getMock('Horde_Kolab_Session_Valid'); $valid->expects($this->once()) ->method('getSession'); $logged = new Horde_Kolab_Session_Valid_Decorator_Logged($valid, $this->logger); @@ -86,7 +92,7 @@ extends Horde_Kolab_Session_SessionTestCase public function testMethodGetauthGetsDelegated() { - $valid = $this->getMock('Horde_Kolab_Session_Valid_Interface'); + $valid = $this->getMock('Horde_Kolab_Session_Valid'); $valid->expects($this->once()) ->method('getAuth'); $logged = new Horde_Kolab_Session_Valid_Decorator_Logged($valid, $this->logger); -- 2.11.0