aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2025-02-03 15:34:01 +0100
committerCôme Chilliet <come.chilliet@nextcloud.com>2025-02-13 11:46:42 +0100
commit64863c9d4631c42d4ce3997d7033bca8f06ca66a (patch)
treeb7e88154522cd827da8163719aeb91b51d5640cd /apps/user_ldap
parent007335dadfcda18330bb853a73bf451ed41c8254 (diff)
downloadnextcloud-server-64863c9d4631c42d4ce3997d7033bca8f06ca66a.tar.gz
nextcloud-server-64863c9d4631c42d4ce3997d7033bca8f06ca66a.zip
chore: Apply new rector configuration to apps folder
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/ajax/clearMappings.php8
-rw-r--r--apps/user_ldap/ajax/deleteConfiguration.php5
-rw-r--r--apps/user_ldap/ajax/getNewServerConfigPrefix.php5
-rw-r--r--apps/user_ldap/ajax/testConfiguration.php4
-rw-r--r--apps/user_ldap/ajax/wizard.php3
-rw-r--r--apps/user_ldap/lib/Access.php8
-rw-r--r--apps/user_ldap/lib/Command/Search.php4
-rw-r--r--apps/user_ldap/lib/Command/SetConfig.php5
-rw-r--r--apps/user_ldap/lib/Configuration.php7
-rw-r--r--apps/user_ldap/lib/Connection.php10
-rw-r--r--apps/user_ldap/lib/Helper.php3
-rw-r--r--apps/user_ldap/lib/Jobs/CleanUp.php8
-rw-r--r--apps/user_ldap/lib/LDAP.php2
-rw-r--r--apps/user_ldap/lib/Proxy.php3
-rw-r--r--apps/user_ldap/lib/Settings/Admin.php5
-rw-r--r--apps/user_ldap/lib/User/User.php7
-rw-r--r--apps/user_ldap/lib/Wizard.php7
-rw-r--r--apps/user_ldap/templates/renewpassword.php4
-rw-r--r--apps/user_ldap/tests/AccessTest.php4
-rw-r--r--apps/user_ldap/tests/Group_LDAPTest.php4
-rw-r--r--apps/user_ldap/tests/HelperTest.php4
-rw-r--r--apps/user_ldap/tests/Integration/AbstractIntegrationTest.php19
-rw-r--r--apps/user_ldap/tests/Integration/Lib/IntegrationTestAttributeDetection.php20
-rw-r--r--apps/user_ldap/tests/Integration/Lib/IntegrationTestFetchUsersByLoginName.php6
-rw-r--r--apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php3
-rw-r--r--apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php30
-rw-r--r--apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserCleanUp.php11
-rw-r--r--apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php11
-rw-r--r--apps/user_ldap/tests/LDAPProviderTest.php6
-rw-r--r--apps/user_ldap/tests/Mapping/AbstractMappingTest.php3
-rw-r--r--apps/user_ldap/tests/User/DeletedUsersIndexTest.php5
-rw-r--r--apps/user_ldap/tests/User_LDAPTest.php22
32 files changed, 155 insertions, 91 deletions
diff --git a/apps/user_ldap/ajax/clearMappings.php b/apps/user_ldap/ajax/clearMappings.php
index 7df622f5e37..ac13d7609bf 100644
--- a/apps/user_ldap/ajax/clearMappings.php
+++ b/apps/user_ldap/ajax/clearMappings.php
@@ -8,6 +8,8 @@
use OCA\User_LDAP\Mapping\GroupMapping;
use OCA\User_LDAP\Mapping\UserMapping;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\IDBConnection;
+use OCP\IUserManager;
use OCP\Server;
use OCP\User\Events\BeforeUserIdUnassignedEvent;
use OCP\User\Events\UserIdUnassignedEvent;
@@ -28,15 +30,15 @@ try {
$result = $mapping->clearCb(
function (string $uid) use ($dispatcher): void {
$dispatcher->dispatchTyped(new BeforeUserIdUnassignedEvent($uid));
- \OC::$server->getUserManager()->emit('\OC\User', 'preUnassignedUserId', [$uid]);
+ Server::get(IUserManager::class)->emit('\OC\User', 'preUnassignedUserId', [$uid]);
},
function (string $uid) use ($dispatcher): void {
$dispatcher->dispatchTyped(new UserIdUnassignedEvent($uid));
- \OC::$server->getUserManager()->emit('\OC\User', 'postUnassignedUserId', [$uid]);
+ Server::get(IUserManager::class)->emit('\OC\User', 'postUnassignedUserId', [$uid]);
}
);
} elseif ($subject === 'group') {
- $mapping = new GroupMapping(\OC::$server->getDatabaseConnection());
+ $mapping = new GroupMapping(Server::get(IDBConnection::class));
$result = $mapping->clear();
}
diff --git a/apps/user_ldap/ajax/deleteConfiguration.php b/apps/user_ldap/ajax/deleteConfiguration.php
index 09899a7c6c6..f09295355ac 100644
--- a/apps/user_ldap/ajax/deleteConfiguration.php
+++ b/apps/user_ldap/ajax/deleteConfiguration.php
@@ -1,6 +1,9 @@
<?php
use OCA\User_LDAP\Helper;
+use OCP\IConfig;
+use OCP\IDBConnection;
+use OCP\Server;
use OCP\Util;
/**
@@ -14,7 +17,7 @@ use OCP\Util;
\OC_JSON::callCheck();
$prefix = (string)$_POST['ldap_serverconfig_chooser'];
-$helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
+$helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class));
if ($helper->deleteServerConfiguration($prefix)) {
\OC_JSON::success();
} else {
diff --git a/apps/user_ldap/ajax/getNewServerConfigPrefix.php b/apps/user_ldap/ajax/getNewServerConfigPrefix.php
index a91c3c516ab..e8746a7c1b1 100644
--- a/apps/user_ldap/ajax/getNewServerConfigPrefix.php
+++ b/apps/user_ldap/ajax/getNewServerConfigPrefix.php
@@ -2,6 +2,9 @@
use OCA\User_LDAP\Configuration;
use OCA\User_LDAP\Helper;
+use OCP\IConfig;
+use OCP\IDBConnection;
+use OCP\Server;
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
@@ -13,7 +16,7 @@ use OCA\User_LDAP\Helper;
\OC_JSON::checkAppEnabled('user_ldap');
\OC_JSON::callCheck();
-$helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
+$helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class));
$serverConnections = $helper->getServerConfigurationPrefixes();
sort($serverConnections);
$lk = array_pop($serverConnections);
diff --git a/apps/user_ldap/ajax/testConfiguration.php b/apps/user_ldap/ajax/testConfiguration.php
index 16f0c583ae0..b91eab8fd92 100644
--- a/apps/user_ldap/ajax/testConfiguration.php
+++ b/apps/user_ldap/ajax/testConfiguration.php
@@ -1,6 +1,8 @@
<?php
use OCA\User_LDAP\LDAP;
+use OCP\ISession;
+use OCP\Server;
use OCP\Util;
/**
@@ -35,7 +37,7 @@ try {
* contact the LDAP backup server the first time when it should, but there shouldn't be any
* problem with that other than the extra connection.
*/
- \OC::$server->getSession()->close();
+ Server::get(ISession::class)->close();
if ($connection->bind()) {
/*
* This shiny if block is an ugly hack to find out whether anonymous
diff --git a/apps/user_ldap/ajax/wizard.php b/apps/user_ldap/ajax/wizard.php
index fa6ed9d3a5a..19980bf4921 100644
--- a/apps/user_ldap/ajax/wizard.php
+++ b/apps/user_ldap/ajax/wizard.php
@@ -4,6 +4,7 @@ use OCA\User_LDAP\AccessFactory;
use OCA\User_LDAP\Configuration;
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\Wizard;
+use OCP\Server;
use OCP\Util;
/**
@@ -36,7 +37,7 @@ $con->setConfiguration($configuration->getConfiguration());
$con->ldapConfigurationActive = (string)true;
$con->setIgnoreValidation(true);
-$factory = \OC::$server->get(AccessFactory::class);
+$factory = Server::get(AccessFactory::class);
$access = $factory->get($con);
$wizard = new Wizard($configuration, $ldapWrapper, $access);
diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php
index 88d34297bbd..aa48f7afedf 100644
--- a/apps/user_ldap/lib/Access.php
+++ b/apps/user_ldap/lib/Access.php
@@ -19,7 +19,9 @@ use OCP\EventDispatcher\IEventDispatcher;
use OCP\HintException;
use OCP\IAppConfig;
use OCP\IConfig;
+use OCP\IGroupManager;
use OCP\IUserManager;
+use OCP\Server;
use OCP\User\Events\UserIdAssignedEvent;
use OCP\Util;
use Psr\Log\LoggerInterface;
@@ -594,7 +596,7 @@ class Access extends LDAPUtility {
$this->connection->setConfiguration(['ldapCacheTTL' => 0]);
if ($intName !== ''
&& (($isUser && !$this->ncUserManager->userExists($intName))
- || (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))
+ || (!$isUser && !Server::get(IGroupManager::class)->groupExists($intName))
)
) {
$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
@@ -828,7 +830,7 @@ class Access extends LDAPUtility {
// Check to be really sure it is unique
// while loop is just a precaution. If a name is not generated within
// 20 attempts, something else is very wrong. Avoids infinite loop.
- if (!\OC::$server->getGroupManager()->groupExists($altName)) {
+ if (!Server::get(IGroupManager::class)->groupExists($altName)) {
return $altName;
}
$altName = $name . '_' . ($lastNo + $attempts);
@@ -1586,7 +1588,7 @@ class Access extends LDAPUtility {
* a *
*/
private function prepareSearchTerm(string $term): string {
- $config = \OC::$server->getConfig();
+ $config = Server::get(IConfig::class);
$allowEnum = $config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes');
diff --git a/apps/user_ldap/lib/Command/Search.php b/apps/user_ldap/lib/Command/Search.php
index fe1b9f34988..ad13c94c84a 100644
--- a/apps/user_ldap/lib/Command/Search.php
+++ b/apps/user_ldap/lib/Command/Search.php
@@ -12,6 +12,8 @@ use OCA\User_LDAP\Helper;
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\User_Proxy;
use OCP\IConfig;
+use OCP\IDBConnection;
+use OCP\Server;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
@@ -81,7 +83,7 @@ class Search extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
- $helper = new Helper($this->ocConfig, \OC::$server->getDatabaseConnection());
+ $helper = new Helper($this->ocConfig, Server::get(IDBConnection::class));
$configPrefixes = $helper->getServerConfigurationPrefixes(true);
$ldapWrapper = new LDAP();
diff --git a/apps/user_ldap/lib/Command/SetConfig.php b/apps/user_ldap/lib/Command/SetConfig.php
index 3a2bc4437e3..5a0b65a2c3e 100644
--- a/apps/user_ldap/lib/Command/SetConfig.php
+++ b/apps/user_ldap/lib/Command/SetConfig.php
@@ -11,6 +11,9 @@ use OCA\User_LDAP\Configuration;
use OCA\User_LDAP\ConnectionFactory;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\LDAP;
+use OCP\IConfig;
+use OCP\IDBConnection;
+use OCP\Server;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@@ -40,7 +43,7 @@ class SetConfig extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
- $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
+ $helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class));
$availableConfigs = $helper->getServerConfigurationPrefixes();
$configID = $input->getArgument('configID');
if (!in_array($configID, $availableConfigs)) {
diff --git a/apps/user_ldap/lib/Configuration.php b/apps/user_ldap/lib/Configuration.php
index 77f8ed0575f..b4a5b847204 100644
--- a/apps/user_ldap/lib/Configuration.php
+++ b/apps/user_ldap/lib/Configuration.php
@@ -7,6 +7,7 @@
*/
namespace OCA\User_LDAP;
+use OCP\IConfig;
use OCP\Server;
use Psr\Log\LoggerInterface;
@@ -439,7 +440,7 @@ class Configuration {
protected function getSystemValue(string $varName): string {
//FIXME: if another system value is added, softcode the default value
- return \OC::$server->getConfig()->getSystemValue($varName, false);
+ return Server::get(IConfig::class)->getSystemValue($varName, false);
}
protected function getValue(string $varName): string {
@@ -447,7 +448,7 @@ class Configuration {
if (is_null($defaults)) {
$defaults = $this->getDefaults();
}
- return \OC::$server->getConfig()->getAppValue('user_ldap',
+ return Server::get(IConfig::class)->getAppValue('user_ldap',
$this->configPrefix . $varName,
$defaults[$varName]);
}
@@ -476,7 +477,7 @@ class Configuration {
}
protected function saveValue(string $varName, string $value): bool {
- \OC::$server->getConfig()->setAppValue(
+ Server::get(IConfig::class)->setAppValue(
'user_ldap',
$this->configPrefix . $varName,
$value
diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php
index 93a83709055..e7f2a413643 100644
--- a/apps/user_ldap/lib/Connection.php
+++ b/apps/user_ldap/lib/Connection.php
@@ -9,6 +9,10 @@ namespace OCA\User_LDAP;
use OC\ServerNotAvailableException;
use OCP\ICache;
+use OCP\ICacheFactory;
+use OCP\IConfig;
+use OCP\IDBConnection;
+use OCP\Server;
use Psr\Log\LoggerInterface;
/**
@@ -145,14 +149,14 @@ class Connection extends LDAPUtility {
) {
parent::__construct($ldap);
$this->configuration = new Configuration($this->configPrefix, !is_null($this->configID));
- $memcache = \OC::$server->getMemCacheFactory();
+ $memcache = Server::get(ICacheFactory::class);
if ($memcache->isAvailable()) {
$this->cache = $memcache->createDistributed();
}
- $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
+ $helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class));
$this->doNotValidate = !in_array($this->configPrefix,
$helper->getServerConfigurationPrefixes());
- $this->logger = \OC::$server->get(LoggerInterface::class);
+ $this->logger = Server::get(LoggerInterface::class);
}
public function __destruct() {
diff --git a/apps/user_ldap/lib/Helper.php b/apps/user_ldap/lib/Helper.php
index 09be9e081e5..27c19e6c4f5 100644
--- a/apps/user_ldap/lib/Helper.php
+++ b/apps/user_ldap/lib/Helper.php
@@ -11,6 +11,7 @@ use OCP\Cache\CappedMemoryCache;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig;
use OCP\IDBConnection;
+use OCP\Server;
class Helper {
/** @var CappedMemoryCache<string> */
@@ -269,7 +270,7 @@ class Helper {
throw new \Exception('key uid is expected to be set in $param');
}
- $userBackend = \OC::$server->get(User_Proxy::class);
+ $userBackend = Server::get(User_Proxy::class);
$uid = $userBackend->loginName2UserName($param['uid']);
if ($uid !== false) {
$param['uid'] = $uid;
diff --git a/apps/user_ldap/lib/Jobs/CleanUp.php b/apps/user_ldap/lib/Jobs/CleanUp.php
index 6e624419424..7cfc473c950 100644
--- a/apps/user_ldap/lib/Jobs/CleanUp.php
+++ b/apps/user_ldap/lib/Jobs/CleanUp.php
@@ -49,7 +49,7 @@ class CleanUp extends TimedJob {
protected DeletedUsersIndex $dui,
) {
parent::__construct($timeFactory);
- $minutes = \OC::$server->getConfig()->getSystemValue(
+ $minutes = Server::get(IConfig::class)->getSystemValue(
'ldapUserCleanupInterval', (string)$this->defaultIntervalMin);
$this->setInterval((int)$minutes * 60);
}
@@ -67,13 +67,13 @@ class CleanUp extends TimedJob {
if (isset($arguments['helper'])) {
$this->ldapHelper = $arguments['helper'];
} else {
- $this->ldapHelper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
+ $this->ldapHelper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class));
}
if (isset($arguments['ocConfig'])) {
$this->ocConfig = $arguments['ocConfig'];
} else {
- $this->ocConfig = \OC::$server->getConfig();
+ $this->ocConfig = Server::get(IConfig::class);
}
if (isset($arguments['userBackend'])) {
@@ -83,7 +83,7 @@ class CleanUp extends TimedJob {
if (isset($arguments['db'])) {
$this->db = $arguments['db'];
} else {
- $this->db = \OC::$server->getDatabaseConnection();
+ $this->db = Server::get(IDBConnection::class);
}
if (isset($arguments['mapping'])) {
diff --git a/apps/user_ldap/lib/LDAP.php b/apps/user_ldap/lib/LDAP.php
index 44d8493b925..50af2556c72 100644
--- a/apps/user_ldap/lib/LDAP.php
+++ b/apps/user_ldap/lib/LDAP.php
@@ -25,7 +25,7 @@ class LDAP implements ILDAPWrapper {
protected string $logFile = '',
) {
/** @var IProfiler $profiler */
- $profiler = \OC::$server->get(IProfiler::class);
+ $profiler = Server::get(IProfiler::class);
if ($profiler->isEnabled()) {
$this->dataCollector = new LdapDataCollector();
$profiler->add($this->dataCollector);
diff --git a/apps/user_ldap/lib/Proxy.php b/apps/user_ldap/lib/Proxy.php
index fe86519884d..22b2c6617af 100644
--- a/apps/user_ldap/lib/Proxy.php
+++ b/apps/user_ldap/lib/Proxy.php
@@ -10,6 +10,7 @@ namespace OCA\User_LDAP;
use OCA\User_LDAP\Mapping\GroupMapping;
use OCA\User_LDAP\Mapping\UserMapping;
use OCP\ICache;
+use OCP\ICacheFactory;
use OCP\Server;
/**
@@ -33,7 +34,7 @@ abstract class Proxy {
private ILDAPWrapper $ldap,
private AccessFactory $accessFactory,
) {
- $memcache = \OC::$server->getMemCacheFactory();
+ $memcache = Server::get(ICacheFactory::class);
if ($memcache->isAvailable()) {
$this->cache = $memcache->createDistributed();
}
diff --git a/apps/user_ldap/lib/Settings/Admin.php b/apps/user_ldap/lib/Settings/Admin.php
index 80d1e6437f7..bf75d3ce378 100644
--- a/apps/user_ldap/lib/Settings/Admin.php
+++ b/apps/user_ldap/lib/Settings/Admin.php
@@ -8,7 +8,10 @@ namespace OCA\User_LDAP\Settings;
use OCA\User_LDAP\Configuration;
use OCA\User_LDAP\Helper;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IConfig;
+use OCP\IDBConnection;
use OCP\IL10N;
+use OCP\Server;
use OCP\Settings\IDelegatedSettings;
use OCP\Template;
@@ -25,7 +28,7 @@ class Admin implements IDelegatedSettings {
* @return TemplateResponse
*/
public function getForm() {
- $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
+ $helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class));
$prefixes = $helper->getServerConfigurationPrefixes();
if (count($prefixes) === 0) {
$newPrefix = $helper->getNextServerConfigurationPrefix();
diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php
index ec06d1d8636..f97867e98d4 100644
--- a/apps/user_ldap/lib/User/User.php
+++ b/apps/user_ldap/lib/User/User.php
@@ -18,6 +18,7 @@ use OCP\Accounts\PropertyDoesNotExistException;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\Image;
+use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Notification\IManager as INotificationManager;
@@ -769,10 +770,10 @@ class User {
if (!empty($pwdGraceAuthNLimit)
&& count($pwdGraceUseTime) < (int)$pwdGraceAuthNLimit[0]) { //at least one more grace login available?
$this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
- header('Location: ' . \OC::$server->getURLGenerator()->linkToRouteAbsolute(
+ header('Location: ' . Server::get(IURLGenerator::class)->linkToRouteAbsolute(
'user_ldap.renewPassword.showRenewPasswordForm', ['user' => $uid]));
} else { //no more grace login available
- header('Location: ' . \OC::$server->getURLGenerator()->linkToRouteAbsolute(
+ header('Location: ' . Server::get(IURLGenerator::class)->linkToRouteAbsolute(
'user_ldap.renewPassword.showLoginFormInvalidPassword', ['user' => $uid]));
}
exit();
@@ -780,7 +781,7 @@ class User {
//handle pwdReset attribute
if (!empty($pwdReset) && $pwdReset[0] === 'TRUE') { //user must change their password
$this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
- header('Location: ' . \OC::$server->getURLGenerator()->linkToRouteAbsolute(
+ header('Location: ' . Server::get(IURLGenerator::class)->linkToRouteAbsolute(
'user_ldap.renewPassword.showRenewPasswordForm', ['user' => $uid]));
exit();
}
diff --git a/apps/user_ldap/lib/Wizard.php b/apps/user_ldap/lib/Wizard.php
index 6df5aba4cac..6fe6c0c2906 100644
--- a/apps/user_ldap/lib/Wizard.php
+++ b/apps/user_ldap/lib/Wizard.php
@@ -11,6 +11,7 @@ namespace OCA\User_LDAP;
use OC\ServerNotAvailableException;
use OCP\IL10N;
use OCP\L10N\IFactory as IL10NFactory;
+use OCP\Server;
use OCP\Util;
use Psr\Log\LoggerInterface;
@@ -40,10 +41,10 @@ class Wizard extends LDAPUtility {
) {
parent::__construct($ldap);
if (is_null(static::$l)) {
- static::$l = \OC::$server->get(IL10NFactory::class)->get('user_ldap');
+ static::$l = Server::get(IL10NFactory::class)->get('user_ldap');
}
$this->result = new WizardResult();
- $this->logger = \OC::$server->get(LoggerInterface::class);
+ $this->logger = Server::get(LoggerInterface::class);
}
public function __destruct() {
@@ -709,7 +710,7 @@ class Wizard extends LDAPUtility {
//this did not help :(
//Let's see whether we can parse the Host URL and convert the domain to
//a base DN
- $helper = \OC::$server->get(Helper::class);
+ $helper = Server::get(Helper::class);
$domain = $helper->getDomainFromURL($this->configuration->ldapHost);
if (!$domain) {
return false;
diff --git a/apps/user_ldap/templates/renewpassword.php b/apps/user_ldap/templates/renewpassword.php
index 6f09230a88c..3345be29c13 100644
--- a/apps/user_ldap/templates/renewpassword.php
+++ b/apps/user_ldap/templates/renewpassword.php
@@ -6,11 +6,11 @@
*/
/** @var \OCP\IL10N $l */
-script('user_ldap', 'renewPassword');
+\OCP\Util::addScript('user_ldap', 'renewPassword', 'core');
style('user_ldap', 'renewPassword');
?>
-<form method="post" name="renewpassword" id="renewpassword" action="<?php p(\OC::$server->getURLGenerator()->linkToRoute('user_ldap.renewPassword.tryRenewPassword')); ?>">
+<form method="post" name="renewpassword" id="renewpassword" action="<?php p(\OCP\Server::get(\OCP\IURLGenerator::class)->linkToRoute('user_ldap.renewPassword.tryRenewPassword')); ?>">
<fieldset>
<div class="warning title">
<?php p($l->t('Please renew your password.')); ?><br>
diff --git a/apps/user_ldap/tests/AccessTest.php b/apps/user_ldap/tests/AccessTest.php
index 1ecc5565bed..5b824a89e96 100644
--- a/apps/user_ldap/tests/AccessTest.php
+++ b/apps/user_ldap/tests/AccessTest.php
@@ -23,9 +23,11 @@ use OCP\HintException;
use OCP\IAppConfig;
use OCP\IAvatarManager;
use OCP\IConfig;
+use OCP\IDBConnection;
use OCP\Image;
use OCP\IUserManager;
use OCP\Notification\IManager as INotificationManager;
+use OCP\Server;
use OCP\Share\IManager;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
@@ -117,7 +119,7 @@ class AccessTest extends TestCase {
$this->createMock(INotificationManager::class),
$this->shareManager])
->getMock();
- $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
+ $helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class));
return [$lw, $connector, $um, $helper];
}
diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php
index 13c5d35dce4..ad97d5024b1 100644
--- a/apps/user_ldap/tests/Group_LDAPTest.php
+++ b/apps/user_ldap/tests/Group_LDAPTest.php
@@ -21,6 +21,8 @@ use OCP\GroupInterface;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
+use OCP\Security\ISecureRandom;
+use OCP\Server;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
@@ -155,7 +157,7 @@ class Group_LDAPTest extends TestCase {
$this->access->expects($this->any())
->method('dn2username')
->willReturnCallback(function () {
- return 'foobar' . \OC::$server->getSecureRandom()->generate(7);
+ return 'foobar' . Server::get(ISecureRandom::class)->generate(7);
});
$this->access->expects($this->any())
->method('isDNPartOfBase')
diff --git a/apps/user_ldap/tests/HelperTest.php b/apps/user_ldap/tests/HelperTest.php
index 38c6a639340..eee5c162b53 100644
--- a/apps/user_ldap/tests/HelperTest.php
+++ b/apps/user_ldap/tests/HelperTest.php
@@ -7,6 +7,8 @@ namespace OCA\User_LDAP\Tests;
use OCA\User_LDAP\Helper;
use OCP\IConfig;
+use OCP\IDBConnection;
+use OCP\Server;
/**
* @group DB
@@ -23,7 +25,7 @@ class HelperTest extends \Test\TestCase {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
- $this->helper = new Helper($this->config, \OC::$server->getDatabaseConnection());
+ $this->helper = new Helper($this->config, Server::get(IDBConnection::class));
}
public function testGetServerConfigurationPrefixes(): void {
diff --git a/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php b/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php
index 12f97637618..be8d7702cd1 100644
--- a/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php
+++ b/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php
@@ -15,7 +15,10 @@ use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\User\Manager;
use OCA\User_LDAP\UserPluginManager;
use OCP\IAvatarManager;
+use OCP\IConfig;
+use OCP\IDBConnection;
use OCP\Image;
+use OCP\IUserManager;
use OCP\Server;
use OCP\Share\IManager;
use Psr\Log\LoggerInterface;
@@ -108,13 +111,13 @@ abstract class AbstractIntegrationTest {
*/
protected function initUserManager() {
$this->userManager = new Manager(
- \OC::$server->getConfig(),
- \OC::$server->get(LoggerInterface::class),
- \OC::$server->get(IAvatarManager::class),
+ Server::get(IConfig::class),
+ Server::get(LoggerInterface::class),
+ Server::get(IAvatarManager::class),
new Image(),
- \OC::$server->getUserManager(),
- \OC::$server->getNotificationManager(),
- \OC::$server->get(IManager::class)
+ Server::get(IUserManager::class),
+ Server::get(\OCP\Notification\IManager::class),
+ Server::get(IManager::class)
);
}
@@ -122,14 +125,14 @@ abstract class AbstractIntegrationTest {
* initializes the test Helper
*/
protected function initHelper() {
- $this->helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
+ $this->helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class));
}
/**
* initializes the Access test instance
*/
protected function initAccess() {
- $this->access = new Access($this->connection, $this->ldap, $this->userManager, $this->helper, \OC::$server->getConfig(), Server::get(LoggerInterface::class));
+ $this->access = new Access($this->connection, $this->ldap, $this->userManager, $this->helper, Server::get(IConfig::class), Server::get(LoggerInterface::class));
}
/**
diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestAttributeDetection.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestAttributeDetection.php
index 27d08861723..e45238fa978 100644
--- a/apps/user_ldap/tests/Integration/Lib/IntegrationTestAttributeDetection.php
+++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestAttributeDetection.php
@@ -14,6 +14,10 @@ use OCA\User_LDAP\User\DeletedUsersIndex;
use OCA\User_LDAP\User_LDAP;
use OCA\User_LDAP\UserPluginManager;
use OCP\IConfig;
+use OCP\IDBConnection;
+use OCP\IGroupManager;
+use OCP\IUserManager;
+use OCP\Server;
use Psr\Log\LoggerInterface;
require_once __DIR__ . '/../Bootstrap.php';
@@ -28,28 +32,28 @@ class IntegrationTestAttributeDetection extends AbstractIntegrationTest {
$this->connection->setConfiguration(['ldapGroupFilter' => 'objectClass=groupOfNames']);
$this->connection->setConfiguration(['ldapGroupMemberAssocAttr' => 'member']);
- $userMapper = new UserMapping(\OC::$server->getDatabaseConnection());
+ $userMapper = new UserMapping(Server::get(IDBConnection::class));
$userMapper->clear();
$this->access->setUserMapper($userMapper);
- $groupMapper = new GroupMapping(\OC::$server->getDatabaseConnection());
+ $groupMapper = new GroupMapping(Server::get(IDBConnection::class));
$groupMapper->clear();
$this->access->setGroupMapper($groupMapper);
- $userBackend = new User_LDAP($this->access, \OC::$server->getNotificationManager(), \OC::$server->get(UserPluginManager::class), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DeletedUsersIndex::class));
- $userManager = \OC::$server->getUserManager();
+ $userBackend = new User_LDAP($this->access, Server::get(\OCP\Notification\IManager::class), Server::get(UserPluginManager::class), Server::get(LoggerInterface::class), Server::get(DeletedUsersIndex::class));
+ $userManager = Server::get(IUserManager::class);
$userManager->clearBackends();
$userManager->registerBackend($userBackend);
- $groupBackend = new Group_LDAP($this->access, \OC::$server->query(GroupPluginManager::class), \OC::$server->get(IConfig::class));
- $groupManger = \OC::$server->getGroupManager();
+ $groupBackend = new Group_LDAP($this->access, Server::get(GroupPluginManager::class), Server::get(IConfig::class));
+ $groupManger = Server::get(IGroupManager::class);
$groupManger->clearBackends();
$groupManger->addBackend($groupBackend);
}
protected function caseNativeUUIDAttributeUsers() {
// trigger importing of users which also triggers UUID attribute detection
- \OC::$server->getUserManager()->search('', 5, 0);
+ Server::get(IUserManager::class)->search('', 5, 0);
return $this->connection->ldapUuidUserAttribute === 'entryuuid';
}
@@ -58,7 +62,7 @@ class IntegrationTestAttributeDetection extends AbstractIntegrationTest {
// are similar, but we take no chances.
// trigger importing of users which also triggers UUID attribute detection
- \OC::$server->getGroupManager()->search('', 5, 0);
+ Server::get(IGroupManager::class)->search('', 5, 0);
return $this->connection->ldapUuidGroupAttribute === 'entryuuid';
}
}
diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestFetchUsersByLoginName.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestFetchUsersByLoginName.php
index fe7a3d2226a..1c2d7145ddf 100644
--- a/apps/user_ldap/tests/Integration/Lib/IntegrationTestFetchUsersByLoginName.php
+++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestFetchUsersByLoginName.php
@@ -12,6 +12,8 @@ use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
use OCA\User_LDAP\User\DeletedUsersIndex;
use OCA\User_LDAP\User_LDAP;
use OCA\User_LDAP\UserPluginManager;
+use OCP\IDBConnection;
+use OCP\Server;
use Psr\Log\LoggerInterface;
require_once __DIR__ . '/../Bootstrap.php';
@@ -31,10 +33,10 @@ class IntegrationTestFetchUsersByLoginName extends AbstractIntegrationTest {
require(__DIR__ . '/../setup-scripts/createExplicitUsers.php');
parent::init();
- $this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
+ $this->mapping = new UserMapping(Server::get(IDBConnection::class));
$this->mapping->clear();
$this->access->setUserMapper($this->mapping);
- $this->backend = new User_LDAP($this->access, \OC::$server->getNotificationManager(), \OC::$server->get(UserPluginManager::class), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DeletedUsersIndex::class));
+ $this->backend = new User_LDAP($this->access, Server::get(\OCP\Notification\IManager::class), Server::get(UserPluginManager::class), Server::get(LoggerInterface::class), Server::get(DeletedUsersIndex::class));
}
/**
diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php
index e7b68735f6e..3e21d22fca3 100644
--- a/apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php
+++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php
@@ -12,6 +12,7 @@ use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
use OCA\User_LDAP\User\DeletedUsersIndex;
use OCA\User_LDAP\User_LDAP;
use OCA\User_LDAP\UserPluginManager;
+use OCP\Server;
use Psr\Log\LoggerInterface;
require_once __DIR__ . '/../Bootstrap.php';
@@ -34,7 +35,7 @@ class IntegrationTestPaging extends AbstractIntegrationTest {
require(__DIR__ . '/../setup-scripts/createExplicitUsers.php');
parent::init();
- $this->backend = new User_LDAP($this->access, \OC::$server->getNotificationManager(), \OC::$server->get(UserPluginManager::class), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DeletedUsersIndex::class));
+ $this->backend = new User_LDAP($this->access, Server::get(\OCP\Notification\IManager::class), Server::get(UserPluginManager::class), Server::get(LoggerInterface::class), Server::get(DeletedUsersIndex::class));
}
public function initConnection() {
diff --git a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php
index 75ce42e299c..2b52120e4d1 100644
--- a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php
+++ b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php
@@ -15,7 +15,11 @@ use OCA\User_LDAP\User\User;
use OCA\User_LDAP\User_LDAP;
use OCA\User_LDAP\UserPluginManager;
use OCP\IAvatarManager;
+use OCP\IConfig;
+use OCP\IDBConnection;
use OCP\Image;
+use OCP\IUserManager;
+use OCP\Server;
use Psr\Log\LoggerInterface;
require_once __DIR__ . '/../../Bootstrap.php';
@@ -31,10 +35,10 @@ class IntegrationTestUserAvatar extends AbstractIntegrationTest {
public function init() {
require(__DIR__ . '/../../setup-scripts/createExplicitUsers.php');
parent::init();
- $this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
+ $this->mapping = new UserMapping(Server::get(IDBConnection::class));
$this->mapping->clear();
$this->access->setUserMapper($this->mapping);
- $userBackend = new User_LDAP($this->access, \OC::$server->getNotificationManager(), \OC::$server->get(UserPluginManager::class), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DeletedUsersIndex::class));
+ $userBackend = new User_LDAP($this->access, Server::get(\OCP\Notification\IManager::class), Server::get(UserPluginManager::class), Server::get(LoggerInterface::class), Server::get(DeletedUsersIndex::class));
\OC_User::useBackend($userBackend);
}
@@ -57,9 +61,9 @@ class IntegrationTestUserAvatar extends AbstractIntegrationTest {
\OC_Util::tearDownFS();
\OC_Util::setupFS($username);
\OC::$server->getUserFolder($username);
- \OC::$server->getConfig()->deleteUserValue($username, 'user_ldap', User::USER_PREFKEY_LASTREFRESH);
- if (\OC::$server->get(IAvatarManager::class)->getAvatar($username)->exists()) {
- \OC::$server->get(IAvatarManager::class)->getAvatar($username)->remove();
+ Server::get(IConfig::class)->deleteUserValue($username, 'user_ldap', User::USER_PREFKEY_LASTREFRESH);
+ if (Server::get(IAvatarManager::class)->getAvatar($username)->exists()) {
+ Server::get(IAvatarManager::class)->getAvatar($username)->remove();
}
// finally attempt to get the avatar set
@@ -79,7 +83,7 @@ class IntegrationTestUserAvatar extends AbstractIntegrationTest {
$this->execFetchTest($dn, $username, $image);
- return \OC::$server->get(IAvatarManager::class)->getAvatar($username)->exists();
+ return Server::get(IAvatarManager::class)->getAvatar($username)->exists();
}
/**
@@ -96,7 +100,7 @@ class IntegrationTestUserAvatar extends AbstractIntegrationTest {
$this->execFetchTest($dn, $username, $image);
- return !\OC::$server->get(IAvatarManager::class)->getAvatar($username)->exists();
+ return !Server::get(IAvatarManager::class)->getAvatar($username)->exists();
}
/**
@@ -113,13 +117,13 @@ class IntegrationTestUserAvatar extends AbstractIntegrationTest {
protected function initUserManager() {
$this->userManager = new Manager(
- \OC::$server->getConfig(),
- \OC::$server->get(LoggerInterface::class),
- \OC::$server->get(IAvatarManager::class),
+ Server::get(IConfig::class),
+ Server::get(LoggerInterface::class),
+ Server::get(IAvatarManager::class),
new Image(),
- \OC::$server->getDatabaseConnection(),
- \OC::$server->getUserManager(),
- \OC::$server->getNotificationManager()
+ Server::get(IDBConnection::class),
+ Server::get(IUserManager::class),
+ Server::get(\OCP\Notification\IManager::class)
);
}
diff --git a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserCleanUp.php b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserCleanUp.php
index ed637155e5a..b29e9f621ea 100644
--- a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserCleanUp.php
+++ b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserCleanUp.php
@@ -13,6 +13,9 @@ use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
use OCA\User_LDAP\User\DeletedUsersIndex;
use OCA\User_LDAP\User_LDAP;
use OCA\User_LDAP\UserPluginManager;
+use OCP\IDBConnection;
+use OCP\IUserManager;
+use OCP\Server;
use Psr\Log\LoggerInterface;
require_once __DIR__ . '/../../Bootstrap.php';
@@ -28,11 +31,11 @@ class IntegrationTestUserCleanUp extends AbstractIntegrationTest {
public function init() {
require(__DIR__ . '/../../setup-scripts/createExplicitUsers.php');
parent::init();
- $this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
+ $this->mapping = new UserMapping(Server::get(IDBConnection::class));
$this->mapping->clear();
$this->access->setUserMapper($this->mapping);
- $userBackend = new User_LDAP($this->access, \OC::$server->getNotificationManager(), \OC::$server->get(UserPluginManager::class), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DeletedUsersIndex::class));
+ $userBackend = new User_LDAP($this->access, Server::get(\OCP\Notification\IManager::class), Server::get(UserPluginManager::class), Server::get(LoggerInterface::class), Server::get(DeletedUsersIndex::class));
\OC_User::useBackend($userBackend);
}
@@ -70,13 +73,13 @@ class IntegrationTestUserCleanUp extends AbstractIntegrationTest {
// user instance must not be requested from global user manager, before
// it is deleted from the LDAP server. The instance will be returned
// from cache and may false-positively confirm the correctness.
- $user = \OC::$server->getUserManager()->get($username);
+ $user = Server::get(IUserManager::class)->get($username);
if ($user === null) {
return false;
}
$user->delete();
- return \OC::$server->getUserManager()->get($username) === null;
+ return Server::get(IUserManager::class)->get($username) === null;
}
}
diff --git a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php
index e8f94dac419..18754c999a5 100644
--- a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php
+++ b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php
@@ -12,6 +12,9 @@ use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
use OCA\User_LDAP\User\DeletedUsersIndex;
use OCA\User_LDAP\User_LDAP;
use OCA\User_LDAP\UserPluginManager;
+use OCP\IDBConnection;
+use OCP\IUserManager;
+use OCP\Server;
use Psr\Log\LoggerInterface;
require_once __DIR__ . '/../../Bootstrap.php';
@@ -27,10 +30,10 @@ class IntegrationTestUserDisplayName extends AbstractIntegrationTest {
public function init() {
require(__DIR__ . '/../../setup-scripts/createExplicitUsers.php');
parent::init();
- $this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
+ $this->mapping = new UserMapping(Server::get(IDBConnection::class));
$this->mapping->clear();
$this->access->setUserMapper($this->mapping);
- $userBackend = new User_LDAP($this->access, \OC::$server->getNotificationManager(), \OC::$server->get(UserPluginManager::class), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DeletedUsersIndex::class));
+ $userBackend = new User_LDAP($this->access, Server::get(\OCP\Notification\IManager::class), Server::get(UserPluginManager::class), Server::get(LoggerInterface::class), Server::get(DeletedUsersIndex::class));
\OC_User::useBackend($userBackend);
}
@@ -54,7 +57,7 @@ class IntegrationTestUserDisplayName extends AbstractIntegrationTest {
$username = 'alice1337';
$dn = 'uid=alice,ou=Users,' . $this->base;
$this->prepareUser($dn, $username);
- $displayName = \OC::$server->getUserManager()->get($username)->getDisplayName();
+ $displayName = Server::get(IUserManager::class)->get($username)->getDisplayName();
return str_contains($displayName, '(Alice@example.com)');
}
@@ -71,7 +74,7 @@ class IntegrationTestUserDisplayName extends AbstractIntegrationTest {
$username = 'boris23421';
$dn = 'uid=boris,ou=Users,' . $this->base;
$this->prepareUser($dn, $username);
- $displayName = \OC::$server->getUserManager()->get($username)->getDisplayName();
+ $displayName = Server::get(IUserManager::class)->get($username)->getDisplayName();
return !str_contains($displayName, '(Boris@example.com)');
}
diff --git a/apps/user_ldap/tests/LDAPProviderTest.php b/apps/user_ldap/tests/LDAPProviderTest.php
index 5888c6624f3..9b0830ae513 100644
--- a/apps/user_ldap/tests/LDAPProviderTest.php
+++ b/apps/user_ldap/tests/LDAPProviderTest.php
@@ -18,7 +18,9 @@ use OCA\User_LDAP\User_LDAP;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ICacheFactory;
use OCP\IConfig;
+use OCP\IDBConnection;
use OCP\IServerContainer;
+use OCP\Server;
use Psr\Log\LoggerInterface;
/**
@@ -204,7 +206,7 @@ class LDAPProviderTest extends \Test\TestCase {
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
- $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
+ $helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class));
$ldapProvider = $this->getLDAPProvider($server);
$this->assertEquals(
@@ -220,7 +222,7 @@ class LDAPProviderTest extends \Test\TestCase {
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
- $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
+ $helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class));
$ldapProvider = $this->getLDAPProvider($server);
$this->assertEquals(
diff --git a/apps/user_ldap/tests/Mapping/AbstractMappingTest.php b/apps/user_ldap/tests/Mapping/AbstractMappingTest.php
index b95856a0f4c..f1e9b1b67bc 100644
--- a/apps/user_ldap/tests/Mapping/AbstractMappingTest.php
+++ b/apps/user_ldap/tests/Mapping/AbstractMappingTest.php
@@ -9,6 +9,7 @@ namespace OCA\User_LDAP\Tests\Mapping;
use OCA\User_LDAP\Mapping\AbstractMapping;
use OCP\IDBConnection;
+use OCP\Server;
abstract class AbstractMappingTest extends \Test\TestCase {
abstract public function getMapper(IDBConnection $dbMock);
@@ -70,7 +71,7 @@ abstract class AbstractMappingTest extends \Test\TestCase {
* users or groups
*/
private function initTest() {
- $dbc = \OC::$server->getDatabaseConnection();
+ $dbc = Server::get(IDBConnection::class);
$mapper = $this->getMapper($dbc);
$data = $this->getTestData();
// make sure DB is pristine, then fill it with test entries
diff --git a/apps/user_ldap/tests/User/DeletedUsersIndexTest.php b/apps/user_ldap/tests/User/DeletedUsersIndexTest.php
index 0e77f5023d5..64e443a064f 100644
--- a/apps/user_ldap/tests/User/DeletedUsersIndexTest.php
+++ b/apps/user_ldap/tests/User/DeletedUsersIndexTest.php
@@ -9,6 +9,7 @@ use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\User\DeletedUsersIndex;
use OCP\IConfig;
use OCP\IDBConnection;
+use OCP\Server;
use OCP\Share\IManager;
/**
@@ -37,8 +38,8 @@ class DeletedUsersIndexTest extends \Test\TestCase {
parent::setUp();
// no mocks for those as tests go against DB
- $this->config = \OC::$server->getConfig();
- $this->db = \OC::$server->getDatabaseConnection();
+ $this->config = Server::get(IConfig::class);
+ $this->db = Server::get(IDBConnection::class);
// ensure a clean database
$this->config->deleteAppFromAllUsers('user_ldap');
diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php
index 5b01b25109f..fedbb2d8e39 100644
--- a/apps/user_ldap/tests/User_LDAPTest.php
+++ b/apps/user_ldap/tests/User_LDAPTest.php
@@ -20,8 +20,12 @@ use OCA\User_LDAP\User_LDAP;
use OCA\User_LDAP\User_LDAP as UserLDAP;
use OCA\User_LDAP\UserPluginManager;
use OCP\HintException;
+use OCP\IConfig;
+use OCP\IGroupManager;
use OCP\IUser;
+use OCP\IUserManager;
use OCP\Notification\IManager as INotificationManager;
+use OCP\Server;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
@@ -57,7 +61,7 @@ class User_LDAPTest extends TestCase {
parent::setUp();
\OC_User::clearBackends();
- \OC::$server->getGroupManager()->clearBackends();
+ Server::get(IGroupManager::class)->clearBackends();
$this->connection = $this->createMock(Connection::class);
$this->userManager = $this->createMock(Manager::class);
@@ -236,7 +240,7 @@ class User_LDAPTest extends TestCase {
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
\OC_User::useBackend($backend);
- $user = \OC::$server->getUserManager()->checkPassword('roland', 'dt19');
+ $user = Server::get(IUserManager::class)->checkPassword('roland', 'dt19');
$result = false;
if ($user !== false) {
$result = $user->getUID();
@@ -249,7 +253,7 @@ class User_LDAPTest extends TestCase {
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
\OC_User::useBackend($backend);
- $user = \OC::$server->getUserManager()->checkPassword('roland', 'wrong');
+ $user = Server::get(IUserManager::class)->checkPassword('roland', 'wrong');
$result = false;
if ($user !== false) {
$result = $user->getUID();
@@ -262,7 +266,7 @@ class User_LDAPTest extends TestCase {
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
\OC_User::useBackend($backend);
- $user = \OC::$server->getUserManager()->checkPassword('mallory', 'evil');
+ $user = Server::get(IUserManager::class)->checkPassword('mallory', 'evil');
$result = false;
if ($user !== false) {
$result = $user->getUID();
@@ -436,7 +440,7 @@ class User_LDAPTest extends TestCase {
}
private function getUsers($search = '', $limit = null, $offset = null) {
- $users = \OC::$server->getUserManager()->search($search, $limit, $offset);
+ $users = Server::get(IUserManager::class)->search($search, $limit, $offset);
$uids = array_map(function (IUser $user) {
return $user->getUID();
}, $users);
@@ -583,7 +587,7 @@ class User_LDAPTest extends TestCase {
->willReturn($this->createMock(UserMapping::class));
//test for existing user
- $result = \OC::$server->getUserManager()->userExists('gunslinger');
+ $result = Server::get(IUserManager::class)->userExists('gunslinger');
$this->assertTrue($result);
}
@@ -653,7 +657,7 @@ class User_LDAPTest extends TestCase {
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
- $dataDir = \OC::$server->getConfig()->getSystemValue(
+ $dataDir = Server::get(IConfig::class)->getSystemValue(
'datadirectory', \OC::$SERVERROOT . '/data');
$this->connection->expects($this->any())
@@ -1000,11 +1004,11 @@ class User_LDAPTest extends TestCase {
});
//with displayName
- $result = \OC::$server->getUserManager()->get('gunslinger')?->getDisplayName();
+ $result = Server::get(IUserManager::class)->get('gunslinger')?->getDisplayName();
$this->assertEquals('Roland Deschain', $result);
//empty displayname retrieved
- $result = \OC::$server->getUserManager()->get('newyorker') === null ? 'newyorker' : \OC::$server->getUserManager()->get('newyorker')->getDisplayName();
+ $result = Server::get(IUserManager::class)->get('newyorker') === null ? 'newyorker' : Server::get(IUserManager::class)->get('newyorker')->getDisplayName();
$this->assertEquals('newyorker', $result);
}