summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-08-04 14:46:48 +0200
committerRobin Appelman <icewind@owncloud.com>2014-10-14 14:37:22 +0200
commit595d43ab3538c16d5201984de5a5d80cf4e59ec3 (patch)
tree8722d9913e07e26d5d77f5c864fd3718cacc7fdc /tests
parent45738b6b7ab4bbf42f677f97ca56d8c31d142bd7 (diff)
downloadnextcloud-server-595d43ab3538c16d5201984de5a5d80cf4e59ec3.tar.gz
nextcloud-server-595d43ab3538c16d5201984de5a5d80cf4e59ec3.zip
Improve unit tests for Cache\Updater
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/files/cache/updater.php367
-rw-r--r--tests/lib/files/cache/updaterlegacy.php330
2 files changed, 416 insertions, 281 deletions
diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php
index 39c521c6ef6..96b4207ad43 100644
--- a/tests/lib/files/cache/updater.php
+++ b/tests/lib/files/cache/updater.php
@@ -8,323 +8,128 @@
namespace Test\Files\Cache;
-use \OC\Files\Filesystem as Filesystem;
+use OC\Files\Filesystem;
use OC\Files\Storage\Temporary;
+use OC\Files\View;
class Updater extends \PHPUnit_Framework_TestCase {
/**
- * @var \OC\Files\Storage\Storage $storage
+ * @var \OC\Files\Storage\Storage
*/
- private $storage;
+ protected $storage;
/**
- * @var \OC\Files\Cache\Scanner $scanner
+ * @var \OC\Files\Cache\Cache
*/
- private $scanner;
-
- private $stateFilesEncryption;
+ protected $cache;
/**
- * @var \OC\Files\Cache\Cache $cache
+ * @var \OC\Files\View
*/
- private $cache;
+ protected $view;
- private static $user;
+ /**
+ * @var \OC\Files\Cache\Updater
+ */
+ protected $updater;
public function setUp() {
-
- // remember files_encryption state
- $this->stateFilesEncryption = \OC_App::isEnabled('files_encryption');
- // we want to tests with the encryption app disabled
- \OC_App::disable('files_encryption');
-
- $this->storage = new \OC\Files\Storage\Temporary(array());
- $textData = "dummy file data\n";
- $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
- $this->storage->mkdir('folder');
- $this->storage->file_put_contents('foo.txt', $textData);
- $this->storage->file_put_contents('foo.png', $imgData);
- $this->storage->file_put_contents('folder/bar.txt', $textData);
- $this->storage->file_put_contents('folder/bar2.txt', $textData);
-
- $this->scanner = $this->storage->getScanner();
- $this->scanner->scan('');
+ $this->storage = new Temporary(array());
+ Filesystem::clearMounts();
+ Filesystem::mount($this->storage, array(), '/');
+ $this->view = new View('');
+ $this->updater = new \OC\Files\Cache\Updater($this->view);
$this->cache = $this->storage->getCache();
+ }
- \OC\Files\Filesystem::tearDown();
- if (!self::$user) {
- self::$user = uniqid();
- }
+ public function testNewFile() {
+ $this->storage->file_put_contents('foo.txt', 'bar');
+ $this->assertFalse($this->cache->inCache('foo.txt'));
- \OC_User::createUser(self::$user, 'password');
- \OC_User::setUserId(self::$user);
+ $this->updater->update('/foo.txt');
- \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files');
+ $this->assertTrue($this->cache->inCache('foo.txt'));
+ $cached = $this->cache->get('foo.txt');
+ $this->assertEquals(3, $cached['size']);
+ $this->assertEquals('text/plain', $cached['mimetype']);
+ }
- Filesystem::clearMounts();
- Filesystem::mount($this->storage, array(), '/' . self::$user . '/files');
+ public function testUpdatedFile() {
+ $this->view->file_put_contents('/foo.txt', 'bar');
+ $cached = $this->cache->get('foo.txt');
+ $this->assertEquals(3, $cached['size']);
+ $this->assertEquals('text/plain', $cached['mimetype']);
- \OC_Hook::clear('OC_Filesystem');
- }
+ $this->storage->file_put_contents('foo.txt', 'qwerty');
- public function tearDown() {
- if ($this->cache) {
- $this->cache->clear();
- }
- $result = \OC_User::deleteUser(self::$user);
- $this->assertTrue($result);
- Filesystem::tearDown();
- // reset app files_encryption
- if ($this->stateFilesEncryption) {
- \OC_App::enable('files_encryption');
- }
- }
+ $cached = $this->cache->get('foo.txt');
+ $this->assertEquals(3, $cached['size']);
- public function testWrite() {
- $textSize = strlen("dummy file data\n");
- $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
- $this->cache->put('foo.txt', array('mtime' => 100, 'storage_mtime' => 150));
- $rootCachedData = $this->cache->get('');
- $this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']);
-
- $fooCachedData = $this->cache->get('foo.txt');
- Filesystem::file_put_contents('foo.txt', 'asd');
- $cachedData = $this->cache->get('foo.txt');
- $this->assertEquals(3, $cachedData['size']);
- $this->assertInternalType('string', $fooCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($fooCachedData['etag'], $cachedData['etag']);
- $cachedData = $this->cache->get('');
- $this->assertEquals(2 * $textSize + $imageSize + 3, $cachedData['size']);
- $this->assertInternalType('string', $rootCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
- $rootCachedData = $cachedData;
+ $this->updater->update('/foo.txt');
- $this->assertFalse($this->cache->inCache('bar.txt'));
- Filesystem::file_put_contents('bar.txt', 'asd');
- $this->assertTrue($this->cache->inCache('bar.txt'));
- $cachedData = $this->cache->get('bar.txt');
- $this->assertEquals(3, $cachedData['size']);
- $mtime = $cachedData['mtime'];
- $cachedData = $this->cache->get('');
- $this->assertEquals(2 * $textSize + $imageSize + 2 * 3, $cachedData['size']);
- $this->assertInternalType('string', $rootCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
- $this->assertGreaterThanOrEqual($rootCachedData['mtime'], $mtime);
+ $cached = $this->cache->get('foo.txt');
+ $this->assertEquals(6, $cached['size']);
}
- public function testWriteWithMountPoints() {
- $storage2 = new \OC\Files\Storage\Temporary(array());
- $storage2->getScanner()->scan(''); //initialize etags
- $cache2 = $storage2->getCache();
- Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage');
- $folderCachedData = $this->cache->get('folder');
- $substorageCachedData = $cache2->get('');
- Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd');
- $this->assertTrue($cache2->inCache('foo.txt'));
- $cachedData = $cache2->get('foo.txt');
- $this->assertEquals(3, $cachedData['size']);
- $mtime = $cachedData['mtime'];
-
- $cachedData = $cache2->get('');
- $this->assertInternalType('string', $substorageCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($substorageCachedData['etag'], $cachedData['etag']);
- $this->assertEquals($mtime, $cachedData['mtime']);
-
- $cachedData = $this->cache->get('folder');
- $this->assertInternalType('string', $folderCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($folderCachedData['etag'], $cachedData['etag']);
- $this->assertEquals($mtime, $cachedData['mtime']);
- }
+ public function testParentSize() {
+ $this->storage->getScanner()->scan('');
- public function testDelete() {
- $textSize = strlen("dummy file data\n");
- $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
- $rootCachedData = $this->cache->get('');
- $this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']);
+ $parentCached = $this->cache->get('');
+ $this->assertEquals(0, $parentCached['size']);
- $this->assertTrue($this->cache->inCache('foo.txt'));
- Filesystem::unlink('foo.txt');
- $this->assertFalse($this->cache->inCache('foo.txt'));
- $cachedData = $this->cache->get('');
- $this->assertEquals(2 * $textSize + $imageSize, $cachedData['size']);
- $this->assertInternalType('string', $rootCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
- $this->assertGreaterThanOrEqual($rootCachedData['mtime'], $cachedData['mtime']);
- $rootCachedData = $cachedData;
-
- Filesystem::mkdir('bar_folder');
- $this->assertTrue($this->cache->inCache('bar_folder'));
- $cachedData = $this->cache->get('');
- $this->assertInternalType('string', $rootCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
- $rootCachedData = $cachedData;
- Filesystem::rmdir('bar_folder');
- $this->assertFalse($this->cache->inCache('bar_folder'));
- $cachedData = $this->cache->get('');
- $this->assertInternalType('string', $rootCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
- $this->assertGreaterThanOrEqual($rootCachedData['mtime'], $cachedData['mtime']);
- }
+ $this->storage->file_put_contents('foo.txt', 'bar');
+
+ $parentCached = $this->cache->get('');
+ $this->assertEquals(0, $parentCached['size']);
+
+ $this->updater->update('foo.txt');
- public function testDeleteWithMountPoints() {
- $storage2 = new \OC\Files\Storage\Temporary(array());
- $cache2 = $storage2->getCache();
- Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage');
- Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd');
- $this->assertTrue($cache2->inCache('foo.txt'));
- $folderCachedData = $this->cache->get('folder');
- $substorageCachedData = $cache2->get('');
- Filesystem::unlink('folder/substorage/foo.txt');
- $this->assertFalse($cache2->inCache('foo.txt'));
-
- $cachedData = $cache2->get('');
- $this->assertInternalType('string', $substorageCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($substorageCachedData['etag'], $cachedData['etag']);
- $this->assertGreaterThanOrEqual($substorageCachedData['mtime'], $cachedData['mtime']);
-
- $cachedData = $this->cache->get('folder');
- $this->assertInternalType('string', $folderCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($folderCachedData['etag'], $cachedData['etag']);
- $this->assertGreaterThanOrEqual($folderCachedData['mtime'], $cachedData['mtime']);
+ $parentCached = $this->cache->get('');
+ $this->assertEquals(3, $parentCached['size']);
+
+ $this->storage->file_put_contents('foo.txt', 'qwerty');
+
+ $parentCached = $this->cache->get('');
+ $this->assertEquals(3, $parentCached['size']);
+
+ $this->updater->update('foo.txt');
+
+ $parentCached = $this->cache->get('');
+ $this->assertEquals(6, $parentCached['size']);
+
+ $this->storage->unlink('foo.txt');
+
+ $parentCached = $this->cache->get('');
+ $this->assertEquals(6, $parentCached['size']);
+
+ $this->updater->remove('foo.txt');
+
+ $parentCached = $this->cache->get('');
+ $this->assertEquals(0, $parentCached['size']);
}
- public function testRename() {
- $textSize = strlen("dummy file data\n");
- $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
- $rootCachedData = $this->cache->get('');
- $this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']);
+ public function testMove() {
+ $this->storage->file_put_contents('foo.txt', 'qwerty');
+ $this->updater->update('foo.txt');
$this->assertTrue($this->cache->inCache('foo.txt'));
- $fooCachedData = $this->cache->get('foo.txt');
$this->assertFalse($this->cache->inCache('bar.txt'));
- Filesystem::rename('foo.txt', 'bar.txt');
- $this->assertFalse($this->cache->inCache('foo.txt'));
- $this->assertTrue($this->cache->inCache('bar.txt'));
- $cachedData = $this->cache->get('bar.txt');
- $this->assertEquals($fooCachedData['fileid'], $cachedData['fileid']);
- $mtime = $cachedData['mtime'];
- $cachedData = $this->cache->get('');
- $this->assertEquals(3 * $textSize + $imageSize, $cachedData['size']);
- $this->assertInternalType('string', $rootCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
- }
+ $cached = $this->cache->get('foo.txt');
- public function testRenameExtension() {
- $fooCachedData = $this->cache->get('foo.txt');
- $this->assertEquals('text/plain', $fooCachedData['mimetype']);
- Filesystem::rename('foo.txt', 'foo.abcd');
- $fooCachedData = $this->cache->get('foo.abcd');
- $this->assertEquals('application/octet-stream', $fooCachedData['mimetype']);
- }
+ $this->storage->rename('foo.txt', 'bar.txt');
- public function testRenameWithMountPoints() {
- $storage2 = new \OC\Files\Storage\Temporary(array());
- $cache2 = $storage2->getCache();
- Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage');
- Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd');
- $this->assertTrue($cache2->inCache('foo.txt'));
- $folderCachedData = $this->cache->get('folder');
- $substorageCachedData = $cache2->get('');
- $fooCachedData = $cache2->get('foo.txt');
- Filesystem::rename('folder/substorage/foo.txt', 'folder/substorage/bar.txt');
- $this->assertFalse($cache2->inCache('foo.txt'));
- $this->assertTrue($cache2->inCache('bar.txt'));
- $cachedData = $cache2->get('bar.txt');
- $this->assertEquals($fooCachedData['fileid'], $cachedData['fileid']);
- $mtime = $cachedData['mtime'];
-
- $cachedData = $cache2->get('');
- $this->assertInternalType('string', $substorageCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($substorageCachedData['etag'], $cachedData['etag']);
- // rename can cause mtime change - invalid assert
-// $this->assertEquals($mtime, $cachedData['mtime']);
-
- $cachedData = $this->cache->get('folder');
- $this->assertInternalType('string', $folderCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($folderCachedData['etag'], $cachedData['etag']);
- // rename can cause mtime change - invalid assert
-// $this->assertEquals($mtime, $cachedData['mtime']);
- }
+ $this->assertTrue($this->cache->inCache('foo.txt'));
+ $this->assertFalse($this->cache->inCache('bar.txt'));
- public function testTouch() {
- $rootCachedData = $this->cache->get('');
- $fooCachedData = $this->cache->get('foo.txt');
- Filesystem::touch('foo.txt');
- $cachedData = $this->cache->get('foo.txt');
- $this->assertInternalType('string', $fooCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertGreaterThanOrEqual($fooCachedData['mtime'], $cachedData['mtime']);
-
- $cachedData = $this->cache->get('');
- $this->assertInternalType('string', $rootCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
- $this->assertGreaterThanOrEqual($rootCachedData['mtime'], $cachedData['mtime']);
- $rootCachedData = $cachedData;
-
- $time = 1371006070;
- $barCachedData = $this->cache->get('folder/bar.txt');
- $folderCachedData = $this->cache->get('folder');
- Filesystem::touch('folder/bar.txt', $time);
- $cachedData = $this->cache->get('folder/bar.txt');
- $this->assertInternalType('string', $barCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($barCachedData['etag'], $cachedData['etag']);
- $this->assertEquals($time, $cachedData['mtime']);
-
- $cachedData = $this->cache->get('folder');
- $this->assertInternalType('string', $folderCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($folderCachedData['etag'], $cachedData['etag']);
-
- $cachedData = $this->cache->get('');
- $this->assertInternalType('string', $rootCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
- $this->assertEquals($time, $cachedData['mtime']);
- }
+ $this->updater->rename('foo.txt', 'bar.txt');
- public function testTouchWithMountPoints() {
- $storage2 = new \OC\Files\Storage\Temporary(array());
- $cache2 = $storage2->getCache();
- Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage');
- Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd');
- $this->assertTrue($cache2->inCache('foo.txt'));
- $folderCachedData = $this->cache->get('folder');
- $substorageCachedData = $cache2->get('');
- $fooCachedData = $cache2->get('foo.txt');
- $cachedData = $cache2->get('foo.txt');
- $time = 1371006070;
- Filesystem::touch('folder/substorage/foo.txt', $time);
- $cachedData = $cache2->get('foo.txt');
- $this->assertInternalType('string', $fooCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($fooCachedData['etag'], $cachedData['etag']);
- $this->assertEquals($time, $cachedData['mtime']);
-
- $cachedData = $cache2->get('');
- $this->assertInternalType('string', $substorageCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($substorageCachedData['etag'], $cachedData['etag']);
-
- $cachedData = $this->cache->get('folder');
- $this->assertInternalType('string', $folderCachedData['etag']);
- $this->assertInternalType('string', $cachedData['etag']);
- $this->assertNotSame($folderCachedData['etag'], $cachedData['etag']);
- $this->assertEquals($time, $cachedData['mtime']);
- }
+ $this->assertFalse($this->cache->inCache('foo.txt'));
+ $this->assertTrue($this->cache->inCache('bar.txt'));
+ $cachedTarget = $this->cache->get('bar.txt');
+ $this->assertEquals($cached['etag'], $cachedTarget['etag']);
+ $this->assertEquals($cached['mtime'], $cachedTarget['mtime']);
+ $this->assertEquals($cached['size'], $cachedTarget['size']);
+ $this->assertEquals($cached['fileid'], $cachedTarget['fileid']);
+ }
}
diff --git a/tests/lib/files/cache/updaterlegacy.php b/tests/lib/files/cache/updaterlegacy.php
new file mode 100644
index 00000000000..a6697c76353
--- /dev/null
+++ b/tests/lib/files/cache/updaterlegacy.php
@@ -0,0 +1,330 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Cache;
+
+use \OC\Files\Filesystem as Filesystem;
+use OC\Files\Storage\Temporary;
+
+class UpdaterLegacy extends \PHPUnit_Framework_TestCase {
+ /**
+ * @var \OC\Files\Storage\Storage $storage
+ */
+ private $storage;
+
+ /**
+ * @var \OC\Files\Cache\Scanner $scanner
+ */
+ private $scanner;
+
+ private $stateFilesEncryption;
+
+ /**
+ * @var \OC\Files\Cache\Cache $cache
+ */
+ private $cache;
+
+ private static $user;
+
+ public function setUp() {
+
+ // remember files_encryption state
+ $this->stateFilesEncryption = \OC_App::isEnabled('files_encryption');
+ // we want to tests with the encryption app disabled
+ \OC_App::disable('files_encryption');
+
+ $this->storage = new \OC\Files\Storage\Temporary(array());
+ $textData = "dummy file data\n";
+ $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
+ $this->storage->mkdir('folder');
+ $this->storage->file_put_contents('foo.txt', $textData);
+ $this->storage->file_put_contents('foo.png', $imgData);
+ $this->storage->file_put_contents('folder/bar.txt', $textData);
+ $this->storage->file_put_contents('folder/bar2.txt', $textData);
+
+ $this->scanner = $this->storage->getScanner();
+ $this->scanner->scan('');
+ $this->cache = $this->storage->getCache();
+
+ \OC\Files\Filesystem::tearDown();
+ if (!self::$user) {
+ self::$user = uniqid();
+ }
+
+ \OC_User::createUser(self::$user, 'password');
+ \OC_User::setUserId(self::$user);
+
+ \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files');
+
+ Filesystem::clearMounts();
+ Filesystem::mount($this->storage, array(), '/' . self::$user . '/files');
+
+ \OC_Hook::clear('OC_Filesystem');
+ }
+
+ public function tearDown() {
+ if ($this->cache) {
+ $this->cache->clear();
+ }
+ $result = \OC_User::deleteUser(self::$user);
+ $this->assertTrue($result);
+ Filesystem::tearDown();
+ // reset app files_encryption
+ if ($this->stateFilesEncryption) {
+ \OC_App::enable('files_encryption');
+ }
+ }
+
+ public function testWrite() {
+ $textSize = strlen("dummy file data\n");
+ $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
+ $this->cache->put('foo.txt', array('mtime' => 100, 'storage_mtime' => 150));
+ $rootCachedData = $this->cache->get('');
+ $this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']);
+
+ $fooCachedData = $this->cache->get('foo.txt');
+ Filesystem::file_put_contents('foo.txt', 'asd');
+ $cachedData = $this->cache->get('foo.txt');
+ $this->assertEquals(3, $cachedData['size']);
+ $this->assertInternalType('string', $fooCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($fooCachedData['etag'], $cachedData['etag']);
+ $cachedData = $this->cache->get('');
+ $this->assertEquals(2 * $textSize + $imageSize + 3, $cachedData['size']);
+ $this->assertInternalType('string', $rootCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
+ $rootCachedData = $cachedData;
+
+ $this->assertFalse($this->cache->inCache('bar.txt'));
+ Filesystem::file_put_contents('bar.txt', 'asd');
+ $this->assertTrue($this->cache->inCache('bar.txt'));
+ $cachedData = $this->cache->get('bar.txt');
+ $this->assertEquals(3, $cachedData['size']);
+ $mtime = $cachedData['mtime'];
+ $cachedData = $this->cache->get('');
+ $this->assertEquals(2 * $textSize + $imageSize + 2 * 3, $cachedData['size']);
+ $this->assertInternalType('string', $rootCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
+ $this->assertGreaterThanOrEqual($rootCachedData['mtime'], $mtime);
+ }
+
+ public function testWriteWithMountPoints() {
+ $storage2 = new \OC\Files\Storage\Temporary(array());
+ $storage2->getScanner()->scan(''); //initialize etags
+ $cache2 = $storage2->getCache();
+ Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage');
+ $folderCachedData = $this->cache->get('folder');
+ $substorageCachedData = $cache2->get('');
+ Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd');
+ $this->assertTrue($cache2->inCache('foo.txt'));
+ $cachedData = $cache2->get('foo.txt');
+ $this->assertEquals(3, $cachedData['size']);
+ $mtime = $cachedData['mtime'];
+
+ $cachedData = $cache2->get('');
+ $this->assertInternalType('string', $substorageCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($substorageCachedData['etag'], $cachedData['etag']);
+ $this->assertEquals($mtime, $cachedData['mtime']);
+
+ $cachedData = $this->cache->get('folder');
+ $this->assertInternalType('string', $folderCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($folderCachedData['etag'], $cachedData['etag']);
+ $this->assertEquals($mtime, $cachedData['mtime']);
+ }
+
+ public function testDelete() {
+ $textSize = strlen("dummy file data\n");
+ $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
+ $rootCachedData = $this->cache->get('');
+ $this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']);
+
+ $this->assertTrue($this->cache->inCache('foo.txt'));
+ Filesystem::unlink('foo.txt');
+ $this->assertFalse($this->cache->inCache('foo.txt'));
+ $cachedData = $this->cache->get('');
+ $this->assertEquals(2 * $textSize + $imageSize, $cachedData['size']);
+ $this->assertInternalType('string', $rootCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
+ $this->assertGreaterThanOrEqual($rootCachedData['mtime'], $cachedData['mtime']);
+ $rootCachedData = $cachedData;
+
+ Filesystem::mkdir('bar_folder');
+ $this->assertTrue($this->cache->inCache('bar_folder'));
+ $cachedData = $this->cache->get('');
+ $this->assertInternalType('string', $rootCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
+ $rootCachedData = $cachedData;
+ Filesystem::rmdir('bar_folder');
+ $this->assertFalse($this->cache->inCache('bar_folder'));
+ $cachedData = $this->cache->get('');
+ $this->assertInternalType('string', $rootCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
+ $this->assertGreaterThanOrEqual($rootCachedData['mtime'], $cachedData['mtime']);
+ }
+
+ public function testDeleteWithMountPoints() {
+ $storage2 = new \OC\Files\Storage\Temporary(array());
+ $cache2 = $storage2->getCache();
+ Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage');
+ Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd');
+ $this->assertTrue($cache2->inCache('foo.txt'));
+ $folderCachedData = $this->cache->get('folder');
+ $substorageCachedData = $cache2->get('');
+ Filesystem::unlink('folder/substorage/foo.txt');
+ $this->assertFalse($cache2->inCache('foo.txt'));
+
+ $cachedData = $cache2->get('');
+ $this->assertInternalType('string', $substorageCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($substorageCachedData['etag'], $cachedData['etag']);
+ $this->assertGreaterThanOrEqual($substorageCachedData['mtime'], $cachedData['mtime']);
+
+ $cachedData = $this->cache->get('folder');
+ $this->assertInternalType('string', $folderCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($folderCachedData['etag'], $cachedData['etag']);
+ $this->assertGreaterThanOrEqual($folderCachedData['mtime'], $cachedData['mtime']);
+ }
+
+ public function testRename() {
+ $textSize = strlen("dummy file data\n");
+ $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
+ $rootCachedData = $this->cache->get('');
+ $this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']);
+
+ $this->assertTrue($this->cache->inCache('foo.txt'));
+ $fooCachedData = $this->cache->get('foo.txt');
+ $this->assertFalse($this->cache->inCache('bar.txt'));
+ Filesystem::rename('foo.txt', 'bar.txt');
+ $this->assertFalse($this->cache->inCache('foo.txt'));
+ $this->assertTrue($this->cache->inCache('bar.txt'));
+ $cachedData = $this->cache->get('bar.txt');
+ $this->assertEquals($fooCachedData['fileid'], $cachedData['fileid']);
+ $mtime = $cachedData['mtime'];
+ $cachedData = $this->cache->get('');
+ $this->assertEquals(3 * $textSize + $imageSize, $cachedData['size']);
+ $this->assertInternalType('string', $rootCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
+ }
+
+ public function testRenameExtension() {
+ $fooCachedData = $this->cache->get('foo.txt');
+ $this->assertEquals('text/plain', $fooCachedData['mimetype']);
+ Filesystem::rename('foo.txt', 'foo.abcd');
+ $fooCachedData = $this->cache->get('foo.abcd');
+ $this->assertEquals('application/octet-stream', $fooCachedData['mimetype']);
+ }
+
+ public function testRenameWithMountPoints() {
+ $storage2 = new \OC\Files\Storage\Temporary(array());
+ $cache2 = $storage2->getCache();
+ Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage');
+ Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd');
+ $this->assertTrue($cache2->inCache('foo.txt'));
+ $folderCachedData = $this->cache->get('folder');
+ $substorageCachedData = $cache2->get('');
+ $fooCachedData = $cache2->get('foo.txt');
+ Filesystem::rename('folder/substorage/foo.txt', 'folder/substorage/bar.txt');
+ $this->assertFalse($cache2->inCache('foo.txt'));
+ $this->assertTrue($cache2->inCache('bar.txt'));
+ $cachedData = $cache2->get('bar.txt');
+ $this->assertEquals($fooCachedData['fileid'], $cachedData['fileid']);
+ $mtime = $cachedData['mtime'];
+
+ $cachedData = $cache2->get('');
+ $this->assertInternalType('string', $substorageCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($substorageCachedData['etag'], $cachedData['etag']);
+ // rename can cause mtime change - invalid assert
+// $this->assertEquals($mtime, $cachedData['mtime']);
+
+ $cachedData = $this->cache->get('folder');
+ $this->assertInternalType('string', $folderCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($folderCachedData['etag'], $cachedData['etag']);
+ // rename can cause mtime change - invalid assert
+// $this->assertEquals($mtime, $cachedData['mtime']);
+ }
+
+ public function testTouch() {
+ $rootCachedData = $this->cache->get('');
+ $fooCachedData = $this->cache->get('foo.txt');
+ Filesystem::touch('foo.txt');
+ $cachedData = $this->cache->get('foo.txt');
+ $this->assertInternalType('string', $fooCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertGreaterThanOrEqual($fooCachedData['mtime'], $cachedData['mtime']);
+
+ $cachedData = $this->cache->get('');
+ $this->assertInternalType('string', $rootCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
+ $this->assertGreaterThanOrEqual($rootCachedData['mtime'], $cachedData['mtime']);
+ $rootCachedData = $cachedData;
+
+ $time = 1371006070;
+ $barCachedData = $this->cache->get('folder/bar.txt');
+ $folderCachedData = $this->cache->get('folder');
+ Filesystem::touch('folder/bar.txt', $time);
+ $cachedData = $this->cache->get('folder/bar.txt');
+ $this->assertInternalType('string', $barCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($barCachedData['etag'], $cachedData['etag']);
+ $this->assertEquals($time, $cachedData['mtime']);
+
+ $cachedData = $this->cache->get('folder');
+ $this->assertInternalType('string', $folderCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($folderCachedData['etag'], $cachedData['etag']);
+
+ $cachedData = $this->cache->get('');
+ $this->assertInternalType('string', $rootCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
+ $this->assertEquals($time, $cachedData['mtime']);
+ }
+
+ public function testTouchWithMountPoints() {
+ $storage2 = new \OC\Files\Storage\Temporary(array());
+ $cache2 = $storage2->getCache();
+ Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage');
+ Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd');
+ $this->assertTrue($cache2->inCache('foo.txt'));
+ $folderCachedData = $this->cache->get('folder');
+ $substorageCachedData = $cache2->get('');
+ $fooCachedData = $cache2->get('foo.txt');
+ $cachedData = $cache2->get('foo.txt');
+ $time = 1371006070;
+ Filesystem::touch('folder/substorage/foo.txt', $time);
+ $cachedData = $cache2->get('foo.txt');
+ $this->assertInternalType('string', $fooCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($fooCachedData['etag'], $cachedData['etag']);
+ $this->assertEquals($time, $cachedData['mtime']);
+
+ $cachedData = $cache2->get('');
+ $this->assertInternalType('string', $substorageCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($substorageCachedData['etag'], $cachedData['etag']);
+
+ $cachedData = $this->cache->get('folder');
+ $this->assertInternalType('string', $folderCachedData['etag']);
+ $this->assertInternalType('string', $cachedData['etag']);
+ $this->assertNotSame($folderCachedData['etag'], $cachedData['etag']);
+ $this->assertEquals($time, $cachedData['mtime']);
+ }
+
+}