implemented working sql backend and moved creation of data needed for
authorLars Kneschke <l.kneschke@metaways.de>
Tue, 20 Nov 2012 06:27:40 +0000 (07:27 +0100)
committerLars Kneschke <l.kneschke@metaways.de>
Tue, 20 Nov 2012 06:27:40 +0000 (07:27 +0100)
unit tests to bootstrap.php

Change-Id: I29edf84644c7dbf17255d35ea65ef835b1fbc7a5

19 files changed:
docs/syncroton.sql
lib/Syncroton/Command/FolderCreate.php
lib/Syncroton/Data/AData.php
lib/Syncroton/Data/Calendar.php
lib/Syncroton/Data/Contacts.php
lib/Syncroton/Data/Email.php
lib/Syncroton/Data/Tasks.php
lib/Syncroton/Model/Folder.php
lib/Syncroton/Model/IFolder.php
tests/Syncroton/Command/FolderCreateTests.php
tests/Syncroton/Command/FolderDeleteTests.php
tests/Syncroton/Command/FolderSyncTests.php
tests/Syncroton/Command/FolderUpdateTests.php
tests/Syncroton/Command/GetAttachmentTests.php
tests/Syncroton/Command/ItemOperationsTests.php
tests/Syncroton/Command/MoveItemsTests.php
tests/Syncroton/Command/SearchTests.php
tests/Syncroton/Data/ContactsTests.php
tests/bootstrap.php

index 41d882b..aca77fc 100644 (file)
@@ -120,9 +120,17 @@ CREATE TABLE IF NOT EXISTS `syncroton_content` (
 
 CREATE TABLE IF NOT EXISTS `syncroton_data` (
     `id` varchar(40) NOT NULL,
-    `type` varchar(40) NOT NULL,
+    `class` varchar(40) NOT NULL,
     `folder_id` varchar(40) NOT NULL,
     `data` longblob,
     PRIMARY KEY (`id`)
 );
-  
\ No newline at end of file
+
+CREATE TABLE IF NOT EXISTS `syncroton_data_folder` (
+    `id` varchar(40) NOT NULL,
+    `type` int(11) NOT NULL,
+    `name` varchar(255) NOT NULL,
+    `owner_id` varchar(40) NOT NULL,
+    `parent_id` varchar(40) DEFAULT NULL,
+    PRIMARY KEY (`id`)
+);
index d87cd9d..e7eda47 100644 (file)
@@ -70,12 +70,13 @@ class Syncroton_Command_FolderCreate extends Syncroton_Command_Wbxml
                 break;
         }
         
-        $folder->deviceId     = $this->_device;\r
-        $folder->creationTime = $this->_syncTimeStamp;\r
-        
-        $dataController = Syncroton_Data_Factory::factory($folder->class, $this->_device, $this->_syncTimeStamp);\r
         \r
-        $this->_folder = $dataController->createFolder($folder);\r
+        $dataController = Syncroton_Data_Factory::factory($folder->class, $this->_device, $this->_syncTimeStamp);\r
+        
+        $this->_folder = $dataController->createFolder($folder);
+        $this->_folder->class        = $folder->class;
+        $this->_folder->deviceId     = $this->_device;\r
+        $this->_folder->creationTime = $this->_syncTimeStamp;\r
         
         $this->_folderBackend->create($this->_folder);\r
     }
