aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorGeorg Ehrke <developer@georgehrke.com>2014-06-05 22:54:27 +0200
committerGeorg Ehrke <developer@georgehrke.com>2014-06-05 22:54:27 +0200
commit0fe8f77c1748d167e115680346ae98bba78da38d (patch)
treea456ff35bb2da1a2778f18ccab1ade63e9aaddda /tests/lib
parentfad3bd7fc0c094bd16e07708557cd1a7676889cd (diff)
parente1beb8c6c38d48eb923ed323dea25110e4bbacfd (diff)
downloadnextcloud-server-0fe8f77c1748d167e115680346ae98bba78da38d.tar.gz
nextcloud-server-0fe8f77c1748d167e115680346ae98bba78da38d.zip
Merge branch 'master' into update_shipped_apps_from_appstore
Conflicts: lib/private/app.php settings/templates/apps.php
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/connector/sabre/aborteduploaddetectionplugin.php12
-rw-r--r--tests/lib/connector/sabre/directory.php6
-rw-r--r--tests/lib/connector/sabre/file.php8
-rw-r--r--tests/lib/connector/sabre/objecttree.php5
-rw-r--r--tests/lib/connector/sabre/quotaplugin.php12
-rw-r--r--tests/lib/db/migrator.php122
-rw-r--r--tests/lib/files/cache/changepropagator.php72
-rw-r--r--tests/lib/files/cache/permissions.php75
-rw-r--r--tests/lib/files/cache/scanner.php10
-rw-r--r--tests/lib/files/cache/updater.php31
-rw-r--r--tests/lib/files/cache/watcher.php2
-rw-r--r--tests/lib/files/filesystem.php10
-rw-r--r--tests/lib/files/mount/mount.php2
-rw-r--r--tests/lib/files/node/folder.php8
-rw-r--r--tests/lib/files/utils/scanner.php64
-rw-r--r--tests/lib/files/view.php32
-rw-r--r--tests/lib/helperstorage.php145
-rw-r--r--tests/lib/util.php2
18 files changed, 427 insertions, 191 deletions
diff --git a/tests/lib/connector/sabre/aborteduploaddetectionplugin.php b/tests/lib/connector/sabre/aborteduploaddetectionplugin.php
index 60d141e72bc..7e9f70ddcd3 100644
--- a/tests/lib/connector/sabre/aborteduploaddetectionplugin.php
+++ b/tests/lib/connector/sabre/aborteduploaddetectionplugin.php
@@ -9,7 +9,7 @@
class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Framework_TestCase {
/**
- * @var Sabre_DAV_Server
+ * @var \Sabre\DAV\Server
*/
private $server;
@@ -19,7 +19,7 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Frame
private $plugin;
private function init($view) {
- $this->server = new Sabre_DAV_Server();
+ $this->server = new \Sabre\DAV\Server();
$this->plugin = new OC_Connector_Sabre_AbortedUploadDetectionPlugin($view);
$this->plugin->initialize($this->server);
}
@@ -30,7 +30,7 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Frame
public function testLength($expected, $headers) {
$this->init(null);
- $this->server->httpRequest = new Sabre_HTTP_Request($headers);
+ $this->server->httpRequest = new \Sabre\HTTP\Request($headers);
$length = $this->plugin->getLength();
$this->assertEquals($expected, $length);
}
@@ -42,14 +42,14 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Frame
$this->init($this->buildFileViewMock($fileSize));
$headers['REQUEST_METHOD'] = $method;
- $this->server->httpRequest = new Sabre_HTTP_Request($headers);
+ $this->server->httpRequest = new Sabre\HTTP\Request($headers);
$this->plugin->verifyContentLength('foo.txt');
$this->assertTrue(true);
}
/**
* @dataProvider verifyContentLengthFailedProvider
- * @expectedException Sabre_DAV_Exception_BadRequest
+ * @expectedException \Sabre\DAV\Exception\BadRequest
*/
public function testVerifyContentLengthFailed($method, $fileSize, $headers) {
$view = $this->buildFileViewMock($fileSize);
@@ -58,7 +58,7 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Frame
$view->expects($this->once())->method('unlink');
$headers['REQUEST_METHOD'] = $method;
- $this->server->httpRequest = new Sabre_HTTP_Request($headers);
+ $this->server->httpRequest = new Sabre\HTTP\Request($headers);
$this->plugin->verifyContentLength('foo.txt');
}
diff --git a/tests/lib/connector/sabre/directory.php b/tests/lib/connector/sabre/directory.php
index b2bf0d4a6d2..8a1550ffa95 100644
--- a/tests/lib/connector/sabre/directory.php
+++ b/tests/lib/connector/sabre/directory.php
@@ -23,7 +23,7 @@ class Test_OC_Connector_Sabre_Directory extends PHPUnit_Framework_TestCase {
}
/**
- * @expectedException Sabre_DAV_Exception_Forbidden
+ * @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testCreateSharedFileFails() {
$dir = $this->getRootDir();
@@ -31,7 +31,7 @@ class Test_OC_Connector_Sabre_Directory extends PHPUnit_Framework_TestCase {
}
/**
- * @expectedException Sabre_DAV_Exception_Forbidden
+ * @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testCreateSharedFolderFails() {
$dir = $this->getRootDir();
@@ -39,7 +39,7 @@ class Test_OC_Connector_Sabre_Directory extends PHPUnit_Framework_TestCase {
}
/**
- * @expectedException Sabre_DAV_Exception_Forbidden
+ * @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testDeleteSharedFolderFails() {
$dir = $this->getRootDir();
diff --git a/tests/lib/connector/sabre/file.php b/tests/lib/connector/sabre/file.php
index a9056460a5c..3dd5b328f46 100644
--- a/tests/lib/connector/sabre/file.php
+++ b/tests/lib/connector/sabre/file.php
@@ -9,7 +9,7 @@
class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase {
/**
- * @expectedException Sabre_DAV_Exception
+ * @expectedException \Sabre\DAV\Exception
*/
public function testSimplePutFails() {
// setup
@@ -33,7 +33,7 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase {
}
/**
- * @expectedException Sabre_DAV_Exception
+ * @expectedException \Sabre\DAV\Exception
*/
public function testSimplePutFailsOnRename() {
// setup
@@ -62,7 +62,7 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase {
}
/**
- * @expectedException Sabre_DAV_Exception_BadRequest
+ * @expectedException \Sabre\DAV\Exception\BadRequest
*/
public function testSimplePutInvalidChars() {
// setup
@@ -86,7 +86,7 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase {
/**
* Test setting name with setName() with invalid chars
- * @expectedException Sabre_DAV_Exception_BadRequest
+ * @expectedException \Sabre\DAV\Exception\BadRequest
*/
public function testSetNameInvalidChars() {
// setup
diff --git a/tests/lib/connector/sabre/objecttree.php b/tests/lib/connector/sabre/objecttree.php
index bc8ec98faee..0075b7832b8 100644
--- a/tests/lib/connector/sabre/objecttree.php
+++ b/tests/lib/connector/sabre/objecttree.php
@@ -12,7 +12,6 @@ namespace Test\OC\Connector\Sabre;
use OC\Files\FileInfo;
use OC_Connector_Sabre_Directory;
use PHPUnit_Framework_TestCase;
-use Sabre_DAV_Exception_Forbidden;
class TestDoubleFileView extends \OC\Files\View{
@@ -43,7 +42,7 @@ class ObjectTree extends PHPUnit_Framework_TestCase {
/**
* @dataProvider moveFailedProvider
- * @expectedException Sabre_DAV_Exception_Forbidden
+ * @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testMoveFailed($source, $dest, $updatables, $deletables) {
$this->moveTest($source, $dest, $updatables, $deletables);
@@ -59,7 +58,7 @@ class ObjectTree extends PHPUnit_Framework_TestCase {
/**
* @dataProvider moveFailedInvalidCharsProvider
- * @expectedException Sabre_DAV_Exception_BadRequest
+ * @expectedException \Sabre\DAV\Exception\BadRequest
*/
public function testMoveFailedInvalidChars($source, $dest, $updatables, $deletables) {
$this->moveTest($source, $dest, $updatables, $deletables);
diff --git a/tests/lib/connector/sabre/quotaplugin.php b/tests/lib/connector/sabre/quotaplugin.php
index 6781b970a4f..1024ae6af8f 100644
--- a/tests/lib/connector/sabre/quotaplugin.php
+++ b/tests/lib/connector/sabre/quotaplugin.php
@@ -9,7 +9,7 @@
class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase {
/**
- * @var Sabre_DAV_Server
+ * @var \Sabre\DAV\Server
*/
private $server;
@@ -20,7 +20,7 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase {
private function init($quota) {
$view = $this->buildFileViewMock($quota);
- $this->server = new Sabre_DAV_Server();
+ $this->server = new \Sabre\DAV\Server();
$this->plugin = new OC_Connector_Sabre_QuotaPlugin($view);
$this->plugin->initialize($this->server);
}
@@ -30,7 +30,7 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase {
*/
public function testLength($expected, $headers) {
$this->init(0);
- $this->server->httpRequest = new Sabre_HTTP_Request($headers);
+ $this->server->httpRequest = new \Sabre\HTTP\Request($headers);
$length = $this->plugin->getLength();
$this->assertEquals($expected, $length);
}
@@ -41,19 +41,19 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase {
public function testCheckQuota($quota, $headers) {
$this->init($quota);
- $this->server->httpRequest = new Sabre_HTTP_Request($headers);
+ $this->server->httpRequest = new Sabre\HTTP\Request($headers);
$result = $this->plugin->checkQuota('');
$this->assertTrue($result);
}
/**
- * @expectedException Sabre_DAV_Exception_InsufficientStorage
+ * @expectedException \Sabre\DAV\Exception\InsufficientStorage
* @dataProvider quotaExceededProvider
*/
public function testCheckExceededQuota($quota, $headers) {
$this->init($quota);
- $this->server->httpRequest = new Sabre_HTTP_Request($headers);
+ $this->server->httpRequest = new Sabre\HTTP\Request($headers);
$this->plugin->checkQuota('');
}
diff --git a/tests/lib/db/migrator.php b/tests/lib/db/migrator.php
new file mode 100644
index 00000000000..e9b986236b8
--- /dev/null
+++ b/tests/lib/db/migrator.php
@@ -0,0 +1,122 @@
+<?php
+
+/**
+ * Copyright (c) 2014 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\DB;
+
+use \Doctrine\DBAL\DBALException;
+use \Doctrine\DBAL\Schema\Schema;
+use \Doctrine\DBAL\Schema\SchemaConfig;
+
+class Migrator extends \PHPUnit_Framework_TestCase {
+ /**
+ * @var \Doctrine\DBAL\Connection $connection
+ */
+ private $connection;
+
+ private $tableName;
+
+ public function setUp() {
+ $this->connection = \OC_DB::getConnection();
+ if ($this->connection->getDriver() instanceof \Doctrine\DBAL\Driver\OCI8\Driver) {
+ $this->markTestSkipped('DB migration tests arent supported on OCI');
+ }
+ $this->tableName = 'test_' . uniqid();
+ }
+
+ public function tearDown() {
+ $this->connection->exec('DROP TABLE ' . $this->tableName);
+ }
+
+ /**
+ * @return \Doctrine\DBAL\Schema\Schema[]
+ */
+ private function getDuplicateKeySchemas() {
+ $startSchema = new Schema(array(), array(), $this->getSchemaConfig());
+ $table = $startSchema->createTable($this->tableName);
+ $table->addColumn('id', 'integer');
+ $table->addColumn('name', 'string');
+ $table->addIndex(array('id'), $this->tableName . '_id');
+
+ $endSchema = new Schema(array(), array(), $this->getSchemaConfig());
+ $table = $endSchema->createTable($this->tableName);
+ $table->addColumn('id', 'integer');
+ $table->addColumn('name', 'string');
+ $table->addUniqueIndex(array('id'), $this->tableName . '_id');
+
+ return array($startSchema, $endSchema);
+ }
+
+ private function getSchemaConfig() {
+ $config = new SchemaConfig();
+ $config->setName($this->connection->getDatabase());
+ return $config;
+ }
+
+ private function isSQLite() {
+ return $this->connection->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver;
+ }
+
+ private function getMigrator() {
+ if ($this->isSQLite()) {
+ return new \OC\DB\SQLiteMigrator($this->connection);
+ } else {
+ return new \OC\DB\Migrator($this->connection);
+ }
+ }
+
+ /**
+ * @expectedException \OC\DB\MigrationException
+ */
+ public function testDuplicateKeyUpgrade() {
+ if ($this->isSQLite()) {
+ $this->markTestSkipped('sqlite doesnt throw errors when creating a new key on existing data');
+ }
+ list($startSchema, $endSchema) = $this->getDuplicateKeySchemas();
+ $migrator = $this->getMigrator();
+ $migrator->migrate($startSchema);
+
+ $this->connection->insert($this->tableName, array('id' => 1, 'name' => 'foo'));
+ $this->connection->insert($this->tableName, array('id' => 2, 'name' => 'bar'));
+ $this->connection->insert($this->tableName, array('id' => 2, 'name' => 'qwerty'));
+
+ $migrator->checkMigrate($endSchema);
+ $this->fail('checkMigrate should have failed');
+ }
+
+ public function testUpgrade() {
+ list($startSchema, $endSchema) = $this->getDuplicateKeySchemas();
+ $migrator = $this->getMigrator();
+ $migrator->migrate($startSchema);
+
+ $this->connection->insert($this->tableName, array('id' => 1, 'name' => 'foo'));
+ $this->connection->insert($this->tableName, array('id' => 2, 'name' => 'bar'));
+ $this->connection->insert($this->tableName, array('id' => 3, 'name' => 'qwerty'));
+
+ $migrator->checkMigrate($endSchema);
+ $migrator->migrate($endSchema);
+ $this->assertTrue(true);
+ }
+
+ public function testInsertAfterUpgrade() {
+ list($startSchema, $endSchema) = $this->getDuplicateKeySchemas();
+ $migrator = $this->getMigrator();
+ $migrator->migrate($startSchema);
+
+ $migrator->migrate($endSchema);
+
+ $this->connection->insert($this->tableName, array('id' => 1, 'name' => 'foo'));
+ $this->connection->insert($this->tableName, array('id' => 2, 'name' => 'bar'));
+ try {
+ $this->connection->insert($this->tableName, array('id' => 2, 'name' => 'qwerty'));
+ $this->fail('Expected duplicate key insert to fail');
+ } catch (DBALException $e) {
+ $this->assertTrue(true);
+ }
+ }
+}
diff --git a/tests/lib/files/cache/changepropagator.php b/tests/lib/files/cache/changepropagator.php
new file mode 100644
index 00000000000..9beff27d50e
--- /dev/null
+++ b/tests/lib/files/cache/changepropagator.php
@@ -0,0 +1,72 @@
+<?php
+/**
+ * Copyright (c) 2014 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;
+use OC\Files\Storage\Temporary;
+use OC\Files\View;
+
+class ChangePropagator extends \PHPUnit_Framework_TestCase {
+ /**
+ * @var \OC\Files\Cache\ChangePropagator
+ */
+ private $propagator;
+
+ /**
+ * @var \OC\Files\View
+ */
+ private $view;
+
+ public function setUp() {
+ $storage = new Temporary(array());
+ $root = '/' . uniqid();
+ Filesystem::mount($storage, array(), $root);
+ $this->view = new View($root);
+ $this->propagator = new \OC\Files\Cache\ChangePropagator($this->view);
+ }
+
+ public function testGetParentsSingle() {
+ $this->propagator->addChange('/foo/bar/asd');
+ $this->assertEquals(array('/', '/foo', '/foo/bar'), $this->propagator->getAllParents());
+ }
+
+ public function testGetParentsMultiple() {
+ $this->propagator->addChange('/foo/bar/asd');
+ $this->propagator->addChange('/foo/qwerty');
+ $this->propagator->addChange('/foo/asd/bar');
+ $this->assertEquals(array('/', '/foo', '/foo/bar', '/foo/asd'), $this->propagator->getAllParents());
+ }
+
+ public function testSinglePropagate() {
+ $this->view->mkdir('/foo');
+ $this->view->mkdir('/foo/bar');
+ $this->view->file_put_contents('/foo/bar/sad.txt', 'qwerty');
+
+ $oldInfo1 = $this->view->getFileInfo('/');
+ $oldInfo2 = $this->view->getFileInfo('/foo');
+ $oldInfo3 = $this->view->getFileInfo('/foo/bar');
+
+ $time = time() + 50;
+
+ $this->propagator->addChange('/foo/bar/sad.txt');
+ $this->propagator->propagateChanges($time);
+
+ $newInfo1 = $this->view->getFileInfo('/');
+ $newInfo2 = $this->view->getFileInfo('/foo');
+ $newInfo3 = $this->view->getFileInfo('/foo/bar');
+
+ $this->assertEquals($newInfo1->getMTime(), $time);
+ $this->assertEquals($newInfo2->getMTime(), $time);
+ $this->assertEquals($newInfo3->getMTime(), $time);
+
+ $this->assertNotEquals($oldInfo1->getEtag(), $newInfo1->getEtag());
+ $this->assertNotEquals($oldInfo2->getEtag(), $newInfo2->getEtag());
+ $this->assertNotEquals($oldInfo3->getEtag(), $newInfo3->getEtag());
+ }
+}
diff --git a/tests/lib/files/cache/permissions.php b/tests/lib/files/cache/permissions.php
deleted file mode 100644
index 4b284c2c8e2..00000000000
--- a/tests/lib/files/cache/permissions.php
+++ /dev/null
@@ -1,75 +0,0 @@
-<?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\Storage\Temporary;
-
-class Permissions extends \PHPUnit_Framework_TestCase {
- /***
- * @var \OC\Files\Cache\Permissions $permissionsCache
- */
- private $permissionsCache;
-
- function setUp() {
- $this->permissionsCache = new \OC\Files\Cache\Permissions('dummy');
- }
-
- function testSimple() {
- $ids = range(1, 10);
- $user = uniqid();
-
- $this->assertEquals(-1, $this->permissionsCache->get(1, $user));
- $this->assertNotContains($user, $this->permissionsCache->getUsers(1));
- $this->permissionsCache->set(1, $user, 1);
- $this->assertEquals(1, $this->permissionsCache->get(1, $user));
- $this->assertContains($user, $this->permissionsCache->getUsers(1));
- $this->assertEquals(-1, $this->permissionsCache->get(2, $user));
- $this->assertEquals(-1, $this->permissionsCache->get(1, $user . '2'));
-
- $this->permissionsCache->set(1, $user, 2);
- $this->assertEquals(2, $this->permissionsCache->get(1, $user));
-
- $this->permissionsCache->set(2, $user, 1);
- $this->assertEquals(1, $this->permissionsCache->get(2, $user));
-
- $this->permissionsCache->remove(1, $user);
- $this->assertEquals(-1, $this->permissionsCache->get(1, $user));
- $this->permissionsCache->remove(1, $user . '2');
- $this->assertEquals(1, $this->permissionsCache->get(2, $user));
-
- $expected = array();
- foreach ($ids as $id) {
- $this->permissionsCache->set($id, $user, 10 + $id);
- $expected[$id] = 10 + $id;
- }
- $this->assertEquals($expected, $this->permissionsCache->getMultiple($ids, $user));
-
- $this->permissionsCache->removeMultiple(array(10, 9), $user);
- unset($expected[9]);
- unset($expected[10]);
- $this->assertEquals($expected, $this->permissionsCache->getMultiple($ids, $user));
-
- $this->permissionsCache->removeMultiple($ids, $user);
- }
-
- public function testUpdatePermissionsOnRescan() {
- $storage = new Temporary(array());
- $scanner = $storage->getScanner();
- $cache = $storage->getCache();
- $permissionsCache = $storage->getPermissionsCache();
-
- $storage->file_put_contents('foo.txt', 'bar');
- $scanner->scan('');
- $id = $cache->getId('foo.txt');
- $permissionsCache->set($id, 'test', 1);
-
- $scanner->scan('');
- $this->assertEquals(-1, $permissionsCache->get($id, 'test'));
- }
-}
diff --git a/tests/lib/files/cache/scanner.php b/tests/lib/files/cache/scanner.php
index fb06f2dff3d..263e5b3445f 100644
--- a/tests/lib/files/cache/scanner.php
+++ b/tests/lib/files/cache/scanner.php
@@ -33,8 +33,6 @@ class Scanner extends \PHPUnit_Framework_TestCase {
function tearDown() {
if ($this->cache) {
$ids = $this->cache->getAll();
- $permissionsCache = $this->storage->getPermissionsCache();
- $permissionsCache->removeMultiple($ids, \OC_User::getUser());
$this->cache->clear();
}
}
@@ -234,13 +232,5 @@ class Scanner extends \PHPUnit_Framework_TestCase {
$newData0 = $this->cache->get('folder/bar.txt');
$this->assertInternalType('string', $newData0['etag']);
$this->assertNotEmpty($newData0['etag']);
-
- $newData1 = $this->cache->get('folder');
- $this->assertInternalType('string', $newData1['etag']);
- $this->assertNotSame($data1['etag'], $newData1['etag']);
-
- $newData2 = $this->cache->get('');
- $this->assertInternalType('string', $newData2['etag']);
- $this->assertNotSame($data2['etag'], $newData2['etag']);
}
}
diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php
index e2fae0ae57f..b874e418100 100644
--- a/tests/lib/files/cache/updater.php
+++ b/tests/lib/files/cache/updater.php
@@ -328,35 +328,4 @@ class Updater extends \PHPUnit_Framework_TestCase {
$this->assertEquals($time, $cachedData['mtime']);
}
- public function testUpdatePermissionsOnRescanOnlyForUpdatedFile() {
- $permissionsCache = $this->storage->getPermissionsCache();
- $scanner = $this->storage->getScanner();
- $scanner->scan('');
- $cache = $this->storage->getCache();
- $loggedInUser = \OC_User::getUser();
- \OC_User::setUserId(self::$user);
- FileSystem::getDirectoryContent('/');
- $past = time() - 600;
- $cache->put('', array('storage_mtime' => $past));
-
- $this->assertNotEquals(-1, $permissionsCache->get($cache->getId('foo.txt'), self::$user));
- $this->assertNotEquals(-1, $permissionsCache->get($cache->getId('foo.png'), self::$user));
-
- $permissionsCache->set($cache->getId('foo.png'), self::$user, 15);
- FileSystem::file_put_contents('/foo.txt', 'asd');
-
- $this->assertEquals(-1, $permissionsCache->get($cache->getId('foo.txt'), self::$user));
- $this->assertEquals(15, $permissionsCache->get($cache->getId('foo.png'), self::$user));
-
- FileSystem::getDirectoryContent('/');
-
- $this->assertEquals(15, $permissionsCache->get($cache->getId('foo.png'), self::$user));
-
- FileSystem::file_put_contents('/qwerty.txt', 'asd');
- FileSystem::getDirectoryContent('/');
-
- $this->assertEquals(15, $permissionsCache->get($cache->getId('foo.png'), self::$user));
-
- \OC_User::setUserId($loggedInUser);
- }
}
diff --git a/tests/lib/files/cache/watcher.php b/tests/lib/files/cache/watcher.php
index 7f4f3c5ee98..22c11b9a4e0 100644
--- a/tests/lib/files/cache/watcher.php
+++ b/tests/lib/files/cache/watcher.php
@@ -23,8 +23,6 @@ class Watcher extends \PHPUnit_Framework_TestCase {
foreach ($this->storages as $storage) {
$cache = $storage->getCache();
$ids = $cache->getAll();
- $permissionsCache = $storage->getPermissionsCache();
- $permissionsCache->removeMultiple($ids, \OC_User::getUser());
$cache->clear();
}
}
diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php
index 53f528af793..930a252bcb2 100644
--- a/tests/lib/files/filesystem.php
+++ b/tests/lib/files/filesystem.php
@@ -173,7 +173,7 @@ class Filesystem extends \PHPUnit_Framework_TestCase {
$homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/');
- $this->assertInstanceOf('\OC\Files\Storage\Local', $homeMount);
+ $this->assertTrue($homeMount->instanceOfStorage('\OC\Files\Storage\Local'));
$this->assertEquals('local::' . $datadir . '/' . $userId . '/', $homeMount->getId());
}
@@ -189,7 +189,7 @@ class Filesystem extends \PHPUnit_Framework_TestCase {
$homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/');
- $this->assertInstanceOf('\OC\Files\Storage\Home', $homeMount);
+ $this->assertTrue($homeMount->instanceOfStorage('\OC\Files\Storage\Home'));
$this->assertEquals('home::' . $userId, $homeMount->getId());
\OC_User::deleteUser($userId);
@@ -214,7 +214,7 @@ class Filesystem extends \PHPUnit_Framework_TestCase {
$homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/');
- $this->assertInstanceOf('\OC\Files\Storage\Home', $homeMount);
+ $this->assertTrue($homeMount->instanceOfStorage('\OC\Files\Storage\Home'));
$this->assertEquals('local::' . $datadir . '/' . $userId . '/', $homeMount->getId());
\OC_User::deleteUser($userId);
@@ -244,7 +244,7 @@ class Filesystem extends \PHPUnit_Framework_TestCase {
\OC\Files\Filesystem::getMountPoint('/' . $userId . '/cache')
);
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath('/' . $userId . '/cache');
- $this->assertInstanceOf('\OC\Files\Storage\Home', $storage);
+ $this->assertTrue($storage->instanceOfStorage('\OC\Files\Storage\Home'));
$this->assertEquals('cache', $internalPath);
\OC_User::deleteUser($userId);
@@ -271,7 +271,7 @@ class Filesystem extends \PHPUnit_Framework_TestCase {
\OC\Files\Filesystem::getMountPoint('/' . $userId . '/cache')
);
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath('/' . $userId . '/cache');
- $this->assertInstanceOf('\OC\Files\Storage\Local', $storage);
+ $this->assertTrue($storage->instanceOfStorage('\OC\Files\Storage\Local'));
$this->assertEquals('', $internalPath);
\OC_User::deleteUser($userId);
diff --git a/tests/lib/files/mount/mount.php b/tests/lib/files/mount/mount.php
index b057204ad35..c3d33e0870b 100644
--- a/tests/lib/files/mount/mount.php
+++ b/tests/lib/files/mount/mount.php
@@ -35,7 +35,7 @@ class Mount extends \PHPUnit_Framework_TestCase {
};
$loader = new Loader();
- $loader->addStorageWrapper($wrapper);
+ $loader->addStorageWrapper('test_wrapper', $wrapper);
$storage = $this->getMockBuilder('\OC\Files\Storage\Temporary')
->disableOriginalConstructor()
diff --git a/tests/lib/files/node/folder.php b/tests/lib/files/node/folder.php
index b1589a276ba..08200f35f57 100644
--- a/tests/lib/files/node/folder.php
+++ b/tests/lib/files/node/folder.php
@@ -155,20 +155,12 @@ class Folder extends \PHPUnit_Framework_TestCase {
array('fileid' => 3, 'path' => '/bar/foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'httpd/unix-directory')
)));
- $permissionsCache = $this->getMock('\OC\Files\Cache\Permissions', array(), array('/'));
- $permissionsCache->expects($this->once())
- ->method('getDirectoryPermissions')
- ->will($this->returnValue(array(2 => \OCP\PERMISSION_ALL)));
-
$root->expects($this->once())
->method('getMountsIn')
->with('/bar/foo')
->will($this->returnValue(array()));
$storage->expects($this->any())
- ->method('getPermissionsCache')
- ->will($this->returnValue($permissionsCache));
- $storage->expects($this->any())
->method('getCache')
->will($this->returnValue($cache));
diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php
index a021d215ae5..5e5cc6ac128 100644
--- a/tests/lib/files/utils/scanner.php
+++ b/tests/lib/files/utils/scanner.php
@@ -8,6 +8,7 @@
namespace Test\Files\Utils;
+use OC\Files\Filesystem;
use OC\Files\Mount\Mount;
use OC\Files\Storage\Temporary;
@@ -27,12 +28,21 @@ class TestScanner extends \OC\Files\Utils\Scanner {
protected function getMounts($dir) {
return $this->mounts;
}
+
+ public function getPropagator() {
+ return $this->propagator;
+ }
+
+ public function setPropagator($propagator) {
+ $this->propagator = $propagator;
+ }
}
class Scanner extends \PHPUnit_Framework_TestCase {
public function testReuseExistingRoot() {
$storage = new Temporary(array());
$mount = new Mount($storage, '');
+ Filesystem::getMountManager()->addMount($mount);
$cache = $storage->getCache();
$storage->mkdir('folder');
@@ -54,6 +64,7 @@ class Scanner extends \PHPUnit_Framework_TestCase {
public function testReuseExistingFile() {
$storage = new Temporary(array());
$mount = new Mount($storage, '');
+ Filesystem::getMountManager()->addMount($mount);
$cache = $storage->getCache();
$storage->mkdir('folder');
@@ -71,4 +82,57 @@ class Scanner extends \PHPUnit_Framework_TestCase {
$new = $cache->get('folder/bar.txt');
$this->assertEquals($old, $new);
}
+
+ public function testChangePropagator() {
+ /**
+ * @var \OC\Files\Cache\ChangePropagator $propagator
+ */
+ $propagator = $this->getMock('\OC\Files\Cache\ChangePropagator', array('propagateChanges'), array(), '', false);
+
+ $storage = new Temporary(array());
+ $mount = new Mount($storage, '/foo');
+ Filesystem::getMountManager()->addMount($mount);
+ $cache = $storage->getCache();
+
+ $storage->mkdir('folder');
+ $storage->file_put_contents('foo.txt', 'qwerty');
+ $storage->file_put_contents('folder/bar.txt', 'qwerty');
+
+ $scanner = new TestScanner('');
+ $originalPropagator = $scanner->getPropagator();
+ $scanner->setPropagator($propagator);
+ $scanner->addMount($mount);
+
+ $scanner->scan('');
+
+ $changes = $propagator->getChanges();
+ $parents = $propagator->getAllParents();
+ sort($changes);
+ sort($parents);
+ $this->assertEquals(array('/foo', '/foo/folder', '/foo/folder/bar.txt', '/foo/foo.txt'), $changes);
+ $this->assertEquals(array('/', '/foo', '/foo/folder'), $parents);
+
+ $cache->put('foo.txt', array('storage_mtime' => time() - 50));
+
+ $propagator = $this->getMock('\OC\Files\Cache\ChangePropagator', array('propagateChanges'), array(), '', false);
+ $scanner->setPropagator($propagator);
+ $storage->file_put_contents('foo.txt', 'asdasd');
+
+ $scanner->scan('');
+
+ $changes = $propagator->getChanges();
+ $parents = $propagator->getAllParents();
+ $this->assertEquals(array('/foo/foo.txt'), $changes);
+ $this->assertEquals(array('/', '/foo'), $parents);
+
+ $scanner->setPropagator($originalPropagator);
+
+ $oldInfo = $cache->get('');
+ $cache->put('foo.txt', array('storage_mtime' => time() - 70));
+ $storage->file_put_contents('foo.txt', 'asdasd');
+
+ $scanner->scan('');
+ $newInfo = $cache->get('');
+ $this->assertNotEquals($oldInfo['etag'], $newInfo['etag']);
+ }
}
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index b5e4d792350..b2e0b59d8e6 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -39,8 +39,6 @@ class View extends \PHPUnit_Framework_TestCase {
foreach ($this->storages as $storage) {
$cache = $storage->getCache();
$ids = $cache->getAll();
- $permissionsCache = $storage->getPermissionsCache();
- $permissionsCache->removeMultiple($ids, \OC_User::getUser());
$cache->clear();
}
}
@@ -52,14 +50,18 @@ class View extends \PHPUnit_Framework_TestCase {
$storage1 = $this->getTestStorage();
$storage2 = $this->getTestStorage();
$storage3 = $this->getTestStorage();
- \OC\Files\Filesystem::mount($storage1, array(), '/');
- \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
- \OC\Files\Filesystem::mount($storage3, array(), '/folder/anotherstorage');
+ $root = '/' . uniqid();
+ \OC\Files\Filesystem::mount($storage1, array(), $root . '/');
+ \OC\Files\Filesystem::mount($storage2, array(), $root . '/substorage');
+ \OC\Files\Filesystem::mount($storage3, array(), $root . '/folder/anotherstorage');
$textSize = strlen("dummy file data\n");
$imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
$storageSize = $textSize * 2 + $imageSize;
- $rootView = new \OC\Files\View('');
+ $storageInfo = $storage3->getCache()->get('');
+ $this->assertEquals($storageSize, $storageInfo['size']);
+
+ $rootView = new \OC\Files\View($root);
$cachedData = $rootView->getFileInfo('/foo.txt');
$this->assertEquals($textSize, $cachedData['size']);
@@ -110,7 +112,7 @@ class View extends \PHPUnit_Framework_TestCase {
$this->assertEquals('foo.png', $folderData[1]['name']);
$this->assertEquals('foo.txt', $folderData[2]['name']);
- $folderView = new \OC\Files\View('/folder');
+ $folderView = new \OC\Files\View($root . '/folder');
$this->assertEquals($rootView->getFileInfo('/folder'), $folderView->getFileInfo('/'));
$cachedData = $rootView->getFileInfo('/foo.txt');
@@ -580,9 +582,9 @@ class View extends \PHPUnit_Framework_TestCase {
$longPath = '';
// 4000 is the maximum path length in file_cache.path
$folderName = 'abcdefghijklmnopqrstuvwxyz012345678901234567890123456789';
- $depth = (4000/57);
- foreach (range(0, $depth-1) as $i) {
- $longPath .= '/'.$folderName;
+ $depth = (4000 / 57);
+ foreach (range(0, $depth - 1) as $i) {
+ $longPath .= '/' . $folderName;
$result = $rootView->mkdir($longPath);
$this->assertTrue($result, "mkdir failed on $i - path length: " . strlen($longPath));
@@ -598,7 +600,7 @@ class View extends \PHPUnit_Framework_TestCase {
$scanner->scan('');
$longPath = $folderName;
- foreach (range(0, $depth-1) as $i) {
+ foreach (range(0, $depth - 1) as $i) {
$cachedFolder = $cache->get($longPath);
$this->assertTrue(is_array($cachedFolder), "No cache entry for folder at $i");
$this->assertEquals($folderName, $cachedFolder['name'], "Wrong cache entry for folder at $i");
@@ -652,14 +654,14 @@ class View extends \PHPUnit_Framework_TestCase {
* @dataProvider tooLongPathDataProvider
* @expectedException \OCP\Files\InvalidPathException
*/
- public function testTooLongPath($operation, $param0 = NULL) {
+ public function testTooLongPath($operation, $param0 = null) {
$longPath = '';
// 4000 is the maximum path length in file_cache.path
$folderName = 'abcdefghijklmnopqrstuvwxyz012345678901234567890123456789';
- $depth = (4000/57);
- foreach (range(0, $depth+1) as $i) {
- $longPath .= '/'.$folderName;
+ $depth = (4000 / 57);
+ foreach (range(0, $depth + 1) as $i) {
+ $longPath .= '/' . $folderName;
}
$storage = new \OC\Files\Storage\Temporary(array());
diff --git a/tests/lib/helperstorage.php b/tests/lib/helperstorage.php
index 010a54e3bb0..4fdd9dd6b9b 100644
--- a/tests/lib/helperstorage.php
+++ b/tests/lib/helperstorage.php
@@ -15,35 +15,78 @@ class Test_Helper_Storage extends PHPUnit_Framework_TestCase {
public function setUp() {
$this->user = 'user_' . uniqid();
+ \OC_User::createUser($this->user, $this->user);
+
\OC\Files\Filesystem::tearDown();
+ \OC_User::setUserId($this->user);
\OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files');
+ \OC\Files\Filesystem::clearMounts();
+
+ $this->storageMock = null;
+ }
+
+ public function tearDown() {
+ $this->user = null;
+ if ($this->storageMock) {
+ $this->storageMock->getCache()->clear();
+ $this->storageMock = null;
+ }
+ \OC\Files\Filesystem::tearDown();
+
+ \OC_User::setUserId('');
+ \OC_User::deleteUser($this->user);
+ \OC_Preferences::deleteUser($this->user);
+ }
+
+ /**
+ * Returns a storage mock that returns the given value as
+ * free space
+ *
+ * @param int $freeSpace free space value
+ * @return \OC\Files\Storage\Storage
+ */
+ private function getStorageMock($freeSpace = 12) {
$this->storageMock = $this->getMock(
'\OC\Files\Storage\Temporary',
array('free_space'),
array('')
);
- \OC\Files\Filesystem::clearMounts();
$this->storageMock->expects($this->once())
->method('free_space')
->will($this->returnValue(12));
+ return $this->storageMock;
}
- public function tearDown() {
- $this->user = null;
+ /**
+ * Test getting the storage info
+ */
+ function testGetStorageInfo() {
+ $homeStorage = $this->getStorageMock(12);
+ \OC\Files\Filesystem::mount($homeStorage, array(), '/' . $this->user . '/files');
+ $homeStorage->file_put_contents('test.txt', '01234');
- $this->storageMock->getCache()->clear();
- \OC\Files\Filesystem::tearDown();
+ $storageInfo = \OC_Helper::getStorageInfo('');
+ $this->assertEquals(12, $storageInfo['free']);
+ $this->assertEquals(5, $storageInfo['used']);
+ $this->assertEquals(17, $storageInfo['total']);
}
/**
- * Test getting the storage info
+ * Test getting the storage info, ignoring extra mount points
*/
- function testGetStorageInfo() {
- \OC\Files\Filesystem::mount($this->storageMock, array(), '/' . $this->user . '/files');
- $this->storageMock->file_put_contents('test.txt', '01234');
+ function testGetStorageInfoExcludingExtStorage() {
+ $homeStorage = $this->getStorageMock(12);
+ \OC\Files\Filesystem::mount($homeStorage, array(), '/' . $this->user . '/files');
+ $homeStorage->file_put_contents('test.txt', '01234');
+
+ $extStorage = new \OC\Files\Storage\Temporary(array());
+ $extStorage->file_put_contents('extfile.txt', 'abcdefghijklmnopq');
+ $extStorage->getScanner()->scan(''); // update root size
+
+ \OC\Files\Filesystem::mount($extStorage, array(), '/' . $this->user . '/files/ext');
$storageInfo = \OC_Helper::getStorageInfo('');
$this->assertEquals(12, $storageInfo['free']);
@@ -52,17 +95,75 @@ class Test_Helper_Storage extends PHPUnit_Framework_TestCase {
}
/**
+ * Test getting the storage info, including extra mount points
+ */
+ function testGetStorageInfoIncludingExtStorage() {
+ $homeStorage = new \OC\Files\Storage\Temporary(array());
+ \OC\Files\Filesystem::mount($homeStorage, array(), '/' . $this->user . '/files');
+ $homeStorage->file_put_contents('test.txt', '01234');
+
+ $extStorage = new \OC\Files\Storage\Temporary(array());
+ $extStorage->file_put_contents('extfile.txt', 'abcdefghijklmnopq');
+ $extStorage->getScanner()->scan(''); // update root size
+
+ \OC\Files\Filesystem::mount($extStorage, array(), '/' . $this->user . '/files/ext');
+
+ $oldConfig = \OC_Config::getValue('quota_include_external_storage', false);
+ \OC_Config::setValue('quota_include_external_storage', 'true');
+
+ $config = \OC::$server->getConfig();
+ $userQuota = $config->setUserValue($this->user, 'files', 'quota', '25');
+
+ $storageInfo = \OC_Helper::getStorageInfo('');
+ $this->assertEquals(3, $storageInfo['free']);
+ $this->assertEquals(22, $storageInfo['used']);
+ $this->assertEquals(25, $storageInfo['total']);
+
+ \OC_Config::setValue('quota_include_external_storage', $oldConfig);
+ $userQuota = $config->setUserValue($this->user, 'files', 'quota', 'default');
+ }
+
+ /**
+ * Test getting the storage info excluding extra mount points
+ * when user has no quota set, even when quota ext storage option
+ * was set
+ */
+ function testGetStorageInfoIncludingExtStorageWithNoUserQuota() {
+ $homeStorage = $this->getStorageMock(12);
+ \OC\Files\Filesystem::mount($homeStorage, array(), '/' . $this->user . '/files');
+ $homeStorage->file_put_contents('test.txt', '01234');
+
+ $extStorage = new \OC\Files\Storage\Temporary(array());
+ $extStorage->file_put_contents('extfile.txt', 'abcdefghijklmnopq');
+ $extStorage->getScanner()->scan(''); // update root size
+
+ \OC\Files\Filesystem::mount($extStorage, array(), '/' . $this->user . '/files/ext');
+
+ $oldConfig = \OC_Config::getValue('quota_include_external_storage', false);
+ \OC_Config::setValue('quota_include_external_storage', 'true');
+
+ $storageInfo = \OC_Helper::getStorageInfo('');
+ $this->assertEquals(12, $storageInfo['free']);
+ $this->assertEquals(5, $storageInfo['used']);
+ $this->assertEquals(17, $storageInfo['total']);
+
+ \OC_Config::setValue('quota_include_external_storage', $oldConfig);
+ }
+
+
+ /**
* Test getting the storage info with quota enabled
*/
function testGetStorageInfoWithQuota() {
- $this->storageMock->file_put_contents('test.txt', '01234');
- $this->storageMock = new \OC\Files\Storage\Wrapper\Quota(
+ $homeStorage = $this->getStorageMock(12);
+ $homeStorage->file_put_contents('test.txt', '01234');
+ $homeStorage = new \OC\Files\Storage\Wrapper\Quota(
array(
- 'storage' => $this->storageMock,
+ 'storage' => $homeStorage,
'quota' => 7
)
);
- \OC\Files\Filesystem::mount($this->storageMock, array(), '/' . $this->user . '/files');
+ \OC\Files\Filesystem::mount($homeStorage, array(), '/' . $this->user . '/files');
$storageInfo = \OC_Helper::getStorageInfo('');
$this->assertEquals(2, $storageInfo['free']);
@@ -74,14 +175,15 @@ class Test_Helper_Storage extends PHPUnit_Framework_TestCase {
* Test getting the storage info when data exceeds quota
*/
function testGetStorageInfoWhenSizeExceedsQuota() {
- $this->storageMock->file_put_contents('test.txt', '0123456789');
- $this->storageMock = new \OC\Files\Storage\Wrapper\Quota(
+ $homeStorage = $this->getStorageMock(12);
+ $homeStorage->file_put_contents('test.txt', '0123456789');
+ $homeStorage = new \OC\Files\Storage\Wrapper\Quota(
array(
- 'storage' => $this->storageMock,
+ 'storage' => $homeStorage,
'quota' => 7
)
);
- \OC\Files\Filesystem::mount($this->storageMock, array(), '/' . $this->user . '/files');
+ \OC\Files\Filesystem::mount($homeStorage, array(), '/' . $this->user . '/files');
$storageInfo = \OC_Helper::getStorageInfo('');
$this->assertEquals(0, $storageInfo['free']);
@@ -95,14 +197,15 @@ class Test_Helper_Storage extends PHPUnit_Framework_TestCase {
* free storage space is less than the quota
*/
function testGetStorageInfoWhenFreeSpaceLessThanQuota() {
- $this->storageMock->file_put_contents('test.txt', '01234');
- $this->storageMock = new \OC\Files\Storage\Wrapper\Quota(
+ $homeStorage = $this->getStorageMock(12);
+ $homeStorage->file_put_contents('test.txt', '01234');
+ $homeStorage = new \OC\Files\Storage\Wrapper\Quota(
array(
- 'storage' => $this->storageMock,
+ 'storage' => $homeStorage,
'quota' => 18
)
);
- \OC\Files\Filesystem::mount($this->storageMock, array(), '/' . $this->user . '/files');
+ \OC\Files\Filesystem::mount($homeStorage, array(), '/' . $this->user . '/files');
$storageInfo = \OC_Helper::getStorageInfo('');
$this->assertEquals(12, $storageInfo['free']);
diff --git a/tests/lib/util.php b/tests/lib/util.php
index 0bafb96cabd..aaa47f033de 100644
--- a/tests/lib/util.php
+++ b/tests/lib/util.php
@@ -154,7 +154,7 @@ class Test_Util extends PHPUnit_Framework_TestCase {
$userMount = \OC\Files\Filesystem::getMountManager()->find('/' . $user1 . '/');
$this->assertNotNull($userMount);
- $this->assertInstanceOf('\OC\Files\Storage\Wrapper\Quota', $userMount->getStorage());
+ $this->assertTrue($userMount->getStorage()->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota'));
// ensure that root wasn't wrapped
$rootMount = \OC\Files\Filesystem::getMountManager()->find('/');