current state of Syncope
authorLars Kneschke <l.kneschke@metaways.de>
Sun, 22 Jan 2012 22:08:42 +0000 (23:08 +0100)
committerLars Kneschke <l.kneschke@metaways.de>
Sun, 22 Jan 2012 22:08:42 +0000 (23:08 +0100)
19 files changed:
docs/syncope.sql
lib/Syncope/Backend/Content.php
lib/Syncope/Backend/Folder.php
lib/Syncope/Backend/IFolder.php
lib/Syncope/Backend/SyncState.php
lib/Syncope/Command/FolderSync.php
lib/Syncope/Command/Sync.php
lib/Syncope/Command/Wbxml.php
lib/Syncope/Data/Contacts.php
lib/Syncope/Data/Factory.php
lib/Syncope/Model/IFolder.php
tests/Syncope/AllTests.php
tests/Syncope/Backend/AllTests.php
tests/Syncope/Backend/ContentTests.php
tests/Syncope/Backend/FolderTests.php
tests/Syncope/Backend/SyncStateTests.php
tests/Syncope/Command/FolderSyncTests.php
tests/Syncope/Command/SyncTests.php
tests/bootstrap.php

index 6e11706..51879d0 100644 (file)
@@ -10,11 +10,14 @@ CREATE TABLE IF NOT EXISTS `syncope_devices` (
     PRIMARY KEY (`id`)
 );
 