index 4e02ef5..1382f68 100644 (file)
 
 abstract class Syncroton_Data_AData implements Syncroton_Data_IData
 {
-    /**
-     * used by unit tests only to simulated added folders
-     */
-    public static $folders = array();
+    const LONGID_DELIMITER = "\xe2\x87\x94"; # UTF8 ⇔
     
     /**
      * used by unit tests only to simulated added folders
      */
-    public static $entries = array();
-    
-    /**
-    * used by unit tests only to simulated added folders
-    */
     public static $changedEntries = array();
     
     public function __construct(Syncroton_Model_IDevice $_device, DateTime $_timeStamp)
     {
-        $this->_device = $_device;
-        $this->_timestamp = $_timeStamp;
-        
+        $this->_device      = $_device;
+        $this->_timestamp   = $_timeStamp;
         $this->_db          = Syncroton_Registry::getDatabase();
         $this->_tablePrefix = 'Syncroton_';
+        $this->_ownerId     = '1234';
+    }
+    
+    public function getFolder($id)
+    {
+        $select = $this->_db->select()
+            ->from($this->_tablePrefix . 'data_folder')
+            ->where('owner_id = ?', $this->_ownerId)
+            ->where('id = ?', $id);
         
-        $this->_initData();
+        $stmt   = $this->_db->query($select);
+        $folder = $stmt->fetch();
+        $stmt = null; # see https://bugs.php.net/bug.php?id=44081
+        
+        if ($folder === false) {
+            throw new Syncroton_Exception_NotFound("folder $id not found");
+        }
+        
+        return new Syncroton_Model_Folder(array(
+            'serverId'    => $folder['id'],
+            'displayName' => $folder['name'],
+            'type'        => $folder['type'],
+            'parentId'    => !empty($folder['parent_id']) ? $folder['parent_id'] : null
+        ));
     }
     
     public function createFolder(Syncroton_Model_IFolder $folder)
     {
-        $folder->id = sha1(mt_rand(). microtime());
+        if (!in_array($folder->type, $this->_supportedFolderTypes)) {
+            throw new Syncroton_Exception_UnexpectedValue();
+        }
         
-        // normaly generated on server backend
-        $folder->serverId = sha1(mt_rand(). microtime());
-    
-        Syncroton_Data_AData::$folders[get_class($this)][$folder->serverId] = $folder;
-    
-        return Syncroton_Data_AData::$folders[get_class($this)][$folder->serverId];
+        $id = !empty($folder->serverId) ? $folder->serverId : sha1(mt_rand(). microtime());
+        
+        $this->_db->insert($this->_tablePrefix . 'data_folder', array(\r
+            'id'        => $id,\r
+            'type'      => $folder->type,\r
+            'name'      => $folder->displayName,
+            'owner_id'  => $this->_ownerId,
+            'parent_id' => $folder->parentId\r
+        ));\r
+        
+        return $this->getFolder($id);
     }
     
     public function createEntry($_folderId, Syncroton_Model_IEntry $_entry)\r
     {\r
         $id = sha1(mt_rand(). microtime());\r
     \r
-        #Syncroton_Data_AData::$entries[get_class($this)][$_folderId][$id] = $_entry;
-        
         $this->_db->insert($this->_tablePrefix . 'data', array(\r
             'id'        => $id,\r
-            'type'      => get_class($this),
+            'class'     => get_class($_entry),
             'folder_id' => $_folderId,
             'data'      => serialize($_entry)\r
         ));\r
@@ -72,26 +90,46 @@ abstract class Syncroton_Data_AData implements Syncroton_Data_IData
     
     public function deleteEntry($_folderId, $_serverId, $_collectionData)
     {
-        #$folderId = $_folderId instanceof Syncroton_Model_IFolder ? $_folderId->serverId : $_folderId;
+        $folderId = $_folderId instanceof Syncroton_Model_IFolder ? $_folderId->serverId : $_folderId;
         
         $result = $this->_db->delete($this->_tablePrefix . 'data', array('id = ?' => $_serverId));\r
         \r
         return (bool) $result;
-        
-        #unset(Syncroton_Data_AData::$entries[get_class($this)][$folderId][$_serverId]);
     }
     
     public function deleteFolder($_folderId)
     {
         $folderId = $_folderId instanceof Syncroton_Model_IFolder ? $_folderId->serverId : $_folderId;
-    
-        unset(Syncroton_Data_AData::$folders[get_class($this)][$folderId]);
-        unset(Syncroton_Data_AData::$entries[get_class($this)][$folderId]);
+        
+        $result = $this->_db->delete($this->_tablePrefix . 'data', array('folder_id = ?' => $folderId));
+        $result = $this->_db->delete($this->_tablePrefix . 'data_folder', array('id = ?' => $folderId));
+        
+        return (bool) $result;
     }
     
     public function getAllFolders()
     {
-        return Syncroton_Data_AData::$folders[get_class($this)];
+        $select = $this->_db->select()
+            ->from($this->_tablePrefix . 'data_folder')
+            ->where('type IN (?)', $this->_supportedFolderTypes)
+            ->where('owner_id = ?', $this->_ownerId);
+        
+        $stmt    = $this->_db->query($select);
+        $folders = $stmt->fetchAll();
+        $stmt = null; # see https://bugs.php.net/bug.php?id=44081
+        
+        $result = array();
+        
+        foreach ((array) $folders as $folder) {
+            $result[$folder['id']] =  new Syncroton_Model_Folder(array(
+                'serverId'    => $folder['id'],
+                'displayName' => $folder['name'],
+                'type'        => $folder['type'],
+                'parentId'    => $folder['parent_id']
+            ));
+        }
+        
+        return $result;
     }
     
     public function getChangedEntries($_folderId, DateTime $_startTimeStamp, DateTime $_endTimeStamp = NULL)
@@ -177,7 +215,6 @@ abstract class Syncroton_Data_AData implements Syncroton_Data_IData
     public function updateEntry($_folderId, $_serverId, Syncroton_Model_IEntry $_entry)\r
     {\r
         $this->_db->update($this->_tablePrefix . 'data', array(
-            'type'      => get_class($this),
             'folder_id' => $_folderId,
             'data'      => serialize($_entry)
         ), array(
@@ -187,10 +224,12 @@ abstract class Syncroton_Data_AData implements Syncroton_Data_IData
     \r
     public function updateFolder(Syncroton_Model_IFolder $folder)\r
     {\r
-        Syncroton_Data_AData::$folders[get_class($this)][$folder->serverId] = $folder;\r
+        $this->_db->update($this->_tablePrefix . 'data_folder', array(
+            'name'      => $folder->displayName,
+            'parent_id' => $folder->parentId
+        ), array(
+            'id = ?' => $folder->serverId
+        ));
     }\r
-    \r
-    
-    abstract protected function _initData();
 }
 
index 5d99ffd..66c8d25 100644 (file)
  *
  * @package     Model
  */
-
 class Syncroton_Data_Calendar extends Syncroton_Data_AData implements Syncroton_Data_IDataCalendar
 {
+    protected $_supportedFolderTypes = array(
+        Syncroton_Command_FolderSync::FOLDERTYPE_CALENDAR,
+        Syncroton_Command_FolderSync::FOLDERTYPE_CALENDAR_USER_CREATED
+    );
+    
     /**
      * set attendee status for meeting
      * 
@@ -26,21 +30,5 @@ class Syncroton_Data_Calendar extends Syncroton_Data_AData implements Syncroton_
     {
         return $reponse->requestId;
     }
-    
-    protected function _initData()
-    {
-        /**
-        * used by unit tests only to simulated added folders
-        */
-        Syncroton_Data_AData::$folders[get_class($this)] = array(
-            'calendarFolderId' => new Syncroton_Model_Folder(array(
-                'id'          => sha1(mt_rand(). microtime()),
-                'serverId'    => 'calendarFolderId',
-                'parentId'    => 0,
-                'displayName' => 'Default Contacts Folder',
-                'type'        => Syncroton_Command_FolderSync::FOLDERTYPE_CALENDAR
-            ))
-        );
-    }
 }
 
index 1f191c2..a9b8d58 100644 (file)
 
 class Syncroton_Data_Contacts extends Syncroton_Data_AData implements Syncroton_Data_IDataSearch
 {
+    protected $_supportedFolderTypes = array(
+        Syncroton_Command_FolderSync::FOLDERTYPE_CONTACT,
+        Syncroton_Command_FolderSync::FOLDERTYPE_CONTACT_USER_CREATED
+    );
+    
     /**
      * (non-PHPdoc)
      * @see Syncroton_Data_IDataSearch::getSearchEntry()
      */
     public function getSearchEntry($longId, $options)
     {
-        list($collectionId, $serverId) = explode('-', $longId, 2);
+        list($collectionId, $serverId) = explode(Syncroton_Data_AData::LONGID_DELIMITER, $longId, 2);
         
         $contact = $this->getEntry(new Syncroton_Model_SyncCollection(array('collectionId' => $collectionId)), $serverId);
         
@@ -56,8 +61,8 @@ class Syncroton_Data_Contacts extends Syncroton_Data_AData implements Syncroton_
                     continue;
                 }
                 $found[] = new Syncroton_Model_StoreResponseResult(array(
-                    'longId' => 'addressbookFolderId-' .  $serverId,
-                    'properties' => $this->getSearchEntry('addressbookFolderId-' .  $serverId, $store->options)
+                    'longId' => 'addressbookFolderId' . Syncroton_Data_AData::LONGID_DELIMITER .  $serverId,
+                    'properties' => $this->getSearchEntry('addressbookFolderId' . Syncroton_Data_AData::LONGID_DELIMITER .  $serverId, $store->options)
                 ));
             }
         }
@@ -72,131 +77,5 @@ class Syncroton_Data_Contacts extends Syncroton_Data_AData implements Syncroton_
         
         return $storeResponse;
     }
-    
-    protected function _initData()
-    {
-        /**
-        * used by unit tests only to simulated added folders
-        */
-        if (!isset(Syncroton_Data_AData::$folders[get_class($this)])) {
-            Syncroton_Data_AData::$folders[get_class($this)] = array(
-                'addressbookFolderId' => new Syncroton_Model_Folder(array(
-                    'id'          => sha1(mt_rand(). microtime()),
-                    'serverId'    => 'addressbookFolderId',
-                    'parentId'    => 0,
-                    'displayName' => 'Default Contacts Folder',
-                    'type'        => Syncroton_Command_FolderSync::FOLDERTYPE_CONTACT
-                )),
-                'anotherAddressbookFolderId' => new Syncroton_Model_Folder(array(
-                    'id'          => sha1(mt_rand(). microtime()),
-                    'serverId'    => 'anotherAddressbookFolderId',
-                    'parentId'    => 0,
-                    'displayName' => 'Another Contacts Folder',
-                    'type'        => Syncroton_Command_FolderSync::FOLDERTYPE_CONTACT_USER_CREATED
-                ))
-            );
-        }
-        
-        /**
-         * used by unit tests only to simulated added folders
-         */
-        $entries = $this->getServerEntries('addressbookFolderId', 1);
-        
-        if (count($entries) == 0) {
-            $testData = array(
-                'addressbookFolderId' => array(
-                    'contact1' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Lars', 
-                        'lastName'  => 'Kneschke'
-                    )),
-                    'contact2' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Cornelius', 
-                        'lastName'  => 'Weiß'
-                    )),
-                    'contact3' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Lars', 
-                        'lastName'  => 'Kneschke'
-                    )),
-                    'contact4' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Cornelius', 
-                        'lastName'  => 'Weiß'
-                    )),
-                    'contact5' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Lars', 
-                        'lastName'  => 'Kneschke'
-                    )),
-                    'contact6' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Cornelius', 
-                        'lastName'  => 'Weiß'
-                    )),
-                    'contact7' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Lars', 
-                        'lastName'  => 'Kneschke'
-                    )),
-                    'contact8' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Cornelius', 
-                        'lastName'  => 'Weiß'
-                    )),
-                    'contact9' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Lars', 
-                        'lastName'  => 'Kneschke'
-                    )),
-                    'contact10' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Cornelius', 
-                        'lastName'  => 'Weiß'
-                    ))
-                ),
-                'anotherAddressbookFolderId' => array(
-                    'contact1' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Lars', 
-                        'lastName'  => 'Kneschke'
-                    )),
-                    'contact2' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Cornelius', 
-                        'lastName'  => 'Weiß'
-                    )),
-                    'contact3' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Lars', 
-                        'lastName'  => 'Kneschke'
-                    )),
-                    'contact4' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Cornelius', 
-                        'lastName'  => 'Weiß'
-                    )),
-                    'contact5' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Lars', 
-                        'lastName'  => 'Kneschke'
-                    )),
-                    'contact6' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Cornelius', 
-                        'lastName'  => 'Weiß'
-                    )),
-                    'contact7' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Lars', 
-                        'lastName'  => 'Kneschke'
-                    )),
-                    'contact8' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Cornelius', 
-                        'lastName'  => 'Weiß'
-                    )),
-                    'contact9' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Lars', 
-                        'lastName'  => 'Kneschke'
-                    )),
-                    'contact10' => new Syncroton_Model_Contact(array(
-                        'firstName' => 'Cornelius', 
-                        'lastName'  => 'Weiß'
-                    ))
-                )
-            );
-            
-            foreach ($testData['addressbookFolderId'] as $data) {
-                $this->createEntry('addressbookFolderId', $data);
-            }
-            foreach ($testData['anotherAddressbookFolderId'] as $data) {
-                $this->createEntry('anotherAddressbookFolderId', $data);
-            }
-        }
-    }
 }
 
