diff options
author | Florin Peter <github@florin-peter.de> | 2013-05-15 03:22:06 +0200 |
---|---|---|
committer | Florin Peter <github@florin-peter.de> | 2013-05-15 03:22:06 +0200 |
commit | 226aec8d5602e112c413f8c0548b18c737a65a02 (patch) | |
tree | aa745db7ea720bfd25ab8d890167885d1c505db4 /tests | |
parent | d017bbb065245212e8aa4091f4bee0a4e8ea9055 (diff) | |
parent | 6a788d1a545d5e0dcd6df6ec3c144fa593cf40c8 (diff) | |
download | nextcloud-server-226aec8d5602e112c413f8c0548b18c737a65a02.tar.gz nextcloud-server-226aec8d5602e112c413f8c0548b18c737a65a02.zip |
Merge branch 'master' into files_encryption
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/autoloader.php | 65 | ||||
-rw-r--r-- | tests/lib/files/cache/cache.php | 7 | ||||
-rw-r--r-- | tests/lib/files/cache/permissions.php | 6 | ||||
-rw-r--r-- | tests/lib/files/cache/updater.php | 9 | ||||
-rw-r--r-- | tests/lib/files/mount.php | 58 | ||||
-rw-r--r-- | tests/lib/files/mount/manager.php | 67 | ||||
-rw-r--r-- | tests/lib/public/contacts.php | 2 | ||||
-rw-r--r-- | tests/lib/streamwrappers.php | 4 | ||||
-rw-r--r-- | tests/lib/template.php | 7 |
9 files changed, 145 insertions, 80 deletions
diff --git a/tests/lib/autoloader.php b/tests/lib/autoloader.php index e769bf3bcf6..0e7d606ccf6 100644 --- a/tests/lib/autoloader.php +++ b/tests/lib/autoloader.php @@ -6,14 +6,69 @@ * See the COPYING-README file. */ -class Test_AutoLoader extends PHPUnit_Framework_TestCase { +namespace Test; - public function testLeadingSlashOnClassName(){ - $this->assertTrue(class_exists('\OC\Files\Storage\Local')); +class AutoLoader extends \PHPUnit_Framework_TestCase { + /** + * @var \OC\Autoloader $loader + */ + private $loader; + + public function setUp() { + $this->loader = new \OC\AutoLoader(); + } + + public function testLeadingSlashOnClassName() { + $this->assertEquals(array('files/storage/local.php'), $this->loader->findClass('\OC\Files\Storage\Local')); + } + + public function testNoLeadingSlashOnClassName() { + $this->assertEquals(array('files/storage/local.php'), $this->loader->findClass('OC\Files\Storage\Local')); + } + + public function testLegacyPath() { + $this->assertEquals(array('legacy/files.php', 'files.php'), $this->loader->findClass('OC_Files')); + } + + public function testClassPath() { + $this->loader->registerClass('Foo\Bar', 'foobar.php'); + $this->assertEquals(array('foobar.php'), $this->loader->findClass('Foo\Bar')); + } + + public function testPrefixNamespace() { + $this->loader->registerPrefix('Foo', 'foo'); + $this->assertEquals(array('foo/Foo/Bar.php'), $this->loader->findClass('Foo\Bar')); } - public function testNoLeadingSlashOnClassName(){ - $this->assertTrue(class_exists('OC\Files\Storage\Local')); + public function testPrefix() { + $this->loader->registerPrefix('Foo_', 'foo'); + $this->assertEquals(array('foo/Foo/Bar.php'), $this->loader->findClass('Foo_Bar')); } + public function testLoadTestNamespace() { + $this->assertEquals(array('tests/lib/foo/bar.php'), $this->loader->findClass('Test\Foo\Bar')); + } + + public function testLoadTest() { + $this->assertEquals(array('tests/lib/foo/bar.php'), $this->loader->findClass('Test_Foo_Bar')); + } + + public function testLoadCoreNamespace() { + $this->assertEquals(array('foo/bar.php'), $this->loader->findClass('OC\Foo\Bar')); + } + + public function testLoadCore() { + $this->assertEquals(array('legacy/foo/bar.php', 'foo/bar.php'), $this->loader->findClass('OC_Foo_Bar')); + } + + public function testLoadPublicNamespace() { + $this->assertEquals(array('public/foo/bar.php'), $this->loader->findClass('OCP\Foo\Bar')); + } + + public function testLoadAppNamespace() { + $result = $this->loader->findClass('OCA\Files\Foobar'); + $this->assertEquals(2, count($result)); + $this->assertStringEndsWith('apps/files/foobar.php', $result[0]); + $this->assertStringEndsWith('apps/files/lib/foobar.php', $result[1]); + } } diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php index 250842805e5..4051a6e234b 100644 --- a/tests/lib/files/cache/cache.php +++ b/tests/lib/files/cache/cache.php @@ -162,10 +162,11 @@ class Cache extends \PHPUnit_Framework_TestCase { $file4 = 'folder/foo/1'; $file5 = 'folder/foo/2'; $data = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/bar'); + $folderData = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'); - $this->cache->put($file1, $data); - $this->cache->put($file2, $data); - $this->cache->put($file3, $data); + $this->cache->put($file1, $folderData); + $this->cache->put($file2, $folderData); + $this->cache->put($file3, $folderData); $this->cache->put($file4, $data); $this->cache->put($file5, $data); diff --git a/tests/lib/files/cache/permissions.php b/tests/lib/files/cache/permissions.php index 56dbbc4518e..7e6e11e2eb2 100644 --- a/tests/lib/files/cache/permissions.php +++ b/tests/lib/files/cache/permissions.php @@ -14,8 +14,8 @@ class Permissions extends \PHPUnit_Framework_TestCase { */ private $permissionsCache; - function setUp(){ - $this->permissionsCache=new \OC\Files\Cache\Permissions('dummy'); + function setUp() { + $this->permissionsCache = new \OC\Files\Cache\Permissions('dummy'); } function testSimple() { @@ -23,8 +23,10 @@ class Permissions extends \PHPUnit_Framework_TestCase { $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')); diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php index aaf932c97fe..dad3cd7e650 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -42,14 +42,11 @@ class Updater extends \PHPUnit_Framework_TestCase { $this->scanner->scan(''); $this->cache = $this->storage->getCache(); + \OC\Files\Filesystem::tearDown(); if (!self::$user) { - if (!\OC\Files\Filesystem::getView()) { - self::$user = uniqid(); - \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files'); - } else { - self::$user = \OC_User::getUser(); - } + self::$user = uniqid(); } + \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files'); Filesystem::clearMounts(); Filesystem::mount($this->storage, array(), '/' . self::$user . '/files'); diff --git a/tests/lib/files/mount.php b/tests/lib/files/mount.php deleted file mode 100644 index a3dc06cc668..00000000000 --- a/tests/lib/files/mount.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php -/** - * Copyright (c) 2013 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; - -use \OC\Files\Storage\Temporary; - -class LongId extends Temporary { - public function getId() { - return 'long:' . str_repeat('foo', 50) . parent::getId(); - } -} - -class Mount extends \PHPUnit_Framework_TestCase { - public function setup() { - \OC_Util::setupFS(); - \OC\Files\Mount::clear(); - } - - public function testFind() { - $this->assertNull(\OC\Files\Mount::find('/')); - - $rootMount = new \OC\Files\Mount(new Temporary(array()), '/'); - $this->assertEquals($rootMount, \OC\Files\Mount::find('/')); - $this->assertEquals($rootMount, \OC\Files\Mount::find('/foo/bar')); - - $storage = new Temporary(array()); - $mount = new \OC\Files\Mount($storage, '/foo'); - $this->assertEquals($rootMount, \OC\Files\Mount::find('/')); - $this->assertEquals($mount, \OC\Files\Mount::find('/foo/bar')); - - $this->assertEquals(1, count(\OC\Files\Mount::findIn('/'))); - new \OC\Files\Mount(new Temporary(array()), '/bar'); - $this->assertEquals(2, count(\OC\Files\Mount::findIn('/'))); - - $id = $mount->getStorageId(); - $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId($id)); - - $mount2 = new \OC\Files\Mount($storage, '/foo/bar'); - $this->assertEquals(array($mount, $mount2), \OC\Files\Mount::findByStorageId($id)); - } - - public function testLong() { - $storage = new LongId(array()); - $mount = new \OC\Files\Mount($storage, '/foo'); - - $id = $mount->getStorageId(); - $storageId = $storage->getId(); - $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId($id)); - $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId($storageId)); - $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId(md5($storageId))); - } -} diff --git a/tests/lib/files/mount/manager.php b/tests/lib/files/mount/manager.php new file mode 100644 index 00000000000..154c35ccead --- /dev/null +++ b/tests/lib/files/mount/manager.php @@ -0,0 +1,67 @@ +<?php +/** + * Copyright (c) 2013 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\Mount; + +use \OC\Files\Storage\Temporary; + +class LongId extends Temporary { + public function getId() { + return 'long:' . str_repeat('foo', 50) . parent::getId(); + } +} + +class Manager extends \PHPUnit_Framework_TestCase { + /** + * @var \OC\Files\Mount\Manager + */ + private $manager; + + public function setup() { + $this->manager = new \OC\Files\Mount\Manager(); + } + + public function testFind() { + $this->assertNull($this->manager->find('/')); + + $rootMount = new \OC\Files\Mount\Mount(new Temporary(array()), '/'); + $this->manager->addMount($rootMount); + $this->assertEquals($rootMount, $this->manager->find('/')); + $this->assertEquals($rootMount, $this->manager->find('/foo/bar')); + + $storage = new Temporary(array()); + $mount1 = new \OC\Files\Mount\Mount($storage, '/foo'); + $this->manager->addMount($mount1); + $this->assertEquals($rootMount, $this->manager->find('/')); + $this->assertEquals($mount1, $this->manager->find('/foo/bar')); + + $this->assertEquals(1, count($this->manager->findIn('/'))); + $mount2 = new \OC\Files\Mount\Mount(new Temporary(array()), '/bar'); + $this->manager->addMount($mount2); + $this->assertEquals(2, count($this->manager->findIn('/'))); + + $id = $mount1->getStorageId(); + $this->assertEquals(array($mount1), $this->manager->findByStorageId($id)); + + $mount3 = new \OC\Files\Mount\Mount($storage, '/foo/bar'); + $this->manager->addMount($mount3); + $this->assertEquals(array($mount1, $mount3), $this->manager->findByStorageId($id)); + } + + public function testLong() { + $storage = new LongId(array()); + $mount = new \OC\Files\Mount\Mount($storage, '/foo'); + $this->manager->addMount($mount); + + $id = $mount->getStorageId(); + $storageId = $storage->getId(); + $this->assertEquals(array($mount), $this->manager->findByStorageId($id)); + $this->assertEquals(array($mount), $this->manager->findByStorageId($storageId)); + $this->assertEquals(array($mount), $this->manager->findByStorageId(md5($storageId))); + } +} diff --git a/tests/lib/public/contacts.php b/tests/lib/public/contacts.php index ce5d762226b..d6008876a00 100644 --- a/tests/lib/public/contacts.php +++ b/tests/lib/public/contacts.php @@ -19,8 +19,6 @@ * License along with this library. If not, see <http://www.gnu.org/licenses/>. */ -OC::autoload('OCP\Contacts'); - class Test_Contacts extends PHPUnit_Framework_TestCase { diff --git a/tests/lib/streamwrappers.php b/tests/lib/streamwrappers.php index 2237ee7d378..c7e51ccfa48 100644 --- a/tests/lib/streamwrappers.php +++ b/tests/lib/streamwrappers.php @@ -77,10 +77,10 @@ class Test_StreamWrappers extends PHPUnit_Framework_TestCase { } public function testOC() { - \OC\Files\Mount::clear(); + \OC\Files\Filesystem::clearMounts(); $storage = new \OC\Files\Storage\Temporary(array()); $storage->file_put_contents('foo.txt', 'asd'); - new \OC\Files\Mount($storage, '/'); + \OC\Files\Filesystem::mount($storage, array(), '/'); $this->assertTrue(file_exists('oc:///foo.txt')); $this->assertEquals('asd', file_get_contents('oc:///foo.txt')); diff --git a/tests/lib/template.php b/tests/lib/template.php index 6e88d4c07fc..fd12119da58 100644 --- a/tests/lib/template.php +++ b/tests/lib/template.php @@ -20,10 +20,13 @@ * */ -OC::autoload('OC_Template'); - class Test_TemplateFunctions extends PHPUnit_Framework_TestCase { + public function setUp() { + $loader = new \OC\Autoloader(); + $loader->load('OC_Template'); + } + public function testP() { // FIXME: do we need more testcases? $htmlString = "<script>alert('xss');</script>"; |