summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2013-09-25 22:14:02 +0200
committerArthur Schiwon <blizzz@owncloud.com>2013-09-27 13:34:16 +0200
commit2cebd8b92e35232b50fe8c9083b718e895ad3211 (patch)
tree6f3d39e5b1334c70a7fa1f101f8fbdcc2cfabf5c
parenta1aff3e8a1b956e0e42ceca2b6c7b6233b195432 (diff)
downloadnextcloud-server-2cebd8b92e35232b50fe8c9083b718e895ad3211.tar.gz
nextcloud-server-2cebd8b92e35232b50fe8c9083b718e895ad3211.zip
added user_ldap tests via public api calls
-rw-r--r--apps/user_ldap/tests/user_ldap_direct.php126
1 files changed, 112 insertions, 14 deletions
diff --git a/apps/user_ldap/tests/user_ldap_direct.php b/apps/user_ldap/tests/user_ldap_direct.php
index ab0563f12d6..6b9b8b3e185 100644
--- a/apps/user_ldap/tests/user_ldap_direct.php
+++ b/apps/user_ldap/tests/user_ldap_direct.php
@@ -75,15 +75,14 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
return false;
}
}));
-
-
}
- public function testCheckPassword() {
- $access = $this->getAccessMock();
- $backend = new UserLDAP($access);
- \OC_User::useBackend($backend);
-
+ /**
+ * @brief Prepares the Access mock for checkPassword tests
+ * @param $access mock of \OCA\user_ldap\lib\Access
+ * @return void
+ */
+ private function prepareAccessForCheckPassword(&$access) {
$access->connection->expects($this->any())
->method('__get')
->will($this->returnCallback(function($name) {
@@ -115,6 +114,13 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
}
return false;
}));
+ }
+
+ public function testCheckPassword() {
+ $access = $this->getAccessMock();
+ $this->prepareAccessForCheckPassword($access);
+ $backend = new UserLDAP($access);
+ \OC_User::useBackend($backend);
$result = $backend->checkPassword('roland', 'dt19');
$this->assertEquals('gunslinger', $result);
@@ -126,10 +132,28 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
$this->assertFalse($result);
}
- public function testGetUsers() {
+ public function testCheckPasswordPublicAPI() {
$access = $this->getAccessMock();
+ $this->prepareAccessForCheckPassword($access);
$backend = new UserLDAP($access);
+ \OC_User::useBackend($backend);
+ $result = \OCP\User::checkPassword('roland', 'dt19');
+ $this->assertEquals('gunslinger', $result);
+
+ $result = \OCP\User::checkPassword('roland', 'wrong');
+ $this->assertFalse($result);
+
+ $result = \OCP\User::checkPassword('mallory', 'evil');
+ $this->assertFalse($result);
+ }
+
+ /**
+ * @brief Prepares the Access mock for getUsers tests
+ * @param $access mock of \OCA\user_ldap\lib\Access
+ * @return void
+ */
+ private function prepareAccessForGetUsers(&$access) {
$access->expects($this->any())
->method('getFilterPartForUserSearch')
->will($this->returnCallback(function($search) {
@@ -165,6 +189,12 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
$access->expects($this->any())
->method('ownCloudUserNames')
->will($this->returnArgument(0));
+ }
+
+ public function testGetUsers() {
+ $access = $this->getAccessMock();
+ $this->prepareAccessForGetUsers($access);
+ $backend = new UserLDAP($access);
$result = $backend->getUsers();
$this->assertEquals(3, count($result));
@@ -182,6 +212,28 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
$this->assertEquals(0, count($result));
}
+ public function testGetUsersViaAPI() {
+ $access = $this->getAccessMock();
+ $this->prepareAccessForGetUsers($access);
+ $backend = new UserLDAP($access);
+ \OC_User::useBackend($backend);
+
+ $result = \OCP\User::getUsers();
+ $this->assertEquals(3, count($result));
+
+ $result = \OCP\User::getUsers('', 1, 2);
+ $this->assertEquals(1, count($result));
+
+ $result = \OCP\User::getUsers('', 2, 1);
+ $this->assertEquals(2, count($result));
+
+ $result = \OCP\User::getUsers('yo');
+ $this->assertEquals(2, count($result));
+
+ $result = \OCP\User::getUsers('nix');
+ $this->assertEquals(0, count($result));
+ }
+
public function testUserExists() {
$access = $this->getAccessMock();
$backend = new UserLDAP($access);
@@ -209,6 +261,34 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
$this->assertFalse($result);
}
+ public function testUserExistsPublicAPI() {
+ $access = $this->getAccessMock();
+ $backend = new UserLDAP($access);
+ $this->prepareMockForUserExists($access);
+ \OC_User::useBackend($backend);
+
+ $access->expects($this->any())
+ ->method('readAttribute')
+ ->will($this->returnCallback(function($dn) {
+ if($dn === 'dnOfRoland') {
+ return array();
+ }
+ return false;
+ }));
+
+ //test for existing user
+ $result = \OCP\User::userExists('gunslinger');
+ $this->assertTrue($result);
+
+ //test for deleted user
+ $result = \OCP\User::userExists('formerUser');
+ $this->assertFalse($result);
+
+ //test for never-existing user
+ $result = \OCP\User::userExists('mallory');
+ $this->assertFalse($result);
+ }
+
public function testDeleteUser() {
$access = $this->getAccessMock();
$backend = new UserLDAP($access);
@@ -268,11 +348,7 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
$this->assertFalse($result);
}
- public function testGetDisplayName() {
- $access = $this->getAccessMock();
- $backend = new UserLDAP($access);
- $this->prepareMockForUserExists($access);
-
+ private function prepareAccessForGetDisplayName(&$access) {
$access->connection->expects($this->any())
->method('__get')
->will($this->returnCallback(function($name) {
@@ -297,6 +373,13 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
return false;
}
}));
+ }
+
+ public function testGetDisplayName() {
+ $access = $this->getAccessMock();
+ $this->prepareAccessForGetDisplayName($access);
+ $backend = new UserLDAP($access);
+ $this->prepareMockForUserExists($access);
//with displayName
$result = $backend->getDisplayName('gunslinger');
@@ -307,7 +390,22 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
$this->assertEquals(null, $result);
}
+ public function testGetDisplayNamePublicAPI() {
+ $access = $this->getAccessMock();
+ $this->prepareAccessForGetDisplayName($access);
+ $backend = new UserLDAP($access);
+ $this->prepareMockForUserExists($access);
+ \OC_User::useBackend($backend);
+
+ //with displayName
+ $result = \OCP\User::getDisplayName('gunslinger');
+ $this->assertEquals('Roland Deschain', $result);
+
+ //empty displayname retrieved
+ $result = \OCP\User::getDisplayName('newyorker');
+ $this->assertEquals('newyorker', $result);
+ }
+
//no test for getDisplayNames, because it just invokes getUsers and
//getDisplayName
-
} \ No newline at end of file