index 9c84aae..5005c97 100644 (file)
  */
 class Syncroton_Data_Email extends Syncroton_Data_AData implements Syncroton_Data_IDataEmail
 {
-    /**
-     * used by unit tests only to simulated added folders
-     */
-    public static $entries = array();
+    protected $_supportedFolderTypes = array(
+        Syncroton_Command_FolderSync::FOLDERTYPE_DELETEDITEMS,
+        Syncroton_Command_FolderSync::FOLDERTYPE_DRAFTS,
+        Syncroton_Command_FolderSync::FOLDERTYPE_INBOX,
+        Syncroton_Command_FolderSync::FOLDERTYPE_MAIL_USER_CREATED,
+        Syncroton_Command_FolderSync::FOLDERTYPE_OUTBOX,
+        Syncroton_Command_FolderSync::FOLDERTYPE_SENTMAIL
+    );
     
     /**
      * (non-PHPdoc)
@@ -40,7 +44,7 @@ class Syncroton_Data_Email extends Syncroton_Data_AData implements Syncroton_Dat
      */
     public function getFileReference($fileReference)\r
     {\r
-        list($messageId, $partId) = explode('-', $fileReference, 2);\r
+        list($messageId, $partId) = explode(Syncroton_Data_AData::LONGID_DELIMITER, $fileReference, 2);\r
     
         // example code\r
         return new Syncroton_Model_FileReference(array(\r
@@ -78,67 +82,5 @@ class Syncroton_Data_Email extends Syncroton_Data_AData implements Syncroton_Dat
         }
         // send email
     }
-    
-    protected function _initData()
-    {
-        /**
-        * used by unit tests only to simulated added folders
-        */
-        Syncroton_Data_AData::$folders[get_class($this)] = array(
-            'emailInboxFolderId' => new Syncroton_Model_Folder(array(
-                'id'          => sha1(mt_rand(). microtime()),
-                'serverId'    => 'emailInboxFolderId',
-                'parentId'    => 0,
-                'displayName' => 'Inbox',
-                'type'        => Syncroton_Command_FolderSync::FOLDERTYPE_INBOX
-            )),
-            'emailSentFolderId' => new Syncroton_Model_Folder(array(
-                'id'          => sha1(mt_rand(). microtime()),
-                'serverId'    => 'emailSentFolderId',
-                'parentId'    => 0,
-                'displayName' => 'Sent',
-                'type'        => Syncroton_Command_FolderSync::FOLDERTYPE_SENTMAIL
-            ))
-        );
-        
-        /**
-         * used by unit tests only to simulated added folders
-         */
-        
-        $entries = $this->getServerEntries('emailInboxFolderId', 1);
-        
-        if (count($entries) == 0) {
-            $testData = array(
-                'emailInboxFolderId' => array(
-                    'email1' => new Syncroton_Model_Email(array(
-                        'accountId'    => 'FooBar',
-                        'attachments'  => array(
-                            new Syncroton_Model_EmailAttachment(array(
-                                'fileReference' => '12345abcd',
-                                'umAttOrder'    => 1
-                            ))
-                        ),
-                        'categories'   => array('123', '456'),
-                        'cc'           => 'l.kneschke@metaways.de',
-                        'dateReceived' => new DateTime('2012-03-21 14:00:00', new DateTimeZone('UTC')), 
-                        'from'         => 'k.kneschke@metaways.de',
-                        'subject'      => 'Test Subject',
-                        'to'           => 'j.kneschke@metaways.de',
-                        'read'         => 1,
-                        'body'         => new Syncroton_Model_EmailBody(array(
-                            'type'              => Syncroton_Model_EmailBody::TYPE_PLAINTEXT, 
-                            'data'              => 'Hello!', 
-                            'truncated'         => true, 
-                            'estimatedDataSize' => 600
-                        ))
-                    )),
-                )
-            );
-            
-            foreach ($testData['emailInboxFolderId'] as $data) {\r
-                $this->createEntry('emailInboxFolderId', $data);\r
-            }
-        }
-    }
 }
 
index 30a80d2..a0c4756 100644 (file)
 
 class Syncroton_Data_Tasks extends Syncroton_Data_AData
 {
-    protected function _initData()
-    {
-        /**
-        * used by unit tests only to simulated added folders
-        */
-        Syncroton_Data_AData::$folders[get_class($this)] = array(
-            'tasksFolderId' => new Syncroton_Model_Folder(array(
-                'id'          => sha1(mt_rand(). microtime()),
-                'serverId'    => 'tasksFolderId',
-                'parentId'    => 0,
-                'displayName' => 'Default Tasks Folder',
-                'type'        => Syncroton_Command_FolderSync::FOLDERTYPE_TASK
-            ))
-        );
-        
-        /**
-         * used by unit tests only to simulated added folders
-         */
-        #Syncroton_Data_AData::$entries[get_class($this)] = array(
-        #    'tasksFolderId' => array(
-        #    )
-        #);
-    }
+    protected $_supportedFolderTypes = array(
+        Syncroton_Command_FolderSync::FOLDERTYPE_TASK,
+        Syncroton_Command_FolderSync::FOLDERTYPE_TASK_USER_CREATED
+    );
 }
 
index 33412cf..dfabc34 100644 (file)
@@ -29,6 +29,7 @@ class Syncroton_Model_Folder extends Syncroton_Model_AEntry implements Syncroton
         'Internal' => array(
             'id'             => array('type' => 'string'),
             'deviceId'       => array('type' => 'string'),
+            'ownerId'        => array('type' => 'string'),
             'class'          => array('type' => 'string'),
             'creationTime'   => array('type' => 'datetime'),
             'lastfiltertype' => array('type' => 'number')
index 4ec3700..f27f523 100644 (file)
@@ -21,6 +21,7 @@
  * @property    string   displayName
  * @property    string   creationTime
  * @property    string   lastfiltertype
+ * @property    string   type
  */
 
 interface Syncroton_Model_IFolder
index 7d9fa9e..c390546 100644 (file)
@@ -78,10 +78,12 @@ class Syncroton_Command_FolderCreateTests extends Syncroton_Command_ATestCase
         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
         $this->assertEquals(2, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
         
+        $allFolders = Syncroton_Data_Factory::factory(Syncroton_Data_Factory::CLASS_CALENDAR, $this->_device, new DateTime('now'))->getAllFolders();
+        
         $nodes = $xpath->query('//FolderHierarchy:FolderCreate/FolderHierarchy:ServerId');
         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
         $this->assertFalse(empty($nodes->item(0)->nodeValue), $responseDoc->saveXML());
-        $this->assertArrayHasKey($nodes->item(0)->nodeValue, Syncroton_Data_AData::$folders['Syncroton_Data_Calendar']);
+        $this->assertArrayHasKey($nodes->item(0)->nodeValue, $allFolders);
     }
     
     /**
@@ -105,10 +107,12 @@ class Syncroton_Command_FolderCreateTests extends Syncroton_Command_ATestCase
         $xpath = new DomXPath($responseDoc);
         $xpath->registerNamespace('FolderHierarchy', 'uri:FolderHierarchy');
         
+        $allFolders = Syncroton_Data_Factory::factory(Syncroton_Data_Factory::CLASS_CONTACTS, $this->_device, new DateTime('now'))->getAllFolders();
+        
         $nodes = $xpath->query('//FolderHierarchy:FolderCreate/FolderHierarchy:ServerId');
         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
         $this->assertFalse(empty($nodes->item(0)->nodeValue), $responseDoc->saveXML());
-        $this->assertArrayHasKey($nodes->item(0)->nodeValue, Syncroton_Data_AData::$folders['Syncroton_Data_Contacts']);
+        $this->assertArrayHasKey($nodes->item(0)->nodeValue, $allFolders);
     }
     
     /**
@@ -132,10 +136,12 @@ class Syncroton_Command_FolderCreateTests extends Syncroton_Command_ATestCase
         $xpath = new DomXPath($responseDoc);
         $xpath->registerNamespace('FolderHierarchy', 'uri:FolderHierarchy');
         
+        $allFolders = Syncroton_Data_Factory::factory(Syncroton_Data_Factory::CLASS_EMAIL, $this->_device, new DateTime('now'))->getAllFolders();
+        
         $nodes = $xpath->query('//FolderHierarchy:FolderCreate/FolderHierarchy:ServerId');
         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
         $this->assertFalse(empty($nodes->item(0)->nodeValue), $responseDoc->saveXML());
-        $this->assertArrayHasKey($nodes->item(0)->nodeValue, Syncroton_Data_AData::$folders['Syncroton_Data_Email']);
+        $this->assertArrayHasKey($nodes->item(0)->nodeValue, $allFolders);
     }
     
     /**
@@ -159,10 +165,12 @@ class Syncroton_Command_FolderCreateTests extends Syncroton_Command_ATestCase
         $xpath = new DomXPath($responseDoc);
         $xpath->registerNamespace('FolderHierarchy', 'uri:FolderHierarchy');
         
+        $allFolders = Syncroton_Data_Factory::factory(Syncroton_Data_Factory::CLASS_TASKS, $this->_device, new DateTime('now'))->getAllFolders();
+        
         $nodes = $xpath->query('//FolderHierarchy:FolderCreate/FolderHierarchy:ServerId');
         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
         $this->assertFalse(empty($nodes->item(0)->nodeValue), $responseDoc->saveXML());
-        $this->assertArrayHasKey($nodes->item(0)->nodeValue, Syncroton_Data_AData::$folders['Syncroton_Data_Tasks']);
+        $this->assertArrayHasKey($nodes->item(0)->nodeValue, $allFolders);
     }
     
     /**
index 66ca807..a6df25d 100644 (file)
@@ -135,7 +135,9 @@ class Syncroton_Command_FolderDeleteTests extends Syncroton_Command_ATestCase
         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
         $this->assertEquals(3, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
         
-        $this->assertArrayNotHasKey($this->_testFolderId, Syncroton_Data_Contacts::$folders);
+        $allFolders = Syncroton_Data_Factory::factory(Syncroton_Data_Factory::CLASS_CALENDAR, $this->_device, new DateTime('now'))->getAllFolders();
+        
+        $this->assertArrayNotHasKey($this->_testFolderId, $allFolders);
     }
     
     /**
index 8980f4f..723e095 100644 (file)
@@ -17,6 +17,8 @@
  */
 class Syncroton_Command_FolderSyncTests extends Syncroton_Command_ATestCase
 {
+    #protected $_logPriority = Zend_Log::DEBUG;
+    
     /**
      * Runs the test methods of this class.
      *
@@ -74,13 +76,14 @@ class Syncroton_Command_FolderSyncTests extends Syncroton_Command_ATestCase
     {
         $this->testGetFoldersSyncKey0();
         
-        Syncroton_Data_AData::$folders['Syncroton_Data_Contacts']['addressbookFolderId2'] = new Syncroton_Model_Folder(array(
-            'id'          => sha1(mt_rand(). microtime()),
-            'serverId'    => 'addressbookFolderId2',
-            'parentId'    => 0,
-            'displayName' => 'User created Contacts Folder',
-            'type'        => Syncroton_Command_FolderSync::FOLDERTYPE_CONTACT_USER_CREATED
-        ));
+        Syncroton_Data_Factory::factory(Syncroton_Data_Factory::CLASS_CONTACTS, $this->_device, new DateTime('now'))->createFolder(
+            new Syncroton_Model_Folder(array(
+                'serverId'    => 'addressbookFolderId2',
+                'parentId'    => null,
+                'displayName' => 'User created Contacts Folder',
+                'type'        => Syncroton_Command_FolderSync::FOLDERTYPE_CONTACT_USER_CREATED
+            ))
+        );
         
         $doc = new DOMDocument();
         $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
@@ -91,7 +94,7 @@ class Syncroton_Command_FolderSyncTests extends Syncroton_Command_ATestCase
         $folderSync = new Syncroton_Command_FolderSync($doc, $this->_device, $this->_device->policykey);
     
         $folderSync->handle();
-    
+        
         $responseDoc = $folderSync->getResponse();
         #$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
         
@@ -147,12 +150,13 @@ class Syncroton_Command_FolderSyncTests extends Syncroton_Command_ATestCase
     {
         $this->testGetFoldersSyncKey0();
         $clientFolders1 = Syncroton_Registry::getFolderBackend()->getFolderState($this->_device, 'Contacts');
+        $testFolderIds = array_keys($clientFolders1);
         
         $this->testGetFoldersInvalidSyncKey();
         
         $this->testGetFoldersSyncKey0();
         $clientFolders2 = Syncroton_Registry::getFolderBackend()->getFolderState($this->_device, 'Contacts');
         
-        $this->assertEquals($clientFolders1["addressbookFolderId"], $clientFolders2["addressbookFolderId"]);
+        $this->assertEquals($clientFolders1[$testFolderIds[0]], $clientFolders2[$testFolderIds[0]]);
     }
 }
index ae80c76..3f2a0db 100644 (file)
@@ -75,8 +75,10 @@ class Syncroton_Command_FolderUpdateTests extends Syncroton_Command_ATestCase
         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
         $this->assertEquals(2, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
         
-        $this->assertArrayHasKey('calendarFolderId', Syncroton_Data_AData::$folders['Syncroton_Data_Calendar']);\r
-        $this->assertEquals('Test Folder Update', Syncroton_Data_AData::$folders['Syncroton_Data_Calendar']['calendarFolderId']->displayName);\r
+        $allFolders = Syncroton_Data_Factory::factory(Syncroton_Data_Factory::CLASS_CALENDAR, $this->_device, new DateTime('now'))->getAllFolders();
+        
+        $this->assertArrayHasKey('calendarFolderId', $allFolders);\r
+        $this->assertEquals('Test Folder Update', $allFolders['calendarFolderId']->displayName);\r
         
     }
         
@@ -109,8 +111,10 @@ class Syncroton_Command_FolderUpdateTests extends Syncroton_Command_ATestCase
         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
         $this->assertEquals(2, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
         
-        $this->assertArrayHasKey('anotherAddressbookFolderId', Syncroton_Data_AData::$folders['Syncroton_Data_Contacts']);
-        $this->assertEquals('Test Folder Update', Syncroton_Data_AData::$folders['Syncroton_Data_Contacts']['anotherAddressbookFolderId']->displayName);
+        $allFolders = Syncroton_Data_Factory::factory(Syncroton_Data_Factory::CLASS_CONTACTS, $this->_device, new DateTime('now'))->getAllFolders();
+        
+        $this->assertArrayHasKey('anotherAddressbookFolderId', $allFolders);
+        $this->assertEquals('Test Folder Update', $allFolders['anotherAddressbookFolderId']->displayName);
     }
     
     /**
index fd50100..6a7f52c 100644 (file)
@@ -36,7 +36,7 @@ class Syncroton_Command_GetAttachmentTests extends Syncroton_Command_ATestCase
      */
     public function testGetAttachment()
     {
-        $getAttachment = new Syncroton_Command_GetAttachment(null, $this->_device, array('attachmentName'  => 'FooBar-1', 'policyKey' => null));
+        $getAttachment = new Syncroton_Command_GetAttachment(null, $this->_device, array('attachmentName'  => 'FooBar' . Syncroton_Data_AData::LONGID_DELIMITER . '1', 'policyKey' => null));
         
         $getAttachment->handle();
         
index d68b454..315e286 100644 (file)
@@ -114,7 +114,7 @@ class Syncroton_Command_ItemOperationsTests extends Syncroton_Command_ATestCase
         $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
             <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
             <ItemOperations xmlns="uri:ItemOperations" xmlns:AirSync="uri:AirSync" xmlns:AirSyncBase="uri:AirSyncBase">
-            <Fetch><Store>Mailbox</Store><AirSyncBase:FileReference>emailInboxFolderId-email1</AirSyncBase:FileReference></Fetch>
+            <Fetch><Store>Mailbox</Store><AirSyncBase:FileReference>emailInboxFolderId' . Syncroton_Data_AData::LONGID_DELIMITER . 'email1</AirSyncBase:FileReference></Fetch>
             </ItemOperations>'
         );
         
@@ -169,7 +169,7 @@ class Syncroton_Command_ItemOperationsTests extends Syncroton_Command_ATestCase
         $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
             <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
             <ItemOperations xmlns="uri:ItemOperations" xmlns:AirSync="uri:AirSync" xmlns:AirSyncBase="uri:AirSyncBase">
-            <Fetch><Store>Mailbox</Store><AirSyncBase:FileReference>emailInboxFolderId-email1</AirSyncBase:FileReference></Fetch>
+            <Fetch><Store>Mailbox</Store><AirSyncBase:FileReference>emailInboxFolderId' . Syncroton_Data_AData::LONGID_DELIMITER . 'email1</AirSyncBase:FileReference></Fetch>
             </ItemOperations>'
         );
         
index c920293..6bcf6e8 100644 (file)
@@ -33,22 +33,6 @@ class Syncroton_Command_MoveItemsTests extends Syncroton_Command_ATestCase
     {
         parent::setUp();
         
-        Syncroton_Data_AData::$entries['Syncroton_Data_Contacts']['addressbookFolderId']['moveItem'] = array(
-               'FirstName' => 'Lars', 
-               'LastName'  => 'Kneschke'
-        );
-    }
-    
-    protected function tearDown()
-    {
-        parent::tearDown();
-        unset(Syncroton_Data_AData::$entries['Syncroton_Data_Contacts']['addressbookFolderId']['moveItem']);
-    }
-    
-    /**
-     */
-    public function testMoveInvalidSrcFolder()
-    {
         // do initial sync first
         $doc = new DOMDocument();
         $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
@@ -59,8 +43,13 @@ class Syncroton_Command_MoveItemsTests extends Syncroton_Command_ATestCase
         $folderSync = new Syncroton_Command_FolderSync($doc, $this->_device, null);
         $folderSync->handle();
         $responseDoc = $folderSync->getResponse();
-        
-        
+        #$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
+    }
+    
+    /**
+     */
+    public function testMoveInvalidSrcFolder()
+    {
         $doc = new DOMDocument();
         $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
             <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
@@ -84,18 +73,6 @@ class Syncroton_Command_MoveItemsTests extends Syncroton_Command_ATestCase
      */
     public function testMoveInvalidDstFolder()
     {
-        // do initial sync first
-        $doc = new DOMDocument();
-        $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
-            <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
-            <FolderSync xmlns="uri:ItemOperations"><SyncKey>0</SyncKey></FolderSync>'
-        );
-        
-        $folderSync = new Syncroton_Command_FolderSync($doc, $this->_device, null);
-        $folderSync->handle();
-        $responseDoc = $folderSync->getResponse();
-        
-        
         $doc = new DOMDocument();
         $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
             <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
@@ -119,18 +96,6 @@ class Syncroton_Command_MoveItemsTests extends Syncroton_Command_ATestCase
      */
     public function testMoveSameDstAndSrcFolder()
     {
-        // do initial sync first
-        $doc = new DOMDocument();
-        $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
-            <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
-            <FolderSync xmlns="uri:ItemOperations"><SyncKey>0</SyncKey></FolderSync>'
-        );
-        
-        $folderSync = new Syncroton_Command_FolderSync($doc, $this->_device, null);
-        $folderSync->handle();
-        $responseDoc = $folderSync->getResponse();
-        
-        
         $doc = new DOMDocument();
         $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
             <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
@@ -154,22 +119,11 @@ class Syncroton_Command_MoveItemsTests extends Syncroton_Command_ATestCase
      */
     public function testMove()
     {
-        // do initial sync first
-        $doc = new DOMDocument();
-        $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
-            <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
-            <FolderSync xmlns="uri:ItemOperations"><SyncKey>0</SyncKey></FolderSync>'
-        );
-        
-        $folderSync = new Syncroton_Command_FolderSync($doc, $this->_device, null);
-        $folderSync->handle();
-        $responseDoc = $folderSync->getResponse();
-        #$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
         
         $doc = new DOMDocument();
         $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
             <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
-            <Moves xmlns="uri:Move"><Move><SrcMsgId>moveItem</SrcMsgId><SrcFldId>addressbookFolderId</SrcFldId><DstFldId>anotherAddressbookFolderId</DstFldId></Move></Moves>'
+            <Moves xmlns="uri:Move"><Move><SrcMsgId>contact1</SrcMsgId><SrcFldId>addressbookFolderId</SrcFldId><DstFldId>anotherAddressbookFolderId</DstFldId></Move></Moves>'
         );
         
         $moveItems = new Syncroton_Command_MoveItems($doc, $this->_device, null);
@@ -186,10 +140,10 @@ class Syncroton_Command_MoveItemsTests extends Syncroton_Command_ATestCase
         
         $nodes = $xpath->query('//Move:Moves/Move:Response/Move:SrcMsgId');
         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
-        $this->assertEquals('moveItem', $nodes->item(0)->nodeValue, $responseDoc->saveXML());
+        $this->assertEquals('contact1', $nodes->item(0)->nodeValue, $responseDoc->saveXML());
         
         $nodes = $xpath->query('//Move:Moves/Move:Response/Move:DstMsgId');
         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
-        $this->assertEquals('moveItem', $nodes->item(0)->nodeValue, $responseDoc->saveXML());
+        $this->assertEquals('contact1', $nodes->item(0)->nodeValue, $responseDoc->saveXML());
     }    
 }
