diff options
Diffstat (limited to 'apps/files/tests/Controller/ViewControllerTest.php')
-rw-r--r-- | apps/files/tests/Controller/ViewControllerTest.php | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/apps/files/tests/Controller/ViewControllerTest.php b/apps/files/tests/Controller/ViewControllerTest.php index dd76e814054..01aa955a13e 100644 --- a/apps/files/tests/Controller/ViewControllerTest.php +++ b/apps/files/tests/Controller/ViewControllerTest.php @@ -1,5 +1,6 @@ <?php +declare(strict_types=1); /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -18,6 +19,7 @@ use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Services\IInitialState; +use OCP\Authentication\TwoFactorAuth\IRegistry; use OCP\Diagnostics\IEventLogger; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\File; @@ -62,6 +64,7 @@ class ViewControllerTest extends TestCase { private UserConfig&MockObject $userConfig; private ViewConfig&MockObject $viewConfig; private Router $router; + private IRegistry&MockObject $twoFactorRegistry; private ViewController&MockObject $viewController; @@ -78,6 +81,7 @@ class ViewControllerTest extends TestCase { $this->userConfig = $this->createMock(UserConfig::class); $this->userSession = $this->createMock(IUserSession::class); $this->viewConfig = $this->createMock(ViewConfig::class); + $this->twoFactorRegistry = $this->createMock(IRegistry::class); $this->user = $this->getMockBuilder(IUser::class)->getMock(); $this->user->expects($this->any()) @@ -137,6 +141,7 @@ class ViewControllerTest extends TestCase { $this->userConfig, $this->viewConfig, $filenameValidator, + $this->twoFactorRegistry, ]) ->onlyMethods([ 'getStorageInfo', @@ -192,7 +197,7 @@ class ViewControllerTest extends TestCase { $this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView')); } - public function dataTestShortRedirect(): array { + public static function dataTestShortRedirect(): array { // openfile is true by default // opendetails is undefined by default // both will be evaluated as truthy @@ -209,10 +214,8 @@ class ViewControllerTest extends TestCase { ]; } - /** - * @dataProvider dataTestShortRedirect - */ - public function testShortRedirect($openfile, $opendetails, $result) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestShortRedirect')] + public function testShortRedirect(?string $openfile, ?string $opendetails, string $result): void { $this->appManager->expects($this->any()) ->method('isEnabledForUser') ->with('files') @@ -239,7 +242,7 @@ class ViewControllerTest extends TestCase { ->with(123456) ->willReturn($node); - $response = $this->viewController->showFile(123456, $opendetails, $openfile); + $response = $this->viewController->showFile('123456', $opendetails, $openfile); $this->assertStringContainsString($result, $response->getHeaders()['Location']); } @@ -248,13 +251,13 @@ class ViewControllerTest extends TestCase { ->method('isEnabledForUser') ->willReturn(true); - $parentNode = $this->getMockBuilder(Folder::class)->getMock(); + $parentNode = $this->createMock(Folder::class); $parentNode->expects($this->once()) ->method('getPath') ->willReturn('testuser1/files_trashbin/files/test.d1462861890/sub'); - $baseFolderFiles = $this->getMockBuilder(Folder::class)->getMock(); - $baseFolderTrash = $this->getMockBuilder(Folder::class)->getMock(); + $baseFolderFiles = $this->createMock(Folder::class); + $baseFolderTrash = $this->createMock(Folder::class); $this->rootFolder->expects($this->any()) ->method('getUserFolder') @@ -270,7 +273,7 @@ class ViewControllerTest extends TestCase { ->with(123) ->willReturn(null); - $node = $this->getMockBuilder(File::class)->getMock(); + $node = $this->createMock(File::class); $node->expects($this->once()) ->method('getParent') ->willReturn($parentNode); @@ -287,4 +290,24 @@ class ViewControllerTest extends TestCase { $expected = new RedirectResponse('/index.php/apps/files/trashbin/123?dir=/test.d1462861890/sub'); $this->assertEquals($expected, $this->viewController->index('', '', '123')); } + + public function testTwoFactorAuthEnabled(): void { + $this->twoFactorRegistry->method('getProviderStates') + ->willReturn([ + 'totp' => true, + 'backup_codes' => true, + ]); + + $invokedCountProvideInitialState = $this->exactly(9); + $this->initialState->expects($invokedCountProvideInitialState) + ->method('provideInitialState') + ->willReturnCallback(function ($key, $data) use ($invokedCountProvideInitialState) { + if ($invokedCountProvideInitialState->numberOfInvocations() === 9) { + $this->assertEquals('isTwoFactorEnabled', $key); + $this->assertTrue($data); + } + }); + + $this->viewController->index('', '', null); + } } |