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.
*
$this->_init();
$a = $this->_cache->loadListData(
$this->_list->getConnectionId(),
- 'FOLDERS'
+ self::FOLDERS
);
if (empty($a)) {
$a = $this->_cacheFolders();
$list = $this->_list->listFolders();
$this->_cache->storeListData(
$this->_list->getConnectionId(),
- 'FOLDERS',
+ self::FOLDERS,
$list
);
return $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;
}
/**
public function synchronize()
{
$this->_cacheFolders();
+ $this->_cacheFolderTypes();
}
}
\ No newline at end of file
$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();
+ }
}