aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Traits
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Traits')
-rw-r--r--tests/lib/Traits/ClientServiceTrait.php20
-rw-r--r--tests/lib/Traits/EncryptionTrait.php55
-rw-r--r--tests/lib/Traits/MountProviderTrait.php19
-rw-r--r--tests/lib/Traits/UserTrait.php36
4 files changed, 78 insertions, 52 deletions
diff --git a/tests/lib/Traits/ClientServiceTrait.php b/tests/lib/Traits/ClientServiceTrait.php
index c35a57268f7..5a091544889 100644
--- a/tests/lib/Traits/ClientServiceTrait.php
+++ b/tests/lib/Traits/ClientServiceTrait.php
@@ -1,22 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Traits;
diff --git a/tests/lib/Traits/EncryptionTrait.php b/tests/lib/Traits/EncryptionTrait.php
index 6b74f7ca8ee..44d5dcab8cb 100644
--- a/tests/lib/Traits/EncryptionTrait.php
+++ b/tests/lib/Traits/EncryptionTrait.php
@@ -1,20 +1,27 @@
<?php
+
/**
- * Copyright (c) 2015 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
+ * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Traits;
use OC\Encryption\EncryptionWrapper;
-use OC\Files\Filesystem;
+use OC\Files\SetupManager;
use OC\Memcache\ArrayCache;
use OCA\Encryption\AppInfo\Application;
+use OCA\Encryption\Crypto\Encryption;
use OCA\Encryption\KeyManager;
use OCA\Encryption\Users\Setup;
+use OCP\App\IAppManager;
use OCP\Encryption\IManager;
+use OCP\IConfig;
+use OCP\IUserManager;
+use OCP\IUserSession;
+use OCP\Server;
+use Psr\Log\LoggerInterface;
/**
* Enables encryption
@@ -31,13 +38,18 @@ trait EncryptionTrait {
private $originalEncryptionModule;
+ /** @var IUserManager */
+ private $userManager;
+ /** @var SetupManager */
+ private $setupManager;
+
/**
- * @var \OCP\IConfig
+ * @var IConfig
*/
private $config;
/**
- * @var \OCA\Encryption\AppInfo\Application
+ * @var Application
*/
private $encryptionApp;
@@ -45,20 +57,22 @@ trait EncryptionTrait {
\OC_Util::tearDownFS();
\OC_User::setUserId('');
// needed for fully logout
- \OC::$server->getUserSession()->setUser(null);
+ Server::get(IUserSession::class)->setUser(null);
+
+ $this->setupManager->tearDown();
- Filesystem::tearDown();
\OC_User::setUserId($user);
$this->postLogin();
\OC_Util::setupFS($user);
- if (\OC::$server->getUserManager()->userExists($user)) {
+ if ($this->userManager->userExists($user)) {
\OC::$server->getUserFolder($user);
}
}
protected function setupForUser($name, $password) {
- \OC_Util::tearDownFS();
- \OC_Util::setupFS($name);
+ $this->setupManager->tearDown();
+ $this->setupManager->setupForUser($this->userManager->get($name));
+
$container = $this->encryptionApp->getContainer();
/** @var KeyManager $keyManager */
$keyManager = $container->query(KeyManager::class);
@@ -73,29 +87,32 @@ trait EncryptionTrait {
protected function postLogin() {
$encryptionWrapper = new EncryptionWrapper(
new ArrayCache(),
- \OC::$server->getEncryptionManager(),
- \OC::$server->getLogger()
+ Server::get(\OCP\Encryption\IManager::class),
+ Server::get(LoggerInterface::class)
);
$this->registerStorageWrapper('oc_encryption', [$encryptionWrapper, 'wrapStorage']);
}
protected function setUpEncryptionTrait() {
- $isReady = \OC::$server->getEncryptionManager()->isReady();
+ $isReady = Server::get(\OCP\Encryption\IManager::class)->isReady();
if (!$isReady) {
$this->markTestSkipped('Encryption not ready');
}
- \OC_App::loadApp('encryption');
+ $this->userManager = Server::get(IUserManager::class);
+ $this->setupManager = Server::get(SetupManager::class);
+
+ Server::get(IAppManager::class)->loadApp('encryption');
$this->encryptionApp = new Application([], $isReady);
- $this->config = \OC::$server->getConfig();
+ $this->config = Server::get(IConfig::class);
$this->encryptionWasEnabled = $this->config->getAppValue('core', 'encryption_enabled', 'no');
$this->originalEncryptionModule = $this->config->getAppValue('core', 'default_encryption_module');
- $this->config->setAppValue('core', 'default_encryption_module', \OCA\Encryption\Crypto\Encryption::ID);
+ $this->config->setAppValue('core', 'default_encryption_module', Encryption::ID);
$this->config->setAppValue('core', 'encryption_enabled', 'yes');
- $this->assertTrue(\OC::$server->getEncryptionManager()->isEnabled());
+ $this->assertTrue(Server::get(\OCP\Encryption\IManager::class)->isEnabled());
}
protected function tearDownEncryptionTrait() {
diff --git a/tests/lib/Traits/MountProviderTrait.php b/tests/lib/Traits/MountProviderTrait.php
index 379d33ea71c..b680c71b2d6 100644
--- a/tests/lib/Traits/MountProviderTrait.php
+++ b/tests/lib/Traits/MountProviderTrait.php
@@ -1,23 +1,26 @@
<?php
+
/**
- * Copyright (c) 2015 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Traits;
use OC\Files\Mount\MountPoint;
use OC\Files\Storage\StorageFactory;
+use OCP\Files\Config\IMountProvider;
+use OCP\Files\Config\IMountProviderCollection;
use OCP\IUser;
+use OCP\Server;
/**
* Allow setting mounts for users
*/
trait MountProviderTrait {
/**
- * @var \OCP\Files\Config\IMountProvider
+ * @var IMountProvider
*/
protected $mountProvider;
@@ -50,7 +53,7 @@ trait MountProviderTrait {
$this->mountProvider = $this->getMockBuilder('\OCP\Files\Config\IMountProvider')->getMock();
$this->mountProvider->expects($this->any())
->method('getMountsForUser')
- ->will($this->returnCallback(function (IUser $user) {
+ ->willReturnCallback(function (IUser $user) {
if (isset($this->mounts[$user->getUID()])) {
return array_map(function ($config) {
return new MountPoint($config['storage'], $config['mountPoint'], $config['arguments'], $this->storageFactory);
@@ -58,7 +61,7 @@ trait MountProviderTrait {
} else {
return [];
}
- }));
- \OC::$server->getMountProviderCollection()->registerProvider($this->mountProvider);
+ });
+ Server::get(IMountProviderCollection::class)->registerProvider($this->mountProvider);
}
}
diff --git a/tests/lib/Traits/UserTrait.php b/tests/lib/Traits/UserTrait.php
index 229087a5200..f80adb76be8 100644
--- a/tests/lib/Traits/UserTrait.php
+++ b/tests/lib/Traits/UserTrait.php
@@ -1,32 +1,52 @@
<?php
+
/**
- * Copyright (c) 2015 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
+ * SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Traits;
+use OC\User\User;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\IUser;
+use OCP\IUserManager;
+use OCP\Server;
+use OCP\UserInterface;
+
+class DummyUser extends User {
+ public function __construct(
+ private string $uid,
+ ) {
+ parent::__construct($this->uid, null, Server::get(IEventDispatcher::class));
+ }
+
+ public function getUID(): string {
+ return $this->uid;
+ }
+}
+
/**
* Allow creating users in a temporary backend
*/
trait UserTrait {
/**
- * @var \Test\Util\User\Dummy|\OCP\UserInterface
+ * @var \Test\Util\User\Dummy|UserInterface
*/
protected $userBackend;
- protected function createUser($name, $password) {
+ protected function createUser($name, $password): IUser {
$this->userBackend->createUser($name, $password);
+ return new DummyUser($name);
}
protected function setUpUserTrait() {
$this->userBackend = new \Test\Util\User\Dummy();
- \OC::$server->getUserManager()->registerBackend($this->userBackend);
+ Server::get(IUserManager::class)->registerBackend($this->userBackend);
}
protected function tearDownUserTrait() {
- \OC::$server->getUserManager()->removeBackend($this->userBackend);
+ Server::get(IUserManager::class)->removeBackend($this->userBackend);
}
}