[Pkg-owncloud-commits] [owncloud] 16/70: Backport of #9156

David Prévot taffit at moszumanska.debian.org
Thu Aug 21 17:40:01 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag v6.0.5RC1
in repository owncloud.

commit 3bec0dc4f115ca4273cc76ac344f733842c4a43c
Author: Arthur Schiwon <blizzz at owncloud.com>
Date:   Fri Jul 4 15:15:45 2014 +0200

    Backport of #9156
---
 lib/private/group/database.php |  5 +++--
 lib/private/group/dummy.php    | 24 ++++++++++++++++++++++--
 lib/private/user/database.php  |  4 ++--
 lib/private/user/dummy.php     | 11 ++++++++++-
 tests/lib/group/backend.php    | 41 ++++++++++++++++++++++++++++++++++++++---
 tests/lib/group/database.php   |  6 ++++--
 tests/lib/user/backend.php     | 17 +++++++++++++++++
 tests/lib/user/database.php    |  3 +++
 8 files changed, 99 insertions(+), 12 deletions(-)

diff --git a/lib/private/group/database.php b/lib/private/group/database.php
index fa43d4e..92d209d 100644
--- a/lib/private/group/database.php
+++ b/lib/private/group/database.php
@@ -169,7 +169,7 @@ class OC_Group_Database extends OC_Group_Backend {
 	 */
 	public function getGroups($search = '', $limit = null, $offset = null) {
 		$stmt = OC_DB::prepare('SELECT `gid` FROM `*PREFIX*groups` WHERE `gid` LIKE ?', $limit, $offset);
-		$result = $stmt->execute(array($search.'%'));
+		$result = $stmt->execute(array('%' . $search . '%'));
 		$groups = array();
 		while ($row = $result->fetchRow()) {
 			$groups[] = $row['gid'];
@@ -203,11 +203,12 @@ class OC_Group_Database extends OC_Group_Backend {
 		$stmt = OC_DB::prepare('SELECT `uid` FROM `*PREFIX*group_user` WHERE `gid` = ? AND `uid` LIKE ?',
 			$limit,
 			$offset);
-		$result = $stmt->execute(array($gid, $search.'%'));
+		$result = $stmt->execute(array($gid, '%'.$search.'%'));
 		$users = array();
 		while ($row = $result->fetchRow()) {
 			$users[] = $row['uid'];
 		}
 		return $users;
 	}
+
 }
diff --git a/lib/private/group/dummy.php b/lib/private/group/dummy.php
index 9516fd5..8dad769 100644
--- a/lib/private/group/dummy.php
+++ b/lib/private/group/dummy.php
@@ -142,7 +142,16 @@ class OC_Group_Dummy extends OC_Group_Backend {
 	 * Returns a list with all groups
 	 */
 	public function getGroups($search = '', $limit = -1, $offset = 0) {
-		return array_keys($this->groups);
+		if(empty($search)) {
+			return array_keys($this->groups);
+		}
+		$result = array();
+		foreach(array_keys($this->groups) as $group) {
+			if(stripos($group, $search) !== false) {
+				$result[] = $group;
+			}
+		}
+		return $result;
 	}
 
 	/**
@@ -151,10 +160,21 @@ class OC_Group_Dummy extends OC_Group_Backend {
 	 */
 	public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
 		if(isset($this->groups[$gid])) {
-			return $this->groups[$gid];
+			if(empty($search)) {
+				return $this->groups[$gid];
+			}
+			$result = array();
+			foreach($this->groups[$gid] as $user) {
+				if(stripos($user, $search) !== false) {
+					$result[] = $user;
+				}
+			}
+			return $result;
 		}else{
 			return array();
 		}
 	}
 
+
+
 }
diff --git a/lib/private/user/database.php b/lib/private/user/database.php
index 1a63755..4fb7132 100644
--- a/lib/private/user/database.php
+++ b/lib/private/user/database.php
@@ -156,7 +156,7 @@ class OC_User_Database extends OC_User_Backend {
 		$query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users`'
 			. ' WHERE LOWER(`displayname`) LIKE LOWER(?) OR '
 			. 'LOWER(`uid`) LIKE LOWER(?)', $limit, $offset);
-		$result = $query->execute(array($search . '%', $search . '%'));
+		$result = $query->execute(array('%' . $search . '%', '%' . $search . '%'));
 		$users = array();
 		while ($row = $result->fetchRow()) {
 			$displayNames[$row['uid']] = $row['displayname'];
@@ -210,7 +210,7 @@ class OC_User_Database extends OC_User_Backend {
 	 */
 	public function getUsers($search = '', $limit = null, $offset = null) {
 		$query = OC_DB::prepare('SELECT `uid` FROM `*PREFIX*users` WHERE LOWER(`uid`) LIKE LOWER(?)', $limit, $offset);
-		$result = $query->execute(array($search . '%'));
+		$result = $query->execute(array('%' . $search . '%'));
 		$users = array();
 		while ($row = $result->fetchRow()) {
 			$users[] = $row['uid'];
diff --git a/lib/private/user/dummy.php b/lib/private/user/dummy.php
index fc15a63..ec05c4d 100644
--- a/lib/private/user/dummy.php
+++ b/lib/private/user/dummy.php
@@ -105,7 +105,16 @@ class OC_User_Dummy extends OC_User_Backend {
 	 * Get a list of all users.
 	 */
 	public function getUsers($search = '', $limit = null, $offset = null) {
-		return array_keys($this->users);
+		if(empty($search)) {
+			return array_keys($this->users);
+		}
+		$result = array();
+		foreach(array_keys($this->users) as $user) {
+			if(stripos($user, $search) !== false) {
+				$result[] = $user;
+			}
+		}
+		return $result;
 	}
 
 	/**
diff --git a/tests/lib/group/backend.php b/tests/lib/group/backend.php
index d308232..8cf24b9 100644
--- a/tests/lib/group/backend.php
+++ b/tests/lib/group/backend.php
@@ -31,8 +31,12 @@ abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase {
 	 * test cases can override this in order to clean up created groups
 	 * @return array
 	 */
-	public function getGroupName() {
-		return uniqid('test_');
+	public function getGroupName($name = null) {
+		if(is_null($name)) {
+			return uniqid('test_');
+		} else {
+			return $name;
+		}
 	}
 
 	/**
@@ -88,7 +92,7 @@ abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase {
 		$this->assertFalse($this->backend->inGroup($user2, $group1));
 		$this->assertFalse($this->backend->inGroup($user1, $group2));
 		$this->assertFalse($this->backend->inGroup($user2, $group2));
-		
+
 		$this->assertFalse($this->backend->addToGroup($user1, $group1));
 
 		$this->assertEquals(array($user1), $this->backend->usersInGroup($group1));
@@ -102,4 +106,35 @@ abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase {
 		$this->assertEquals(array(), $this->backend->usersInGroup($group1));
 		$this->assertFalse($this->backend->inGroup($user1, $group1));
 	}
+
+	public function testSearchGroups() {
+		$name1 = $this->getGroupName('foobarbaz');
+		$name2 = $this->getGroupName('bazbarfoo');
+		$name3 = $this->getGroupName('notme');
+
+		$this->backend->createGroup($name1);
+		$this->backend->createGroup($name2);
+		$this->backend->createGroup($name3);
+
+		$result = $this->backend->getGroups('bar');
+		$this->assertSame(2, count($result));
+	}
+
+	public function testSearchUsers() {
+		$group = $this->getGroupName();
+		$this->backend->createGroup($group);
+
+		$name1 = 'foobarbaz';
+		$name2 = 'bazbarfoo';
+		$name3 = 'notme';
+
+		$this->backend->addToGroup($name1, $group);
+		$this->backend->addToGroup($name2, $group);
+		$this->backend->addToGroup($name3, $group);
+
+		$result = $this->backend->usersInGroup($group, 'bar');
+		$this->assertSame(2, count($result));
+	}
+
+
 }
diff --git a/tests/lib/group/database.php b/tests/lib/group/database.php
index 5278c26..53436a7 100644
--- a/tests/lib/group/database.php
+++ b/tests/lib/group/database.php
@@ -28,8 +28,10 @@ class Test_Group_Database extends Test_Group_Backend {
 	 * test cases can override this in order to clean up created groups
 	 * @return array
 	 */
-	public function getGroupName() {
-		$name=uniqid('test_');
+	public function getGroupName($name = null) {
+		if(is_null($name)) {
+			$name=uniqid('test_');
+		}
 		$this->groups[]=$name;
 		return $name;
 	}
diff --git a/tests/lib/user/backend.php b/tests/lib/user/backend.php
index 1384c54..0d3914c 100644
--- a/tests/lib/user/backend.php
+++ b/tests/lib/user/backend.php
@@ -96,4 +96,21 @@ abstract class Test_User_Backend extends PHPUnit_Framework_TestCase {
 		$this->assertSame($name1, $this->backend->checkPassword($name1, 'newpass1'));
 		$this->assertFalse($this->backend->checkPassword($name2, 'newpass1'));
 	}
+
+	public function testSearch() {
+		$name1 = 'foobarbaz';
+		$name2 = 'bazbarfoo';
+		$name3 = 'notme';
+
+		$this->backend->createUser($name1, 'pass1');
+		$this->backend->createUser($name2, 'pass2');
+		$this->backend->createUser($name3, 'pass3');
+
+		$result = $this->backend->getUsers('bar');
+		$this->assertSame(2, count($result));
+
+		$result = $this->backend->getDisplayNames('bar');
+		$this->assertSame(2, count($result));
+	}
+
 }
diff --git a/tests/lib/user/database.php b/tests/lib/user/database.php
index d7cc39a..a8e4977 100644
--- a/tests/lib/user/database.php
+++ b/tests/lib/user/database.php
@@ -32,6 +32,9 @@ class Test_User_Database extends Test_User_Backend {
 	}
 	
 	public function tearDown() {
+		if(!isset($this->users)) {
+			return;
+		}
 		foreach($this->users as $user) {
 			$this->backend->deleteUser($user);
 		}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list