summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-05-05 14:08:45 +0200
committerVincent Petry <pvince81@owncloud.com>2014-05-05 14:08:45 +0200
commit1a454f61ed2211e8a5cf11f1292c53a4d6801dd5 (patch)
tree3da9c5f5b28959369a0b9a0c91530643ae02ed60 /tests/lib
parent341fcdc37a74b630ef7d47b5f0b336622c072ddc (diff)
parent837a02184b38f62b87993a4da2afbd9daefedd98 (diff)
downloadnextcloud-server-1a454f61ed2211e8a5cf11f1292c53a4d6801dd5.tar.gz
nextcloud-server-1a454f61ed2211e8a5cf11f1292c53a4d6801dd5.zip
Merge pull request #8386 from owncloud/fix_6946_master
Fix 6946 master
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/group.php19
-rw-r--r--tests/lib/group/manager.php50
-rw-r--r--tests/lib/user/manager.php10
3 files changed, 55 insertions, 24 deletions
diff --git a/tests/lib/group.php b/tests/lib/group.php
index 8de8d033e19..26232187c36 100644
--- a/tests/lib/group.php
+++ b/tests/lib/group.php
@@ -109,25 +109,6 @@ class Test_Group extends PHPUnit_Framework_TestCase {
$this->assertEquals(array(), OC_Group::getGroups());
}
- public function testDisplayNamesInGroup() {
- OC_Group::useBackend(new OC_Group_Dummy());
- $userBackend = new \OC_User_Dummy();
- \OC_User::getManager()->registerBackend($userBackend);
-
- $group1 = uniqid();
- $user1 = 'uid1';
- $user2 = 'uid2';
- OC_Group::createGroup($group1);
- $userBackend->createUser($user1, '');
- $userBackend->createUser($user2, '');
- OC_Group::addToGroup($user1, $group1);
- OC_Group::addToGroup($user2, $group1);
- //Dummy backend does not support setting displaynames, uid will always
- //be returned. This checks primarily, that the return format is okay.
- $expected = array($user1 => $user1, $user2 => $user2);
- $this->assertEquals($expected, OC_Group::displayNamesInGroup($group1));
- }
-
public function testUsersInGroup() {
OC_Group::useBackend(new OC_Group_Dummy());
$userBackend = new \OC_User_Dummy();
diff --git a/tests/lib/group/manager.php b/tests/lib/group/manager.php
index a03997c58eb..9d1f175c109 100644
--- a/tests/lib/group/manager.php
+++ b/tests/lib/group/manager.php
@@ -343,4 +343,54 @@ class Manager extends \PHPUnit_Framework_TestCase {
$this->assertEquals('group1', $group1->getGID());
$this->assertEquals('group2', $group2->getGID());
}
+
+ public function testDisplayNamesInGroupMultipleUserBackends() {
+ $user1 = new User('user1', null);
+ $user2 = new User('user2', null);
+ $user3 = new User('user3', null);
+ $user4 = new User('user33', null);
+
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1
+ */
+ $backend = $this->getMock('\OC_Group_Database');
+ $backend->expects($this->exactly(1))
+ ->method('groupExists')
+ ->with('testgroup')
+ ->will($this->returnValue(true));
+
+ $backend->expects($this->once())
+ ->method('usersInGroup')
+ ->with('testgroup', '', -1, 0)
+ ->will($this->returnValue(array('user2', 'user33')));
+
+ /**
+ * @var \OC\User\Manager $userManager
+ */
+ $userManager = $this->getMock('\OC\User\Manager');
+ $userManager->expects($this->once())
+ ->method('search')
+ ->with('user3')
+ ->will($this->returnValue(array('user3' => $user3, 'user33' => $user4)));
+
+ $userManager->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(function($uid) {
+ switch($uid) {
+ case 'user1' : return new User('user1', null);
+ case 'user2' : return new User('user2', null);
+ case 'user3' : return new User('user3', null);
+ case 'user33': return new User('user33', null);
+ default:
+ return null;
+ }
+ }));
+
+ $manager = new \OC\Group\Manager($userManager);
+ $manager->addBackend($backend);
+
+ $users = $manager->displayNamesInGroup('testgroup', 'user3');
+ $this->assertEquals(1, count($users));
+ $this->assertTrue(isset($users['user33']));
+ }
}
diff --git a/tests/lib/user/manager.php b/tests/lib/user/manager.php
index 8ca0f94c6fa..fd0931af7e4 100644
--- a/tests/lib/user/manager.php
+++ b/tests/lib/user/manager.php
@@ -190,8 +190,8 @@ class Manager extends \PHPUnit_Framework_TestCase {
$result = $manager->search('fo');
$this->assertEquals(2, count($result));
- $this->assertEquals('afoo', $result[0]->getUID());
- $this->assertEquals('foo', $result[1]->getUID());
+ $this->assertEquals('afoo', array_shift($result)->getUID());
+ $this->assertEquals('foo', array_shift($result)->getUID());
}
public function testSearchTwoBackendLimitOffset() {
@@ -219,9 +219,9 @@ class Manager extends \PHPUnit_Framework_TestCase {
$result = $manager->search('fo', 3, 1);
$this->assertEquals(3, count($result));
- $this->assertEquals('foo1', $result[0]->getUID());
- $this->assertEquals('foo2', $result[1]->getUID());
- $this->assertEquals('foo3', $result[2]->getUID());
+ $this->assertEquals('foo1', array_shift($result)->getUID());
+ $this->assertEquals('foo2', array_shift($result)->getUID());
+ $this->assertEquals('foo3', array_shift($result)->getUID());
}
public function testCreateUserSingleBackendNotExists() {