From: Gunnar Wrobel
Date: Wed, 28 Oct 2009 21:39:42 +0000 (+0100)
Subject: Fix the Kolab_Session factories now that the Kolab_Server factories are complete...
X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=90d3e576ac9aa82c82caaf0c1659290ca60d953d;p=horde.git
Fix the Kolab_Session factories now that the Kolab_Server factories are complete. Additional testing.
---
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Configuration.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Configuration.php
index 52d8864d1..382f337e9 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Configuration.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Configuration.php
@@ -47,12 +47,28 @@ implements Horde_Kolab_Session_Factory
*
* @param array $config Configuration parameters for the session.
*/
- public function __construct(
- Horde_Kolab_Session_Factory $factory,
- array $config
- ) {
+ public function __construct(array $config)
+ {
$this->_configuration = $config;
+ if (isset($config['server'])) {
+ $server_configuration = $config['server'];
+ } elseif (isset($config['ldap'])) {
+ $server_configuration = $config['ldap'];
+ } else {
+ throw new Horde_Kolab_Session_Exception(
+ 'The server configuration is missing!'
+ );
+ }
+
+ $server_factory = new Horde_Kolab_Server_Factory_Configuration(
+ $server_configuration
+ );
+
+ $factory = new Horde_Kolab_Session_Factory_Default(
+ $config, $server_factory
+ );
+
if (isset($config['logger'])) {
$factory = new Horde_Kolab_Session_Factory_Logged(
$factory, $config['logger']
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Default.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Default.php
index 4150c4f8d..5c6d36526 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Default.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Default.php
@@ -65,7 +65,7 @@ extends Horde_Kolab_Session_Factory_Base
*/
public function getServer()
{
- return $this->_server_factory->getServer();
+ return $this->_server_factory->getComposite();
}
/**
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Injector.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Injector.php
index 2da569f27..161919de9 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Injector.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Injector.php
@@ -90,9 +90,10 @@ extends Horde_Kolab_Session_Factory_Base
*/
private function _setupStorage()
{
- $this->_injector->bindImplementation(
+ $this->_injector->bindFactory(
'Horde_Kolab_Session_Storage',
- 'Horde_Kolab_Session_Storage_Sessionobjects'
+ 'Horde_Kolab_Session_Factory_Injector',
+ 'getStorage'
);
}
@@ -123,13 +124,34 @@ extends Horde_Kolab_Session_Factory_Base
}
/**
+ * A helper method to seed the injector with a Horde_Kolab_Server factory
+ * definition. This should usually be done by an external setup method
+ * before constructing the session injcetion factory.
+ *
+ * @parm Horde_Injector
+ *
+ * @return NULL
+ */
+ static public function setupMockServerFactory(
+ Horde_Injector $injector
+ ) {
+ Horde_Kolab_Server_Factory_Injector::setup(
+ 'Horde_Kolab_Server_Factory_Conn_Mock',
+ array('basedn' => ''),
+ $injector
+ );
+ /** Setup the injector by constructing the server factory */
+ $injector->getInstance('Horde_Kolab_Server_Factory_Injector');
+ }
+
+ /**
* Return the kolab user db connection.
*
* @return Horde_Kolab_Server The server connection.
*/
public function getServer()
{
- return $this->_injector->getInstance('Horde_Kolab_Server');
+ return $this->_injector->getInstance('Horde_Kolab_Server_Composite');
}
/**
@@ -159,6 +181,9 @@ extends Horde_Kolab_Session_Factory_Base
*/
public function getSessionStorage()
{
- return $this->_injector->getInstance('Horde_Kolab_Session_Storage');
+ $storage = new Horde_Kolab_Session_Storage_Sessionobjects(
+ Horde_SessionObjects::singleton()
+ );
+ return $storage;
}
}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Singleton.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Singleton.php
index edef55c12..e060043ba 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Singleton.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Singleton.php
@@ -56,14 +56,10 @@ class Horde_Kolab_Session_Singleton
global $conf;
if (!isset(self::$_instance)) {
+ $config = $conf['kolab'];
$config['logger'] = Horde::getLogger();
- $config['server'] = $conf['kolab']['server'];
- $server_factory = new Horde_Kolab_Server_Factory_Default($config);
- $server_factory = new Horde_Kolab_Server_Factory_Configuration($server_factory, $config);
- $factory = new Horde_Kolab_Session_Factory_Default($config, $server_factory);
- $factory = new Horde_Kolab_Session_Factory_Configuration($factory, $config);
+ $factory = new Horde_Kolab_Session_Factory_Configuration($config);
self::$_instance = $factory->getSession($user);
- self::$_instance->connect($credentials);
}
return self::$_instance;
}
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/ConfigurationTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/ConfigurationTest.php
index 69a2aeade..7a656100e 100644
--- a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/ConfigurationTest.php
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/ConfigurationTest.php
@@ -38,21 +38,31 @@ class Horde_Kolab_Session_Class_Factory_ConfigurationTest extends Horde_Kolab_Se
$this->setupLogger();
}
+ public function testMethodConstructThrowsExceptionIfTheServerConfigurationIsMissing()
+ {
+ try {
+ $factory = new Horde_Kolab_Session_Factory_Configuration(array());
+ $this->fail('No exception!');
+ } catch (Horde_Kolab_Session_Exception $e) {
+ $this->assertEquals(
+ 'The server configuration is missing!',
+ $e->getMessage()
+ );
+ }
+ }
+
public function testMethodCreatesessionHasResultHordekolabsessionanonymousIfConfiguredThatWay()
{
- $session = $this->getMock('Horde_Kolab_Session');
- $factory = $this->getMock('Horde_Kolab_Session_Factory');
- $factory->expects($this->once())
- ->method('createSession')
- ->will($this->returnValue($session));
$factory = new Horde_Kolab_Session_Factory_Configuration(
- $factory,
array(
'session' => array(
'anonymous' => array(
'user' => 'anonymous',
'pass' => ''
)
+ ),
+ 'server' => array(
+ 'basedn' => ''
)
)
);
@@ -64,13 +74,13 @@ class Horde_Kolab_Session_Class_Factory_ConfigurationTest extends Horde_Kolab_Se
public function testMethodCreatesessionHasResultHordekolabsessionloggedIfConfiguredThatWay()
{
- $session = $this->getMock('Horde_Kolab_Session');
- $factory = $this->getMock('Horde_Kolab_Session_Factory');
- $factory->expects($this->once())
- ->method('createSession')
- ->will($this->returnValue($session));
$factory = new Horde_Kolab_Session_Factory_Configuration(
- $factory, array('logger' => $this->logger)
+ array(
+ 'logger' => $this->logger,
+ 'server' => array(
+ 'basedn' => ''
+ )
+ )
);
$this->assertType(
'Horde_Kolab_Session_Logged',
@@ -82,13 +92,13 @@ class Horde_Kolab_Session_Class_Factory_ConfigurationTest extends Horde_Kolab_Se
{
$session = $this->getMock('Horde_Kolab_Session');
$auth = $this->getMock('Horde_Kolab_Session_Auth');
- $validator = $this->getMock('Horde_Kolab_Session_Valid');
- $factory = $this->getMock('Horde_Kolab_Session_Factory');
- $factory->expects($this->once())
- ->method('getSessionValidator')
- ->will($this->returnValue($validator));
$factory = new Horde_Kolab_Session_Factory_Configuration(
- $factory, array('logger' => $this->logger)
+ array(
+ 'logger' => $this->logger,
+ 'server' => array(
+ 'basedn' => ''
+ )
+ )
);
$this->assertType(
'Horde_Kolab_Session_Valid_Logged',
@@ -96,28 +106,29 @@ class Horde_Kolab_Session_Class_Factory_ConfigurationTest extends Horde_Kolab_Se
);
}
- public function testMethodGetserverGetsDelegated()
+ public function testMethodGetserverHasResultServercomposite()
{
- $server = $this->getMock('Horde_Kolab_Server');
- $factory = $this->getMock('Horde_Kolab_Session_Factory');
- $factory->expects($this->once())
- ->method('getServer')
- ->will($this->returnValue($server));
$factory = new Horde_Kolab_Session_Factory_Configuration(
- $factory, array()
+ array(
+ 'server' => array(
+ 'basedn' => ''
+ )
+ )
+ );
+ $this->assertType(
+ 'Horde_Kolab_Server_Composite',
+ $factory->getServer()
);
- $this->assertType('Horde_Kolab_Server', $factory->getServer());
}
- public function testMethodGetsessionauthGetsDelegated()
+ public function testMethodGetsessionauthHasResultSessionauth()
{
- $auth = $this->getMock('Horde_Kolab_Session_Auth');
- $factory = $this->getMock('Horde_Kolab_Session_Factory');
- $factory->expects($this->once())
- ->method('getSessionAuth')
- ->will($this->returnValue($auth));
$factory = new Horde_Kolab_Session_Factory_Configuration(
- $factory, array()
+ array(
+ 'server' => array(
+ 'basedn' => ''
+ )
+ )
);
$this->assertType(
'Horde_Kolab_Session_Auth',
@@ -125,27 +136,26 @@ class Horde_Kolab_Session_Class_Factory_ConfigurationTest extends Horde_Kolab_Se
);
}
- public function testMethodGetsessionconfigurationGetsDelegated()
+ public function testMethodGetsessionconfigurationHasResultArray()
{
- $factory = $this->getMock('Horde_Kolab_Session_Factory');
- $factory->expects($this->once())
- ->method('getSessionConfiguration')
- ->will($this->returnValue(array()));
$factory = new Horde_Kolab_Session_Factory_Configuration(
- $factory, array()
+ array(
+ 'server' => array(
+ 'basedn' => ''
+ )
+ )
);
$this->assertType('array', $factory->getSessionConfiguration());
}
- public function testMethodGetsessionstorageGetsDelegated()
+ public function testMethodGetsessionstorageHasresultSessionstorage()
{
- $storage = $this->getMock('Horde_Kolab_Session_Storage');
- $factory = $this->getMock('Horde_Kolab_Session_Factory');
- $factory->expects($this->once())
- ->method('getSessionStorage')
- ->will($this->returnValue($storage));
$factory = new Horde_Kolab_Session_Factory_Configuration(
- $factory, array()
+ array(
+ 'server' => array(
+ 'basedn' => ''
+ )
+ )
);
$this->assertType(
'Horde_Kolab_Session_Storage',
@@ -153,17 +163,16 @@ class Horde_Kolab_Session_Class_Factory_ConfigurationTest extends Horde_Kolab_Se
);
}
- public function testMethodGetsessionvalidatorGetsDelegated()
+ public function testMethodGetsessionvalidatorHasResultSessionvalid()
{
$session = $this->getMock('Horde_Kolab_Session');
$auth = $this->getMock('Horde_Kolab_Session_Auth');
- $validator = $this->getMock('Horde_Kolab_Session_Valid');
- $factory = $this->getMock('Horde_Kolab_Session_Factory');
- $factory->expects($this->once())
- ->method('getSessionValidator')
- ->will($this->returnValue($validator));
$factory = new Horde_Kolab_Session_Factory_Configuration(
- $factory, array()
+ array(
+ 'server' => array(
+ 'basedn' => ''
+ )
+ )
);
$this->assertType(
'Horde_Kolab_Session_Valid',
@@ -171,41 +180,39 @@ class Horde_Kolab_Session_Class_Factory_ConfigurationTest extends Horde_Kolab_Se
);
}
- public function testMethodValidateGetsDelegated()
+ public function testMethodValidateHasResultBooleanTrueIfTheSessionIsStillValid()
{
$session = $this->getMock('Horde_Kolab_Session');
- $factory = $this->getMock('Horde_Kolab_Session_Factory');
- $factory->expects($this->once())
- ->method('validate')
- ->will($this->returnValue(true));
$factory = new Horde_Kolab_Session_Factory_Configuration(
- $factory, array()
+ array(
+ 'server' => array(
+ 'basedn' => ''
+ )
+ )
);
- $this->assertTrue($factory->validate($session, 'test'));
+ $this->assertTrue($factory->validate($session, ''));
}
- public function testMethodCreatesessionGetsDelegated()
+ public function testMethodCreatesessionHasResultSession()
{
- $session = $this->getMock('Horde_Kolab_Session');
- $factory = $this->getMock('Horde_Kolab_Session_Factory');
- $factory->expects($this->once())
- ->method('createSession')
- ->will($this->returnValue($session));
$factory = new Horde_Kolab_Session_Factory_Configuration(
- $factory, array()
+ array(
+ 'server' => array(
+ 'basedn' => ''
+ )
+ )
);
$this->assertType('Horde_Kolab_Session', $factory->createSession());
}
- public function testMethodGetsessionGetsDelegated()
+ public function testMethodGetsessionHasResultSession()
{
- $session = $this->getMock('Horde_Kolab_Session');
- $factory = $this->getMock('Horde_Kolab_Session_Factory');
- $factory->expects($this->once())
- ->method('getSession')
- ->will($this->returnValue($session));
$factory = new Horde_Kolab_Session_Factory_Configuration(
- $factory, array()
+ array(
+ 'server' => array(
+ 'basedn' => ''
+ )
+ )
);
$this->assertType('Horde_Kolab_Session', $factory->getSession());
}
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/DefaultTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/DefaultTest.php
index d6c856c77..a2fc27dac 100644
--- a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/DefaultTest.php
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/DefaultTest.php
@@ -34,17 +34,18 @@ class Horde_Kolab_Session_Class_Factory_DefaultTest extends Horde_Kolab_Session_
{
public function testMethodGetserverHasResultHordekolabserver()
{
- $this->markTestIncomplete('The factory in the Kolab_Server package needs to be fixed.');
- $server = $this->getMock('Horde_Kolab_Server');
+ $server = $this->getMock(
+ 'Horde_Kolab_Server_Composite', array(), array(), '', false, false
+ );
$server_factory = $this->getMock('Horde_Kolab_Server_Factory');
$server_factory->expects($this->once())
- ->method('getServer')
+ ->method('getComposite')
->will($this->returnValue($server));
$factory = new Horde_Kolab_Session_Factory_Default(
array('server' => array()),
$server_factory
);
- $this->assertType('Horde_Kolab_Server', $factory->getServer());
+ $this->assertType('Horde_Kolab_Server_Composite', $factory->getServer());
}
public function testMethodGetsessionauthHasResultHordekolabsessionauth()
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/InjectorTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/InjectorTest.php
index a6ec495b3..a5fab4a9c 100644
--- a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/InjectorTest.php
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/InjectorTest.php
@@ -35,7 +35,7 @@ class Horde_Kolab_Session_Class_Factory_InjectorTest extends Horde_Kolab_Session
public function setUp()
{
$this->injector = new Horde_Injector(new Horde_Injector_TopLevel());
- $this->markTestIncomplete('This needs an injector factory in the Kolab_Server package.');
+ Horde_Kolab_Session_Factory_Injector::setupMockServerFactory($this->injector);
}
public function testMethodGetserverHasResultHordekolabserver()
@@ -43,7 +43,7 @@ class Horde_Kolab_Session_Class_Factory_InjectorTest extends Horde_Kolab_Session
$factory = new Horde_Kolab_Session_Factory_Injector(
array('server' => array()), $this->injector
);
- $this->assertType('Horde_Kolab_Server', $factory->getServer());
+ $this->assertType('Horde_Kolab_Server_Composite', $factory->getServer());
}
public function testMethodGetsessionauthHasResultHordekolabsessionauth()
diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/SingletonTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/SingletonTest.php
index f9969cbd3..bf12f4677 100644
--- a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/SingletonTest.php
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/SingletonTest.php
@@ -32,9 +32,16 @@ require_once dirname(__FILE__) . '/../Autoload.php';
*/
class Horde_Kolab_Session_Class_SingletonTest extends Horde_Kolab_Session_SessionTestCase
{
+ public function setUp()
+ {
+ global $conf;
+
+ /** Provide a minimal configuration for the server */
+ $conf['kolab']['ldap']['basedn'] = '';
+ }
+
public function testMethodSingletonHasResultHordekolabsession()
{
- $this->markTestIncomplete('The factory in the Kolab_Server package needs to be fixed.');
$this->assertType(
'Horde_Kolab_Session',
Horde_Kolab_Session_Singleton::singleton(
@@ -45,7 +52,6 @@ class Horde_Kolab_Session_Class_SingletonTest extends Horde_Kolab_Session_Sessio
public function testMethodSingletonHasResultHordekolabsessionAlwaysTheSameIfTheSessionIsValid()
{
- $this->markTestIncomplete('The factory in the Kolab_Server package needs to be fixed.');
$session1 = Horde_Kolab_Session_Singleton::singleton(
'user', array('password' => 'pass')
);
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..f56009ee6
--- /dev/null
+++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Integration/SessionTest.php
@@ -0,0 +1,222 @@
+
+ * @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.
+ *
+ * Copyright 2008-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package Kolab_Session
+ * @author Gunnar Wrobel