index e83e803..75e1a67 100644 (file)
@@ -73,5 +73,5 @@ class Syncroton_Command_SearchTests extends Syncroton_Command_ATestCase
         $nodes = $xpath->query('//Search:Search/Search:Response/Search:Store/Search:Result');
         $this->assertEquals(4, $nodes->length, $responseDoc->saveXML());
         #$this->assertEquals(Syncroton_Command_Search::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
-    }    
+    }
 }
index 7655324..612ff31 100644 (file)
@@ -260,7 +260,7 @@ class Syncroton_Data_ContactsTests extends Syncroton_Command_ATestCase
         Syncroton_Data_AData::$changedEntries['Syncroton_Data_Contacts'][] = 'contact1';
         
         $entries = $dataController->getChangedEntries('addressbook-root', new DateTime(null, new DateTimeZone('UTC')));
-        #var_dump($entries);
+        
         $this->assertContains('contact1', $entries);
         $this->assertNotContains('contact2', $entries);
     }
index 80ca8a6..20a82a0 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 
 $paths = array(
-realpath(dirname(__FILE__)),
-realpath(dirname(__FILE__) . '/../lib'),
-get_include_path()
+    realpath(dirname(__FILE__)),
+    realpath(dirname(__FILE__) . '/../lib'),
+    get_include_path()
 );
 set_include_path(implode(PATH_SEPARATOR, $paths));
 
