Page MenuHomePhorge

D5060.1775261383.diff
No OneTemporary

Authored By
Unknown
Size
17 KB
Referenced Files
None
Subscribers
None

D5060.1775261383.diff

diff --git a/lib/kolab_sync.php b/lib/kolab_sync.php
--- a/lib/kolab_sync.php
+++ b/lib/kolab_sync.php
@@ -385,8 +385,10 @@
/**
* Initializes and returns the storage backend object
+ *
+ * @param bool $init Reset the driver internal state
*/
- public static function storage()
+ public static function storage($init = false)
{
$class = 'kolab_sync_storage';
$self = self::get_instance();
@@ -395,6 +397,15 @@
$class .= '_' . strtolower($name);
}
+ if ($init) {
+ // Reset storage driver internal state
+ $reflection = new ReflectionClass($class);
+ $property = $reflection->getProperty('instance');
+ $property->setAccessible(true);
+ $property->setValue($class::get_instance(), null);
+ $property->setAccessible(false);
+ }
+
return $class::get_instance();
}
diff --git a/tests/Sync/FoldersTest.php b/tests/Sync/FoldersTest.php
--- a/tests/Sync/FoldersTest.php
+++ b/tests/Sync/FoldersTest.php
@@ -5,17 +5,16 @@
/**
* Cleanup folders
*/
- public function setUp(): void
+ protected function foldersCleanup(): void
{
// Note: We essentially assume the test account is in an initial state, extra folders may break tests
// Anyway, we first remove folders that might have been created during tests in this file
- $this->deleteTestFolder('Test Folder', 'mail');
$this->deleteTestFolder('NewFolder', 'mail');
$this->deleteTestFolder('NewFolder2', 'mail');
+ $this->deleteTestFolder('Test Folder', 'mail');
$this->deleteTestFolder('Test Folder New', 'mail');
$this->deleteTestFolder('Test Contacts Folder', 'contact');
$this->deleteTestFolder('Test Contacts New', 'contact');
- parent::setUp();
}
/**
@@ -23,6 +22,8 @@
*/
public function testFolderSyncBasic()
{
+ $this->foldersCleanup();
+
$request = <<<EOF
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
@@ -63,13 +64,12 @@
// No changes on second sync
$this->assertSame(strval(0), $xpath->query("//ns:FolderSync/ns:Changes/ns:Count")->item(0)->nodeValue);
-
//Clear the creation_synckey (that's the migration scenario)
//Shouldn't trigger a change
$rcube = \rcube::get_instance();
$db = $rcube->get_dbh();
$result = $db->query(
- "UPDATE `syncroton_folder` SET `creation_synckey` = null",
+ "UPDATE `syncroton_folder` SET `creation_synckey` = 0",
);
$request = <<<EOF
@@ -84,7 +84,6 @@
$this->assertEquals(200, $response->getStatusCode());
$dom = $this->fromWbxml($response->getBody());
$xpath = $this->xpath($dom);
- $this->printDom($dom);
$this->assertSame('1', $xpath->query("//ns:FolderSync/ns:Status")->item(0)->nodeValue);
$this->assertSame('1', $xpath->query("//ns:FolderSync/ns:SyncKey")->item(0)->nodeValue);
// No changes on second sync
@@ -114,14 +113,11 @@
$this->assertSame('9', $xpath->query("//ns:FolderSync/ns:Status")->item(0)->nodeValue);
}
-
/**
* Test synckey reuse
*/
public function testSyncKeyResend()
{
- $this->deleteTestFolder('NewFolder', 'mail');
- $this->deleteTestFolder('NewFolder2', 'mail');
$request = <<<EOF
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
@@ -216,10 +212,6 @@
$dom = $this->fromWbxml($response->getBody());
$xpath = $this->xpath($dom);
$this->assertSame('9', $xpath->query("//ns:FolderSync/ns:Status")->item(0)->nodeValue);
-
- // Cleanup for the other tests
- $this->deleteTestFolder('NewFolder', 'mail');
- $this->deleteTestFolder('NewFolder2', 'mail');
}
/**
@@ -227,6 +219,8 @@
*/
public function testFolderSync()
{
+ $this->foldersCleanup();
+ $this->resetDevice();
$request = <<<EOF
<?xml version="1.0" encoding="utf-8"?>
diff --git a/tests/Sync/MoveItemsTest.php b/tests/Sync/MoveItemsTest.php
--- a/tests/Sync/MoveItemsTest.php
+++ b/tests/Sync/MoveItemsTest.php
@@ -205,8 +205,7 @@
// Test with multi-folder support enabled
self::$deviceType = 'iphone';
- // @phpstan-ignore-next-line
- $davFolder = $this->isStorageDriver('kolab') ? 'Contacts' : 'Addressbook';
+ $davFolder = 'Contacts';
$this->emptyTestFolder($davFolder, 'contact');
$this->deleteTestFolder($folderName = 'Test Contacts Folder', 'contact');
$this->appendObject($davFolder, 'contact.vcard1', 'contact');
diff --git a/tests/Sync/PingTest.php b/tests/Sync/PingTest.php
--- a/tests/Sync/PingTest.php
+++ b/tests/Sync/PingTest.php
@@ -27,7 +27,6 @@
$dom = $this->fromWbxml($response->getBody());
$xpath = $this->xpath($dom);
- $this->printDom($dom);
//Initially we know no folders
$this->assertSame('7', $xpath->query("//ns:Ping/ns:Status")->item(0)->nodeValue);
@@ -64,8 +63,7 @@
$this->assertEquals(200, $response->getStatusCode());
$dom = $this->fromWbxml($response->getBody());
$xpath = $this->xpath($dom);
- // $this->printDom($dom);
- //Initially we know no folders
+ // Initially we know no folders
$this->assertSame('2', $xpath->query("//ns:Ping/ns:Status")->item(0)->nodeValue);
}
@@ -94,7 +92,6 @@
$dom = $this->fromWbxml($response->getBody());
$xpath = $this->xpath($dom);
- // $this->printDom($dom);
$this->assertSame('7', $xpath->query("//ns:Ping/ns:Status")->item(0)->nodeValue);
}
diff --git a/tests/Sync/Sync/ContactsTest.php b/tests/Sync/Sync/ContactsTest.php
--- a/tests/Sync/Sync/ContactsTest.php
+++ b/tests/Sync/Sync/ContactsTest.php
@@ -9,7 +9,7 @@
*/
public function testSync()
{
- $davFolder = $this->isStorageDriver('kolab') ? 'Contacts' : 'Addressbook';
+ $davFolder = 'Contacts';
$this->emptyTestFolder($davFolder, 'contact');
$this->deleteTestFolder('Test Contacts Folder', 'contact'); // from other test files
$this->registerDevice();
diff --git a/tests/Sync/Sync/EmailITipTest.php b/tests/Sync/Sync/EmailITipTest.php
--- a/tests/Sync/Sync/EmailITipTest.php
+++ b/tests/Sync/Sync/EmailITipTest.php
@@ -69,8 +69,6 @@
$dom = $this->fromWbxml($response->getBody());
$xpath = $this->xpath($dom);
- // print($dom->saveXML());
-
$root = "//ns:Sync/ns:Collections/ns:Collection";
$this->assertSame('1', $xpath->query("{$root}/ns:Status")->item(0)->nodeValue);
$this->assertSame(strval(++$syncKey), $xpath->query("{$root}/ns:SyncKey")->item(0)->nodeValue);
diff --git a/tests/Sync/Sync/EmailTest.php b/tests/Sync/Sync/EmailTest.php
--- a/tests/Sync/Sync/EmailTest.php
+++ b/tests/Sync/Sync/EmailTest.php
@@ -148,6 +148,7 @@
$this->assertSame(strval(++$syncKey), $xpath->query("{$root}/ns:SyncKey")->item(0)->nodeValue);
$this->assertSame($folderId, $xpath->query("{$root}/ns:CollectionId")->item(0)->nodeValue);
$this->assertSame(1, $xpath->query("{$root}/ns:Commands/ns:Add")->count());
+ $this->assertSame('0', $xpath->query("{$root}/ns:Commands/ns:Add/ns:ApplicationData/Email:Read")->item(0)->nodeValue);
// Note: We assume messages are in IMAP default order, it may change in future
$root .= "/ns:Commands/ns:Add";
@@ -238,7 +239,6 @@
$this->assertEquals(200, $response->getStatusCode());
$dom = $this->fromWbxml($response->getBody());
$xpath = $this->xpath($dom);
- // print($dom->saveXML());
$root = "//ns:Sync/ns:Collections/ns:Collection";
$this->assertSame('1', $xpath->query("{$root}/ns:Status")->item(0)->nodeValue);
@@ -247,10 +247,10 @@
$this->assertSame(0, $xpath->query("{$root}/ns:Commands/ns:Add")->count());
$this->assertSame(2, $xpath->query("{$root}/ns:Commands/ns:Change")->count());
$this->assertSame(2, $xpath->query("{$root}/ns:Commands/ns:Change/ns:ApplicationData/Email:Read")->count());
- $this->assertSame('0', $xpath->query("{$root}/ns:Commands/ns:Change/ns:ApplicationData/Email:Read")->item(0)->nodeValue);
- $this->assertSame('0', $xpath->query("{$root}/ns:Commands/ns:Change/ns:ApplicationData/Email:Read")->item(1)->nodeValue);
-
+ $this->assertSame('1', $xpath->query("{$root}/ns:Commands/ns:Change/ns:ApplicationData/Email:Read")->item(0)->nodeValue);
+ $this->assertSame('1', $xpath->query("{$root}/ns:Commands/ns:Change/ns:ApplicationData/Email:Read")->item(1)->nodeValue);
$this->assertSame(0, $xpath->query("{$root}/ns:Commands/ns:Change/ns:ApplicationData/AirSyncBase:Body")->count());
+
return $syncKey;
}
@@ -293,7 +293,6 @@
$this->assertEquals(200, $response->getStatusCode());
$dom = $this->fromWbxml($response->getBody());
$xpath = $this->xpath($dom);
- // print($dom->saveXML());
$root = "//ns:Sync/ns:Collections/ns:Collection";
$this->assertSame('1', $xpath->query("{$root}/ns:Status")->item(0)->nodeValue);
@@ -349,7 +348,6 @@
$this->assertEquals(200, $response->getStatusCode());
$dom = $this->fromWbxml($response->getBody());
$xpath = $this->xpath($dom);
- // print($dom->saveXML());
$root = "//ns:Sync/ns:Collections/ns:Collection";
$this->assertSame('1', $xpath->query("{$root}/ns:Status")->item(0)->nodeValue);
@@ -404,7 +402,6 @@
$this->assertEquals(200, $response->getStatusCode());
$dom = $this->fromWbxml($response->getBody());
$xpath = $this->xpath($dom);
- // print($dom->saveXML());
$root = "//ns:Sync/ns:Collections/ns:Collection";
$this->assertSame('1', $xpath->query("{$root}/ns:Status")->item(0)->nodeValue);
@@ -422,7 +419,6 @@
return $syncKey;
}
-
/**
* Test a sync key that doesn't exist yet.
* @depends testDeleteFromClient
@@ -460,7 +456,6 @@
$this->assertEquals(200, $response->getStatusCode());
$dom = $this->fromWbxml($response->getBody());
$xpath = $this->xpath($dom);
- // print($dom->saveXML());
$root = "//ns:Sync/ns:Collections/ns:Collection";
$this->assertSame('3', $xpath->query("{$root}/ns:Status")->item(0)->nodeValue);
@@ -469,5 +464,4 @@
//We have to start over after this. The sync state was removed.
return 0;
}
-
}
diff --git a/tests/Sync/Sync/InconsistencyTest.php b/tests/Sync/Sync/InconsistencyTest.php
--- a/tests/Sync/Sync/InconsistencyTest.php
+++ b/tests/Sync/Sync/InconsistencyTest.php
@@ -124,15 +124,11 @@
$this->assertSame($folderId, $xpath->query("{$root}/ns:CollectionId")->item(0)->nodeValue);
$this->assertSame(1, $xpath->query("{$root}/ns:Commands/ns:Add")->count());
-
- //Assert that we have all content parts back
- $sync = \kolab_sync::get_instance();
- $device = $sync->storage()->device_get(self::$deviceId);
-
+ // Assert that we have all content parts back
$result = $db->query(
"SELECT `contentid` FROM `syncroton_content`"
- . " WHERE `device_id` = ?",
- $device['ID']
+ . " WHERE `device_id` IN (SELECT `id` FROM `syncroton_device` WHERE `deviceid` = ?)",
+ self::$deviceId
);
$data = [];
while ($state = $db->fetch_assoc($result)) {
@@ -142,5 +138,4 @@
return $syncKey;
}
-
}
diff --git a/tests/Sync/Sync/RelationsTest.php b/tests/Sync/Sync/RelationsTest.php
--- a/tests/Sync/Sync/RelationsTest.php
+++ b/tests/Sync/Sync/RelationsTest.php
@@ -55,7 +55,7 @@
$db = \rcube::get_instance()->get_dbh();
$result = $db->query(
"SELECT `data`, `synctime` FROM `syncroton_relations_state`"
- . " WHERE `device_id` = ? AND `folder_id` = ?"
+ . " WHERE `device_id` IN (SELECT `id` FROM `syncroton_device` WHERE `deviceid` = ?) AND `folder_id` = ?"
. " ORDER BY `synctime` DESC",
$device_id,
$folderId
@@ -103,10 +103,8 @@
$sync = \kolab_sync::get_instance();
- $device = $sync->storage()->device_get(self::$deviceId);
-
- //Add a tag
- $sync->storage()->updateItem($folderId, $device['ID'], \kolab_sync_storage::MODEL_EMAIL, $uid1, null, ['categories' => ['test1']]);
+ // Add a tag
+ $sync->storage(true)->updateItem($folderId, self::$deviceId, \kolab_sync_storage::MODEL_EMAIL, $uid1, null, ['categories' => ['test1']]);
sleep(1);
$response = $this->syncRequest($syncKey, $folderId, 10);
@@ -123,8 +121,8 @@
$this->assertSame(1, $xpath->query("{$root}/ns:ApplicationData/Email:Categories")->count());
$this->assertSame("test1", $xpath->query("{$root}/ns:ApplicationData/Email:Categories")->item(0)->nodeValue);
- //Add a second tag
- $sync->storage()->updateItem($folderId, $device['ID'], \kolab_sync_storage::MODEL_EMAIL, $uid1, null, ['categories' => ['test1', 'test2']]);
+ // Add a second tag
+ $sync->storage(true)->updateItem($folderId, self::$deviceId, \kolab_sync_storage::MODEL_EMAIL, $uid1, null, ['categories' => ['test1', 'test2']]);
sleep(1); // Necessary to make sure we pick up on the tag.
$response = $this->syncRequest($syncKey, $folderId, 10);
@@ -163,7 +161,7 @@
$this->assertSame("test1test2", $xpath->query("{$root}/ns:ApplicationData/Email:Categories")->item(0)->nodeValue);
// Assert the db state
- $this->assertSame(2, count($this->getRelationsState($device['ID'], $folderId)));
+ $this->assertSame(2, count($this->getRelationsState(self::$deviceId, $folderId)));
// Make sure we have a new timestamp after the first iteration.
// This way we can potentially catch errors when we end up using the same or a different timestamp.
sleep(1);
@@ -171,7 +169,7 @@
$syncKey += ($retries + 1);
// Reset to no tags
- $sync->storage()->updateItem($folderId, $device['ID'], \kolab_sync_storage::MODEL_EMAIL, $uid1, null, ['categories' => []]);
+ $sync->storage(true)->updateItem($folderId, self::$deviceId, \kolab_sync_storage::MODEL_EMAIL, $uid1, null, ['categories' => []]);
sleep(1); // Necessary to make sure we pick up on the tag.
$response = $this->syncRequest($syncKey, $folderId, 10);
@@ -192,7 +190,7 @@
// Assert the db state
- $this->assertSame(2, count($this->getRelationsState($device['ID'], $folderId)));
+ $this->assertSame(2, count($this->getRelationsState(self::$deviceId, $folderId)));
$response = $this->syncRequest($syncKey, $folderId, 10);
$this->assertEquals(200, $response->getStatusCode());
@@ -208,10 +206,9 @@
// Setup with a tag and an initial sync completed
$folderId = '38b950ebd62cd9a66929c89615d0fc04';
$sync = \kolab_sync::get_instance();
- $device = $sync->storage()->device_get(self::$deviceId);
$uid1 = $this->appendMail('INBOX', 'mail.sync1');
- $sync->storage()->updateItem($folderId, $device['ID'], \kolab_sync_storage::MODEL_EMAIL, $uid1, null, ['categories' => ['test1']]);
+ $sync->storage(true)->updateItem($folderId, self::$deviceId, \kolab_sync_storage::MODEL_EMAIL, $uid1, null, ['categories' => ['test1']]);
sleep(1);
$response = $this->syncRequest(0, $folderId, 10);
@@ -219,8 +216,7 @@
$response = $this->syncRequest(1, $folderId, 10);
$this->assertEquals(200, $response->getStatusCode());
-
- $this->assertSame(2, count($this->getRelationsState($device['ID'], $folderId)));
+ $this->assertSame(2, count($this->getRelationsState(self::$deviceId, $folderId)));
// Make sure the timestamp changes
sleep(1);
@@ -244,7 +240,7 @@
$response = $this->request($request, 'Ping');
$this->assertEquals(200, $response->getStatusCode());
- $this->assertSame(1, count($this->getRelationsState($device['ID'], $folderId)));
+ $this->assertSame(1, count($this->getRelationsState(self::$deviceId, $folderId)));
}
// This simulates a specific case where we had:
@@ -273,7 +269,6 @@
$response = $this->request($request, 'Ping');
$this->assertEquals(200, $response->getStatusCode());
- $this->assertSame(1, count($this->getRelationsState($device['ID'], $folderId)));
-
+ $this->assertSame(1, count($this->getRelationsState(self::$deviceId, $folderId)));
}
}
diff --git a/tests/SyncTestCase.php b/tests/SyncTestCase.php
--- a/tests/SyncTestCase.php
+++ b/tests/SyncTestCase.php
@@ -43,7 +43,7 @@
return;
}
- self::$deviceId = 'test' . time();
+ self::$deviceId = 'test' . str_replace('.', '', microtime(true));
$db->query('DELETE FROM syncroton_device');
$db->query('DELETE FROM syncroton_synckey');
@@ -379,6 +379,19 @@
}
}
+ protected function resetDevice()
+ {
+ $sync = \kolab_sync::get_instance();
+
+ if (self::$deviceId) {
+ $storage = $sync->storage();
+ $storage->device_delete(self::$deviceId);
+ }
+
+ $db = $sync->get_dbh();
+ $db->query('DELETE FROM syncroton_device');
+ }
+
/**
* Convert XML into WBXML binary content
*/

File Metadata

Mime Type
text/plain
Expires
Sat, Apr 4, 12:09 AM (1 h, 56 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18827371
Default Alt Text
D5060.1775261383.diff (17 KB)

Event Timeline