From c7fb3f057f1c1fc6f4f723b5aba1251ca0994922 Mon Sep 17 00:00:00 2001
From: Gunnar Wrobel
Date: Tue, 21 Dec 2010 21:08:13 +0100
Subject: [PATCH] Start a log decorator for the list handler.
---
.../Kolab_Storage/lib/Horde/Kolab/Storage/Base.php | 41 +++++++--
.../lib/Horde/Kolab/Storage/Decorator/Log.php | 99 ++++++++++++++++++++++
.../Kolab_Storage/lib/Horde/Kolab/Storage/List.php | 37 ++++++++
.../lib/Horde/Kolab/Storage/List/Base.php | 57 +++++++++++++
.../lib/Horde/Kolab/Storage/List/Decorator/Log.php | 74 ++++++++++++++++
framework/Kolab_Storage/package.xml | 33 ++++++--
.../test/Horde/Kolab/Storage/TestCase.php | 64 ++++++++++++++
.../Horde/Kolab/Storage/Unit/Decorator/LogTest.php | 49 +++++++++++
.../Horde/Kolab/Storage/Unit/List/BaseTest.php | 52 ++++++++++++
.../Kolab/Storage/Unit/List/Decorator/LogTest.php | 57 +++++++++++++
10 files changed, 552 insertions(+), 11 deletions(-)
create mode 100644 framework/Kolab_Storage/lib/Horde/Kolab/Storage/Decorator/Log.php
create mode 100644 framework/Kolab_Storage/lib/Horde/Kolab/Storage/List.php
create mode 100644 framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Base.php
create mode 100644 framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Decorator/Log.php
create mode 100644 framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Decorator/LogTest.php
create mode 100644 framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/BaseTest.php
create mode 100644 framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Decorator/LogTest.php
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Base.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Base.php
index e427b848b..859f76016 100644
--- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Base.php
+++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Base.php
@@ -26,6 +26,7 @@
* @link http://pear.horde.org/index.php?package=Kolab_Storage
*/
class Horde_Kolab_Storage_Base
+implements Horde_Kolab_Storage
{
/**
* The master Kolab storage system.
@@ -47,14 +48,44 @@ class Horde_Kolab_Storage_Base
}
/**
- * Returns the list of folders visible to the current user.
+ * Get the folder list object.
*
- * @return array The list of IMAP folders, represented as
- * a list of strings.
+ * @return Horde_Kolab_Storage_List The handler for the list of folders
+ * present in the Kolab backend.
*/
- public function listFolders()
+ public function getList()
+ {
+ return new Horde_Kolab_Storage_List_Base(
+ $this->_master
+ );
+ }
+
+ /**
+ * Get a Folder object.
+ *
+ * @param string $folder The folder name.
+ *
+ * @return Horde_Kolab_Storage_Folder The Kolab folder object.
+ */
+ public function getFolder($folder)
+ {
+ return new Horde_Kolab_Storage_Folder_Base(
+ $this, $this->_master, $folder
+ );
+ }
+
+ /**
+ * Return a data handler for accessing data in the specified
+ * folder.
+ *
+ * @param string $folder The name of the folder.
+ * @param string $type The type of data we want to
+ * access in the folder.
+ *
+ * @return Horde_Kolab_Data The data object.
+ */
+ public function getData($folder, $type)
{
- return $this->_master->getMailboxes();
}
}
\ No newline at end of file
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Decorator/Log.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Decorator/Log.php
new file mode 100644
index 000000000..29b9c82a0
--- /dev/null
+++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Decorator/Log.php
@@ -0,0 +1,99 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * A log decorator for the Kolab storage handler.
+ *
+ * Copyright 2004-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_Storage
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Decorator_Log
+implements Horde_Kolab_Storage
+{
+ /**
+ * The decorated storage handler.
+ *
+ * @var Horde_Kolab_Storage
+ */
+ private $_storage;
+
+ /**
+ * A log handler.
+ *
+ * @var mixed
+ */
+ private $_logger;
+
+ /**
+ * Constructor.
+ *
+ * @param Horde_Kolab_Storage $storage The storage handler.
+ * @param mixed $logger The log handler. This instance
+ * must provide the info() method.
+ */
+ public function __construct(Horde_Kolab_Storage $storage, $logger)
+ {
+ $this->_storage = $storage;
+ $this->_logger = $logger;
+ }
+
+ /**
+ * Get the folder list object.
+ *
+ * @return Horde_Kolab_Storage_List The handler for the list of folders
+ * present in the Kolab backend.
+ */
+ public function getList()
+ {
+ return new Horde_Kolab_Storage_List_Decorator_Log(
+ $this->_storage->getList(),
+ $this->_logger
+ );
+ }
+
+ /**
+ * Get a Folder object.
+ *
+ * @param string $folder The folder name.
+ *
+ * @return Horde_Kolab_Storage_Folder The Kolab folder object.
+ */
+ public function getFolder($folder)
+ {
+ return $this->_storage->getFolder();
+ }
+
+ /**
+ * Return a data handler for accessing data in the specified
+ * folder.
+ *
+ * @param string $folder The name of the folder.
+ * @param string $type The type of data we want to
+ * access in the folder.
+ *
+ * @return Horde_Kolab_Data The data object.
+ */
+ public function getData($folder, $type)
+ {
+ return $this->_storage->getData();
+ }
+
+}
\ No newline at end of file
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List.php
new file mode 100644
index 000000000..fa6f0fd5d
--- /dev/null
+++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List.php
@@ -0,0 +1,37 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * The interface describing a list of Kolab folders.
+ *
+ * Copyright 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_Storage
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+interface Horde_Kolab_Storage_List
+{
+ /**
+ * Returns the list of folders visible to the current user.
+ *
+ * @return array The list of folders, represented as strings.
+ */
+ public function listFolders();
+
+}
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Base.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Base.php
new file mode 100644
index 000000000..805e4df0d
--- /dev/null
+++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Base.php
@@ -0,0 +1,57 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * The basic handler for accessing folder lists from Kolab storage.
+ *
+ * Copyright 2004-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_Storage
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_List_Base
+implements Horde_Kolab_Storage_List
+{
+ /**
+ * The driver for accessing the Kolab storage system.
+ *
+ * @var Horde_Kolab_Storage_Driver
+ */
+ private $_driver;
+
+ /**
+ * Constructor.
+ *
+ * @param Horde_Kolab_Storage_Driver $driver The primary connection driver.
+ */
+ public function __construct(Horde_Kolab_Storage_Driver $driver)
+ {
+ $this->_driver = $driver;
+ }
+
+ /**
+ * Returns the list of folders visible to the current user.
+ *
+ * @return array The list of folders, represented as a list of strings.
+ */
+ public function listFolders()
+ {
+ return $this->_driver->getMailboxes();
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Decorator/Log.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Decorator/Log.php
new file mode 100644
index 000000000..cfd77bbf5
--- /dev/null
+++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Decorator/Log.php
@@ -0,0 +1,74 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * The log decorator for folder lists from Kolab storage.
+ *
+ * Copyright 2004-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_Storage
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_List_Decorator_Log
+implements Horde_Kolab_Storage_List
+{
+ /**
+ * Decorated list handler.
+ *
+ * @var Horde_Kolab_Storage_List
+ */
+ private $_list;
+
+ /**
+ * A log handler.
+ *
+ * @var mixed
+ */
+ private $_logger;
+
+ /**
+ * Constructor.
+ *
+ * @param Horde_Kolab_Storage_List $list The original list handler.
+ * @param mixed $logger The log handler. This instance
+ * must provide the info() method.
+ */
+ public function __construct(
+ Horde_Kolab_Storage_List $list,
+ $logger
+ ) {
+ $this->_list = $list;
+ $this->_logger = $logger;
+ }
+
+ /**
+ * Returns the list of folders visible to the current user.
+ *
+ * @return array The list of folders, represented as a list of strings.
+ */
+ public function listFolders()
+ {
+ $this->_logger->info('Listing folders.');
+ $result = $this->_list->listFolders();
+ $this->_logger->info(
+ sprintf('List contained %s folders.', count($result))
+ );
+ return $result;
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Storage/package.xml b/framework/Kolab_Storage/package.xml
index e266280f1..a3a74c029 100644
--- a/framework/Kolab_Storage/package.xml
+++ b/framework/Kolab_Storage/package.xml
@@ -31,8 +31,8 @@
jan@horde.org
yes
- 2010-12-16
-
+ 2010-12-21
+
0.4.0
0.1.0
@@ -73,6 +73,9 @@
+
+
+
@@ -131,6 +134,9 @@
+
+
+
@@ -143,7 +149,6 @@
-
@@ -420,12 +425,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
@@ -437,7 +454,6 @@
-
@@ -535,6 +551,7 @@
+
@@ -573,6 +590,7 @@
+
@@ -668,7 +686,6 @@
-
@@ -678,10 +695,14 @@
+
+
+
+
@@ -753,7 +774,7 @@
alpha
alpha
- 2010-12-16
+ 2010-12-21
LGPL
* Added namespace support (Bug #6691).
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/TestCase.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/TestCase.php
index d890ce0a2..12ca1f2c2 100644
--- a/framework/Kolab_Storage/test/Horde/Kolab/Storage/TestCase.php
+++ b/framework/Kolab_Storage/test/Horde/Kolab/Storage/TestCase.php
@@ -30,4 +30,68 @@
class Horde_Kolab_Storage_TestCase
extends PHPUnit_Framework_TestCase
{
+ protected function getNullMock()
+ {
+ return new Horde_Kolab_Storage_Driver_Mock(
+ new Horde_Kolab_Storage_Factory()
+ );
+ }
+
+ protected function getEmptyMock()
+ {
+ return new Horde_Kolab_Storage_Driver_Mock(
+ new Horde_Kolab_Storage_Factory(),
+ $this->getEmptyAccount()
+ );
+ }
+
+ protected function getEmptyAccount()
+ {
+ return array(
+ 'username' => 'test@example.com',
+ 'data' => array()
+ );
+ }
+
+ protected function getTwoFolderMock()
+ {
+ return new Horde_Kolab_Storage_Driver_Mock(
+ new Horde_Kolab_Storage_Factory(),
+ $this->getTwoFolderAccount()
+ );
+ }
+
+ protected function getTwoFolderAccount()
+ {
+ return array(
+ 'username' => 'test@example.com',
+ 'data' => array(
+ 'user/test' => null,
+ 'user/test/a' => null
+ )
+ );
+ }
+
+ protected function getMockLogger()
+ {
+ $this->logHandler = new Horde_Log_Handler_Mock();
+ return new Horde_Log_Logger($this->logHandler);
+ }
+
+ protected function assertLogCount($count)
+ {
+ $this->assertEquals(count($this->logHandler->events), $count);
+ }
+
+ protected function assertLogContains($message)
+ {
+ $found = false;
+ foreach ($this->logHandler->events as $event) {
+ if (strstr($event['message'], $message) !== false) {
+ $found = true;
+ break;
+ }
+ }
+ $this->assertTrue($found);
+ }
}
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Decorator/LogTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Decorator/LogTest.php
new file mode 100644
index 000000000..de9e136fe
--- /dev/null
+++ b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Decorator/LogTest.php
@@ -0,0 +1,49 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the log decorator for the storage handler.
+ *
+ * Copyright 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_Storage
+ * @subpackage UnitTests
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Unit_Decorator_LogTest
+extends Horde_Kolab_Storage_TestCase
+{
+ public function testListLogsEntry()
+ {
+ $storage = new Horde_Kolab_Storage_Decorator_Log(
+ new Horde_Kolab_Storage_Base($this->getNullMock()),
+ $this->getMockLogger()
+ );
+ $this->assertInstanceOf(
+ 'Horde_Kolab_Storage_List_Decorator_Log',
+ $storage->getList()
+ );
+ }
+}
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/BaseTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/BaseTest.php
new file mode 100644
index 000000000..dc27dbe49
--- /dev/null
+++ b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/BaseTest.php
@@ -0,0 +1,52 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the basic folder list handler.
+ *
+ * Copyright 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_Storage
+ * @subpackage UnitTests
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Unit_List_BaseTest
+extends Horde_Kolab_Storage_TestCase
+{
+ public function testListReturnsArray()
+ {
+ $list = new Horde_Kolab_Storage_List_Base($this->getNullMock());
+ $this->assertType('array', $list->listFolders());
+ }
+
+ public function testListReturnsFolders()
+ {
+ $list = new Horde_Kolab_Storage_List_Base($this->getTwoFolderMock());
+ $this->assertEquals(
+ array('INBOX', 'INBOX/a'),
+ $list->listFolders()
+ );
+ }
+}
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Decorator/LogTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Decorator/LogTest.php
new file mode 100644
index 000000000..ab26a0288
--- /dev/null
+++ b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Decorator/LogTest.php
@@ -0,0 +1,57 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../../Autoload.php';
+
+/**
+ * Test the folder list log decorator.
+ *
+ * Copyright 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_Storage
+ * @subpackage UnitTests
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Unit_List_Decorator_LogTest
+extends Horde_Kolab_Storage_TestCase
+{
+ public function testListLogsEntry()
+ {
+ $list = new Horde_Kolab_Storage_List_Decorator_Log(
+ new Horde_Kolab_Storage_List_Base($this->getNullMock()),
+ $this->getMockLogger()
+ );
+ $list->listFolders();
+ $this->assertLogCount(2);
+ }
+
+ public function testListFolderCount()
+ {
+ $list = new Horde_Kolab_Storage_List_Decorator_Log(
+ new Horde_Kolab_Storage_List_Base($this->getTwoFolderMock()),
+ $this->getMockLogger()
+ );
+ $list->listFolders();
+ $this->assertLogContains('List contained 2 folders.');
+ }
+}
--
2.11.0