summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/files/cache/updater.php74
-rw-r--r--tests/lib/files/node/integration.php7
-rw-r--r--tests/lib/repair/repairlegacystorage.php74
3 files changed, 136 insertions, 19 deletions
diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php
index 7c3ebd5a6f9..726ee360479 100644
--- a/tests/lib/files/cache/updater.php
+++ b/tests/lib/files/cache/updater.php
@@ -172,4 +172,78 @@ class Updater extends \Test\TestCase {
$this->assertTrue($this->cache->inCache('foo.txt'));
$this->assertFalse($this->cache->inCache('bar.txt'));
}
+
+ public function testMoveCrossStorage() {
+ $storage2 = new Temporary(array());
+ $cache2 = $storage2->getCache();
+ Filesystem::mount($storage2, array(), '/bar');
+ $this->storage->file_put_contents('foo.txt', 'qwerty');
+
+ $this->updater->update('foo.txt');
+
+ $this->assertTrue($this->cache->inCache('foo.txt'));
+ $this->assertFalse($cache2->inCache('bar.txt'));
+ $cached = $this->cache->get('foo.txt');
+
+ // "rename"
+ $storage2->file_put_contents('bar.txt', 'qwerty');
+ $this->storage->unlink('foo.txt');
+
+ $this->assertTrue($this->cache->inCache('foo.txt'));
+ $this->assertFalse($cache2->inCache('bar.txt'));
+
+ $this->updater->rename('foo.txt', 'bar/bar.txt');
+
+ $this->assertFalse($this->cache->inCache('foo.txt'));
+ $this->assertTrue($cache2->inCache('bar.txt'));
+
+ $cachedTarget = $cache2->get('bar.txt');
+ $this->assertEquals($cached['mtime'], $cachedTarget['mtime']);
+ $this->assertEquals($cached['size'], $cachedTarget['size']);
+ $this->assertEquals($cached['etag'], $cachedTarget['etag']);
+ $this->assertEquals($cached['fileid'], $cachedTarget['fileid']);
+ }
+
+ public function testMoveFolderCrossStorage() {
+ $storage2 = new Temporary(array());
+ $cache2 = $storage2->getCache();
+ Filesystem::mount($storage2, array(), '/bar');
+ $this->storage->mkdir('foo');
+ $this->storage->mkdir('foo/bar');
+ $this->storage->file_put_contents('foo/foo.txt', 'qwerty');
+ $this->storage->file_put_contents('foo/bar.txt', 'foo');
+ $this->storage->file_put_contents('foo/bar/bar.txt', 'qwertyuiop');
+
+ $this->storage->getScanner()->scan('');
+
+ $this->assertTrue($this->cache->inCache('foo/foo.txt'));
+ $this->assertTrue($this->cache->inCache('foo/bar.txt'));
+ $this->assertTrue($this->cache->inCache('foo/bar/bar.txt'));
+ $cached = [];
+ $cached[] = $this->cache->get('foo/foo.txt');
+ $cached[] = $this->cache->get('foo/bar.txt');
+ $cached[] = $this->cache->get('foo/bar/bar.txt');
+
+ $this->view->rename('/foo', '/bar/foo');
+
+ $this->assertFalse($this->cache->inCache('foo/foo.txt'));
+ $this->assertFalse($this->cache->inCache('foo/bar.txt'));
+ $this->assertFalse($this->cache->inCache('foo/bar/bar.txt'));
+ $this->assertTrue($cache2->inCache('foo/foo.txt'));
+ $this->assertTrue($cache2->inCache('foo/bar.txt'));
+ $this->assertTrue($cache2->inCache('foo/bar/bar.txt'));
+
+ $cachedTarget = [];
+ $cachedTarget[] = $cache2->get('foo/foo.txt');
+ $cachedTarget[] = $cache2->get('foo/bar.txt');
+ $cachedTarget[] = $cache2->get('foo/bar/bar.txt');
+
+ foreach ($cached as $i => $old) {
+ $new = $cachedTarget[$i];
+ $this->assertEquals($old['mtime'], $new['mtime']);
+ $this->assertEquals($old['size'], $new['size']);
+ $this->assertEquals($old['etag'], $new['etag']);
+ $this->assertEquals($old['fileid'], $new['fileid']);
+ }
+ }
}
diff --git a/tests/lib/files/node/integration.php b/tests/lib/files/node/integration.php
index 4e362607240..545793be54a 100644
--- a/tests/lib/files/node/integration.php
+++ b/tests/lib/files/node/integration.php
@@ -37,11 +37,6 @@ class IntegrationTests extends \Test\TestCase {
\OC_Hook::clear('OC_Filesystem');
- \OC_Hook::connect('OC_Filesystem', 'post_write', '\OC\Files\Cache\Updater', 'writeHook');
- \OC_Hook::connect('OC_Filesystem', 'post_delete', '\OC\Files\Cache\Updater', 'deleteHook');
- \OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Updater', 'renameHook');
- \OC_Hook::connect('OC_Filesystem', 'post_touch', '\OC\Files\Cache\Updater', 'touchHook');
-
$user = new User($this->getUniqueID('user'), new \OC_User_Dummy);
$this->loginAsUser($user->getUID());
@@ -83,7 +78,7 @@ class IntegrationTests extends \Test\TestCase {
$this->assertEquals('bar.txt', $file->getInternalPath());
$file->move('/substorage/bar.txt');
- $this->assertNotEquals($id, $file->getId());
+ $this->assertEquals($id, $file->getId());
$this->assertEquals('qwerty', $file->getContent());
}
diff --git a/tests/lib/repair/repairlegacystorage.php b/tests/lib/repair/repairlegacystorage.php
index 2df0f6b94b4..e1edf704424 100644
--- a/tests/lib/repair/repairlegacystorage.php
+++ b/tests/lib/repair/repairlegacystorage.php
@@ -5,18 +5,25 @@
* later.
* See the COPYING-README file.
*/
+
namespace Test\Repair;
+use OC\Files\Cache\Cache;
+use OC\Files\Cache\Storage;
+use Test\TestCase;
+
/**
* Tests for the converting of legacy storages to home storages.
*
* @see \OC\Repair\RepairLegacyStorages
*/
-class RepairLegacyStorages extends \Test\TestCase {
-
+class RepairLegacyStorages extends TestCase {
+ /** @var \OCP\IDBConnection */
private $connection;
+ /** @var \OCP\IConfig */
private $config;
private $user;
+ /** @var \OC\Repair\RepairLegacyStorages */
private $repair;
private $dataDir;
@@ -31,7 +38,7 @@ class RepairLegacyStorages extends \Test\TestCase {
parent::setUp();
$this->config = \OC::$server->getConfig();
- $this->connection = \OC_DB::getConnection();
+ $this->connection = \OC::$server->getDatabaseConnection();
$this->oldDataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/');
$this->repair = new \OC\Repair\RepairLegacyStorages($this->config, $this->connection);
@@ -44,40 +51,49 @@ class RepairLegacyStorages extends \Test\TestCase {
}
protected function tearDown() {
- \OC_User::deleteUser($this->user);
+ $user = \OC::$server->getUserManager()->get($this->user);
+ if ($user) {
+ $user->delete();
+ }
$sql = 'DELETE FROM `*PREFIX*storages`';
$this->connection->executeQuery($sql);
$sql = 'DELETE FROM `*PREFIX*filecache`';
$this->connection->executeQuery($sql);
- \OCP\Config::setSystemValue('datadirectory', $this->oldDataDir);
+ $this->config->setSystemValue('datadirectory', $this->oldDataDir);
$this->config->setAppValue('core', 'repairlegacystoragesdone', 'no');
parent::tearDown();
}
+ /**
+ * @param string $dataDir
+ * @param string $userId
+ * @throws \Exception
+ */
function prepareSettings($dataDir, $userId) {
// hard-coded string as we want a predictable fixed length
// no data will be written there
$this->dataDir = $dataDir;
- \OCP\Config::setSystemValue('datadirectory', $this->dataDir);
+ $this->config->setSystemValue('datadirectory', $this->dataDir);
$this->user = $userId;
$this->legacyStorageId = 'local::' . $this->dataDir . $this->user . '/';
$this->newStorageId = 'home::' . $this->user;
- \OC_User::createUser($this->user, $this->user);
+ \OC::$server->getUserManager()->createUser($this->user, $this->user);
}
/**
* Create a storage entry
*
* @param string $storageId
+ * @return int
*/
private function createStorage($storageId) {
$sql = 'INSERT INTO `*PREFIX*storages` (`id`)'
. ' VALUES (?)';
- $storageId = \OC\Files\Cache\Storage::adjustStorageId($storageId);
+ $storageId = Storage::adjustStorageId($storageId);
$numRows = $this->connection->executeUpdate($sql, array($storageId));
$this->assertEquals(1, $numRows);
@@ -87,11 +103,11 @@ class RepairLegacyStorages extends \Test\TestCase {
/**
* Returns the storage id based on the numeric id
*
- * @param int $numericId numeric id of the storage
+ * @param int $storageId numeric id of the storage
* @return string storage id or null if not found
*/
private function getStorageId($storageId) {
- $numericId = \OC\Files\Cache\Storage::getNumericStorageId($storageId);
+ $numericId = Storage::getNumericStorageId($storageId);
if (!is_null($numericId)) {
return (int)$numericId;
}
@@ -104,7 +120,7 @@ class RepairLegacyStorages extends \Test\TestCase {
* @param string $storageId storage id
*/
private function createData($storageId) {
- $cache = new \OC\Files\Cache\Cache($storageId);
+ $cache = new Cache($storageId);
$cache->put(
'dummyfile.txt',
array('size' => 5, 'mtime' => 12, 'mimetype' => 'text/plain')
@@ -113,7 +129,11 @@ class RepairLegacyStorages extends \Test\TestCase {
/**
* Test that existing home storages are left alone when valid.
+ *
* @dataProvider settingsProvider
+ *
+ * @param string $dataDir
+ * @param string $userId
*/
public function testNoopWithExistingHomeStorage($dataDir, $userId) {
$this->prepareSettings($dataDir, $userId);
@@ -128,7 +148,11 @@ class RepairLegacyStorages extends \Test\TestCase {
/**
* Test that legacy storages are converted to home storages when
* the latter does not exist.
+ *
* @dataProvider settingsProvider
+ *
+ * @param string $dataDir
+ * @param string $userId
*/
public function testConvertLegacyToHomeStorage($dataDir, $userId) {
$this->prepareSettings($dataDir, $userId);
@@ -143,12 +167,16 @@ class RepairLegacyStorages extends \Test\TestCase {
/**
* Test that legacy storages are converted to home storages
* when home storage already exists but has no data.
+ *
* @dataProvider settingsProvider
+ *
+ * @param string $dataDir
+ * @param string $userId
*/
public function testConvertLegacyToExistingEmptyHomeStorage($dataDir, $userId) {
$this->prepareSettings($dataDir, $userId);
$legacyStorageNumId = $this->createStorage($this->legacyStorageId);
- $newStorageNumId = $this->createStorage($this->newStorageId);
+ $this->createStorage($this->newStorageId);
$this->createData($this->legacyStorageId);
@@ -162,11 +190,15 @@ class RepairLegacyStorages extends \Test\TestCase {
* Test that legacy storages are converted to home storages
* when home storage already exists and the legacy storage
* has no data.
+ *
* @dataProvider settingsProvider
+ *
+ * @param string $dataDir
+ * @param string $userId
*/
public function testConvertEmptyLegacyToHomeStorage($dataDir, $userId) {
$this->prepareSettings($dataDir, $userId);
- $legacyStorageNumId = $this->createStorage($this->legacyStorageId);
+ $this->createStorage($this->legacyStorageId);
$newStorageNumId = $this->createStorage($this->newStorageId);
$this->createData($this->newStorageId);
@@ -180,7 +212,11 @@ class RepairLegacyStorages extends \Test\TestCase {
/**
* Test that nothing is done when both conflicting legacy
* and home storage have data.
+ *
* @dataProvider settingsProvider
+ *
+ * @param string $dataDir
+ * @param string $userId
*/
public function testConflictNoop($dataDir, $userId) {
$this->prepareSettings($dataDir, $userId);
@@ -205,7 +241,11 @@ class RepairLegacyStorages extends \Test\TestCase {
/**
* Test that the data dir local entry is left alone
+ *
* @dataProvider settingsProvider
+ *
+ * @param string $dataDir
+ * @param string $userId
*/
public function testDataDirEntryNoop($dataDir, $userId) {
$this->prepareSettings($dataDir, $userId);
@@ -219,7 +259,11 @@ class RepairLegacyStorages extends \Test\TestCase {
/**
* Test that external local storages are left alone
+ *
* @dataProvider settingsProvider
+ *
+ * @param string $dataDir
+ * @param string $userId
*/
public function testLocalExtStorageNoop($dataDir, $userId) {
$this->prepareSettings($dataDir, $userId);
@@ -233,7 +277,11 @@ class RepairLegacyStorages extends \Test\TestCase {
/**
* Test that other external storages are left alone
+ *
* @dataProvider settingsProvider
+ *
+ * @param string $dataDir
+ * @param string $userId
*/
public function testExtStorageNoop($dataDir, $userId) {
$this->prepareSettings($dataDir, $userId);