summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-04-13 21:48:30 +0200
committerMorris Jobke <hey@morrisjobke.de>2015-04-13 21:48:30 +0200
commit9eff199a174a1635ebd8a671ac33f7a87f3cce9d (patch)
treeac452eb6b6deddb5c12895d1e9e4b087dfb775b4 /tests
parent660aa7ff1e7bcb61d5dcb103014da39b8a257899 (diff)
parentf605c985311fc652d1744704061af38f3ac62919 (diff)
downloadnextcloud-server-9eff199a174a1635ebd8a671ac33f7a87f3cce9d.tar.gz
nextcloud-server-9eff199a174a1635ebd8a671ac33f7a87f3cce9d.zip
Merge pull request #15360 from owncloud/cross-storage-move-cache
Preserve cache data when doing a cross storage move
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/files/cache/updater.php74
-rw-r--r--tests/lib/files/node/integration.php7
2 files changed, 75 insertions, 6 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());
}