-CREATE TABLE IF NOT EXISTS `syncope_folderstates` (
+CREATE TABLE IF NOT EXISTS `syncope_folders` (
   `id` varchar(40) NOT NULL,
   `device_id` varchar(64) NOT NULL,
   `class` varchar(64) NOT NULL,
   `folderid` varchar(254) NOT NULL,
+  `parentid` varchar(254) DEFAULT NULL,
+  `displayname` varchar(254) NOT NULL,
+  `type` int(11) DEFAULT NULL,
   `creation_time` datetime NOT NULL,
   `lastfiltertype` int(11) DEFAULT NULL,
   PRIMARY KEY (`id`),
@@ -36,13 +39,12 @@ CREATE TABLE `syncope_synckeys` (
 CREATE TABLE `syncope_contents` (                                                                                                                                           
   `id` varchar(40) NOT NULL,                                                                                                                                                                               
   `device_id` varchar(64) DEFAULT NULL,                                                                                                                                                                    
-  `class` varchar(64) DEFAULT NULL,                                                                                                                                                                        
+  `folder_id` varchar(64) DEFAULT NULL,                                                                                                                                                                        
   `contentid` varchar(64) DEFAULT NULL,                                                                                                                                                                    
-  `collectionid` varchar(254) DEFAULT NULL,                                                                                                                                                                
   `creation_time` datetime DEFAULT NULL,                                                                                                                                                                   
   `is_deleted` tinyint(1) unsigned DEFAULT '0',                                                                                                                                                            
   PRIMARY KEY (`id`),                                                                                                                                                                                      
-  UNIQUE KEY `device_id--class--collectionid--contentid` (`device_id`(40),`class`(40),`collectionid`(40),`contentid`(40)),                                                                                 
+  UNIQUE KEY `device_id--folder_id--contentid` (`device_id`(40),`folder_id`(40),`contentid`(40)),                                                                                 
   KEY `acsync_contents::device_id--acsync_devices::id` (`device_id`),                                                                                                                                        
   CONSTRAINT `acsync_contents::device_id--acsync_devices::id` FOREIGN KEY (`device_id`) REFERENCES `syncope_devices` (`id`) ON DELETE CASCADE ON UPDATE CASCADE                                         
 );
\ No newline at end of file
index fda8929..eb48828 100644 (file)
@@ -42,14 +42,14 @@ class Syncope_Backend_Content implements Syncope_Backend_IContent
     public function create(Syncope_Model_IContent $_state)
     {
         $id = sha1(mt_rand(). microtime());
+        
         $deviceId = $_state->device_id instanceof Syncope_Model_IDevice ? $_state->device_id->id : $_state->device_id;
         $folderId = $_state->folder_id instanceof Syncope_Model_IFolder ? $_state->folder_id->id : $_state->folder_id;
     
-        $this->_db->insert('syncope_contentstates', array(
+        $this->_db->insert('syncope_contents', array(
                'id'            => $id, 
                'device_id'     => $deviceId,
-               'folder_id'     => $_state->folder_id,
-               'collectionid'  => $_state->collectionid,
+               'folder_id'     => $folderId,
                'contentid'     => $_state->contentid,
                'creation_time' => $_state->creation_time->format('Y-m-d H:i:s'),
                'is_deleted'    => isset($_state->is_deleted) ? (int)!!$_state->is_deleted : 0
@@ -68,10 +68,10 @@ class Syncope_Backend_Content implements Syncope_Backend_IContent
     {
         $id = $_id instanceof Syncope_Model_IContent ? $_id->id : $_id;
         
-        $this->_db->update('syncope_contentstates', array(
-                       'is_deleted' => 1
+        $this->_db->update('syncope_contents', array(
+               'is_deleted' => 1
         ), array(
-                       'id = ?' => $id
+               'id = ?' => $id
         ));
         
     }
@@ -84,7 +84,7 @@ class Syncope_Backend_Content implements Syncope_Backend_IContent
     public function get($_id)
     {
         $select = $this->_db->select()
-            ->from('syncope_contentstates')
+            ->from('syncope_contents')
             ->where('id = ?', $_id);
     
         $stmt = $this->_db->query($select);
@@ -100,23 +100,23 @@ class Syncope_Backend_Content implements Syncope_Backend_IContent
     
         return $state;
     }
+    
     /**
-    * get array of ids which got send to the client for a given class
-    *
-    * @param Syncope_Model_IDevice $_deviceId
-    * @param string $_class
-    * @return array
-    */
-    public function getClientState($_deviceId, $_class, $_collectionId)
+     * get array of ids which got send to the client for a given class
+     *
+     * @param Syncope_Model_IDevice|string $_deviceId
+     * @param Syncope_Model_IFolder|string $_folderId
+     * @return array
+     */
+    public function getFolderState($_deviceId, $_folderId)
     {
         $deviceId = $_deviceId instanceof Syncope_Model_IDevice ? $_deviceId->id : $_deviceId;
+        $folderId = $_folderId instanceof Syncope_Model_IFolder ? $_folderId->id : $_folderId;
                 
         $select = $this->_db->select()
-            ->from('syncope_contentstates', 'contentid')
-            ->where($this->_db->quoteIdentifier('device_id') . ' = ?',    $deviceId)
-            ->where($this->_db->quoteIdentifier('class') . ' = ?',        $_class)
-            ->where($this->_db->quoteIdentifier('collectionid') . ' = ?', $_collectionId);
-
+            ->from('syncope_contents', 'contentid')
+            ->where($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId)
+            ->where($this->_db->quoteIdentifier('folder_id') . ' = ?', $folderId);
         
         $stmt = $this->_db->query($select);
         $result = $stmt->fetchAll(Zend_Db::FETCH_COLUMN);
@@ -124,16 +124,22 @@ class Syncope_Backend_Content implements Syncope_Backend_IContent
         return $result;
     }
     
-    public function resetState($_deviceId, $_class, $_collectionId)
+    /**
+     * reset list of stored id
+     *
+     * @param Syncope_Model_IDevice|string $_deviceId
+     * @param Syncope_Model_IFolder|string $_folderId
+     */
+    public function resetState($_deviceId, $_folderId)
     {
         $deviceId = $_deviceId instanceof Syncope_Model_IDevice ? $_deviceId->id : $_deviceId;
+        $folderId = $_folderId instanceof Syncope_Model_IFolder ? $_folderId->id : $_folderId;
          
         $where = array(
-            $this->_db->quoteInto($this->_db->quoteIdentifier('device_id') . ' = ?',    $deviceId),
-            $this->_db->quoteInto($this->_db->quoteIdentifier('class') . ' = ?',        $_class),
-            $this->_db->quoteInto($this->_db->quoteIdentifier('collectionid') . ' = ?', $_collectionId)
+            $this->_db->quoteInto($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId),
+            $this->_db->quoteInto($this->_db->quoteIdentifier('folder_id') . ' = ?', $folderId)
         );
         
-        $this->_db->delete('syncope_contentstates', $where);
+        $this->_db->delete('syncope_contents', $where);
     }
 }
index da5ae2a..97d5475 100644 (file)
@@ -44,11 +44,14 @@ class Syncope_Backend_Folder implements Syncope_Backend_IFolder
         $id = sha1(mt_rand(). microtime());
         $deviceId = $_folderState->device_id instanceof Syncope_Model_IDevice ? $_folderState->device_id->id : $_folderState->device_id;
     
-        $this->_db->insert('syncope_folderstates', array(
+        $this->_db->insert('syncope_folders', array(
                'id'             => $id, 
                'device_id'      => $deviceId,
                'class'          => $_folderState->class,
-               'folderid'       => $_folderState->folderid,
+               'folderid'       => $_folderState->folderid instanceof Syncope_Model_IFolder ? $_folderState->folderid->id : $_folderState->folderid,
+               'parentid'       => $_folderState->parentid,
+               'displayname'    => $_folderState->displayname,
+               'type'           => $_folderState->type,
                'creation_time'  => $_folderState->creation_time->format('Y-m-d H:i:s'),
                'lastfiltertype' => $_folderState->lastfiltertype
         ));
@@ -64,7 +67,7 @@ class Syncope_Backend_Folder implements Syncope_Backend_IFolder
     public function get($_id)
     {
         $select = $this->_db->select()
-            ->from('syncope_folderstates')
+            ->from('syncope_folders')
             ->where('id = ?', $_id);
     
         $stmt = $this->_db->query($select);
@@ -95,14 +98,14 @@ class Syncope_Backend_Folder implements Syncope_Backend_IFolder
             $this->_db->quoteInto($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId)
         );
         
-        $this->_db->delete('syncope_folderstates', $where);
+        $this->_db->delete('syncope_folders', $where);
     }
     
     public function update(Syncope_Model_IFolder $_state)
     {
         $deviceId = $_state->device_id instanceof Syncope_Model_IDevice ? $_state->device_id->id : $_state->device_id;
     
-        $this->_db->update('syncope_folderstates', array(
+        $this->_db->update('syncope_folders', array(
                'lastfiltertype'     => $_state->lastfiltertype
         ), array(
                'id = ?' => $_state->id
@@ -118,18 +121,22 @@ class Syncope_Backend_Folder implements Syncope_Backend_IFolder
      * @param string $_class
      * @return array
      */
-    public function getClientState($_deviceId, $_class)
+    public function getFolderState($_deviceId, $_class)
     {
         $deviceId = $_deviceId instanceof Syncope_Model_IDevice ? $_deviceId->id : $_deviceId;
         
         $select = $this->_db->select()
-            ->from('syncope_folderstates', array('folderid'))
+            ->from('syncope_folders')
             ->where($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId)
             ->where($this->_db->quoteIdentifier('class') . ' = ?', $_class);
         
+        $result = array();
+        
         $stmt = $this->_db->query($select);
-        $result = $stmt->fetchAll(Zend_Db::FETCH_COLUMN);
-
+        while ($row = $stmt->fetchObject("Syncope_Model_Folder")) {
+            $result[$row->folderid] = $row; 
+        }
+        
         return $result;
     }
     
@@ -145,7 +152,7 @@ class Syncope_Backend_Folder implements Syncope_Backend_IFolder
         $deviceId = $_deviceId instanceof Syncope_Model_IDevice ? $_deviceId->id : $_deviceId;
         
         $select = $this->_db->select()
-            ->from('syncope_folderstates')
+            ->from('syncope_folders')
             ->where($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId)
             ->where($this->_db->quoteIdentifier('folderid') . ' = ?', $_folderId);
         
index bc8f786..3f3d225 100755 (executable)
@@ -42,5 +42,5 @@ interface Syncope_Backend_IFolder
      * @param string $_class
      * @return array
      */
-    public function getClientState($_deviceId, $_class);
+    public function getFolderState($_deviceId, $_class);
 }
index 9e786fa..9111442 100644 (file)
@@ -146,16 +146,16 @@ class Syncope_Backend_SyncState implements Syncope_Backend_ISyncState
      * @param string $_class
      * @return Syncope_Model_ISyncState
      */
-    public function validate($_deviceId, $_syncKey, $_class, $_collectionId = NULL)
+    public function validate($_deviceId, $_folderId, $_syncKey)
     {
         $deviceId = $_deviceId instanceof Syncope_Model_IDevice ? $_deviceId->id : $_deviceId;
-        $type     = $_collectionId !== NULL ? $_class . '-' . $_collectionId : $_class;
+        $folderId = $_folderId instanceof Syncope_Model_IFolder ? $_folderId->id : $_folderId;
         
         $select = $this->_db->select()
             ->from('syncope_synckeys')
             ->where($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId)
             ->where($this->_db->quoteIdentifier('counter') . ' = ?', $_syncKey)
-            ->where($this->_db->quoteIdentifier('type') . ' = ?', $type);
+            ->where($this->_db->quoteIdentifier('type') . ' = ?', $folderId);
         
         $stmt = $this->_db->query($select);
         $state = $stmt->fetchObject('Syncope_Model_SyncState');
@@ -176,38 +176,35 @@ class Syncope_Backend_SyncState implements Syncope_Backend_ISyncState
             ->from('syncope_synckeys')
             ->where($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId)
             ->where($this->_db->quoteIdentifier('counter') . ' = ?', $_syncKey + 1)
-            ->where($this->_db->quoteIdentifier('type') . ' = ?', $type);
+            ->where($this->_db->quoteIdentifier('type') . ' = ?', $folderId);
         
         $stmt = $this->_db->query($select);
         $moreRecentState = $stmt->fetchObject('Syncope_Model_SyncState');
         
         // found more recent synckey => the last sync repsone got not received by the client
         if ($moreRecentState instanceof Syncope_Model_ISyncState) {
-            // undelete entries marked as deleted in syncope_contentstates table
-            $this->_db->update('syncope_contentstates', array(
+            // undelete entries marked as deleted in syncope_contents table
+            $this->_db->update('syncope_contents', array(
                'is_deleted'  => 0,
             ), array(
-               'device_id = ?'    => $deviceId,
-               'class = ?'        => $_class,
-               'collectionid = ?' => $_collectionId,
-               'is_deleted = ?'   => 1
+               'device_id = ?'  => $deviceId,
+               'folder_id = ?'  => $folderId,
+               'is_deleted = ?' => 1
             ));
             
-            // remove entries added during latest sync in syncope_contentstates table
-            $this->_db->delete('syncope_contentstates', array(
+            // remove entries added during latest sync in syncope_contents table
+            $this->_db->delete('syncope_contents', array(
                'device_id = ?'     => $deviceId,
-               'class = ?'         => $_class,
-               'collectionid = ?'  => $_collectionId,
+               'folder_id = ?'     => $folderId,
                'creation_time > ?' => $state->lastsync->format('Y-m-d H:i:s'),
             ));
             
         } else {
-            // finaly delete all entries marked for removal in syncope_contentstates table    
-            $this->_db->delete('syncope_contentstates', array(
-               'device_id = ?'     => $deviceId,
-               'class = ?'         => $_class,
-               'collectionid = ?'  => $_collectionId,
-               'is_deleted = ?'    => 1
+            // finaly delete all entries marked for removal in syncope_contents table    
+            $this->_db->delete('syncope_contents', array(
+               'device_id = ?'  => $deviceId,
+               'folder_id = ?'  => $folderId,
+               'is_deleted = ?' => 1
             ));
             
         }
index 34f4d66..b49bb65 100644 (file)
@@ -57,10 +57,10 @@ class Syncope_Command_FolderSync extends Syncope_Command_Wbxml
     protected $_documentElement     = 'FolderSync';
     
     protected $_classes             = array(
-        Syncope_Data_Factory::CALENDAR,
-        Syncope_Data_Factory::CONTACTS,
-        Syncope_Data_Factory::EMAIL,
-        Syncope_Data_Factory::TASKS
+        Syncope_Data_Factory::CLASS_CALENDAR,
+        Syncope_Data_Factory::CLASS_CONTACTS,
+        Syncope_Data_Factory::CLASS_EMAIL,
+        Syncope_Data_Factory::CLASS_TASKS
     );
 
     /**
@@ -84,14 +84,14 @@ class Syncope_Command_FolderSync extends Syncope_Command_Wbxml
             $this->_syncState = new Syncope_Model_SyncState(array(
                 'device_id' => $this->_device,
                 'counter'   => 0,
-                'type'      => 'FolderSync', // this is not the complete type the class is missing, but thats ok in this case
+                'type'      => 'FolderSync',
                 'lastsync'  => $this->_syncTimeStamp
             ));
         } else {
-            if (($this->_syncState = $this->_syncStateBackend->validate($this->_device, $syncKey, 'FolderSync')) instanceof Syncope_Model_SyncState) {
+            if (($this->_syncState = $this->_syncStateBackend->validate($this->_device, 'FolderSync', $syncKey)) instanceof Syncope_Model_SyncState) {
                 $this->_syncState->lastsync = $this->_syncTimeStamp;
             } else  {
-                $this->_folderStateBackend->resetState($this->_device);
+                $this->_folderBackend->resetState($this->_device);
                 $this->_syncStateBackend->resetState($this->_device, 'FolderSync');
             }
         }
@@ -99,12 +99,11 @@ class Syncope_Command_FolderSync extends Syncope_Command_Wbxml
     
     /**
      * generate FolderSync response
-     *
-     * @todo currently we support only the main folder which contains all contacts/tasks/events/notes per class
      * 
-     * @param boolean $_keepSession keep session active(don't logout user) when true
+     * @todo changes are missing in response (folder got renamed for example)
+     * @todo handle ParentId => getParent()
      */
-    public function getResponse($_keepSession = FALSE)
+    public function getResponse()
     {
         $folderSync = $this->_outputDom->documentElement;
         
@@ -117,41 +116,63 @@ class Syncope_Command_FolderSync extends Syncope_Command_Wbxml
             
             $adds = array();
             $deletes = array();
-            $count = 0;
             
             foreach($this->_classes as $class) {
                 $dataController = Syncope_Data_Factory::factory($class, $this->_device, $this->_syncTimeStamp);
 
-                $folders = $dataController->getAllFolders();
-
+                // is this the first sync?
                 if($this->_syncState->counter == 0) {
-                    foreach($folders as $folderId => $folder) {
-                        $adds[$class][$folderId] = $folder;
-                        $count++;
+                    // retrieve all folders available in data backend
+                    $serverFolders = $dataController->getAllFolders();
+                
+                    foreach($serverFolders as $folderId => $folderData) {
+                        $adds[] = new Syncope_Model_Folder(array(
+                            'device_id'         => $this->_device,
+                            'class'             => $class,
+                            'folderid'          => $folderData['folderId'],
+                               'parentid'          => $folderData['parentId'],
+                               'displayname'       => $folderData['displayName'],
+                               'type'              => $folderData['type'],
+                            'creation_time'     => $this->_syncTimeStamp,
+                            'lastfiltertype'    => null
+                        ));
                     }
                 } else {
-                    $allServerEntries = array_keys($folders);
-                    $allClientEntries = $this->_folderStateBackend->getClientState($this->_device, $class);
+                    // retrieve all folders available in data backend
+                    $serverFolders = $dataController->getAllFolders();
+                    
+                    // all folders sent to client
+                    $clientFolders = $this->_folderBackend->getFolderState($this->_device, $class);
+                    
+                    $serverFoldersIds = array_keys($serverFolders);
+                    $clientFoldersIds = array_keys($clientFolders);
                     
                     // added entries
-                    $serverDiff = array_diff($allServerEntries, $allClientEntries);
-                    foreach($serverDiff as $folderId) {
+                    $serverDiff = array_diff($serverFoldersIds, $clientFoldersIds);
+                    foreach($serverDiff as $serverFolderId) {
                         #if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " add $class $folderId");
-                        $adds[$class][$folderId] = $folders[$folderId];
-                        $count++;
+                        $adds[] = new Syncope_Model_Folder(array(
+                            'device_id'         => $this->_device,
+                            'class'             => $class,
+                            'folderid'          => $serverFolders[$serverFolderId]['folderId'],
+                               'parentid'          => $serverFolders[$serverFolderId]['parentId'],
+                               'displayname'       => $serverFolders[$serverFolderId]['displayName'],
+                               'type'              => $serverFolders[$serverFolderId]['type'],
+                            'creation_time'     => $this->_syncTimeStamp,
+                            'lastfiltertype'    => null
+                        ));
                     }
                     
                     // deleted entries
-                    $serverDiff = array_diff($allClientEntries, $allServerEntries);
-                    foreach($serverDiff as $folderId) {
+                    $serverDiff = array_diff($clientFoldersIds, $serverFoldersIds);
+                    foreach($serverDiff as $serverFolderId) {
                         #if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " delete $class $folderId");
-                        $deletes[$class][$folderId] = $folderId;
-                        $count++;
+                        $deletes[] = $clientFolders[$serverFolderId];
                     }
                 }                
             }
             
-            
+            $count = count($adds) + /*count($changes) + */count($deletes);
             if($count > 0) {
                 $this->_syncState->counter++;
             }
@@ -161,35 +182,25 @@ class Syncope_Command_FolderSync extends Syncope_Command_Wbxml
             
             $changes = $folderSync->appendChild($this->_outputDom->createElementNS('uri:FolderHierarchy', 'Changes'));            
             $changes->appendChild($this->_outputDom->createElementNS('uri:FolderHierarchy', 'Count', $count));
-            foreach($adds as $class => $folders) {
-                foreach((array)$folders as $folder) {
-                    $add = $changes->appendChild($this->_outputDom->createElementNS('uri:FolderHierarchy', 'Add'));
-                    $add->appendChild($this->_outputDom->createElementNS('uri:FolderHierarchy', 'ServerId', $folder['folderId']));
-                    $add->appendChild($this->_outputDom->createElementNS('uri:FolderHierarchy', 'ParentId', $folder['parentId']));
-                    $add->appendChild($this->_outputDom->createElementNS('uri:FolderHierarchy', 'DisplayName', $folder['displayName']));
-                    $add->appendChild($this->_outputDom->createElementNS('uri:FolderHierarchy', 'Type', $folder['type']));
-                    
-                    // store state in backend
-                    $this->_folderStateBackend->create(new Syncope_Model_Folder(array(
-                        'device_id'         => $this->_device,
-                        'class'             => $class,
-                        'folderid'          => $folder['folderId'],
-                        'creation_time'     => $this->_syncTimeStamp,
-                        'lastfiltertype'    => null
-                    )));
-                    
-                    #if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " $class => " . $folder['folderId']);
-                }
+            foreach($adds as $folder) {
+                
+                $add = $changes->appendChild($this->_outputDom->createElementNS('uri:FolderHierarchy', 'Add'));
+                $add->appendChild($this->_outputDom->createElementNS('uri:FolderHierarchy', 'ServerId', $folder->folderid));
+                $add->appendChild($this->_outputDom->createElementNS('uri:FolderHierarchy', 'ParentId', $folder->parentid));
+                $add->appendChild($this->_outputDom->createElementNS('uri:FolderHierarchy', 'DisplayName', $folder->displayname));
+                $add->appendChild($this->_outputDom->createElementNS('uri:FolderHierarchy', 'Type', $folder->type));
+                
+                #if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " $class => " . $folder['folderId']);
+                
+                // store folder in backend and retrieve $folder-id
+                $this->_folderBackend->create($folder);
             }
             
-            foreach($deletes as $class => $folders) {
-                if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " $class");
-                foreach((array)$folders as $folderId) {
-                    $delete = $changes->appendChild($this->_outputDom->createElementNS('uri:FolderHierarchy', 'Delete'));
-                    $delete->appendChild($this->_outputDom->createElementNS('uri:FolderHierarchy', 'ServerId', $folderId));
-                    
-                    $this->_deleteFolder($class, $folderId);
-                }
+            foreach($deletes as $folder) {
+                $delete = $changes->appendChild($this->_outputDom->createElementNS('uri:FolderHierarchy', 'Delete'));
+                $delete->appendChild($this->_outputDom->createElementNS('uri:FolderHierarchy', 'ServerId', $folder->folderid));
+                
+                $this->_folderBackend->delete($folder);
             }
             
             if (empty($this->_syncState->id)) {
@@ -227,10 +238,10 @@ class Syncope_Command_FolderSync extends Syncope_Command_Wbxml
                     'value'     => $_folderId
             )
         ));
-        $state = $this->_folderStateBackend->search($folderStateFilter, NULL, true);
+        $state = $this->_folderBackend->search($folderStateFilter, NULL, true);
         
         if(count($state) > 0) {
-            $this->_folderStateBackend->delete($state[0]);
+            $this->_folderBackend->delete($state[0]);
         } else {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . " no folderstate found for " . print_r($folderStateFilter->toArray(), true));
         }
index fd8a938..bea52a8 100644 (file)
@@ -167,7 +167,7 @@ class Syncope_Command_Sync extends Syncope_Command_Wbxml
             
             // got the folder synchronized to the device already
             try {
-                $folder = $this->_folderStateBackend->getFolder($this->_device, $collectionData['collectionId']);
+                $folder = $this->_folderBackend->getFolder($this->_device, $collectionData['collectionId']);
                 
                 $collectionData['class'] = $folder->class;
                 
@@ -205,7 +205,7 @@ class Syncope_Command_Sync extends Syncope_Command_Wbxml
                 
                 continue;
             }
-            
+            die('fix validate');
             // check for invalid sycnkey
             if(($collectionData['syncState'] = $this->_syncStateBackend->validate($this->_device, $collectionData['syncKey'], $collectionData['class'], $collectionData['collectionId'])) === false) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::WARN))
@@ -490,7 +490,7 @@ class Syncope_Command_Sync extends Syncope_Command_Wbxml
                             } else {
                                 // fetch entries added since last sync
                                 
-                                $allClientEntries = $this->_contentStateBackend->getClientState($this->_device, $collectionData['class'], $collectionData['collectionId']);
+                                $allClientEntries = $this->_contentStateBackend->getFolderState($this->_device, $collectionData['class'], $collectionData['collectionId']);
                                 $allServerEntries = $dataController->getServerEntries($collectionData['collectionId'], $collectionData['filterType']);
                                 
                                 // add entries
@@ -660,9 +660,9 @@ class Syncope_Command_Sync extends Syncope_Command_Wbxml
                     
                     // store current filter type
                     try {
-                        $folderState = $this->_folderStateBackend->getFolder($this->_device, $collectionData['collectionId']);
+                        $folderState = $this->_folderBackend->getFolder($this->_device, $collectionData['collectionId']);
                         $folderState->lastfiltertype = $collectionData['filterType'];
-                        $this->_folderStateBackend->update($folderState);
+                        $this->_folderBackend->update($folderState);
                     } catch (Syncope_Exception_NotFound $senf) {
                         // failed to get folderstate => should not happen but is also no problem in this state
                         if (Tinebase_Core::isLogLevel(Zend_Log::CRIT)) 
@@ -718,7 +718,7 @@ class Syncope_Command_Sync extends Syncope_Command_Wbxml
                 'value'     => $_folderId
             )
         ));
-        $folderStates = $this->_folderStateBackend->search($filter);
+        $folderStates = $this->_folderBackend->search($filter);
 
         if ($folderStates->count() == 0) {
             throw new Tinebase_Exception_NotFound('folderstate for device not found');
index a843434..c67c32b 100644 (file)
@@ -40,7 +40,7 @@ abstract class Syncope_Command_Wbxml implements Syncope_Command_Interface
      *
      * @var Syncope_Backend_IFolder
      */
-    protected $_folderStateBackend;
+    protected $_folderBackend;
     
     /**
      * @var Syncope_Backend_ISyncState
@@ -121,7 +121,7 @@ abstract class Syncope_Command_Wbxml implements Syncope_Command_Interface
         $this->_device    = $_device;
         
         $this->_deviceBackend       = Zend_Registry::get('deviceBackend');
-        $this->_folderStateBackend  = Zend_Registry::get('folderStateBackend');
+        $this->_folderBackend  = Zend_Registry::get('folderStateBackend');
         $this->_syncStateBackend    = Zend_Registry::get('syncStateBackend');
         $this->_contentStateBackend = Zend_Registry::get('contentStateBackend');
         
index 5068b1c..42348c6 100644 (file)
 
 class Syncope_Data_Contacts implements Syncope_Data_IData
 {
+    /**
+     * used by unit tests only to simulated added folders
+     */
+    public static $folders = array(
+       'addressbookFolderId' => array(
+            'folderId'    => 'addressbookFolderId',
+            'parentId'    => null,
+            'displayName' => 'Default Contacts Folder',
+            'type'        => Syncope_Command_FolderSync::FOLDERTYPE_CONTACT
+        )
+    );
+    
     public function appendXML(DOMElement $_domParrent, $_collectionData, $_serverId)
     {
         $_domParrent->ownerDocument->documentElement->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:Contacts', 'uri:Contacts');
@@ -28,14 +40,7 @@ class Syncope_Data_Contacts implements Syncope_Data_IData
     
     public function getAllFolders()
     {
-        return array(
-            'addressbookFolderId' => array(
-                'folderId'    => 'addressbookFolderId',
-                'parentId'    => null,
-                'displayName' => 'Default Contacts Folder',
-                'type'        => Syncope_Command_FolderSync::FOLDERTYPE_CONTACT
-            )
-        );
+        return self::$folders;
     }
     
     public function getServerEntries()
index fc68ce8..a034646 100644 (file)
 
 class Syncope_Data_Factory
 {
-    const CALENDAR = 'Calendar';
-    const CONTACTS = 'Contacts';
-    const EMAIL    = 'Email';
-    const TASKS    = 'Tasks';
+    const CLASS_CALENDAR = 'Calendar';
+    const CLASS_CONTACTS = 'Contacts';
+    const CLASS_EMAIL    = 'Email';
+    const CLASS_TASKS    = 'Tasks';
     
     /**
      * @param unknown_type $_class
@@ -35,19 +35,19 @@ class Syncope_Data_Factory
     public static function factory($_class, Syncope_Model_IDevice $_device, DateTime $_timeStamp)
     {
         switch($_class) {
-            case self::CALENDAR:
+            case self::CLASS_CALENDAR:
                 $class = new Syncope_Data_Calendar($_device, $_timeStamp);
                 break;
                 
-            case self::CONTACTS:
+            case self::CLASS_CONTACTS:
                 $class = new Syncope_Data_Contacts($_device, $_timeStamp);
                 break;
                 
-            case self::EMAIL:
+            case self::CLASS_EMAIL:
                 $class = new Syncope_Data_Email($_device, $_timeStamp);
                 break;
                 
-            case self::TASKS:
+            case self::CLASS_TASKS:
                 $class = new Syncope_Data_Tasks($_device, $_timeStamp);
                 break;
                 
index f0a4589..e81b3fa 100644 (file)
@@ -20,6 +20,8 @@
  * @property    string   device_id
  * @property    string   class
  * @property    string   folderid
+ * @property    string   parentid
+ * @property    string   displayname
  * @property    string   creation_time
  * @property    string   lastfiltertype
  */
index 306d212..a9c5994 100755 (executable)
@@ -20,7 +20,7 @@ class Syncope_AllTests
         $suite = new PHPUnit_Framework_TestSuite('Syncope All Tests');
         
         $suite->addTestSuite('Syncope_Backend_AllTests');
-        #$suite->addTestSuite('Syncope_Command_AllTests');
+        $suite->addTestSuite('Syncope_Command_AllTests');
         
         return $suite;
     }
index bccccc5..3f6013a 100755 (executable)
@@ -19,7 +19,7 @@ class Syncope_Backend_AllTests
     {
         $suite = new PHPUnit_Framework_TestSuite('Syncope All Backend Tests');
         
-        #$suite->addTestSuite('Syncope_Backend_ContentTests');
+        $suite->addTestSuite('Syncope_Backend_ContentTests');
         $suite->addTestSuite('Syncope_Backend_DeviceTests');
         $suite->addTestSuite('Syncope_Backend_FolderTests');
         $suite->addTestSuite('Syncope_Backend_SyncStateTests');
index e8032b0..013e738 100644 (file)
@@ -21,6 +21,16 @@ class Syncope_Backend_ContentTests extends PHPUnit_Framework_TestCase
     protected $_device;
     
     /**
+     * @var Syncope_Model_Folder
+     */
+    protected $_folder;
+    
+    /**
+     * @var Syncope_Backend_Content
+     */
+    protected $_contentBackend;
+    
+    /**
      * @var Syncope_Backend_Device
      */
     protected $_deviceBackend;
@@ -28,7 +38,7 @@ class Syncope_Backend_ContentTests extends PHPUnit_Framework_TestCase
     /**
      * @var Syncope_Backend_Folder
      */
-    protected $_folderStateBackend;
+    protected $_folderBackend;
     
     /**
      * @var Syncope_Backend_SyncState
@@ -62,12 +72,17 @@ class Syncope_Backend_ContentTests extends PHPUnit_Framework_TestCase
         
         $this->_db->beginTransaction();
 
-        $this->_deviceBackend      = new Syncope_Backend_Device($this->_db);
-        $this->_folderStateBackend = new Syncope_Backend_Folder($this->_db);
-        $this->_syncStateBackend   = new Syncope_Backend_SyncState($this->_db);
+        $this->_contentBackend   = new Syncope_Backend_Content($this->_db);
+        $this->_deviceBackend    = new Syncope_Backend_Device($this->_db);
+        $this->_folderBackend    = new Syncope_Backend_Folder($this->_db);
+        $this->_syncStateBackend = new Syncope_Backend_SyncState($this->_db);
 
-        $newDevice = Syncope_Backend_DeviceTests::getTestDevice();
-        $this->_device    = $this->_deviceBackend->create($newDevice);
+        $this->_device = $this->_deviceBackend->create(
+            Syncope_Backend_DeviceTests::getTestDevice()
+        );
+        $this->_folder = $this->_folderBackend->create(
+            Syncope_Backend_FolderTests::getTestFolder($this->_device)
+        );
     }
 
     /**
@@ -86,129 +101,57 @@ class Syncope_Backend_ContentTests extends PHPUnit_Framework_TestCase
      */
     public function testCreate()
     {
-        $syncState = new Syncope_Model_Content(array(
-            'device_id'     => $this->_device,
-            'folder_id'     => $this->_folder,
-            'contentid'     => '0',
-            'creation_time' => new DateTime(null, new DateTimeZone('utc')),
-            'is_deleted'    => null
-        ));
-        
-        $syncState = $this->_syncStateBackend->create($syncState);
+        $content = self::getTestContent($this->_device, $this->_folder);
         
-        $this->assertTrue($syncState->lastsync instanceof DateTime);
+        $content = $this->_contentBackend->create($content);
         
-        return $syncState;
-    }
-    
-    /**
-     * @return Syncope_Model_ISyncState
-     */
-    public function testUpdate()
-    {
-        $syncState = $this->testCreate();
+        $this->assertTrue($content->creation_time instanceof DateTime);
         
-        $syncState->counter++;
-    
-        $syncState = $this->_syncStateBackend->update($syncState);
-    
-        $this->assertEquals(1, $syncState->counter);
-        $this->assertTrue($syncState->lastsync instanceof DateTime);
-    
-        return $syncState;
+        return $content;
     }
     
     /**
-     * test validating synckey
+     * 
      */
-    public function testValidateSyncKey()
+    public function testDelete()
     {
-        $syncState = $this->testUpdate();
-        
-        $validatedSyncState =  $this->_syncStateBackend->validate($this->_device, 1, 'FolderSync');
-        
-        $this->assertTrue($validatedSyncState instanceof Syncope_Model_ISyncState);
-        $this->assertEquals(1, $validatedSyncState->counter);
-        $this->assertTrue($validatedSyncState->lastsync instanceof DateTime);
-        
+        $content = $this->testCreate();
         
-        // invalid synckey must return false
-        $validatedSyncState =  $this->_syncStateBackend->validate($this->_device, 2, 'FolderSync');
+        $this->_contentBackend->delete($content);
         
-        $this->assertFalse($validatedSyncState);
-    }
+        $content = $this->_contentBackend->get($content->id);
         
-    /**
-     * test if the previous synckey gets deleted after validating the lastest synckey
-     */
-    public function testDeletePreviousSynckeyAfterValidate()
+        $this->assertTrue($content instanceof Syncope_Model_IContent);
+        $this->assertEquals(1, $content->is_deleted);
+        $this->assertTrue($content->creation_time instanceof DateTime);
+    }  
+
+    public function testGetFolderState()
     {
-        $syncState = new Syncope_Model_SyncState(array(
-            'device_id'   => $this->_device,
-            'type'        => 'FolderSync',
-            'counter'     => '0',
-            'lastsync'    => new DateTime(null, new DateTimeZone('utc')),
-            'pendingdata' => null
-        ));
-        $syncState->lastsync->modify('-2 min');
-        $syncState = $this->_syncStateBackend->create($syncState);
+        $content = $this->testCreate();
         
-        $syncState = new Syncope_Model_SyncState(array(
-            'device_id'   => $this->_device,
-            'type'        => 'FolderSync',
-            'counter'     => '1',
-            'lastsync'    => new DateTime(null, new DateTimeZone('utc')),
-            'pendingdata' => null
-        ));
+        $state = $this->_contentBackend->getFolderState($this->_device, $this->_folder);
         
-        $syncState = $this->_syncStateBackend->create($syncState);
+        $this->assertContains($content->contentid, $state);
+    }
     
-        $syncState = $this->_syncStateBackend->validate($this->_device, '1', 'FolderSync');
+    public function testResetState()
+    {
+        $content = $this->testCreate();
     
-        $this->assertEquals('FolderSync', $syncState->type);
-        $this->assertEquals(1,            $syncState->counter);
-        
-        
-        // the other synckey must be deleted now
-        $syncState = $this->_syncStateBackend->validate($this->_device, '0', 'FolderSync');
+        $this->_contentBackend->resetState($this->_device, $this->_folder);
+        $state = $this->_contentBackend->getFolderState($this->_device, $this->_folder);
     
-        $this->assertFalse($syncState);
+        $this->assertEmpty($state);
     }
     
-    /**
-     * test if the latest synckey gets deleted after validating the previous synckey
-     */
-    public function testDeleteLatestSynckeyAfterValidate()
+    public static function getTestContent(Syncope_Model_IDevice $_device, Syncope_Model_IFolder $_folder)
     {
-        $syncState = new Syncope_Model_SyncState(array(
-            'device_id'   => $this->_device,
-            'type'        => 'FolderSync',
-            'counter'     => '0',
-            'lastsync'    => new DateTime(null, new DateTimeZone('utc')),
-            'pendingdata' => null
+        return new Syncope_Model_Content(array(
+            'device_id'     => $_device,
+            'folder_id'     => $_folder,
+            'contentid'     => 'abc1234',
+            'creation_time' => new DateTime(null, new DateTimeZone('utc'))
         ));
-        $syncState->lastsync->modify('-2 min');
-        $syncState = $this->_syncStateBackend->create($syncState);
-        
-        $syncState = new Syncope_Model_SyncState(array(
-            'device_id'   => $this->_device,
-            'type'        => 'FolderSync',
-            'counter'     => '1',
-            'lastsync'    => new DateTime(null, new DateTimeZone('utc')),
-            'pendingdata' => null
-        ));
-        
-        $syncState = $this->_syncStateBackend->create($syncState);
-    
-        $syncState = $this->_syncStateBackend->validate($this->_device, '0', 'FolderSync');
-    
-        $this->assertEquals('FolderSync', $syncState->type);
-        $this->assertEquals(0,            $syncState->counter);
-        
-        
-        // the other synckey must be deleted now
-        $syncState = $this->_syncStateBackend->validate($this->_device, '1', 'FolderSync');
-    
-        $this->assertFalse($syncState);
     }
 }
index 1064f01..2bb12cc 100644 (file)
 class Syncope_Backend_FolderTests extends PHPUnit_Framework_TestCase
 {
     /**
-     * @var Syncope_Model_IDevice
+     * @var Syncope_Model_Device
      */
     protected $_device;
     
     /**
-     * @var Syncope_Backend_IDevice
+     * @var Syncope_Backend_Device
      */
     protected $_deviceBackend;
 
     /**
-     * @var Syncope_Backend_IFolder
+     * @var Syncope_Backend_Folder
      */
-    protected $_folderStateBackend;
+    protected $_folderBackend;
     
     /**
      * @var Zend_Db_Adapter_Abstract
@@ -58,7 +58,7 @@ class Syncope_Backend_FolderTests extends PHPUnit_Framework_TestCase
         $this->_db->beginTransaction();
 
         $this->_deviceBackend      = new Syncope_Backend_Device($this->_db);
-        $this->_folderStateBackend = new Syncope_Backend_Folder($this->_db);
+        $this->_folderBackend = new Syncope_Backend_Folder($this->_db);
 
         $newDevice = Syncope_Backend_DeviceTests::getTestDevice();
         $this->_device    = $this->_deviceBackend->create($newDevice);
@@ -78,21 +78,16 @@ class Syncope_Backend_FolderTests extends PHPUnit_Framework_TestCase
     /**
      * @return Syncope_Model_IFolder
      */
-    public function testCreate()
+    public function testCreate(Syncope_Model_IFolder $_folder = null)
     {
-        $folderState = new Syncope_Model_Folder(array(
-            'device_id'         => $this->_device,
-            'class'             => Syncope_Data_Factory::CONTACTS,
-            'folderid'          => '1234567890',
-            'creation_time'     => new DateTime(null, new DateTimeZone('utc')),
-            'lastfiltertype'    => null
-        ));
-        
-        $folderState = $this->_folderStateBackend->create($folderState);
+        $folder = $_folder instanceof Syncope_Model_IFolder ? $_folder : self::getTestFolder($this->_device);
         
-        $this->assertTrue($folderState->creation_time instanceof DateTime);
+        $folder = $this->_folderBackend->create($folder);
+                
+        $this->assertTrue($folder->creation_time instanceof DateTime);
+        $this->assertNotEmpty($folder->displayname);
         
-        return $folderState;
+        return $folder;
     }
     
     /**
@@ -100,19 +95,53 @@ class Syncope_Backend_FolderTests extends PHPUnit_Framework_TestCase
      */
     public function testResetState()
     {
-        $this->_folderStateBackend->resetState($this->_device);
+        $this->_folderBackend->resetState($this->_device);
         
-        $state = $this->_folderStateBackend->getClientState($this->_device, 'Contact');
+        $state = $this->_folderBackend->getFolderState($this->_device, 'Contact');
         
         $this->assertEmpty($state);
     }
     
     public function testGetFolder()
     {
-        $folderState = $this->testCreate();
+        $folder = $this->testCreate();
+        
+        $folder = $this->_folderBackend->getFolder($folder->device_id, $folder->folderid);
+        
+        $this->assertTrue($folder->creation_time instanceof DateTime);
+    }
+    
+    public function testGetFolderState()
+    {
+        $folder = self::getTestFolder($this->_device);
+        $folder1 = $this->testCreate($folder);
         
-        $folderState = $this->_folderStateBackend->getFolder($folderState->device_id, $folderState->folderid);
+        $folder = self::getTestFolder($this->_device);
+        $folder->folderid = '1234567891';
+        $folder2 = $this->testCreate($folder);
         
-        $this->assertTrue($folderState->creation_time instanceof DateTime);
+        $folders = $this->_folderBackend->getFolderState($folder->device_id, Syncope_Data_Factory::CLASS_CONTACTS);
+        
+        $this->assertEquals(2, count($folders));
+        $this->assertArrayHasKey($folder1->id, $folders);
+        $this->assertArrayHasKey($folder2->id, $folders);
+    }
+    
+    /**
+     * 
+     * @return Syncope_Model_Device
+     */
+    public static function getTestFolder(Syncope_Model_IDevice $_device)
+    {
+        return new Syncope_Model_Folder(array(
+            'device_id'         => $_device,
+            'class'             => Syncope_Data_Factory::CLASS_CONTACTS,
+            'folderid'          => '1234567890',
+            'parentid'          => null,
+            'displayname'       => 'test contact folder',
+            'type'              => Syncope_Command_FolderSync::FOLDERTYPE_CONTACT,
+            'creation_time'     => new DateTime(null, new DateTimeZone('utc')),
+            'lastfiltertype'    => null
+        ));
     }
 }
index e3b5694..69014f7 100644 (file)
@@ -21,6 +21,11 @@ class Syncope_Backend_SyncStateTests extends PHPUnit_Framework_TestCase
     protected $_device;
     
     /**
+     * @var Syncope_Model_Folder
+     */
+    protected $_folder;
+    
+    /**
      * @var Syncope_Backend_Device
      */
     protected $_deviceBackend;
@@ -28,7 +33,7 @@ class Syncope_Backend_SyncStateTests extends PHPUnit_Framework_TestCase
     /**
      * @var Syncope_Backend_Folder
      */
-    protected $_folderStateBackend;
+    protected $_folderBackend;
     
     /**
      * @var Syncope_Backend_SyncState
@@ -62,12 +67,16 @@ class Syncope_Backend_SyncStateTests extends PHPUnit_Framework_TestCase
         
         $this->_db->beginTransaction();
 
-        $this->_deviceBackend      = new Syncope_Backend_Device($this->_db);
-        $this->_folderStateBackend = new Syncope_Backend_Folder($this->_db);
-        $this->_syncStateBackend   = new Syncope_Backend_SyncState($this->_db);
+        $this->_deviceBackend     = new Syncope_Backend_Device($this->_db);
+        $this->_folderBackend     = new Syncope_Backend_Folder($this->_db);
+        $this->_syncStateBackend  = new Syncope_Backend_SyncState($this->_db);
 
-        $newDevice = Syncope_Backend_DeviceTests::getTestDevice();
-        $this->_device    = $this->_deviceBackend->create($newDevice);
+        $this->_device = $this->_deviceBackend->create(
+            Syncope_Backend_DeviceTests::getTestDevice()
+        );
+        $this->_folder = $this->_folderBackend->create(
+            Syncope_Backend_FolderTests::getTestFolder($this->_device)
+        );
     }
 
     /**
@@ -125,7 +134,7 @@ class Syncope_Backend_SyncStateTests extends PHPUnit_Framework_TestCase
     {
         $syncState = $this->testUpdate();
         
-        $validatedSyncState =  $this->_syncStateBackend->validate($this->_device, 1, 'FolderSync');
+        $validatedSyncState =  $this->_syncStateBackend->validate($this->_device, 'FolderSync', 1);
         
         $this->assertTrue($validatedSyncState instanceof Syncope_Model_ISyncState);
         $this->assertEquals(1, $validatedSyncState->counter);
@@ -133,7 +142,7 @@ class Syncope_Backend_SyncStateTests extends PHPUnit_Framework_TestCase
         
         
         // invalid synckey must return false
-        $validatedSyncState =  $this->_syncStateBackend->validate($this->_device, 2, 'FolderSync');
+        $validatedSyncState =  $this->_syncStateBackend->validate($this->_device, 'FolderSync', 2);
         
         $this->assertFalse($validatedSyncState);
     }
@@ -163,14 +172,14 @@ class Syncope_Backend_SyncStateTests extends PHPUnit_Framework_TestCase
         
         $syncState = $this->_syncStateBackend->create($syncState);
     
-        $syncState = $this->_syncStateBackend->validate($this->_device, '1', 'FolderSync');
+        $syncState = $this->_syncStateBackend->validate($this->_device, 'FolderSync', '1');
     
         $this->assertEquals('FolderSync', $syncState->type);
         $this->assertEquals(1,            $syncState->counter);
         
         
         // the other synckey must be deleted now
-        $syncState = $this->_syncStateBackend->validate($this->_device, '0', 'FolderSync');
+        $syncState = $this->_syncStateBackend->validate($this->_device, 'FolderSync', '0');
     
         $this->assertFalse($syncState);
     }
@@ -200,14 +209,14 @@ class Syncope_Backend_SyncStateTests extends PHPUnit_Framework_TestCase
         
         $syncState = $this->_syncStateBackend->create($syncState);
     
-        $syncState = $this->_syncStateBackend->validate($this->_device, '0', 'FolderSync');
+        $syncState = $this->_syncStateBackend->validate($this->_device, 'FolderSync', '0');
     
         $this->assertEquals('FolderSync', $syncState->type);
         $this->assertEquals(0,            $syncState->counter);
         
         
         // the other synckey must be deleted now
-        $syncState = $this->_syncStateBackend->validate($this->_device, '1', 'FolderSync');
+        $syncState = $this->_syncStateBackend->validate($this->_device, 'FolderSync', '1');
     
         $this->assertFalse($syncState);
     }
index 931917b..262cdd0 100644 (file)
@@ -28,7 +28,7 @@ class Syncope_Command_FolderSyncTests extends PHPUnit_Framework_TestCase
     /**
      * @var Syncope_Backend_IFolder
      */
-    protected $_folderStateBackend;
+    protected $_folderBackend;
     
     /**
      * @var Syncope_Backend_ISyncState
@@ -68,7 +68,7 @@ class Syncope_Command_FolderSyncTests extends PHPUnit_Framework_TestCase
         $this->_db->beginTransaction();
 
         $this->_deviceBackend       = new Syncope_Backend_Device($this->_db);
-        $this->_folderStateBackend  = new Syncope_Backend_Folder($this->_db);
+        $this->_folderBackend  = new Syncope_Backend_Folder($this->_db);
         $this->_syncStateBackend    = new Syncope_Backend_SyncState($this->_db);
         $this->_contentStateBackend = new Syncope_Backend_Content($this->_db);
 
@@ -77,7 +77,7 @@ class Syncope_Command_FolderSyncTests extends PHPUnit_Framework_TestCase
         );
         
         Zend_Registry::set('deviceBackend',       $this->_deviceBackend);
-        Zend_Registry::set('folderStateBackend',  $this->_folderStateBackend);
+        Zend_Registry::set('folderStateBackend',  $this->_folderBackend);
         Zend_Registry::set('syncStateBackend',    $this->_syncStateBackend);
         Zend_Registry::set('contentStateBackend', $this->_contentStateBackend);
     }
@@ -133,6 +133,13 @@ class Syncope_Command_FolderSyncTests extends PHPUnit_Framework_TestCase
     {
         $this->testGetFoldersSyncKey0();
         
+        Syncope_Data_Contacts::$folders['addressbookFolderId2'] = array(
+            'folderId'    => 'addressbookFolderId2',
+            'parentId'    => null,
+            'displayName' => 'User created Contacts Folder',
+            'type'        => Syncope_Command_FolderSync::FOLDERTYPE_CONTACT_USER_CREATED
+        );
+        
         $doc = new DOMDocument();
         $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
             <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
@@ -155,9 +162,9 @@ class Syncope_Command_FolderSyncTests extends PHPUnit_Framework_TestCase
         
         $nodes = $xpath->query('//FolderHierarchy:FolderSync/FolderHierarchy:SyncKey');
         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
-        $this->assertEquals(1, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
+        $this->assertEquals(2, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
 
-        $nodes = $xpath->query('//FolderHierarchy:FolderSync/FolderHierarchy:Changes');
+        $nodes = $xpath->query('//FolderHierarchy:FolderSync/FolderHierarchy:Changes/FolderHierarchy:Add');
         $this->assertGreaterThanOrEqual(1, $nodes->length, $responseDoc->saveXML());
     }
     
index a1be00c..2ef64e4 100644 (file)
@@ -28,7 +28,7 @@ class Syncope_Command_SyncTests extends PHPUnit_Framework_TestCase
     /**
      * @var Syncope_Backend_IFolder
      */
-    protected $_folderStateBackend;
+    protected $_folderBackend;
     
     /**
      * @var Syncope_Backend_ISyncState
@@ -68,7 +68,7 @@ class Syncope_Command_SyncTests extends PHPUnit_Framework_TestCase
         $this->_db->beginTransaction();
         
         $this->_deviceBackend       = new Syncope_Backend_Device($this->_db);
-        $this->_folderStateBackend  = new Syncope_Backend_Folder($this->_db);
+        $this->_folderBackend  = new Syncope_Backend_Folder($this->_db);
         $this->_syncStateBackend    = new Syncope_Backend_SyncState($this->_db);
         $this->_contentStateBackend = new Syncope_Backend_Content($this->_db);
         
@@ -77,7 +77,7 @@ class Syncope_Command_SyncTests extends PHPUnit_Framework_TestCase
         );
         
         Zend_Registry::set('deviceBackend',       $this->_deviceBackend);
-        Zend_Registry::set('folderStateBackend',  $this->_folderStateBackend);
+        Zend_Registry::set('folderStateBackend',  $this->_folderBackend);
         Zend_Registry::set('syncStateBackend',    $this->_syncStateBackend);
         Zend_Registry::set('contentStateBackend', $this->_contentStateBackend);
     }
index 807b51b..18faed2 100644 (file)
@@ -40,11 +40,14 @@ function getTestDatabase()
         PRIMARY KEY (`id`)
        )");
 
-    $db->query("CREATE TABLE IF NOT EXISTS `syncope_folderstates` (
+    $db->query("CREATE TABLE IF NOT EXISTS `syncope_folders` (
         `id` varchar(40) NOT NULL,
         `device_id` varchar(64) NOT NULL,
         `class` varchar(64) NOT NULL,
         `folderid` varchar(254) NOT NULL,
+        `parentid` varchar(254) DEFAULT NULL,
+        `displayname` varchar(254) NOT NULL,
+        `type` int(11) DEFAULT NULL,
         `creation_time` datetime NOT NULL,
         `lastfiltertype` int(11) DEFAULT NULL,
         PRIMARY KEY (`id`),
@@ -62,16 +65,15 @@ function getTestDatabase()
        UNIQUE (`device_id`,`type`,`counter`)
     )");
     
-    $db->query("CREATE TABLE `syncope_contentstates` (
+    $db->query("CREATE TABLE `syncope_contents` (
         `id` varchar(40) NOT NULL,
         `device_id` varchar(64) NOT NULL,
-        `class` varchar(64) NOT NULL,
+        `folder_id` varchar(64) NOT NULL,
         `contentid` varchar(64) NOT NULL,
-        `collectionid` varchar(254) NOT NULL,
         `creation_time` datetime NOT NULL,
         `is_deleted` int(11) DEFAULT '0',
         PRIMARY KEY (`id`),
-        UNIQUE (`device_id`,`class`,`collectionid`,`contentid`)
+        UNIQUE (`device_id`,`folder_id`,`contentid`)
     )");
     
     return $db;