diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-07-30 00:37:05 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-07-30 00:37:05 +0200 |
commit | f658852276204fbf1a76d58ac2f585cf9db8c75d (patch) | |
tree | 5fbd6d93c7435022e8539065a45469bd249799ad /tests | |
parent | 085fdfec2f298fd89d0265d0f97edfdda5a12954 (diff) | |
parent | 7c6246fa451c4646dfaa1396dd37e0b3eb9706ba (diff) | |
download | nextcloud-server-f658852276204fbf1a76d58ac2f585cf9db8c75d.tar.gz nextcloud-server-f658852276204fbf1a76d58ac2f585cf9db8c75d.zip |
Merge branch 'master' into fixing-testGetById-master
Diffstat (limited to 'tests')
-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/memcache/apc.php | 4 | ||||
-rw-r--r-- | tests/lib/memcache/apcu.php | 20 | ||||
-rw-r--r-- | tests/lib/template/resourcelocator.php | 69 | ||||
-rw-r--r-- | tests/phpunit-autotest.xml | 1 |
10 files changed, 803 insertions, 102 deletions
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/memcache/apc.php b/tests/lib/memcache/apc.php index 6b2a49470ba..e5d753a4fa5 100644 --- a/tests/lib/memcache/apc.php +++ b/tests/lib/memcache/apc.php @@ -15,6 +15,10 @@ class APC extends Cache { $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/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" |