@@ -63,5 +63,269 @@ function getTestDatabase()
         }
     }
     
+    // create test folders
+    $folders = array(
+        array(
+            'id'        => 'addressbookFolderId',
+            'type'      => Syncroton_Command_FolderSync::FOLDERTYPE_CONTACT,
+            'name'      => 'Default Contacts Folder',
+            'owner_id'  => '1234',
+            'parent_id' => '0'
+        ),
+        array(
+            'id'        => 'anotherAddressbookFolderId',
+            'type'      => Syncroton_Command_FolderSync::FOLDERTYPE_CONTACT_USER_CREATED,
+            'name'      => 'Another Contacts Folder',
+            'owner_id'  => '1234',
+            'parent_id' => '0'
+        ),
+        array(
+            'id'        => 'calendarFolderId',
+            'type'      => Syncroton_Command_FolderSync::FOLDERTYPE_CALENDAR,
+            'name'      => 'Default Contacts Folder',
+            'owner_id'  => '1234',
+            'parent_id' => '0'
+        ),
+        array(
+            'id'        => 'tasksFolderId',
+            'type'      => Syncroton_Command_FolderSync::FOLDERTYPE_TASK,
+            'name'      => 'Default Tasks Folder',
+            'owner_id'  => '1234',
+            'parent_id' => '0'
+        ),
+        array(
+            'id'        => 'emailInboxFolderId',
+            'type'      => Syncroton_Command_FolderSync::FOLDERTYPE_INBOX,
+            'name'      => 'Inbox',
+            'owner_id'  => '1234',
+            'parent_id' => '0'
+        ),
+        array(
+            'id'        => 'emailSentFolderId',
+            'type'      => Syncroton_Command_FolderSync::FOLDERTYPE_SENTMAIL,
+            'name'      => 'Sent',
+            'owner_id'  => '1234',
+            'parent_id' => '0'
+        )
+    );
+    
+    foreach ($folders as $folder) {
+        $db->insert('syncroton_data_folder', $folder);
+    }
+    
+    $entries = array(
+        array(
+            'id'        => 'contact1',
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'addressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Lars', 
+                'lastName'  => 'Kneschke'
+            )))
+        ),
+        array(
+            'id'        => sha1(mt_rand(). microtime()),
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'addressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Cornelius', 
+                'lastName'  => 'Weiß'
+            )))
+        ),
+        array(
+            'id'        => sha1(mt_rand(). microtime()),
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'addressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Lars', 
+                'lastName'  => 'Kneschke'
+            )))
+        ),
+        array(
+            'id'        => sha1(mt_rand(). microtime()),
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'addressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Cornelius', 
+                'lastName'  => 'Weiß'
+            )))
+        ),
+        array(
+            'id'        => sha1(mt_rand(). microtime()),
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'addressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Lars', 
+                'lastName'  => 'Kneschke'
+            )))
+        ),
+        array(
+            'id'        => sha1(mt_rand(). microtime()),
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'addressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Cornelius', 
+                'lastName'  => 'Weiß'
+            )))
+        ),
+        array(
+            'id'        => sha1(mt_rand(). microtime()),
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'addressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Lars', 
+                'lastName'  => 'Kneschke'
+            )))
+        ),
+        array(
+            'id'        => sha1(mt_rand(). microtime()),
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'addressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Cornelius', 
+                'lastName'  => 'Weiß'
+            )))
+        ),
+        array(
+            'id'        => sha1(mt_rand(). microtime()),
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'addressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Lars', 
+                'lastName'  => 'Kneschke'
+            )))
+        ),
+        array(
+            'id'        => sha1(mt_rand(). microtime()),
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'addressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Cornelius', 
+                'lastName'  => 'Weiß'
+            )))
+        ),
+        array(
+            'id'        => sha1(mt_rand(). microtime()),
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'anotherAddressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Lars', 
+                'lastName'  => 'Kneschke'
+            )))
+        ),
+        array(
+            'id'        => sha1(mt_rand(). microtime()),
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'anotherAddressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Cornelius', 
+                'lastName'  => 'Weiß'
+            )))
+        ),
+        array(
+            'id'        => sha1(mt_rand(). microtime()),
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'anotherAddressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Lars', 
+                'lastName'  => 'Kneschke'
+            )))
+        ),
+        array(
+            'id'        => sha1(mt_rand(). microtime()),
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'anotherAddressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Cornelius', 
+                'lastName'  => 'Weiß'
+            )))
+        ),
+        array(
+            'id'        => sha1(mt_rand(). microtime()),
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'anotherAddressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Lars', 
+                'lastName'  => 'Kneschke'
+            )))
+        ),
+        array(
+            'id'        => sha1(mt_rand(). microtime()),
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'anotherAddressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Cornelius', 
+                'lastName'  => 'Weiß'
+            )))
+        ),
+        array(
+            'id'        => sha1(mt_rand(). microtime()),
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'anotherAddressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Lars', 
+                'lastName'  => 'Kneschke'
+            )))
+        ),
+        array(
+            'id'        => sha1(mt_rand(). microtime()),
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'anotherAddressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Cornelius', 
+                'lastName'  => 'Weiß'
+            )))
+        ),
+        array(
+            'id'        => sha1(mt_rand(). microtime()),
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'anotherAddressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Lars', 
+                'lastName'  => 'Kneschke'
+            )))
+        ),
+        array(
+            'id'        => sha1(mt_rand(). microtime()),
+            'class'     => 'Syncroton_Model_Contact',
+            'folder_id' => 'anotherAddressbookFolderId',
+            'data'      => serialize(new Syncroton_Model_Contact(array(
+                'firstName' => 'Cornelius', 
+                'lastName'  => 'Weiß'
+            )))
+        ),
+        array(
+            'id'        => 'email1',
+            'class'     => 'Syncroton_Model_Email',
+            'folder_id' => 'emailInboxFolderId',
+            'data'      => serialize(new Syncroton_Model_Email(array(
+                'accountId'    => 'FooBar',
+                'attachments'  => array(
+                    new Syncroton_Model_EmailAttachment(array(
+                        'fileReference' => '12345abcd',
+                        'umAttOrder'    => 1
+                    ))
+                ),
+                'categories'   => array('123', '456'),
+                'cc'           => 'l.kneschke@metaways.de',
+                'dateReceived' => new DateTime('2012-03-21 14:00:00', new DateTimeZone('UTC')), 
+                'from'         => 'k.kneschke@metaways.de',
+                'subject'      => 'Test Subject',
+                'to'           => 'j.kneschke@metaways.de',
+                'read'         => 1,
+                'body'         => new Syncroton_Model_EmailBody(array(
+                    'type'              => Syncroton_Model_EmailBody::TYPE_PLAINTEXT, 
+                    'data'              => 'Hello!', 
+                    'truncated'         => true, 
+                    'estimatedDataSize' => 600
+                ))
+            )))
+        )
+    );
+    
+    foreach ($entries as $entry) {
+        $db->insert('syncroton_data', $entry);
+    }
+    
     return $db;
 }