encryptionManager = $this->createMock(IManager::class); $this->globalStoragesService = $this->createMock(GlobalStoragesService::class); $this->backendService = $this->createMock(BackendService::class); $this->globalAuth = $this->createMock(GlobalAuth::class); $this->initialState = $this->createMock(IInitialState::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->l10n = $this->createMock(IL10N::class); $this->l10n->method('t')->willReturnCallback(function ($text) { return $text; }); $this->admin = new Admin( $this->encryptionManager, $this->globalStoragesService, $this->backendService, $this->globalAuth, $this->initialState, $this->urlGenerator, $this->l10n, ); } public function testGetForm(): void { $backends = [ $this->createMock(Backend::class), ]; $backends[0]->method('checkDependencies')->willReturn([]); $backends[0]->method('getIdentifier')->willReturn('backend1'); $authMechanism = $this->createMock(GlobalAuth::class); $this->encryptionManager ->expects($this->once()) ->method('isEnabled') ->willReturn(false); $this->backendService ->expects($this->atLeastOnce()) ->method('getAvailableBackends') ->willReturn($backends); $this->backendService ->expects($this->atLeastOnce()) ->method('getAuthMechanisms') ->willReturn([$authMechanism]); $this->backendService ->expects($this->atLeastOnce()) ->method('isUserMountingAllowed') ->willReturn(true); $this->globalAuth ->expects($this->once()) ->method('getAuth') ->with('') ->willReturn(['asdf' => 'asdf']); $initialState = []; $this->initialState ->expects($this->atLeastOnce()) ->method('provideInitialState') ->willReturnCallback(function () use (&$initialState): void { $args = func_get_args(); $initialState[$args[0]] = $args[1]; }); $expected = new TemplateResponse('files_external', 'settings', renderAs: ''); $this->assertEquals($expected, $this->admin->getForm()); $this->assertEquals($initialState, [ 'settings' => [ 'docUrl' => '', 'dependencyIssues' => [ 'messages' => [], 'modules' => [], ], 'isAdmin' => true, 'hasEncryption' => false, ], 'global-credentials' => [ 'uid' => '', 'asdf' => 'asdf', ], 'allowedBackends' => ['backend1'], 'backends' => $backends, 'authMechanisms' => [$authMechanism], 'user-mounting' => [ 'allowUserMounting' => true, 'allowedBackends' => [], ], ]); } public function testGetSection(): void { $this->assertSame('externalstorages', $this->admin->getSection()); } public function testGetPriority(): void { $this->assertSame(40, $this->admin->getPriority()); } public function testGetName(): void { $this->l10n->expects($this->once()) ->method('t') ->with('External storage') ->willReturn('External storage'); $this->assertSame('External storage', $this->admin->getName()); } public function testGetAuthorizedAppConfig(): void { $this->assertSame([], $this->admin->getAuthorizedAppConfig()); } public function testImplementsIDelegatedSettings(): void { $this->assertInstanceOf(\OCP\Settings\IDelegatedSettings::class, $this->admin); $this->assertInstanceOf(\OCP\Settings\ISettings::class, $this->admin); } }