public function dataByType($type);
/**
+ * List basic folder data for the specified folder.
+ *
+ * @param string $folder The folder path.
+ *
+ * @return array The folder data.
+ */
+ public function folderData($folder);
+
+ /**
* List all folders of a specific type.
*
* @param string $type The folder type the listing should be limited to.
}
/**
+ * List basic folder data for the specified folder.
+ *
+ * @param string $folder The folder path.
+ *
+ * @return array The folder data.
+ */
+ public function folderData($folder)
+ {
+ $list = $this->_list->listFolders();
+ if (!in_array($folder, $list)) {
+ throw new Horde_Kolab_Storage_Exception(
+ sprintf('Folder %s does not exist!', $folder)
+ );
+ }
+ $annotations = $this->listFolderTypeAnnotations();
+ if (!isset($annotations[$folder])) {
+ $type = $this->_factory->createFolderType('mail');
+ } else {
+ $type = $annotations[$folder];
+ }
+ $namespace = $this->_list->getNamespace();
+ return array(
+ 'type' => $type->getType(),
+ 'default' => $type->isDefault(),
+ 'namespace' => $namespace->matchNamespace($folder)->getType(),
+ 'owner' => $namespace->getOwner($folder),
+ 'name' => $namespace->getTitle($folder),
+ 'subpath' => $namespace->getSubpath($folder),
+ );
+ }
+
+ /**
* Get the folder owners.
*
* @return array The folder owners with the folder names as key and the
/** The folder list sorted by type */
const BY_TYPE = 'BY_TYPE';
+ /** The list of folder data */
+ const FOLDERS = 'FOLDERS';
+
/** The folder owner list */
const OWNERS = 'OWNERS';
}
/**
+ * List basic folder data for the specified folder.
+ *
+ * @param string $folder The folder path.
+ *
+ * @return array The folder data.
+ */
+ public function folderData($folder)
+ {
+ $folders = $this->_list_cache->getQuery(self::FOLDERS);
+ if (isset($folders[$folder])) {
+ return $folders[$folder];
+ } else {
+ throw new Horde_Kolab_Storage_Exception(
+ sprintf('Folder %s does not exist!', $folder)
+ );
+ }
+ }
+
+ /**
* Get the folder owners.
*
* @return array The folder owners with the folder names as key and the
public function synchronize()
{
$namespace = $this->_list->getNamespace();
+ $annotations = $this->listFolderTypeAnnotations();
+ $mail_type = $this->_factory->createFolderType('mail');
+ $folders = array();
$owners = array();
- foreach ($this->_list->listFolders() as $folder) {
- $owners[$folder] = $namespace->getOwner($folder);
- }
- $this->_list_cache->setQuery(self::OWNERS, $owners);
-
$types = array();
$by_type = array();
$personal_defaults = array();
$defaults = array();
- foreach ($this->listFolderTypeAnnotations() as $folder => $annotation) {
- $type = $annotation->getType();
+ foreach ($this->_list->listFolders() as $folder) {
+ if (!isset($annotations[$folder])) {
+ $type = $mail_type;
+ } else {
+ $type = $annotations[$folder];
+ }
+ $folder_type = $type->getType();
$owner = $namespace->getOwner($folder);
- $title = $namespace->getTitle($folder);
- $types[$folder] = $type;
- $by_type[$type][$folder] = array(
- 'owner' => $owner, 'name' => $title
+ $owners[$folder] = $owner;
+ $folders[$folder] = array(
+ 'type' => $folder_type,
+ 'default' => $type->isDefault(),
+ 'namespace' => $namespace->matchNamespace($folder)->getType(),
+ 'owner' => $owner,
+ 'name' => $namespace->getTitle($folder),
+ 'subpath' => $namespace->getSubpath($folder),
+ );
+
+ $types[$folder] = $folders[$folder]['type'];
+ $by_type[$folder_type][$folder] = array(
+ 'owner' => $folders[$folder]['owner'],
+ 'name' => $folders[$folder]['name']
);
- if ($annotation->isDefault()) {
- if (!isset($defaults[$owner][$type])) {
- $defaults[$owner][$type] = $folder;
+ if ($folders[$folder]['default']) {
+ if (!isset($defaults[$owner][$folder_type])) {
+ $defaults[$owner][$folder_type] = $folder;
} else {
throw new Horde_Kolab_Storage_Exception(
sprintf(
'Both folders %s and %s are marked as default folder of type %s!',
- $defaults[$owner][$type],
+ $defaults[$owner][$folder_type],
$folder,
- $type
+ $folder_type
)
);
}
- if ($namespace->matchNamespace($folder)->getType()
+ if ($folders[$folder]['namespace']
== Horde_Kolab_Storage_Folder_Namespace::PERSONAL) {
- if (!isset($personal_defaults[$type])) {
- $personal_defaults[$type] = $folder;
+ if (!isset($personal_defaults[$folder_type])) {
+ $personal_defaults[$folder_type] = $folder;
} else {
throw new Horde_Kolab_Storage_Exception(
sprintf(
'Both folders %s and %s are marked as default folder of type %s!',
- $personal_defaults[$type],
+ $personal_defaults[$folder_type],
$folder,
- $type
+ $folder_type
)
);
}
}
}
}
+
+ $this->_list_cache->setQuery(self::FOLDERS, $folders);
+ $this->_list_cache->setQuery(self::OWNERS, $owners);
$this->_list_cache->setQuery(self::TYPES, $types);
$this->_list_cache->setQuery(self::BY_TYPE, $by_type);
$this->_list_cache->setQuery(self::DEFAULTS, $defaults);
$data['INBOX/Calendar']['name']
);
}
+
+ /**
+ * @expectedException Horde_Kolab_Storage_Exception
+ */
+ public function testMissingFolderData()
+ {
+ $this->assertType('array', $this->getNullQuery()->folderData('INBOX/Calendar'));
+ }
+
+ public function testFolderDataReturnsArray()
+ {
+ $this->assertType('array', $this->getAnnotatedQuery()->folderData('INBOX/Calendar'));
+ }
+
+ public function testFolderDataHasOwner()
+ {
+ $data = $this->getAnnotatedQuery()->folderData('INBOX/Calendar');
+ $this->assertEquals(
+ 'test@example.com',
+ $data['owner']
+ );
+ }
+
+ public function testFolderDataHasTitle()
+ {
+ $data = $this->getAnnotatedQuery()->folderData('INBOX/Calendar');
+ $this->assertEquals(
+ 'Calendar',
+ $data['name']
+ );
+ }
+
+ public function testFolderDataHasType()
+ {
+ $data = $this->getAnnotatedQuery()->folderData('INBOX/Calendar');
+ $this->assertEquals(
+ 'event',
+ $data['type']
+ );
+ }
+
+ public function testFolderDataHasDefault()
+ {
+ $data = $this->getAnnotatedQuery()->folderData('INBOX/Calendar');
+ $this->assertTrue(
+ $data['default']
+ );
+ }
+
+ public function testMailFolderDataType()
+ {
+ $data = $this->getAnnotatedQuery()->folderData('INBOX');
+ $this->assertEquals(
+ 'mail',
+ $data['type']
+ );
+ }
+
+ public function testMailFolderDataNoDefault()
+ {
+ $data = $this->getAnnotatedQuery()->folderData('INBOX');
+ $this->assertFalse(
+ $data['default']
+ );
+ }
+
+ public function testFolderDataHasNamespace()
+ {
+ $data = $this->getAnnotatedQuery()->folderData('INBOX/Calendar');
+ $this->assertEquals(
+ 'personal',
+ $data['namespace']
+ );
+ }
+
+ public function testFolderDataHasSubpath()
+ {
+ $data = $this->getAnnotatedQuery()->folderData('INBOX/Calendar');
+ $this->assertEquals(
+ 'Calendar',
+ $data['subpath']
+ );
+ }
}
$query = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory);
$this->assertEquals(
array(
+ 'INBOX' => 'mail',
'INBOX/Calendar' => 'event',
'INBOX/Contacts' => 'contact',
'INBOX/Notes' => 'note',
'INBOX/Tasks' => 'task',
+ 'INBOX/a' => 'mail',
),
$query->listTypes()
);
$data['INBOX/Calendar']['name']
);
}
+
+ /**
+ * @expectedException Horde_Kolab_Storage_Exception
+ */
+ public function testMissingFolderData()
+ {
+ $this->assertType('array', $this->getNullQuery()->folderData('INBOX/Calendar'));
+ }
+
+ public function testFolderDataReturnsArray()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $data = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory)->folderData('INBOX/Calendar');
+ $this->assertType('array', $data);
+ }
+
+ public function testFolderDataHasOwner()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $data = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory)->folderData('INBOX/Calendar');
+ $this->assertEquals(
+ 'test@example.com',
+ $data['owner']
+ );
+ }
+
+ public function testFolderDataHasTitle()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $data = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory)->folderData('INBOX/Calendar');
+ $this->assertEquals(
+ 'Calendar',
+ $data['name']
+ );
+ }
+
+ public function testFolderDataHasType()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $data = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory)->folderData('INBOX/Calendar');
+ $this->assertEquals(
+ 'event',
+ $data['type']
+ );
+ }
+
+ public function testFolderDataHasDefault()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $data = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory)->folderData('INBOX/Calendar');
+ $this->assertTrue(
+ $data['default']
+ );
+ }
+
+ public function testMailFolderDataType()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $data = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory)->folderData('INBOX');
+ $this->assertEquals(
+ 'mail',
+ $data['type']
+ );
+ }
+
+ public function testMailFolderDataNoDefault()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $data = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory)->folderData('INBOX');
+ $this->assertFalse(
+ $data['default']
+ );
+ }
+
+ public function testFolderDataHasNamespace()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $data = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory)->folderData('INBOX/Calendar');
+ $this->assertEquals(
+ 'personal',
+ $data['namespace']
+ );
+ }
+
+ public function testFolderDataHasSubpath()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $data = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory)->folderData('INBOX/Calendar');
+ $this->assertEquals(
+ 'Calendar',
+ $data['subpath']
+ );
+ }
}