*
* @return string|boolean The name of the default folder, false if there is no default.
*/
-// public function getDefault($type);
+ public function getDefault($type);
/**
* Get the default folder for a certain type from a different owner.
public function listTypes()
{
$result = array();
- $list = $this->listFolderTypeAnnotations();
- foreach ($list as $folder => $annotation) {
+ foreach ($this->listFolderTypeAnnotations() as $folder => $annotation) {
$result[$folder] = $annotation->getType();
}
return $result;
public function listFolderTypeAnnotations()
{
$result = array();
- $list = $this->_list->listFolderTypes();
- foreach ($list as $folder => $annotation) {
+ foreach ($this->_list->listFolderTypes() as $folder => $annotation) {
$result[$folder] = $this->_factory->createFolderType($annotation);
}
return $result;
}
/**
+ * Get the default folder for a certain type.
+ *
+ * @param string $type The type of the share/folder.
+ *
+ * @return string|boolean The name of the default folder, false if there is no default.
+ */
+ public function getDefault($type)
+ {
+ $result = null;
+ $namespace = $this->_list->getNamespace();
+ foreach ($this->listFolderTypeAnnotations() as $folder => $annotation) {
+ if ($annotation->getType() == $type
+ && $annotation->isDefault()
+ && ($namespace->matchNamespace($folder)->getType()
+ == Horde_Kolab_Storage_Folder_Namespace::PERSONAL)) {
+ if ($result === null) {
+ $result = $folder;
+ } else {
+ throw new Horde_Kolab_Storage_Exception(
+ sprintf(
+ 'Both folders %s and %s are marked as default folder of type %s!',
+ $result,
+ $folder,
+ $type
+ )
+ );
+ }
+ }
+ }
+ if ($result === null) {
+ return false;
+ } else {
+ return $result;
+ }
+ }
+
+ /**
* Synchronize the query data with the information from the backend.
*
* @return NULL
/** The folder owner list */
const OWNERS = 'OWNERS';
+ /** The default folder list for the current user */
+ const PERSONAL_DEFAULTS = 'PERSONAL_DEFAULTS';
+
+ /** The default folder list */
+ const DEFAULTS = 'DEFAULTS';
+
/**
* The queriable list.
*
}
/**
+ * Get the default folder for a certain type.
+ *
+ * @param string $type The type of the share/folder.
+ *
+ * @return string|boolean The name of the default folder, false if there is no default.
+ */
+ public function getDefault($type)
+ {
+ $defaults = $this->_list_cache->getQuery(self::PERSONAL_DEFAULTS);
+ if (isset($defaults[$type])) {
+ return $defaults[$type];
+ } else {
+ return false;
+ }
+ }
+
+ /**
* Synchronize the query data with the information from the backend.
*
* @return NULL
$owners[$folder] = $namespace->getOwner($folder);
}
$this->_list_cache->setQuery(self::OWNERS, $owners);
+
+ $personal_defaults = array();
+ $namespace = $this->_list->getNamespace();
+ foreach ($this->listFolderTypeAnnotations() as $folder => $annotation) {
+ if ($annotation->isDefault()
+ && ($namespace->matchNamespace($folder)->getType()
+ == Horde_Kolab_Storage_Folder_Namespace::PERSONAL)) {
+ $type = $annotation->getType();
+ if (!isset($personal_defaults[$type])) {
+ $personal_defaults[$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],
+ $folder,
+ $type
+ )
+ );
+ }
+ }
+ }
+ $this->_list_cache->setQuery(
+ self::PERSONAL_DEFAULTS, $personal_defaults
+ );
}
}
\ No newline at end of file
);
}
+ protected function getForeignDefaultAccount()
+ {
+ return array(
+ 'username' => 'test@example.com',
+ 'data' => array(
+ 'user/test' => null,
+ 'user/example/Calendar' => array(
+ 'annotations' => array(
+ '/shared/vendor/kolab/folder-type' => 'event.default',
+ )
+ ),
+ 'user/someone/Calendars/Events' => array(
+ 'annotations' => array(
+ '/shared/vendor/kolab/folder-type' => 'event.default',
+ )
+ ),
+ )
+ );
+ }
+
+ protected function getForeignDefaultMock($factory = null)
+ {
+ $factory = $this->completeFactory($factory);
+ return new Horde_Kolab_Storage_Driver_Mock(
+ $factory,
+ $this->getForeignDefaultAccount()
+ );
+ }
+
+ protected function getForeignDefaultList($factory = null)
+ {
+ $factory = $this->completeFactory($factory);
+ return new Horde_Kolab_Storage_List_Base(
+ $this->getForeignDefaultMock($factory),
+ $factory
+ );
+ }
+
+ protected function getEventAccount()
+ {
+ return array(
+ 'username' => 'test@example.com',
+ 'data' => array(
+ 'user/test' => null,
+ 'user/test/Calendar' => array(
+ 'annotations' => array(
+ '/shared/vendor/kolab/folder-type' => 'event',
+ )
+ ),
+ 'user/test/Events' => array(
+ 'annotations' => array(
+ '/shared/vendor/kolab/folder-type' => 'event.default',
+ )
+ ),
+ )
+ );
+ }
+
+ protected function getEventMock($factory = null)
+ {
+ $factory = $this->completeFactory($factory);
+ return new Horde_Kolab_Storage_Driver_Mock(
+ $factory,
+ $this->getEventAccount()
+ );
+ }
+
+ protected function getEventList($factory = null)
+ {
+ $factory = $this->completeFactory($factory);
+ return new Horde_Kolab_Storage_List_Base(
+ $this->getEventMock($factory),
+ $factory
+ );
+ }
+
+ protected function getDoubleEventAccount()
+ {
+ return array(
+ 'username' => 'test@example.com',
+ 'data' => array(
+ 'user/test' => null,
+ 'user/test/Calendar' => array(
+ 'annotations' => array(
+ '/shared/vendor/kolab/folder-type' => 'event.default',
+ )
+ ),
+ 'user/test/Events' => array(
+ 'annotations' => array(
+ '/shared/vendor/kolab/folder-type' => 'event.default',
+ )
+ ),
+ )
+ );
+ }
+
+ protected function getDoubleEventMock($factory = null)
+ {
+ $factory = $this->completeFactory($factory);
+ return new Horde_Kolab_Storage_Driver_Mock(
+ $factory,
+ $this->getDoubleEventAccount()
+ );
+ }
+
+ protected function getDoubleEventList($factory = null)
+ {
+ $factory = $this->completeFactory($factory);
+ return new Horde_Kolab_Storage_List_Base(
+ $this->getDoubleEventMock($factory),
+ $factory
+ );
+ }
+
protected function getCachedQueryForList($bare_list, $factory)
{
$list_cache = $this->getMockListCache();
$query->listOwners()
);
}
+
+ public function testDefaultReturn()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $factory->createListQuery('Base', $this->getAnnotatedList($factory));
+ $this->assertType(
+ 'string',
+ $query->getDefault('event')
+ );
+ }
+
+ public function testDefaultCalendar()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $factory->createListQuery('Base', $this->getAnnotatedList($factory));
+ $this->assertEquals(
+ 'INBOX/Calendar',
+ $query->getDefault('event')
+ );
+ }
+
+ public function testDefaultNotes()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $factory->createListQuery('Base', $this->getAnnotatedList($factory));
+ $this->assertEquals(
+ 'INBOX/Notes',
+ $query->getDefault('note')
+ );
+ }
+
+ public function testMissingDefault()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $factory->createListQuery('Base', $this->getNullList($factory));
+ $this->assertFalse(
+ $query->getDefault('note')
+ );
+ }
+
+ public function testIgnoreForeignDefault()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $factory->createListQuery('Base', $this->getForeignDefaultList($factory));
+ $this->assertFalse(
+ $query->getDefault('event')
+ );
+ }
+
+ public function testIdentifyDefault()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $factory->createListQuery('Base', $this->getEventList($factory));
+ $this->assertEquals(
+ 'INBOX/Events',
+ $query->getDefault('event')
+ );
+ }
+
+ /**
+ * @expectedException Horde_Kolab_Storage_Exception
+ */
+ public function testBailOnDoubleDefault()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $factory->createListQuery('Base', $this->getDoubleEventList($factory));
+ $query->getDefault('event');
+ }
}
$query->listOwners()
);
}
+
+ public function testDefaultReturn()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory);
+ $this->assertType(
+ 'string',
+ $query->getDefault('event')
+ );
+ }
+
+ public function testDefaultCalendar()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory);
+ $this->assertEquals(
+ 'INBOX/Calendar',
+ $query->getDefault('event')
+ );
+ }
+
+ public function testDefaultNotes()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $this->getCachedQueryForList($this->getAnnotatedList($factory), $factory);
+ $this->assertEquals(
+ 'INBOX/Notes',
+ $query->getDefault('note')
+ );
+ }
+
+ public function testMissingDefault()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $this->getCachedQueryForList($this->getNullList($factory), $factory);
+ $this->assertFalse(
+ $query->getDefault('note')
+ );
+ }
+
+ public function testIgnoreForeignDefault()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $this->getCachedQueryForList($this->getForeignDefaultList($factory), $factory);
+ $this->assertFalse(
+ $query->getDefault('event')
+ );
+ }
+
+ public function testIdentifyDefault()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $this->getCachedQueryForList($this->getEventList($factory), $factory);
+ $this->assertEquals(
+ 'INBOX/Events',
+ $query->getDefault('event')
+ );
+ }
+
+ /**
+ * @expectedException Horde_Kolab_Storage_Exception
+ */
+ public function testBailOnDoubleDefault()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $this->getCachedQueryForList($this->getDoubleEventList($factory), $factory);
+ $query->getDefault('event');
+ }
}