public function listFolders();
/**
- * Returns the folder types as associative array.
- *
- * @return array The list folder types with the folder names as key and the
- * type as values.
- */
- public function listTypes();
-
- /**
* Returns the folder type annotation as associative array.
*
* @return array The list folder types with the folder names as key and the
- * type handler as values.
+ * folder type as values.
*/
- public function listFolderTypeAnnotations();
+ public function listFolderTypes();
}
private $_driver;
/**
- * The factory for generating additional resources.
- *
- * @var Horde_Kolab_Storage_Factory
- */
- private $_factory;
-
- /**
* Constructor.
*
* @param Horde_Kolab_Storage_Driver $driver The primary connection driver.
* @param Horde_Kolab_Storage_Factory $factory The factory.
*/
public function __construct(
- Horde_Kolab_Storage_Driver $driver,
- Horde_Kolab_Storage_Factory $factory
+ Horde_Kolab_Storage_Driver $driver
) {
$this->_driver = $driver;
- $this->_factory = $factory;
}
/**
}
/**
- * Returns the folder types as associative array.
- *
- * @return array The list folder types with the folder names as key and the
- * type as values.
- */
- public function listTypes()
- {
- $result = array();
- $list = $this->listFolderTypeAnnotations();
- foreach ($list as $folder => $annotation) {
- $result[$folder] = $annotation->getType();
- }
- return $result;
- }
-
- /**
* Returns the folder type annotation as associative array.
*
* @return array The list folder types with the folder names as key and the
- * type handler as values.
+ * folder type as values.
*/
- public function listFolderTypeAnnotations()
+ public function listFolderTypes()
{
- $result = array();
- $list = $this->_driver->listAnnotation(
+ return $this->_driver->listAnnotation(
'/shared/vendor/kolab/folder-type'
);
- foreach ($list as $folder => $annotation) {
- $result[$folder] = $this->_factory->createFolderType($annotation);
- }
- return $result;
- }
-
- /**
- * Return the specified query type.
- *
- * @param string $name The query name.
- *
- * @return Horde_Kolab_Storage_Query A query handler.
- *
- * @throws Horde_Kolab_Storage_Exception In case the requested query is not supported.
- */
- public function getQuery($name)
- {
- return $this->getQueryWithParent($name, $this);
- }
-
- /**
- * Return the specified query type based on the specified parent object.
- *
- * @param string $name The query name.
- * @param Horde_Kolab_Storage_List $parent The base for the query object.
- *
- * @return Horde_Kolab_Storage_Query A query handler.
- *
- * @throws Horde_Kolab_Storage_Exception In case the requested query is not supported.
- */
- public function getQueryWithParent($name, Horde_Kolab_Storage_List $parent)
- {
- $class = 'Horde_Kolab_Storage_List_Query_' . $name;
- if (class_exists($class)) {
- return new $class($parent);
- }
- throw new Horde_Kolab_Storage_Exception(sprintf('No such query "%s"!', $name));
}
}
\ No newline at end of file
}
/**
- * Returns the folder types as associative array.
- *
- * @return array The list folder types with the folder names as key and the
- * type as values.
- */
- public function listTypes()
- {
- $result = $this->_list->listTypes();
- return $result;
- }
-
- /**
* Returns the folder type annotation as associative array.
*
* @return array The list folder types with the folder names as key and the
- * type handler as values.
+ * folder type as values.
*/
- public function listFolderTypeAnnotations()
+ public function listFolderTypes()
{
- $result = $this->_list->listFolderTypeAnnotations();
+ $result = $this->_list->listFolderTypes();
return $result;
}
{
$this->_cacheFolders();
}
-
- /**
- * Return the specified query type.
- *
- * @param string $name The query name.
- *
- * @return Horde_Kolab_Storage_Query A query handler.
- *
- * @throws Horde_Kolab_Storage_Exception In case the requested query is not supported.
- */
- public function getQuery($name)
- {
- return $this->_list->getQueryWithParent($name, $this);
- }
-
}
\ No newline at end of file
*/
public function listFolders()
{
- $this->_logger->info('Listing folders.');
- $result = $this->_list->listFolders();
$this->_logger->info(
- sprintf('List contained %s folders.', count($result))
+ sprintf(
+ 'Listing folders for %s.',
+ $this->getConnectionId()
+ )
);
- return $result;
- }
-
- /**
- * Returns the folder types as associative array.
- *
- * @return array The list folder types with the folder names as key and the
- * type as values.
- */
- public function listTypes()
- {
- $this->_logger->info('Listing folder types.');
- $result = $this->_list->listTypes();
+ $result = $this->_list->listFolders();
$this->_logger->info(
- sprintf('List contained %s folders and types.', count($result))
+ sprintf(
+ 'List for %s contained %s folders.',
+ $this->getConnectionId(),
+ count($result)
+ )
);
return $result;
}
* Returns the folder type annotation as associative array.
*
* @return array The list folder types with the folder names as key and the
- * type handler as values.
+ * folder type as values.
*/
- public function listFolderTypeAnnotations()
+ public function listFolderTypes()
{
- $this->_logger->info('Listing folder type annotations.');
- $result = $this->_list->listFolderTypeAnnotations();
$this->_logger->info(
- sprintf('List contained %s folders and annotations.', count($result))
+ sprintf(
+ 'Listing folder type annotations for %s.',
+ $this->getConnectionId()
+ )
+ );
+ $result = $this->_list->listFolderTypes();
+ $this->_logger->info(
+ sprintf(
+ 'List for %s contained %s folders and annotations.',
+ $this->getConnectionId(),
+ count($result)
+ )
);
return $result;
}
-
- /**
- * Return the specified query type.
- *
- * @param string $name The query name.
- *
- * @return Horde_Kolab_Storage_Query A query handler.
- *
- * @throws Horde_Kolab_Storage_Exception In case the requested query is not supported.
- */
- public function getQuery($name)
- {
- return $this->_list->getQueryWithParent($name, $this);
- }
-
}
\ No newline at end of file
private $_queriable;
/**
+ * The factory for generating additional resources.
+ *
+ * @var Horde_Kolab_Storage_Factory
+ */
+ private $_factory;
+
+ /**
* Constructor.
*
* @param Horde_Kolab_Storage_Queriable $queriable The queriable list.
}
/**
+ * Inject the factory.
+ *
+ * @param Horde_Kolab_Storage_Factory $factory The factory.
+ *
+ * @return NULL
+ */
+ public function setFactory(Horde_Kolab_Storage_Factory $factory)
+ {
+ $this->_factory = $factory;
+ }
+
+ /**
+ * Returns the folder types as associative array.
+ *
+ * @return array The list folder types with the folder names as key and the
+ * type as values.
+ */
+ public function listTypes()
+ {
+ $result = array();
+ $list = $this->listFolderTypeAnnotations();
+ foreach ($list as $folder => $annotation) {
+ $result[$folder] = $annotation->getType();
+ }
+ return $result;
+ }
+
+ /**
+ * Returns the folder type annotation as associative array.
+ *
+ * @return array The list folder types with the folder names as key and the
+ * type handler as values.
+ */
+ public function listFolderTypeAnnotations()
+ {
+ $result = array();
+ $list = $this->_queriable->listFolderTypes();
+ foreach ($list as $folder => $annotation) {
+ $result[$folder] = $this->_factory->createFolderType($annotation);
+ }
+ return $result;
+ }
+
+ /**
* List all folders of a specific type.
*
* @param string $type The folder type the listing should be limited to.
public function listByType($type)
{
$result = array();
- foreach ($this->_queriable->listTypes() as $folder => $folder_type) {
+ foreach ($this->listTypes() as $folder => $folder_type) {
if ($folder_type == $type) {
$result[] = $folder;
}
*/
interface Horde_Kolab_Storage_Queriable
{
- /**
- * Return the specified query type.
- *
- * @param string $name The query name.
- *
- * @return Horde_Kolab_Storage_Query A query handler.
- *
- * @throws Horde_Kolab_Storage_Exception In case the requested query is not supported.
- */
- public function getQuery($name);
}
/** Load the basic test definition */
require_once dirname(__FILE__) . '/TestCase.php';
+
+/** Load stub definitions */
+require_once dirname(__FILE__) . '/Stub/FactoryQuery.php';
--- /dev/null
+<?php
+class Horde_Kolab_Storage_Stub_FactoryQuery
+implements Horde_Kolab_Storage_Query
+{
+ public $called = false;
+
+ /**
+ * Constructor.
+ *
+ * @param Horde_Kolab_Storage_Queriable $queriable The queriable object.
+ */
+ public function __construct(Horde_Kolab_Storage_Queriable $queriable)
+ {
+ }
+
+ /**
+ * Inject the factory.
+ *
+ * @param Horde_Kolab_Storage_Factory $factory The factory.
+ *
+ * @return NULL
+ */
+ public function setFactory(Horde_Kolab_Storage_Factory $factory)
+ {
+ $this->called = true;
+ }
+}
\ No newline at end of file
);
}
- protected function getNullList()
+ protected function getNullList($factory = null)
{
- $factory = new Horde_Kolab_Storage_Factory();
+ $factory = $this->completeFactory($factory);
return new Horde_Kolab_Storage_List_Base(
$this->getNullMock($factory),
$factory
);
}
- protected function getAnnotatedList()
+ protected function getAnnotatedList($factory = null)
{
- $factory = new Horde_Kolab_Storage_Factory();
+ $factory = $this->completeFactory($factory);
return new Horde_Kolab_Storage_List_Base(
$this->getAnnotatedMock($factory),
$factory
)
);
}
+
+ /**
+ * @expectedException Horde_Kolab_Storage_Exception
+ */
+ public function testCreateQueryForUnsupported()
+ {
+ $list = new Horde_Kolab_Storage_List_Base(
+ $this->getNullMock(),
+ new Horde_Kolab_Storage_Factory()
+ );
+ $factory = new Horde_Kolab_Storage_Factory();
+ $factory->createListQuery('NO_SUCH_QUERY', $list);
+ }
+
+ public function testQueryReturnsQuery()
+ {
+ $list = new Horde_Kolab_Storage_List_Base(
+ $this->getNullMock(),
+ new Horde_Kolab_Storage_Factory()
+ );
+ $factory = new Horde_Kolab_Storage_Factory();
+ $this->assertInstanceOf(
+ 'Horde_Kolab_Storage_Query',
+ $factory->createListQuery('Base', $list)
+ );
+ }
+
+ public function testFactoryInjection()
+ {
+ $list = new Horde_Kolab_Storage_List_Base(
+ $this->getNullMock(),
+ new Horde_Kolab_Storage_Factory()
+ );
+ $factory = new Horde_Kolab_Storage_Factory();
+ $this->assertInstanceOf(
+ 'Horde_Kolab_Storage_Query',
+ $factory->createListQuery('Base', $list)
+ );
+ }
+
+ public function testQueryStub()
+ {
+ $list = new Horde_Kolab_Storage_List_Base(
+ $this->getNullMock(),
+ new Horde_Kolab_Storage_Factory()
+ );
+ $factory = new Horde_Kolab_Storage_Factory();
+ $this->assertInstanceOf(
+ 'Horde_Kolab_Storage_Query',
+ $factory->createListQuery(
+ 'Horde_Kolab_Storage_Stub_FactoryQuery',
+ $list
+ )
+ );
+ }
+
+ public function testQueryFactoryInjection()
+ {
+ $list = new Horde_Kolab_Storage_List_Base(
+ $this->getNullMock(),
+ new Horde_Kolab_Storage_Factory()
+ );
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $factory->createListQuery(
+ 'Horde_Kolab_Storage_Stub_FactoryQuery',
+ $list
+ );
+ $this->assertTrue($query->called);
+ }
+
}
);
}
- public function testTypeReturnsArray()
+ public function testListFolderTypesReturnsArray()
{
$list = new Horde_Kolab_Storage_List_Base(
$this->getNullMock(),
new Horde_Kolab_Storage_Factory()
);
- $this->assertType('array', $list->listTypes());
- }
-
- public function testTypeReturnsAnnotations()
- {
- $list = new Horde_Kolab_Storage_List_Base(
- $this->getAnnotatedMock(),
- new Horde_Kolab_Storage_Factory()
- );
- $this->assertEquals(
- array(
- 'INBOX/Calendar' => 'event',
- 'INBOX/Contacts' => 'contact',
- 'INBOX/Notes' => 'note',
- 'INBOX/Tasks' => 'task',
- ),
- $list->listTypes()
- );
- }
-
- public function testAnnotationsReturnsHandlers()
- {
- $list = new Horde_Kolab_Storage_List_Base(
- $this->getAnnotatedMock(),
- new Horde_Kolab_Storage_Factory()
- );
- foreach ($list->listFolderTypeAnnotations() as $folder => $type) {
- $this->assertInstanceOf('Horde_Kolab_Storage_Folder_Type', $type);
- };
+ $this->assertType('array', $list->listFolderTypes());
}
public function testListQueriable()
);
$this->assertTrue($list instanceOf Horde_Kolab_Storage_Queriable);
}
-
- /**
- * @expectedException Horde_Kolab_Storage_Exception
- */
- public function testGetQueryForUnsupported()
- {
- $list = new Horde_Kolab_Storage_List_Base(
- $this->getNullMock(),
- new Horde_Kolab_Storage_Factory()
- );
- $list->getQuery('NO_SUCH_QUERY');
- }
-
- public function testQueryReturnsQuery()
- {
- $list = new Horde_Kolab_Storage_List_Base(
- $this->getNullMock(),
- new Horde_Kolab_Storage_Factory()
- );
- $this->assertInstanceOf('Horde_Kolab_Storage_Query', $list->getQuery('Base'));
- }
}
$this->getMockLogger()
);
$list->listFolders();
- $this->assertLogContains('List contained 2 folders.');
- }
-
- public function testListTypesFolderCount()
- {
- $list = new Horde_Kolab_Storage_List_Decorator_Log(
- $this->getNullList(),
- $this->getMockLogger()
- );
- $list->listTypes();
- $this->assertLogCount(2);
- }
-
- public function testListTypesLogsEntry()
- {
- $list = new Horde_Kolab_Storage_List_Decorator_Log(
- $this->getAnnotatedList(),
- $this->getMockLogger()
- );
- $list->listTypes();
- $this->assertLogContains('List contained 4 folders and types.');
+ $this->assertLogContains('List for test@example.com@mock:0 contained 2 folders.');
}
public function testListAnnotationsLogsEntry()
$this->getAnnotatedList(),
$this->getMockLogger()
);
- $list->listFolderTypeAnnotations();
- $this->assertLogContains('List contained 4 folders and annotations.');
- }
-
- public function testGetQueryReturnsQuery()
- {
- $list = new Horde_Kolab_Storage_List_Decorator_Log(
- $this->getNullList(),
- $this->getMockLogger()
- );
- $this->assertInstanceOf(
- 'Horde_Kolab_Storage_Query',
- $list->getQuery('Base')
- );
+ $list->listFolderTypes();
+ $this->assertLogContains('List for test@example.com@mock:0 contained 4 folders and annotations.');
}
}
{
public function testByTypeReturnsArray()
{
- $list = new Horde_Kolab_Storage_List_Base(
- $this->getNullMock(),
- new Horde_Kolab_Storage_Factory()
- );
- $query = $list->getQuery('Base');
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $factory->createListQuery('Base', $this->getNullList($factory));
$this->assertType('array', $query->listByType('test'));
}
public function testListCalendarsListsCalendars()
{
- $list = new Horde_Kolab_Storage_List_Base(
- $this->getAnnotatedMock(),
- new Horde_Kolab_Storage_Factory()
- );
- $query = $list->getQuery('Base');
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $factory->createListQuery('Base', $this->getAnnotatedList($factory));
$this->assertEquals(array('INBOX/Calendar'), $query->listByType('event'));
}
public function testListTasklistsListsTasklists()
{
- $list = new Horde_Kolab_Storage_List_Base(
- $this->getAnnotatedMock(),
- new Horde_Kolab_Storage_Factory()
- );
- $query = $list->getQuery('Base');
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $factory->createListQuery('Base', $this->getAnnotatedList($factory));
$this->assertEquals(array('INBOX/Tasks'), $query->listByType('task'));
}
+
+ public function testTypeReturnsArray()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $factory->createListQuery('Base', $this->getNullList($factory));
+ $this->assertType('array', $query->listTypes());
+ }
+
+ public function testTypeReturnsAnnotations()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $factory->createListQuery('Base', $this->getAnnotatedList($factory));
+ $this->assertEquals(
+ array(
+ 'INBOX/Calendar' => 'event',
+ 'INBOX/Contacts' => 'contact',
+ 'INBOX/Notes' => 'note',
+ 'INBOX/Tasks' => 'task',
+ ),
+ $query->listTypes()
+ );
+ }
+
+ public function testAnnotationsReturnsHandlers()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $factory->createListQuery('Base', $this->getAnnotatedList($factory));
+ foreach ($query->listFolderTypeAnnotations() as $folder => $type) {
+ $this->assertInstanceOf('Horde_Kolab_Storage_Folder_Type', $type);
+ };
+ }
}