From b6121f278cb38ea57f7a69600c6308e0ee20f1a9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 14 Feb 2025 17:19:29 +0100 Subject: [PATCH] test: add basic test for guest migration Signed-off-by: Robin Appelman --- .../Migration/OwncloudGuestMigrationTest.php | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 tests/unit/Migration/OwncloudGuestMigrationTest.php diff --git a/tests/unit/Migration/OwncloudGuestMigrationTest.php b/tests/unit/Migration/OwncloudGuestMigrationTest.php new file mode 100644 index 00000000..cd76bdc2 --- /dev/null +++ b/tests/unit/Migration/OwncloudGuestMigrationTest.php @@ -0,0 +1,78 @@ +config = Server::get(IConfig::class); + $this->userManager = Server::get(IUserManager::class); + $this->consoleOutput = new BufferedOutput(); + $this->migrationOutput = new ConsoleOutput($this->consoleOutput); + $this->guestManager = Server::get(GuestManager::class); + + parent::setUp(); + } + + private function createOcGuest(string $userId): void { + $this->userManager->createUser($userId, $userId . '_password'); + $this->config->setUserValue($userId, 'owncloud', 'isGuest', '1'); + } + + public function testMigrateNoGuests(): void { + $migration = Server::get(OwncloudGuestsMigration::class); + + $migration->run($this->migrationOutput); + $this->assertEmpty($this->consoleOutput->fetch()); + + $this->assertEmpty($this->guestManager->listGuests()); + } + + public function testMigrateSingleGuest(): void { + $this->createOcGuest('test@example.com'); + $this->assertEmpty($this->guestManager->listGuests()); + + $migration = Server::get(OwncloudGuestsMigration::class); + + $migration->run($this->migrationOutput); + $this->assertNotEmpty($this->consoleOutput->fetch()); + + // clear the backend-cache + $this->userManager->removeBackend(new Dummy()); + + /** @var $guests */ + $guests = $this->guestManager->listGuests(); + $this->assertCount(1, $guests); + $this->assertEquals('test@example.com', $guests[0]); + + $user = $this->userManager->get('test@example.com'); + $this->assertInstanceOf(UserBackend::class, $user->getBackend()); + $this->userManager->checkPassword('test@example.com', 'test@example.com_password'); + } +}