]> source.dussan.org Git - nextcloud-server.git/commitdiff
LDAP: add tests for countUsers
authorArthur Schiwon <blizzz@owncloud.com>
Wed, 8 Jan 2014 11:24:29 +0000 (12:24 +0100)
committerArthur Schiwon <blizzz@owncloud.com>
Wed, 8 Jan 2014 11:24:29 +0000 (12:24 +0100)
apps/user_ldap/tests/user_ldap.php

index 6b9b8b3e18503162fcfc90638c5b09250df6b126..9193a005ae5da9aa9d0861e1d085282756d02858 100644 (file)
@@ -408,4 +408,58 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
 
        //no test for getDisplayNames, because it just invokes getUsers and
        //getDisplayName
+
+       public function testCountUsers() {
+               $access = $this->getAccessMock();
+
+               $access->connection->expects($this->once())
+                          ->method('__get')
+                          ->will($this->returnCallback(function($name) {
+                                       if($name === 'ldapLoginFilter') {
+                                               return 'uid=%uid';
+                                       }
+                                       return null;
+                          }));
+
+               $access->expects($this->once())
+                          ->method('countUsers')
+                          ->will($this->returnCallback(function($filter, $a, $b, $c) {
+                                  if($filter !== 'uid=*') {
+                                          return false;
+                                  }
+                                  return 5;
+                          }));
+
+               $backend = new UserLDAP($access);
+
+               $result = $backend->countUsers();
+               $this->assertEquals(5, $result);
+       }
+
+       public function testCountUsersFailing() {
+               $access = $this->getAccessMock();
+
+               $access->connection->expects($this->once())
+                          ->method('__get')
+                          ->will($this->returnCallback(function($name) {
+                                       if($name === 'ldapLoginFilter') {
+                                               return 'invalidFilter';
+                                       }
+                                       return null;
+                          }));
+
+               $access->expects($this->once())
+                          ->method('countUsers')
+                          ->will($this->returnCallback(function($filter, $a, $b, $c) {
+                                  if($filter !== 'uid=*') {
+                                          return false;
+                                  }
+                                  return 5;
+                          }));
+
+               $backend = new UserLDAP($access);
+
+               $result = $backend->countUsers();
+               $this->assertFalse($result);
+       }
 }
\ No newline at end of file