From dc3a33f28041147a868e85862ec1c6770ab6a3f4 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Mon, 3 Jan 2011 14:06:35 +0100 Subject: [PATCH] Cache the folder types. --- .../Horde/Kolab/Storage/List/Decorator/Cache.php | 39 ++++++++- .../Storage/Unit/List/Decorator/CacheTest.php | 94 ++++++++++++++++++++++ 2 files changed, 129 insertions(+), 4 deletions(-) diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Decorator/Cache.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Decorator/Cache.php index 5aa6b99bc..31cf8aa24 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Decorator/Cache.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Decorator/Cache.php @@ -28,6 +28,12 @@ class Horde_Kolab_Storage_List_Decorator_Cache implements Horde_Kolab_Storage_List { + /** Marks the folder list. */ + const FOLDERS = 'F'; + + /** Marks the type list. */ + const TYPES = 'T'; + /** * Decorated list handler. * @@ -86,7 +92,7 @@ implements Horde_Kolab_Storage_List $this->_init(); $a = $this->_cache->loadListData( $this->_list->getConnectionId(), - 'FOLDERS' + self::FOLDERS ); if (empty($a)) { $a = $this->_cacheFolders(); @@ -104,7 +110,7 @@ implements Horde_Kolab_Storage_List $list = $this->_list->listFolders(); $this->_cache->storeListData( $this->_list->getConnectionId(), - 'FOLDERS', + self::FOLDERS, $list ); return $list; @@ -118,8 +124,32 @@ implements Horde_Kolab_Storage_List */ public function listFolderTypes() { - $result = $this->_list->listFolderTypes(); - return $result; + $this->_init(); + $a = $this->_cache->loadListData( + $this->_list->getConnectionId(), + self::TYPES + ); + if (empty($a)) { + $a = $this->_cacheFolderTypes(); + } + return $a; + } + + /** + * Cache and returns the folder type annotation as associative array. + * + * @return array The list folder types with the folder names as key and the + * folder type as values. + */ + private function _cacheFolderTypes() + { + $types = $this->_list->listFolderTypes(); + $this->_cache->storeListData( + $this->_list->getConnectionId(), + self::TYPES, + $types + ); + return $types; } /** @@ -130,5 +160,6 @@ implements Horde_Kolab_Storage_List public function synchronize() { $this->_cacheFolders(); + $this->_cacheFolderTypes(); } } \ No newline at end of file diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Decorator/CacheTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Decorator/CacheTest.php index 4aa60a2d9..0a9e8eb4e 100644 --- a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Decorator/CacheTest.php +++ b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Decorator/CacheTest.php @@ -159,4 +159,98 @@ extends Horde_Kolab_Storage_TestCase $list->synchronize(); $list->listFolders(); } + + public function testTypeListIsArray() + { + $list = new Horde_Kolab_Storage_List_Decorator_Cache( + $this->getNullList(), + $this->getMockCache() + ); + $this->assertType('array', $list->listFolderTypes()); + } + + public function testFolderTypes() + { + $list = new Horde_Kolab_Storage_List_Decorator_Cache( + $this->getTwoFolderList(), + $this->getMockCache() + ); + $this->assertEquals( + array(), + $list->listFolderTypes() + ); + } + + public function testMoreTypes() + { + $list = new Horde_Kolab_Storage_List_Decorator_Cache( + $this->getAnnotatedList(), + $this->getMockCache() + ); + $this->assertEquals( + array( + 'INBOX/Calendar' => 'event.default', + 'INBOX/Contacts' => 'contact.default', + 'INBOX/Notes' => 'note.default', + 'INBOX/Tasks' => 'task.default' + ), + $list->listFolderTypes() + ); + } + + public function testMockedTypes() + { + $list = new Horde_Kolab_Storage_List_Decorator_Cache( + $this->getMockDriverList(), + $this->getMockCache() + ); + $this->mockDriver->expects($this->once()) + ->method('listAnnotation') + ->will($this->returnValue(array('INBOX' => 'mail.default'))); + $this->assertEquals( + array('INBOX' => 'mail.default'), + $list->listFolderTypes() + ); + } + + public function testCachedTypes() + { + $list = new Horde_Kolab_Storage_List_Decorator_Cache( + $this->getMockDriverList(), + $this->getMockCache() + ); + $this->mockDriver->expects($this->once()) + ->method('listAnnotation') + ->will($this->returnValue(array('INBOX' => 'mail.default'))); + $list->listFolderTypes(); + $this->assertEquals( + array('INBOX' => 'mail.default'), + $list->listFolderTypes() + ); + } + + public function testSynchronizeTypes() + { + $list = new Horde_Kolab_Storage_List_Decorator_Cache( + $this->getMockDriverList(), + $this->getMockCache() + ); + $this->mockDriver->expects($this->once()) + ->method('listAnnotation') + ->will($this->returnValue(array('INBOX' => 'mail.default'))); + $list->synchronize(); + } + + public function testSynchronizeTypeCache() + { + $list = new Horde_Kolab_Storage_List_Decorator_Cache( + $this->getMockDriverList(), + $this->getMockCache() + ); + $this->mockDriver->expects($this->once()) + ->method('listAnnotation') + ->will($this->returnValue(array('INBOX' => 'mail.default'))); + $list->synchronize(); + $list->listFolderTypes(); + } } -- 2.11.0