diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-07-30 00:34:36 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-07-30 00:34:36 +0200 |
commit | 7425efade78a04f20cb3cc83f964c6a00094b6ce (patch) | |
tree | 967aa50e8873c88f0adf6f91d0285ab1c54b7189 /tests | |
parent | b4a523927823ab8bc80c5f1fc0d5bd5ef61f8eb8 (diff) | |
parent | 7c6246fa451c4646dfaa1396dd37e0b3eb9706ba (diff) | |
download | nextcloud-server-7425efade78a04f20cb3cc83f964c6a00094b6ce.tar.gz nextcloud-server-7425efade78a04f20cb3cc83f964c6a00094b6ce.zip |
Merge branch 'master' into oc_preview
Conflicts:
3rdparty
lib/template.php
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/cache/apc.php | 35 | ||||
-rw-r--r-- | tests/lib/cache/xcache.php | 31 | ||||
-rw-r--r-- | tests/lib/config.php | 85 | ||||
-rw-r--r-- | tests/lib/db.php | 4 | ||||
-rw-r--r-- | tests/lib/files/storage/storage.php | 61 | ||||
-rw-r--r-- | tests/lib/files/view.php | 9 | ||||
-rw-r--r-- | tests/lib/group.php | 108 | ||||
-rw-r--r-- | tests/lib/group/group.php | 316 | ||||
-rw-r--r-- | tests/lib/group/manager.php | 313 | ||||
-rw-r--r-- | tests/lib/helper.php | 60 | ||||
-rw-r--r-- | tests/lib/hooks/forwardingemitter.php | 74 | ||||
-rw-r--r-- | tests/lib/memcache/apc.php | 24 | ||||
-rw-r--r-- | tests/lib/memcache/apcu.php | 20 | ||||
-rw-r--r-- | tests/lib/memcache/cache.php | 58 | ||||
-rw-r--r-- | tests/lib/memcache/memcached.php | 20 | ||||
-rw-r--r-- | tests/lib/memcache/xcache.php | 20 | ||||
-rw-r--r-- | tests/lib/template/resourcelocator.php | 69 | ||||
-rw-r--r-- | tests/phpunit-autotest.xml | 1 |
18 files changed, 1140 insertions, 168 deletions
diff --git a/tests/lib/cache/apc.php b/tests/lib/cache/apc.php deleted file mode 100644 index bb5eb483dbf..00000000000 --- a/tests/lib/cache/apc.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php -/** -* ownCloud -* -* @author Robin Appelman -* @copyright 2012 Robin Appelman icewind@owncloud.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - -class Test_Cache_APC extends Test_Cache { - public function setUp() { - if(!extension_loaded('apc')) { - $this->markTestSkipped('The apc extension is not available.'); - return; - } - if(!ini_get('apc.enable_cli') && OC::$CLI) { - $this->markTestSkipped('apc not available in CLI.'); - return; - } - $this->instance=new OC_Cache_APC(); - } -} diff --git a/tests/lib/cache/xcache.php b/tests/lib/cache/xcache.php deleted file mode 100644 index 43bed2db037..00000000000 --- a/tests/lib/cache/xcache.php +++ /dev/null @@ -1,31 +0,0 @@ -<?php -/** -* ownCloud -* -* @author Robin Appelman -* @copyright 2012 Robin Appelman icewind@owncloud.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - -class Test_Cache_XCache extends Test_Cache { - public function setUp() { - if(!function_exists('xcache_get')) { - $this->markTestSkipped('The xcache extension is not available.'); - return; - } - $this->instance=new OC_Cache_XCache(); - } -} diff --git a/tests/lib/config.php b/tests/lib/config.php new file mode 100644 index 00000000000..c67a66c832e --- /dev/null +++ b/tests/lib/config.php @@ -0,0 +1,85 @@ +<?php +/** + * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class Test_Config extends PHPUnit_Framework_TestCase { + const CONFIG_FILE = 'static://config.php'; + const CONFIG_DIR = 'static://'; + const TESTCONTENT = '<?php $CONFIG=array("foo"=>"bar");'; + + /** + * @var \OC\Config + */ + private $config; + + function setUp() { + file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); + $this->config = new OC\Config(self::CONFIG_DIR); + } + + public function testReadData() { + $config = new OC\Config('/non-existing'); + $this->assertAttributeEquals(array(), 'cache', $config); + + $this->assertAttributeEquals(array('foo' => 'bar'), 'cache', $this->config); + } + + public function testGetKeys() { + $this->assertEquals(array('foo'), $this->config->getKeys()); + } + + public function testGetValue() { + $this->assertEquals('bar', $this->config->getValue('foo')); + $this->assertEquals(null, $this->config->getValue('bar')); + $this->assertEquals('moo', $this->config->getValue('bar', 'moo')); + } + + public function testSetValue() { + $this->config->setDebugMode(false); + $this->config->setValue('foo', 'moo'); + $this->assertAttributeEquals(array('foo' => 'moo'), 'cache', $this->config); + $content = file_get_contents(self::CONFIG_FILE); + + $expected = "<?php\n\$CONFIG = array (\n 'foo' => 'moo',\n);\n"; + $this->assertEquals($expected, $content); + $this->config->setValue('bar', 'red'); + $this->assertAttributeEquals(array('foo' => 'moo', 'bar' => 'red'), 'cache', $this->config); + $content = file_get_contents(self::CONFIG_FILE); + + $expected = "<?php\n\$CONFIG = array (\n 'foo' => 'moo',\n 'bar' => 'red',\n);\n"; + $this->assertEquals($expected, $content); + } + + public function testDeleteKey() { + $this->config->setDebugMode(false); + $this->config->deleteKey('foo'); + $this->assertAttributeEquals(array(), 'cache', $this->config); + $content = file_get_contents(self::CONFIG_FILE); + + $expected = "<?php\n\$CONFIG = array (\n);\n"; + $this->assertEquals($expected, $content); + } + + public function testSavingDebugMode() { + $this->config->setDebugMode(true); + $this->config->deleteKey('foo'); // change something so we save to the config file + $this->assertAttributeEquals(array(), 'cache', $this->config); + $this->assertAttributeEquals(true, 'debugMode', $this->config); + $content = file_get_contents(self::CONFIG_FILE); + + $expected = "<?php\ndefine('DEBUG',true);\n\$CONFIG = array (\n);\n"; + $this->assertEquals($expected, $content); + } + + /** + * @expectedException \OC\HintException + */ + public function testWriteData() { + $config = new OC\Config('/non-writable'); + $config->setValue('foo', 'bar'); + } +} diff --git a/tests/lib/db.php b/tests/lib/db.php index 69e3542f926..e817a2db5ed 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -37,7 +37,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { $result = $query->execute(array('uri_1')); $this->assertTrue((bool)$result); $row = $result->fetchRow(); - $this->assertFalse((bool)$row); //PDO returns false, MDB2 returns null + $this->assertFalse($row); $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (?,?)'); $result = $query->execute(array('fullname test', 'uri_1')); $this->assertEquals(1, $result); @@ -94,7 +94,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { $query = OC_DB::prepare('SELECT * FROM `*PREFIX*'.$this->table3.'`'); $result = $query->execute(); $this->assertTrue((bool)$result); - $this->assertEquals(4, $result->numRows()); + $this->assertEquals(4, count($result->fetchAll())); } public function testinsertIfNotExistDontOverwrite() { diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index fb3e05e66b3..3f339a10016 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -168,74 +168,27 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertTrue($this->instance->isReadable('/lorem.txt')); $ctimeEnd = time(); $mTime = $this->instance->filemtime('/lorem.txt'); - $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $ctimeStart - 1)); - $this->assertTrue($this->instance->hasUpdated('/', $ctimeStart - 1)); + $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $ctimeStart - 5)); + $this->assertTrue($this->instance->hasUpdated('/', $ctimeStart - 5)); - $this->assertTrue(($ctimeStart - 1) <= $mTime); + $this->assertTrue(($ctimeStart - 5) <= $mTime); $this->assertTrue($mTime <= ($ctimeEnd + 1)); $this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt')); $stat = $this->instance->stat('/lorem.txt'); - //only size and mtime are requered in the result + //only size and mtime are required in the result $this->assertEquals($stat['size'], $this->instance->filesize('/lorem.txt')); $this->assertEquals($stat['mtime'], $mTime); - $mtimeStart = time(); - $supportsTouch = $this->instance->touch('/lorem.txt'); - $mtimeEnd = time(); - if ($supportsTouch !== false) { + if ($this->instance->touch('/lorem.txt', 100) !== false) { $mTime = $this->instance->filemtime('/lorem.txt'); - $this->assertTrue(($mtimeStart - 1) <= $mTime); - $this->assertTrue($mTime <= ($mtimeEnd + 1)); - - $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $mtimeStart - 1)); - - if ($this->instance->touch('/lorem.txt', 100) !== false) { - $mTime = $this->instance->filemtime('/lorem.txt'); - $this->assertEquals($mTime, 100); - } + $this->assertEquals($mTime, 100); } $mtimeStart = time(); - $fh = $this->instance->fopen('/lorem.txt', 'a'); - fwrite($fh, ' '); - fclose($fh); - clearstatcache(); - $mtimeEnd = time(); - $mTime = $this->instance->filemtime('/lorem.txt'); - $this->assertTrue(($mtimeStart - 1) <= $mTime); - $this->assertTrue($mTime <= ($mtimeEnd + 1)); $this->instance->unlink('/lorem.txt'); - $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 1)); - } - - public function testSearch() { - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; - $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile, 'r')); - $pngFile = \OC::$SERVERROOT . '/tests/data/logo-wide.png'; - $this->instance->file_put_contents('/logo-wide.png', file_get_contents($pngFile, 'r')); - $svgFile = \OC::$SERVERROOT . '/tests/data/logo-wide.svg'; - $this->instance->file_put_contents('/logo-wide.svg', file_get_contents($svgFile, 'r')); - $result = $this->instance->search('logo'); - $this->assertEquals(2, count($result)); - $this->assertContains('/logo-wide.svg', $result); - $this->assertContains('/logo-wide.png', $result); - } - - public function testSearchInSubFolder() { - $this->instance->mkdir('sub'); - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; - $this->instance->file_put_contents('/sub/lorem.txt', file_get_contents($textFile, 'r')); - $pngFile = \OC::$SERVERROOT . '/tests/data/logo-wide.png'; - $this->instance->file_put_contents('/sub/logo-wide.png', file_get_contents($pngFile, 'r')); - $svgFile = \OC::$SERVERROOT . '/tests/data/logo-wide.svg'; - $this->instance->file_put_contents('/sub/logo-wide.svg', file_get_contents($svgFile, 'r')); - - $result = $this->instance->search('logo'); - $this->assertEquals(2, count($result)); - $this->assertContains('/sub/logo-wide.svg', $result); - $this->assertContains('/sub/logo-wide.png', $result); + $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 5)); } public function testFOpen() { diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index 830913a91ad..3bac9e770aa 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -20,10 +20,19 @@ class View extends \PHPUnit_Framework_TestCase { private $storages = array(); public function setUp() { + \OC_User::clearBackends(); + \OC_User::useBackend(new \OC_User_Dummy()); + + //login + \OC_User::createUser('test', 'test'); + $this->user=\OC_User::getUser(); + \OC_User::setUserId('test'); + \OC\Files\Filesystem::clearMounts(); } public function tearDown() { + \OC_User::setUserId($this->user); foreach ($this->storages as $storage) { $cache = $storage->getCache(); $ids = $cache->getAll(); diff --git a/tests/lib/group.php b/tests/lib/group.php index 9128bd7ddce..d2c9ce46148 100644 --- a/tests/lib/group.php +++ b/tests/lib/group.php @@ -1,56 +1,61 @@ <?php /** -* ownCloud -* -* @author Robin Appelman -* @author Bernhard Posselt -* @copyright 2012 Robin Appelman icewind@owncloud.com -* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ + * ownCloud + * + * @author Robin Appelman + * @author Bernhard Posselt + * @copyright 2012 Robin Appelman icewind@owncloud.com + * @copyright 2012 Bernhard Posselt nukeawhale@gmail.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ class Test_Group extends PHPUnit_Framework_TestCase { function setUp() { OC_Group::clearBackends(); + OC_User::clearBackends(); } function testSingleBackend() { + $userBackend = new \OC_User_Dummy(); + \OC_User::getManager()->registerBackend($userBackend); OC_Group::useBackend(new OC_Group_Dummy()); - - $group1=uniqid(); - $group2=uniqid(); + + $group1 = uniqid(); + $group2 = uniqid(); OC_Group::createGroup($group1); OC_Group::createGroup($group2); - $user1=uniqid(); - $user2=uniqid(); + $user1 = uniqid(); + $user2 = uniqid(); + $userBackend->createUser($user1, ''); + $userBackend->createUser($user2, ''); $this->assertFalse(OC_Group::inGroup($user1, $group1)); $this->assertFalse(OC_Group::inGroup($user2, $group1)); $this->assertFalse(OC_Group::inGroup($user1, $group2)); $this->assertFalse(OC_Group::inGroup($user2, $group2)); - $this->assertTrue((bool)OC_Group::addToGroup($user1, $group1)); + $this->assertTrue(OC_Group::addToGroup($user1, $group1)); $this->assertTrue(OC_Group::inGroup($user1, $group1)); $this->assertFalse(OC_Group::inGroup($user2, $group1)); $this->assertFalse(OC_Group::inGroup($user1, $group2)); $this->assertFalse(OC_Group::inGroup($user2, $group2)); - $this->assertFalse((bool)OC_Group::addToGroup($user1, $group1)); + $this->assertTrue(OC_Group::addToGroup($user1, $group1)); $this->assertEquals(array($user1), OC_Group::usersInGroup($group1)); $this->assertEquals(array(), OC_Group::usersInGroup($group2)); @@ -65,37 +70,37 @@ class Test_Group extends PHPUnit_Framework_TestCase { } - public function testNoEmptyGIDs(){ + public function testNoEmptyGIDs() { OC_Group::useBackend(new OC_Group_Dummy()); $emptyGroup = null; - $this->assertEquals(false, OC_Group::createGroup($emptyGroup)); + $this->assertFalse(OC_Group::createGroup($emptyGroup)); } - public function testNoGroupsTwice(){ + public function testNoGroupsTwice() { OC_Group::useBackend(new OC_Group_Dummy()); $group = uniqid(); OC_Group::createGroup($group); $groupCopy = $group; - $this->assertEquals(false, OC_Group::createGroup($groupCopy)); + OC_Group::createGroup($groupCopy); $this->assertEquals(array($group), OC_Group::getGroups()); } - public function testDontDeleteAdminGroup(){ + public function testDontDeleteAdminGroup() { OC_Group::useBackend(new OC_Group_Dummy()); $adminGroup = 'admin'; OC_Group::createGroup($adminGroup); - $this->assertEquals(false, OC_Group::deleteGroup($adminGroup)); + $this->assertFalse(OC_Group::deleteGroup($adminGroup)); $this->assertEquals(array($adminGroup), OC_Group::getGroups()); } - public function testDontAddUserToNonexistentGroup(){ + public function testDontAddUserToNonexistentGroup() { OC_Group::useBackend(new OC_Group_Dummy()); $groupNonExistent = 'notExistent'; $user = uniqid(); @@ -105,8 +110,11 @@ class Test_Group extends PHPUnit_Framework_TestCase { } - public function testUsersInGroup(){ + public function testUsersInGroup() { OC_Group::useBackend(new OC_Group_Dummy()); + $userBackend = new \OC_User_Dummy(); + \OC_User::getManager()->registerBackend($userBackend); + $group1 = uniqid(); $group2 = uniqid(); $group3 = uniqid(); @@ -117,27 +125,32 @@ class Test_Group extends PHPUnit_Framework_TestCase { OC_Group::createGroup($group2); OC_Group::createGroup($group3); + $userBackend->createUser($user1, ''); + $userBackend->createUser($user2, ''); + $userBackend->createUser($user3, ''); + OC_Group::addToGroup($user1, $group1); OC_Group::addToGroup($user2, $group1); OC_Group::addToGroup($user3, $group1); OC_Group::addToGroup($user3, $group2); $this->assertEquals(array($user1, $user2, $user3), - OC_Group::usersInGroups(array($group1, $group2, $group3))); + OC_Group::usersInGroups(array($group1, $group2, $group3))); // FIXME: needs more parameter variation } - function testMultiBackend() { - $backend1=new OC_Group_Dummy(); - $backend2=new OC_Group_Dummy(); + $userBackend = new \OC_User_Dummy(); + \OC_User::getManager()->registerBackend($userBackend); + $backend1 = new OC_Group_Dummy(); + $backend2 = new OC_Group_Dummy(); OC_Group::useBackend($backend1); OC_Group::useBackend($backend2); - $group1=uniqid(); - $group2=uniqid(); + $group1 = uniqid(); + $group2 = uniqid(); OC_Group::createGroup($group1); //groups should be added to the first registered backend @@ -154,20 +167,23 @@ class Test_Group extends PHPUnit_Framework_TestCase { $this->assertTrue(OC_Group::groupExists($group1)); $this->assertTrue(OC_Group::groupExists($group2)); - $user1=uniqid(); - $user2=uniqid(); + $user1 = uniqid(); + $user2 = uniqid(); + + $userBackend->createUser($user1, ''); + $userBackend->createUser($user2, ''); $this->assertFalse(OC_Group::inGroup($user1, $group1)); $this->assertFalse(OC_Group::inGroup($user2, $group1)); - $this->assertTrue((bool)OC_Group::addToGroup($user1, $group1)); + $this->assertTrue(OC_Group::addToGroup($user1, $group1)); $this->assertTrue(OC_Group::inGroup($user1, $group1)); $this->assertFalse(OC_Group::inGroup($user2, $group1)); $this->assertFalse($backend2->inGroup($user1, $group1)); - $this->assertFalse((bool)OC_Group::addToGroup($user1, $group1)); + OC_Group::addToGroup($user1, $group1); $this->assertEquals(array($user1), OC_Group::usersInGroup($group1)); diff --git a/tests/lib/group/group.php b/tests/lib/group/group.php new file mode 100644 index 00000000000..75e975d9e65 --- /dev/null +++ b/tests/lib/group/group.php @@ -0,0 +1,316 @@ +<?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\Group; + +use OC\User\User; + +class Group extends \PHPUnit_Framework_TestCase { + /** + * @return \PHPUnit_Framework_MockObject_MockObject | \OC\User\Manager + */ + protected function getUserManager() { + $userManager = $this->getMock('\OC\User\Manager'); + $user1 = new User('user1', null); + $user2 = new User('user2', null); + $user3 = new User('user3', null); + $userManager->expects($this->any()) + ->method('get') + ->will($this->returnValueMap(array( + array('user1', $user1), + array('user2', $user2), + array('user3', $user3) + ))); + return $userManager; + } + + public function testGetUsersSingleBackend() { + $backend = $this->getMock('OC_Group_Database'); + $userManager = $this->getUserManager(); + $group = new \OC\Group\Group('group1', array($backend), $userManager); + + $backend->expects($this->once()) + ->method('usersInGroup') + ->with('group1') + ->will($this->returnValue(array('user1', 'user2'))); + + $users = $group->getUsers(); + + $this->assertEquals(2, count($users)); + $user1 = $users[0]; + $user2 = $users[1]; + $this->assertEquals('user1', $user1->getUID()); + $this->assertEquals('user2', $user2->getUID()); + } + + public function testGetUsersMultipleBackends() { + $backend1 = $this->getMock('OC_Group_Database'); + $backend2 = $this->getMock('OC_Group_Database'); + $userManager = $this->getUserManager(); + $group = new \OC\Group\Group('group1', array($backend1, $backend2), $userManager); + + $backend1->expects($this->once()) + ->method('usersInGroup') + ->with('group1') + ->will($this->returnValue(array('user1', 'user2'))); + + $backend2->expects($this->once()) + ->method('usersInGroup') + ->with('group1') + ->will($this->returnValue(array('user2', 'user3'))); + + $users = $group->getUsers(); + + $this->assertEquals(3, count($users)); + $user1 = $users[0]; + $user2 = $users[1]; + $user3 = $users[2]; + $this->assertEquals('user1', $user1->getUID()); + $this->assertEquals('user2', $user2->getUID()); + $this->assertEquals('user3', $user3->getUID()); + } + + public function testInGroupSingleBackend() { + $backend = $this->getMock('OC_Group_Database'); + $userManager = $this->getUserManager(); + $group = new \OC\Group\Group('group1', array($backend), $userManager); + + $backend->expects($this->once()) + ->method('inGroup') + ->with('user1', 'group1') + ->will($this->returnValue(true)); + + $this->assertTrue($group->inGroup(new User('user1', null))); + } + + public function testInGroupMultipleBackends() { + $backend1 = $this->getMock('OC_Group_Database'); + $backend2 = $this->getMock('OC_Group_Database'); + $userManager = $this->getUserManager(); + $group = new \OC\Group\Group('group1', array($backend1, $backend2), $userManager); + + $backend1->expects($this->once()) + ->method('inGroup') + ->with('user1', 'group1') + ->will($this->returnValue(false)); + + $backend2->expects($this->once()) + ->method('inGroup') + ->with('user1', 'group1') + ->will($this->returnValue(true)); + + $this->assertTrue($group->inGroup(new User('user1', null))); + } + + public function testAddUser() { + $backend = $this->getMock('OC_Group_Database'); + $userManager = $this->getUserManager(); + $group = new \OC\Group\Group('group1', array($backend), $userManager); + + $backend->expects($this->once()) + ->method('inGroup') + ->with('user1', 'group1') + ->will($this->returnValue(false)); + $backend->expects($this->any()) + ->method('implementsActions') + ->will($this->returnValue(true)); + + $backend->expects($this->once()) + ->method('addToGroup') + ->with('user1', 'group1'); + + $group->addUser(new User('user1', null)); + } + + public function testAddUserAlreadyInGroup() { + $backend = $this->getMock('OC_Group_Database'); + $userManager = $this->getUserManager(); + $group = new \OC\Group\Group('group1', array($backend), $userManager); + + $backend->expects($this->once()) + ->method('inGroup') + ->with('user1', 'group1') + ->will($this->returnValue(true)); + $backend->expects($this->any()) + ->method('implementsActions') + ->will($this->returnValue(true)); + + $backend->expects($this->never()) + ->method('addToGroup'); + + $group->addUser(new User('user1', null)); + } + + public function testRemoveUser() { + $backend = $this->getMock('OC_Group_Database'); + $userManager = $this->getUserManager(); + $group = new \OC\Group\Group('group1', array($backend), $userManager); + + $backend->expects($this->once()) + ->method('inGroup') + ->with('user1', 'group1') + ->will($this->returnValue(true)); + $backend->expects($this->any()) + ->method('implementsActions') + ->will($this->returnValue(true)); + + $backend->expects($this->once()) + ->method('removeFromGroup') + ->with('user1', 'group1'); + + $group->removeUser(new User('user1', null)); + } + + public function testRemoveUserNotInGroup() { + $backend = $this->getMock('OC_Group_Database'); + $userManager = $this->getUserManager(); + $group = new \OC\Group\Group('group1', array($backend), $userManager); + + $backend->expects($this->once()) + ->method('inGroup') + ->with('user1', 'group1') + ->will($this->returnValue(false)); + $backend->expects($this->any()) + ->method('implementsActions') + ->will($this->returnValue(true)); + + $backend->expects($this->never()) + ->method('removeFromGroup'); + + $group->removeUser(new User('user1', null)); + } + + public function testRemoveUserMultipleBackends() { + $backend1 = $this->getMock('OC_Group_Database'); + $backend2 = $this->getMock('OC_Group_Database'); + $userManager = $this->getUserManager(); + $group = new \OC\Group\Group('group1', array($backend1, $backend2), $userManager); + + $backend1->expects($this->once()) + ->method('inGroup') + ->with('user1', 'group1') + ->will($this->returnValue(true)); + $backend1->expects($this->any()) + ->method('implementsActions') + ->will($this->returnValue(true)); + + $backend1->expects($this->once()) + ->method('removeFromGroup') + ->with('user1', 'group1'); + + $backend2->expects($this->once()) + ->method('inGroup') + ->with('user1', 'group1') + ->will($this->returnValue(true)); + $backend2->expects($this->any()) + ->method('implementsActions') + ->will($this->returnValue(true)); + + $backend2->expects($this->once()) + ->method('removeFromGroup') + ->with('user1', 'group1'); + + $group->removeUser(new User('user1', null)); + } + + public function testSearchUsers() { + $backend = $this->getMock('OC_Group_Database'); + $userManager = $this->getUserManager(); + $group = new \OC\Group\Group('group1', array($backend), $userManager); + + $backend->expects($this->once()) + ->method('usersInGroup') + ->with('group1', '2') + ->will($this->returnValue(array('user2'))); + + $users = $group->searchUsers('2'); + + $this->assertEquals(1, count($users)); + $user2 = $users[0]; + $this->assertEquals('user2', $user2->getUID()); + } + + public function testSearchUsersMultipleBackends() { + $backend1 = $this->getMock('OC_Group_Database'); + $backend2 = $this->getMock('OC_Group_Database'); + $userManager = $this->getUserManager(); + $group = new \OC\Group\Group('group1', array($backend1, $backend2), $userManager); + + $backend1->expects($this->once()) + ->method('usersInGroup') + ->with('group1', '2') + ->will($this->returnValue(array('user2'))); + $backend2->expects($this->once()) + ->method('usersInGroup') + ->with('group1', '2') + ->will($this->returnValue(array('user2'))); + + $users = $group->searchUsers('2'); + + $this->assertEquals(1, count($users)); + $user2 = $users[0]; + $this->assertEquals('user2', $user2->getUID()); + } + + public function testSearchUsersLimitAndOffset() { + $backend = $this->getMock('OC_Group_Database'); + $userManager = $this->getUserManager(); + $group = new \OC\Group\Group('group1', array($backend), $userManager); + + $backend->expects($this->once()) + ->method('usersInGroup') + ->with('group1', 'user', 1, 1) + ->will($this->returnValue(array('user2'))); + + $users = $group->searchUsers('user', 1, 1); + + $this->assertEquals(1, count($users)); + $user2 = $users[0]; + $this->assertEquals('user2', $user2->getUID()); + } + + public function testSearchUsersMultipleBackendsLimitAndOffset() { + $backend1 = $this->getMock('OC_Group_Database'); + $backend2 = $this->getMock('OC_Group_Database'); + $userManager = $this->getUserManager(); + $group = new \OC\Group\Group('group1', array($backend1, $backend2), $userManager); + + $backend1->expects($this->once()) + ->method('usersInGroup') + ->with('group1', 'user', 2, 1) + ->will($this->returnValue(array('user2'))); + $backend2->expects($this->once()) + ->method('usersInGroup') + ->with('group1', 'user', 1, 0) + ->will($this->returnValue(array('user1'))); + + $users = $group->searchUsers('user', 2, 1); + + $this->assertEquals(2, count($users)); + $user2 = $users[0]; + $user1 = $users[1]; + $this->assertEquals('user2', $user2->getUID()); + $this->assertEquals('user1', $user1->getUID()); + } + + public function testDelete() { + $backend = $this->getMock('OC_Group_Database'); + $userManager = $this->getUserManager(); + $group = new \OC\Group\Group('group1', array($backend), $userManager); + + $backend->expects($this->once()) + ->method('deleteGroup') + ->with('group1'); + $backend->expects($this->any()) + ->method('implementsActions') + ->will($this->returnValue(true)); + + $group->delete(); + } +} diff --git a/tests/lib/group/manager.php b/tests/lib/group/manager.php new file mode 100644 index 00000000000..9d3adf51a0c --- /dev/null +++ b/tests/lib/group/manager.php @@ -0,0 +1,313 @@ +<?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\Group; + +use OC\User\User; + +class Manager extends \PHPUnit_Framework_TestCase { + public function testGet() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + */ + $backend = $this->getMock('\OC_Group_Database'); + $backend->expects($this->any()) + ->method('groupExists') + ->with('group1') + ->will($this->returnValue(true)); + + /** + * @var \OC\User\Manager $userManager + */ + $userManager = $this->getMock('\OC\User\Manager'); + $manager = new \OC\Group\Manager($userManager); + $manager->addBackend($backend); + + $group = $manager->get('group1'); + $this->assertNotNull($group); + $this->assertEquals('group1', $group->getGID()); + } + + public function testGetNoBackend() { + /** + * @var \OC\User\Manager $userManager + */ + $userManager = $this->getMock('\OC\User\Manager'); + $manager = new \OC\Group\Manager($userManager); + + $this->assertNull($manager->get('group1')); + } + + public function testGetNotExists() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + */ + $backend = $this->getMock('\OC_Group_Database'); + $backend->expects($this->once()) + ->method('groupExists') + ->with('group1') + ->will($this->returnValue(false)); + + /** + * @var \OC\User\Manager $userManager + */ + $userManager = $this->getMock('\OC\User\Manager'); + $manager = new \OC\Group\Manager($userManager); + $manager->addBackend($backend); + + $this->assertNull($manager->get('group1')); + } + + public function testGetDeleted() { + $backend = new \OC_Group_Dummy(); + $backend->createGroup('group1'); + + /** + * @var \OC\User\Manager $userManager + */ + $userManager = $this->getMock('\OC\User\Manager'); + $manager = new \OC\Group\Manager($userManager); + $manager->addBackend($backend); + + $group = $manager->get('group1'); + $group->delete(); + $this->assertNull($manager->get('group1')); + } + + public function testGetMultipleBackends() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1 + */ + $backend1 = $this->getMock('\OC_Group_Database'); + $backend1->expects($this->any()) + ->method('groupExists') + ->with('group1') + ->will($this->returnValue(false)); + + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 + */ + $backend2 = $this->getMock('\OC_Group_Database'); + $backend2->expects($this->any()) + ->method('groupExists') + ->with('group1') + ->will($this->returnValue(true)); + + /** + * @var \OC\User\Manager $userManager + */ + $userManager = $this->getMock('\OC\User\Manager'); + $manager = new \OC\Group\Manager($userManager); + $manager->addBackend($backend1); + $manager->addBackend($backend2); + + $group = $manager->get('group1'); + $this->assertNotNull($group); + $this->assertEquals('group1', $group->getGID()); + } + + public function testCreate() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + */ + $backend = $this->getMock('\OC_Group_Database'); + $backend->expects($this->any()) + ->method('groupExists') + ->with('group1') + ->will($this->returnValue(false)); + $backend->expects($this->once()) + ->method('implementsActions') + ->will($this->returnValue(true)); + $backend->expects($this->once()) + ->method('createGroup'); + + /** + * @var \OC\User\Manager $userManager + */ + $userManager = $this->getMock('\OC\User\Manager'); + $manager = new \OC\Group\Manager($userManager); + $manager->addBackend($backend); + + $group = $manager->createGroup('group1'); + $this->assertEquals('group1', $group->getGID()); + } + + public function testCreateExists() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + */ + $backend = $this->getMock('\OC_Group_Database'); + $backend->expects($this->any()) + ->method('groupExists') + ->with('group1') + ->will($this->returnValue(true)); + $backend->expects($this->never()) + ->method('createGroup'); + + /** + * @var \OC\User\Manager $userManager + */ + $userManager = $this->getMock('\OC\User\Manager'); + $manager = new \OC\Group\Manager($userManager); + $manager->addBackend($backend); + + $group = $manager->createGroup('group1'); + $this->assertEquals('group1', $group->getGID()); + } + + public function testSearch() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + */ + $backend = $this->getMock('\OC_Group_Database'); + $backend->expects($this->once()) + ->method('getGroups') + ->with('1') + ->will($this->returnValue(array('group1'))); + + /** + * @var \OC\User\Manager $userManager + */ + $userManager = $this->getMock('\OC\User\Manager'); + $manager = new \OC\Group\Manager($userManager); + $manager->addBackend($backend); + + $groups = $manager->search('1'); + $this->assertEquals(1, count($groups)); + $group1 = $groups[0]; + $this->assertEquals('group1', $group1->getGID()); + } + + public function testSearchMultipleBackends() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1 + */ + $backend1 = $this->getMock('\OC_Group_Database'); + $backend1->expects($this->once()) + ->method('getGroups') + ->with('1') + ->will($this->returnValue(array('group1'))); + + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 + */ + $backend2 = $this->getMock('\OC_Group_Database'); + $backend2->expects($this->once()) + ->method('getGroups') + ->with('1') + ->will($this->returnValue(array('group12', 'group1'))); + + /** + * @var \OC\User\Manager $userManager + */ + $userManager = $this->getMock('\OC\User\Manager'); + $manager = new \OC\Group\Manager($userManager); + $manager->addBackend($backend1); + $manager->addBackend($backend2); + + $groups = $manager->search('1'); + $this->assertEquals(2, count($groups)); + $group1 = $groups[0]; + $group12 = $groups[1]; + $this->assertEquals('group1', $group1->getGID()); + $this->assertEquals('group12', $group12->getGID()); + } + + public function testSearchMultipleBackendsLimitAndOffset() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1 + */ + $backend1 = $this->getMock('\OC_Group_Database'); + $backend1->expects($this->once()) + ->method('getGroups') + ->with('1', 2, 1) + ->will($this->returnValue(array('group1'))); + + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 + */ + $backend2 = $this->getMock('\OC_Group_Database'); + $backend2->expects($this->once()) + ->method('getGroups') + ->with('1', 1, 0) + ->will($this->returnValue(array('group12'))); + + /** + * @var \OC\User\Manager $userManager + */ + $userManager = $this->getMock('\OC\User\Manager'); + $manager = new \OC\Group\Manager($userManager); + $manager->addBackend($backend1); + $manager->addBackend($backend2); + + $groups = $manager->search('1', 2, 1); + $this->assertEquals(2, count($groups)); + $group1 = $groups[0]; + $group12 = $groups[1]; + $this->assertEquals('group1', $group1->getGID()); + $this->assertEquals('group12', $group12->getGID()); + } + + public function testGetUserGroups() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + */ + $backend = $this->getMock('\OC_Group_Database'); + $backend->expects($this->once()) + ->method('getUserGroups') + ->with('user1') + ->will($this->returnValue(array('group1'))); + + /** + * @var \OC\User\Manager $userManager + */ + $userManager = $this->getMock('\OC\User\Manager'); + $manager = new \OC\Group\Manager($userManager); + $manager->addBackend($backend); + + $groups = $manager->getUserGroups(new User('user1', null)); + $this->assertEquals(1, count($groups)); + $group1 = $groups[0]; + $this->assertEquals('group1', $group1->getGID()); + } + + public function testGetUserGroupsMultipleBackends() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1 + */ + $backend1 = $this->getMock('\OC_Group_Database'); + $backend1->expects($this->once()) + ->method('getUserGroups') + ->with('user1') + ->will($this->returnValue(array('group1'))); + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 + */ + $backend2 = $this->getMock('\OC_Group_Database'); + $backend2->expects($this->once()) + ->method('getUserGroups') + ->with('user1') + ->will($this->returnValue(array('group1', 'group2'))); + + /** + * @var \OC\User\Manager $userManager + */ + $userManager = $this->getMock('\OC\User\Manager'); + $manager = new \OC\Group\Manager($userManager); + $manager->addBackend($backend1); + $manager->addBackend($backend2); + + $groups = $manager->getUserGroups(new User('user1', null)); + $this->assertEquals(2, count($groups)); + $group1 = $groups[0]; + $group2 = $groups[1]; + $this->assertEquals('group1', $group1->getGID()); + $this->assertEquals('group2', $group2->getGID()); + } +} diff --git a/tests/lib/helper.php b/tests/lib/helper.php index 6acb0dfaa6b..67b5a3d43ec 100644 --- a/tests/lib/helper.php +++ b/tests/lib/helper.php @@ -146,4 +146,64 @@ class Test_Helper extends PHPUnit_Framework_TestCase { $result = OC_Helper::recursiveArraySearch($haystack, "NotFound"); $this->assertFalse($result); } + + function testBuildNotExistingFileNameForView() { + $viewMock = $this->getMock('\OC\Files\View', array(), array(), '', false); + $this->assertEquals('/filename', OC_Helper::buildNotExistingFileNameForView('/', 'filename', $viewMock)); + $this->assertEquals('dir/filename.ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename.ext', $viewMock)); + + $viewMock->expects($this->at(0)) + ->method('file_exists') + ->will($this->returnValue(true)); // filename.ext exists + $this->assertEquals('dir/filename (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename.ext', $viewMock)); + + $viewMock->expects($this->at(0)) + ->method('file_exists') + ->will($this->returnValue(true)); // filename.ext exists + $viewMock->expects($this->at(1)) + ->method('file_exists') + ->will($this->returnValue(true)); // filename (2).ext exists + $this->assertEquals('dir/filename (3).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename.ext', $viewMock)); + + $viewMock->expects($this->at(0)) + ->method('file_exists') + ->will($this->returnValue(true)); // filename (1).ext exists + $this->assertEquals('dir/filename (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename (1).ext', $viewMock)); + + $viewMock->expects($this->at(0)) + ->method('file_exists') + ->will($this->returnValue(true)); // filename (2).ext exists + $this->assertEquals('dir/filename (3).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename (2).ext', $viewMock)); + + $viewMock->expects($this->at(0)) + ->method('file_exists') + ->will($this->returnValue(true)); // filename (2).ext exists + $viewMock->expects($this->at(1)) + ->method('file_exists') + ->will($this->returnValue(true)); // filename (3).ext exists + $this->assertEquals('dir/filename (4).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename (2).ext', $viewMock)); + + $viewMock->expects($this->at(0)) + ->method('file_exists') + ->will($this->returnValue(true)); // filename(1).ext exists + $this->assertEquals('dir/filename(2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1).ext', $viewMock)); + + $viewMock->expects($this->at(0)) + ->method('file_exists') + ->will($this->returnValue(true)); // filename(1) (1).ext exists + $this->assertEquals('dir/filename(1) (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (1).ext', $viewMock)); + + $viewMock->expects($this->at(0)) + ->method('file_exists') + ->will($this->returnValue(true)); // filename(1) (1).ext exists + $viewMock->expects($this->at(1)) + ->method('file_exists') + ->will($this->returnValue(true)); // filename(1) (2).ext exists + $this->assertEquals('dir/filename(1) (3).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (1).ext', $viewMock)); + + $viewMock->expects($this->at(0)) + ->method('file_exists') + ->will($this->returnValue(true)); // filename(1) (2) (3).ext exists + $this->assertEquals('dir/filename(1) (2) (4).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (2) (3).ext', $viewMock)); + } } diff --git a/tests/lib/hooks/forwardingemitter.php b/tests/lib/hooks/forwardingemitter.php new file mode 100644 index 00000000000..decf6bb354c --- /dev/null +++ b/tests/lib/hooks/forwardingemitter.php @@ -0,0 +1,74 @@ +<?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\Hooks; +use OC\Hooks\PublicEmitter; + +class DummyForwardingEmitter extends \OC\Hooks\ForwardingEmitter { + public function emitEvent($scope, $method, $arguments = array()) { + $this->emit($scope, $method, $arguments); + } + + /** + * @param \OC\Hooks\Emitter $emitter + */ + public function forward($emitter) { + parent::forward($emitter); + } +} + +/** + * Class ForwardingEmitter + * + * allows forwarding all listen calls to other emitters + * + * @package OC\Hooks + */ +class ForwardingEmitter extends BasicEmitter { + public function testSingleForward() { + $baseEmitter = new PublicEmitter(); + $forwardingEmitter = new DummyForwardingEmitter(); + $forwardingEmitter->forward($baseEmitter); + $hookCalled = false; + $forwardingEmitter->listen('Test', 'test', function () use (&$hookCalled) { + $hookCalled = true; + }); + $baseEmitter->emit('Test', 'test'); + $this->assertTrue($hookCalled); + } + + public function testMultipleForwards() { + $baseEmitter1 = new PublicEmitter(); + $baseEmitter2 = new PublicEmitter(); + $forwardingEmitter = new DummyForwardingEmitter(); + $forwardingEmitter->forward($baseEmitter1); + $forwardingEmitter->forward($baseEmitter2); + $hookCalled = 0; + $forwardingEmitter->listen('Test', 'test1', function () use (&$hookCalled) { + $hookCalled++; + }); + $forwardingEmitter->listen('Test', 'test2', function () use (&$hookCalled) { + $hookCalled++; + }); + $baseEmitter1->emit('Test', 'test1'); + $baseEmitter1->emit('Test', 'test2'); + $this->assertEquals(2, $hookCalled); + } + + public function testForwardExistingHooks() { + $baseEmitter = new PublicEmitter(); + $forwardingEmitter = new DummyForwardingEmitter(); + $hookCalled = false; + $forwardingEmitter->listen('Test', 'test', function () use (&$hookCalled) { + $hookCalled = true; + }); + $forwardingEmitter->forward($baseEmitter); + $baseEmitter->emit('Test', 'test'); + $this->assertTrue($hookCalled); + } +} diff --git a/tests/lib/memcache/apc.php b/tests/lib/memcache/apc.php new file mode 100644 index 00000000000..e5d753a4fa5 --- /dev/null +++ b/tests/lib/memcache/apc.php @@ -0,0 +1,24 @@ +<?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\Memcache; + +class APC extends Cache { + public function setUp() { + if(!\OC\Memcache\APC::isAvailable()) { + $this->markTestSkipped('The apc extension is not available.'); + return; + } + if(\OC\Memcache\APCu::isAvailable()) { + $this->markTestSkipped('The apc extension is emulated by ACPu.'); + return; + } + $this->instance=new \OC\Memcache\APC(uniqid()); + } +} diff --git a/tests/lib/memcache/apcu.php b/tests/lib/memcache/apcu.php new file mode 100644 index 00000000000..7b99e7cd5e0 --- /dev/null +++ b/tests/lib/memcache/apcu.php @@ -0,0 +1,20 @@ +<?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\Memcache; + +class APCu extends Cache { + public function setUp() { + if(!\OC\Memcache\APCu::isAvailable()) { + $this->markTestSkipped('The APCu extension is not available.'); + return; + } + $this->instance=new \OC\Memcache\APCu(uniqid()); + } +} diff --git a/tests/lib/memcache/cache.php b/tests/lib/memcache/cache.php new file mode 100644 index 00000000000..d07c492cef0 --- /dev/null +++ b/tests/lib/memcache/cache.php @@ -0,0 +1,58 @@ +<?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\Memcache; + +abstract class Cache extends \Test_Cache { + public function testExistsAfterSet() { + $this->assertFalse($this->instance->hasKey('foo')); + $this->instance->set('foo', 'bar'); + $this->assertTrue($this->instance->hasKey('foo')); + } + + public function testGetAfterSet() { + $this->assertNull($this->instance->get('foo')); + $this->instance->set('foo', 'bar'); + $this->assertEquals('bar', $this->instance->get('foo')); + } + + public function testDoesNotExistAfterRemove() { + $this->instance->set('foo', 'bar'); + $this->instance->remove('foo'); + $this->assertFalse($this->instance->hasKey('foo')); + } + + public function testArrayAccessSet() { + $this->instance['foo'] = 'bar'; + $this->assertEquals('bar', $this->instance->get('foo')); + } + + public function testArrayAccessGet() { + $this->instance->set('foo', 'bar'); + $this->assertEquals('bar', $this->instance['foo']); + } + + public function testArrayAccessExists() { + $this->assertFalse(isset($this->instance['foo'])); + $this->instance->set('foo', 'bar'); + $this->assertTrue(isset($this->instance['foo'])); + } + + public function testArrayAccessUnset() { + $this->instance->set('foo', 'bar'); + unset($this->instance['foo']); + $this->assertFalse($this->instance->hasKey('foo')); + } + + public function tearDown() { + if ($this->instance) { + $this->instance->clear(); + } + } +} diff --git a/tests/lib/memcache/memcached.php b/tests/lib/memcache/memcached.php new file mode 100644 index 00000000000..4b38ae8ef3c --- /dev/null +++ b/tests/lib/memcache/memcached.php @@ -0,0 +1,20 @@ +<?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\Memcache; + +class Memcached extends Cache { + public function setUp() { + if (!\OC\Memcache\Memcached::isAvailable()) { + $this->markTestSkipped('The memcached extension is not available.'); + return; + } + $this->instance = new \OC\Memcache\Memcached(uniqid()); + } +} diff --git a/tests/lib/memcache/xcache.php b/tests/lib/memcache/xcache.php new file mode 100644 index 00000000000..f59afda3966 --- /dev/null +++ b/tests/lib/memcache/xcache.php @@ -0,0 +1,20 @@ +<?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\Memcache; + +class XCache extends Cache { + public function setUp() { + if (!\OC\Memcache\XCache::isAvailable()) { + $this->markTestSkipped('The xcache extension is not available.'); + return; + } + $this->instance = new \OC\Memcache\XCache(uniqid()); + } +} diff --git a/tests/lib/template/resourcelocator.php b/tests/lib/template/resourcelocator.php new file mode 100644 index 00000000000..d80d222e2c9 --- /dev/null +++ b/tests/lib/template/resourcelocator.php @@ -0,0 +1,69 @@ +<?php +/** + * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class Test_ResourceLocator extends PHPUnit_Framework_TestCase { + public function getResourceLocator( $theme, $form_factor, $core_map, $party_map, $appsroots ) { + return $this->getMockForAbstractClass('OC\Template\ResourceLocator', + array( $theme, $form_factor, $core_map, $party_map, $appsroots ), + '', true, true, true, array()); + } + + public function testConstructor() { + $locator = $this->getResourceLocator('theme', 'form_factor', + array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar')); + $this->assertAttributeEquals('theme', 'theme', $locator); + $this->assertAttributeEquals('form_factor', 'form_factor', $locator); + $this->assertAttributeEquals('core', 'serverroot', $locator); + $this->assertAttributeEquals(array('core'=>'map','3rd'=>'party'), 'mapping', $locator); + $this->assertAttributeEquals('3rd', 'thirdpartyroot', $locator); + $this->assertAttributeEquals('map', 'webroot', $locator); + $this->assertAttributeEquals(array(), 'resources', $locator); + } + + public function testFind() { + $locator = $this->getResourceLocator('theme', 'form_factor', + array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar')); + $locator->expects($this->once()) + ->method('doFind') + ->with('foo'); + $locator->expects($this->once()) + ->method('doFindTheme') + ->with('foo'); + $locator->find(array('foo')); + + $locator = $this->getResourceLocator('theme', 'form_factor', + array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar')); + $locator->expects($this->once()) + ->method('doFind') + ->with('foo') + ->will($this->throwException(new Exception('test'))); + try { + $locator->find(array('foo')); + } catch (\Exception $e) { + $this->assertEquals('test formfactor:form_factor serverroot:core', $e->getMessage()); + } + } + + public function testAppendIfExist() { + $locator = $this->getResourceLocator('theme', 'form_factor', + array(__DIR__=>'map'), array('3rd'=>'party'), array('foo'=>'bar')); + $method = new ReflectionMethod($locator, 'appendIfExist'); + $method->setAccessible(true); + + $method->invoke($locator, __DIR__, basename(__FILE__), 'webroot'); + $resource1 = array(__DIR__, 'webroot', basename(__FILE__)); + $this->assertEquals(array($resource1), $locator->getResources()); + + $method->invoke($locator, __DIR__, basename(__FILE__)); + $resource2 = array(__DIR__, 'map', basename(__FILE__)); + $this->assertEquals(array($resource1, $resource2), $locator->getResources()); + + $method->invoke($locator, __DIR__, 'does-not-exist'); + $this->assertEquals(array($resource1, $resource2), $locator->getResources()); + } +} diff --git a/tests/phpunit-autotest.xml b/tests/phpunit-autotest.xml index 23b2d6c0060..a893e96ad97 100644 --- a/tests/phpunit-autotest.xml +++ b/tests/phpunit-autotest.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="utf-8" ?> <phpunit bootstrap="bootstrap.php" strict="true" + verbose="true" timeoutForSmallTests="900" timeoutForMediumTests="900" timeoutForLargeTests="900" |