public function testCountWithSearchString()
 {
     $access = $this->getAccessMock();
     $this->enableGroups($access);
     $access->expects($this->any())->method('groupname2dn')->will($this->returnValue('cn=group,dc=foo,dc=bar'));
     $access->expects($this->any())->method('fetchListOfUsers')->will($this->returnValue(array()));
     $access->expects($this->any())->method('readAttribute')->will($this->returnCallback(function ($name) {
         //the search operation will call readAttribute, thus we need
         //to anaylze the "dn". All other times we just need to return
         //something that is neither null or false, but once an array
         //with the users in the group – so we do so all other times for
         //simplicicity.
         if (strpos($name, 'u') === 0) {
             return strpos($name, '3');
         }
         return array('u11', 'u22', 'u33', 'u34');
     }));
     $access->expects($this->any())->method('dn2username')->will($this->returnCallback(function () {
         return 'foobar' . \OCP\Util::generateRandomBytes(7);
     }));
     $groupBackend = new GroupLDAP($access);
     $users = $groupBackend->countUsersInGroup('group', '3');
     $this->assertSame(2, $users);
 }
Example #2
0
 /**
  * tests that a user counting is complete, if all it's members have the group
  * as their primary.
  */
 public function testCountUsersInGroupPrimaryMembersOnly()
 {
     $access = $this->getAccessMock();
     $this->enableGroups($access);
     $access->connection->expects($this->any())->method('getFromCache')->will($this->returnValue(null));
     $access->expects($this->any())->method('readAttribute')->will($this->returnCallback(function ($dn, $attr) {
         if ($attr === 'primaryGroupToken') {
             return array(1337);
         }
         return array();
     }));
     $access->expects($this->any())->method('groupname2dn')->will($this->returnValue('cn=foobar,dc=foo,dc=bar'));
     $access->expects($this->once())->method('countUsers')->will($this->returnValue(4));
     $groupBackend = new GroupLDAP($access);
     $users = $groupBackend->countUsersInGroup('foobar');
     $this->assertSame(4, $users);
 }