public function test_getCountOfUsersMatchingFilter_ReturnsLdapEntityCount()
 {
     $mockLdapClient = $this->makeMockLdapClient($forSuccess = true);
     $passedFilter = null;
     $mockLdapClient->expects($this->any())->method('count')->will($this->returnCallback(function ($baseDn, $filter) use(&$passedFilter) {
         $passedFilter = $filter;
         return 10;
     }));
     $this->ldapUsers->setLdapClientClass($mockLdapClient);
     $this->setSingleLdapServer();
     $count = $this->ldapUsers->getCountOfUsersMatchingFilter("dummy filter");
     $this->assertEquals("dummy filter", $passedFilter);
     $this->assertEquals(10, $count);
 }
示例#2
0
 /**
  * Returns count of users in LDAP that match an LDAP filter. If the filter is incorrect,
  * `null` is returned.
  *
  * @param string $filter The filter to match.
  * @return int|null
  * @throws Exception if the current user is not a Super User or something goes wrong with LDAP.
  */
 public function getCountOfUsersMatchingFilter($filter)
 {
     Piwik::checkUserHasSuperUserAccess();
     $filter = Common::unsanitizeInputValue($filter);
     try {
         return $this->ldapUsers->getCountOfUsersMatchingFilter($filter);
     } catch (Exception $ex) {
         if (stripos($ex->getMessage(), "Bad search filter") !== false) {
             throw new Exception(Piwik::translate("LoginLdap_InvalidFilter"));
         } else {
             throw $ex;
         }
     }
 }