From 1c468129afa2b2ec4a370a879f8eaffd22768baf Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 23 Feb 2022 18:29:08 +0100 Subject: adjust tests to new fs setup Signed-off-by: Robin Appelman --- tests/lib/Traits/EncryptionTrait.php | 21 ++++++++++++++++----- tests/lib/Traits/UserTrait.php | 18 +++++++++++++++++- 2 files changed, 33 insertions(+), 6 deletions(-) (limited to 'tests/lib/Traits') diff --git a/tests/lib/Traits/EncryptionTrait.php b/tests/lib/Traits/EncryptionTrait.php index 6b74f7ca8ee..9cb64c12d00 100644 --- a/tests/lib/Traits/EncryptionTrait.php +++ b/tests/lib/Traits/EncryptionTrait.php @@ -9,12 +9,13 @@ 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\KeyManager; use OCA\Encryption\Users\Setup; use OCP\Encryption\IManager; +use OCP\IUserManager; /** * Enables encryption @@ -31,6 +32,11 @@ trait EncryptionTrait { private $originalEncryptionModule; + /** @var IUserManager */ + private $userManager; + /** @var SetupManager */ + private $setupManager; + /** * @var \OCP\IConfig */ @@ -47,18 +53,20 @@ trait EncryptionTrait { // needed for fully logout \OC::$server->getUserSession()->setUser(null); - Filesystem::tearDown(); + $this->setupManager->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); @@ -86,6 +94,9 @@ trait EncryptionTrait { $this->markTestSkipped('Encryption not ready'); } + $this->userManager = \OC::$server->get(IUserManager::class); + $this->setupManager = \OC::$server->get(SetupManager::class); + \OC_App::loadApp('encryption'); $this->encryptionApp = new Application([], $isReady); diff --git a/tests/lib/Traits/UserTrait.php b/tests/lib/Traits/UserTrait.php index 229087a5200..3f7cfe419db 100644 --- a/tests/lib/Traits/UserTrait.php +++ b/tests/lib/Traits/UserTrait.php @@ -8,6 +8,21 @@ namespace Test\Traits; +use OC\User\User; +use OCP\IUser; + +class DummyUser extends User { + private string $uid; + + public function __construct(string $uid) { + $this->uid = $uid; + } + + public function getUID(): string { + return $this->uid; + } +} + /** * Allow creating users in a temporary backend */ @@ -17,8 +32,9 @@ trait UserTrait { */ 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() { -- cgit v1.2.3