diff options
Diffstat (limited to 'tests/Core/Controller')
17 files changed, 79 insertions, 79 deletions
diff --git a/tests/Core/Controller/AppPasswordControllerTest.php b/tests/Core/Controller/AppPasswordControllerTest.php index b33033edac3..eb1566eca8b 100644 --- a/tests/Core/Controller/AppPasswordControllerTest.php +++ b/tests/Core/Controller/AppPasswordControllerTest.php @@ -123,7 +123,7 @@ class AppPasswordControllerTest extends TestCase { $credentials->method('getLoginName') ->willReturn('myLoginName'); $this->request->method('getHeader') - ->with('USER_AGENT') + ->with('user-agent') ->willReturn('myUA'); $this->random->method('generate') ->with( @@ -164,7 +164,7 @@ class AppPasswordControllerTest extends TestCase { $credentials->method('getLoginName') ->willReturn('myLoginName'); $this->request->method('getHeader') - ->with('USER_AGENT') + ->with('user-agent') ->willReturn('myUA'); $this->random->method('generate') ->with( diff --git a/tests/Core/Controller/AutoCompleteControllerTest.php b/tests/Core/Controller/AutoCompleteControllerTest.php index 23fd0ac8399..c5574f78fc1 100644 --- a/tests/Core/Controller/AutoCompleteControllerTest.php +++ b/tests/Core/Controller/AutoCompleteControllerTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -153,9 +154,7 @@ class AutoCompleteControllerTest extends TestCase { ]; } - /** - * @dataProvider searchDataProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('searchDataProvider')] public function testGet(array $searchResults, array $expected, string $searchTerm, ?string $itemType, ?string $itemId, ?string $sorter): void { $this->collaboratorSearch->expects($this->once()) ->method('search') diff --git a/tests/Core/Controller/AvatarControllerTest.php b/tests/Core/Controller/AvatarControllerTest.php index 0dca611b020..a78e2c1bb5c 100644 --- a/tests/Core/Controller/AvatarControllerTest.php +++ b/tests/Core/Controller/AvatarControllerTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -130,7 +131,7 @@ class AvatarControllerTest extends \Test\TestCase { */ public function testGetAvatarNoAvatar(): void { $this->avatarManager->method('getAvatar')->willReturn($this->avatarMock); - $this->avatarMock->method('getFile')->will($this->throwException(new NotFoundException())); + $this->avatarMock->method('getFile')->willThrowException(new NotFoundException()); $response = $this->avatarController->getAvatar('userId', 32); //Comment out until JS is fixed @@ -183,7 +184,7 @@ class AvatarControllerTest extends \Test\TestCase { $this->avatarManager ->method('getAvatar') ->with('userDoesNotExist') - ->will($this->throwException(new \Exception('user does not exist'))); + ->willThrowException(new \Exception('user does not exist')); $response = $this->avatarController->getAvatar('userDoesNotExist', 32); @@ -287,7 +288,7 @@ class AvatarControllerTest extends \Test\TestCase { * Test what happens if the removing of the avatar fails */ public function testDeleteAvatarException(): void { - $this->avatarMock->method('remove')->will($this->throwException(new \Exception('foo'))); + $this->avatarMock->method('remove')->willThrowException(new \Exception('foo')); $this->avatarManager->method('getAvatar')->willReturn($this->avatarMock); $this->logger->expects($this->once()) @@ -469,7 +470,7 @@ class AvatarControllerTest extends \Test\TestCase { public function testPostAvatarException(): void { $this->cache->expects($this->once()) ->method('set') - ->will($this->throwException(new \Exception('foo'))); + ->willThrowException(new \Exception('foo')); $file = $this->getMockBuilder('OCP\Files\File') ->disableOriginalConstructor()->getMock(); $file->expects($this->once()) @@ -514,7 +515,7 @@ class AvatarControllerTest extends \Test\TestCase { public function testPostCroppedAvatarNoSquareCrop(): void { $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/testimage.jpg')); - $this->avatarMock->method('set')->will($this->throwException(new \OC\NotSquareException)); + $this->avatarMock->method('set')->willThrowException(new \OC\NotSquareException); $this->avatarManager->method('getAvatar')->willReturn($this->avatarMock); $response = $this->avatarController->postCroppedAvatar(['x' => 0, 'y' => 0, 'w' => 10, 'h' => 11]); @@ -539,7 +540,7 @@ class AvatarControllerTest extends \Test\TestCase { public function testPostCroppedAvatarException(): void { $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/testimage.jpg')); - $this->avatarMock->method('set')->will($this->throwException(new \Exception('foo'))); + $this->avatarMock->method('set')->willThrowException(new \Exception('foo')); $this->avatarManager->method('getAvatar')->willReturn($this->avatarMock); $this->logger->expects($this->once()) diff --git a/tests/Core/Controller/ChangePasswordControllerTest.php b/tests/Core/Controller/ChangePasswordControllerTest.php index a806b091477..aae36fb52b8 100644 --- a/tests/Core/Controller/ChangePasswordControllerTest.php +++ b/tests/Core/Controller/ChangePasswordControllerTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -96,7 +97,7 @@ class ChangePasswordControllerTest extends \Test\TestCase { $user->expects($this->once()) ->method('setPassword') ->with('new') - ->will($this->throwException(new HintException('Common password'))); + ->willThrowException(new HintException('Common password')); $expects = new JSONResponse([ 'status' => 'error', diff --git a/tests/Core/Controller/ClientFlowLoginControllerTest.php b/tests/Core/Controller/ClientFlowLoginControllerTest.php index b10055ef542..b182bb1bb39 100644 --- a/tests/Core/Controller/ClientFlowLoginControllerTest.php +++ b/tests/Core/Controller/ClientFlowLoginControllerTest.php @@ -18,6 +18,9 @@ use OCA\OAuth2\Db\AccessTokenMapper; use OCA\OAuth2\Db\Client; use OCA\OAuth2\Db\ClientMapper; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\ContentSecurityPolicy; +use OCP\AppFramework\Http\RedirectResponse; +use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\StandaloneTemplateResponse; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Defaults; @@ -101,8 +104,8 @@ class ClientFlowLoginControllerTest extends TestCase { 'core', 'error', [ - 'errors' => - [ + 'errors' + => [ [ 'error' => 'Access Forbidden', 'hint' => 'Invalid request', @@ -119,7 +122,7 @@ class ClientFlowLoginControllerTest extends TestCase { $this->request ->method('getHeader') ->willReturnMap([ - ['USER_AGENT', 'Mac OS X Sync Client'], + ['user-agent', 'Mac OS X Sync Client'], ['OCS-APIREQUEST', 'true'], ]); $this->random @@ -168,7 +171,7 @@ class ClientFlowLoginControllerTest extends TestCase { ], 'guest' ); - $csp = new Http\ContentSecurityPolicy(); + $csp = new ContentSecurityPolicy(); $csp->addAllowedFormActionDomain('nc://*'); $expected->setContentSecurityPolicy($csp); $this->assertEquals($expected, $this->clientFlowLoginController->showAuthPickerPage()); @@ -178,7 +181,7 @@ class ClientFlowLoginControllerTest extends TestCase { $this->request ->method('getHeader') ->willReturnMap([ - ['USER_AGENT', 'Mac OS X Sync Client'], + ['user-agent', 'Mac OS X Sync Client'], ['OCS-APIREQUEST', 'false'], ]); $client = new Client(); @@ -235,7 +238,7 @@ class ClientFlowLoginControllerTest extends TestCase { ], 'guest' ); - $csp = new Http\ContentSecurityPolicy(); + $csp = new ContentSecurityPolicy(); $csp->addAllowedFormActionDomain('https://example.com/redirect.php'); $expected->setContentSecurityPolicy($csp); $this->assertEquals($expected, $this->clientFlowLoginController->showAuthPickerPage('MyClientIdentifier')); @@ -279,7 +282,7 @@ class ClientFlowLoginControllerTest extends TestCase { ->method('getId') ->willThrowException(new SessionNotAvailableException()); - $expected = new Http\Response(); + $expected = new Response(); $expected->setStatus(Http::STATUS_FORBIDDEN); $this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken')); } @@ -304,7 +307,7 @@ class ClientFlowLoginControllerTest extends TestCase { ->with('SessionId') ->willThrowException(new InvalidTokenException()); - $expected = new Http\Response(); + $expected = new Response(); $expected->setStatus(Http::STATUS_FORBIDDEN); $this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken')); } @@ -380,7 +383,7 @@ class ClientFlowLoginControllerTest extends TestCase { $this->eventDispatcher->expects($this->once()) ->method('dispatchTyped'); - $expected = new Http\RedirectResponse('nc://login/server:http://example.com&user:MyLoginName&password:MyGeneratedToken'); + $expected = new RedirectResponse('nc://login/server:http://example.com&user:MyLoginName&password:MyGeneratedToken'); $this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken')); } @@ -406,7 +409,7 @@ class ClientFlowLoginControllerTest extends TestCase { ]; $this->session ->method('remove') - ->willReturnCallback(function ($key) use (&$calls) { + ->willReturnCallback(function ($key) use (&$calls): void { $expected = array_shift($calls); $this->assertEquals($expected, $key); }); @@ -470,7 +473,7 @@ class ClientFlowLoginControllerTest extends TestCase { $this->eventDispatcher->expects($this->once()) ->method('dispatchTyped'); - $expected = new Http\RedirectResponse($redirectUrl); + $expected = new RedirectResponse($redirectUrl); $this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken', 'MyClientIdentifier')); } @@ -545,7 +548,7 @@ class ClientFlowLoginControllerTest extends TestCase { $this->eventDispatcher->expects($this->once()) ->method('dispatchTyped'); - $expected = new Http\RedirectResponse('nc://login/server:http://example.com&user:MyLoginName&password:MyGeneratedToken'); + $expected = new RedirectResponse('nc://login/server:http://example.com&user:MyLoginName&password:MyGeneratedToken'); $this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken')); } @@ -555,7 +558,7 @@ class ClientFlowLoginControllerTest extends TestCase { [ ['X-Forwarded-Proto', 'http'], ['X-Forwarded-Ssl', 'off'], - ['USER_AGENT', ''], + ['user-agent', ''], ], 'http', 'http', @@ -564,7 +567,7 @@ class ClientFlowLoginControllerTest extends TestCase { [ ['X-Forwarded-Proto', 'http'], ['X-Forwarded-Ssl', 'off'], - ['USER_AGENT', ''], + ['user-agent', ''], ], 'https', 'https', @@ -573,7 +576,7 @@ class ClientFlowLoginControllerTest extends TestCase { [ ['X-Forwarded-Proto', 'https'], ['X-Forwarded-Ssl', 'off'], - ['USER_AGENT', ''], + ['user-agent', ''], ], 'http', 'https', @@ -582,7 +585,7 @@ class ClientFlowLoginControllerTest extends TestCase { [ ['X-Forwarded-Proto', 'https'], ['X-Forwarded-Ssl', 'on'], - ['USER_AGENT', ''], + ['user-agent', ''], ], 'http', 'https', @@ -591,7 +594,7 @@ class ClientFlowLoginControllerTest extends TestCase { [ ['X-Forwarded-Proto', 'http'], ['X-Forwarded-Ssl', 'on'], - ['USER_AGENT', ''], + ['user-agent', ''], ], 'http', 'https', @@ -600,11 +603,11 @@ class ClientFlowLoginControllerTest extends TestCase { } /** - * @dataProvider dataGeneratePasswordWithHttpsProxy * @param array $headers * @param string $protocol * @param string $expected */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataGeneratePasswordWithHttpsProxy')] public function testGeneratePasswordWithHttpsProxy(array $headers, $protocol, $expected): void { $this->session ->expects($this->once()) @@ -676,7 +679,7 @@ class ClientFlowLoginControllerTest extends TestCase { $this->eventDispatcher->expects($this->once()) ->method('dispatchTyped'); - $expected = new Http\RedirectResponse('nc://login/server:' . $expected . '://example.com&user:MyLoginName&password:MyGeneratedToken'); + $expected = new RedirectResponse('nc://login/server:' . $expected . '://example.com&user:MyLoginName&password:MyGeneratedToken'); $this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken')); } } diff --git a/tests/Core/Controller/ClientFlowLoginV2ControllerTest.php b/tests/Core/Controller/ClientFlowLoginV2ControllerTest.php index 81de4cd92da..d130eb75c1a 100644 --- a/tests/Core/Controller/ClientFlowLoginV2ControllerTest.php +++ b/tests/Core/Controller/ClientFlowLoginV2ControllerTest.php @@ -15,6 +15,8 @@ use OC\Core\Exception\LoginFlowV2ClientForbiddenException; use OC\Core\Exception\LoginFlowV2NotFoundException; use OC\Core\Service\LoginFlowV2Service; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\RedirectResponse; +use OCP\AppFramework\Http\StandaloneTemplateResponse; use OCP\Defaults; use OCP\IL10N; use OCP\IRequest; @@ -111,7 +113,7 @@ class ClientFlowLoginV2ControllerTest extends TestCase { $result = $this->controller->landing('token'); $this->assertSame(Http::STATUS_FORBIDDEN, $result->getStatus()); - $this->assertInstanceOf(Http\StandaloneTemplateResponse::class, $result); + $this->assertInstanceOf(StandaloneTemplateResponse::class, $result); } public function testLandingValid(): void { @@ -129,7 +131,7 @@ class ClientFlowLoginV2ControllerTest extends TestCase { $result = $this->controller->landing('token'); - $this->assertInstanceOf(Http\RedirectResponse::class, $result); + $this->assertInstanceOf(RedirectResponse::class, $result); $this->assertSame(Http::STATUS_SEE_OTHER, $result->getStatus()); $this->assertSame('https://server/path', $result->getRedirectURL()); } @@ -168,7 +170,7 @@ class ClientFlowLoginV2ControllerTest extends TestCase { $result = $this->controller->showAuthPickerPage(); - $this->assertInstanceOf(Http\StandaloneTemplateResponse::class, $result); + $this->assertInstanceOf(StandaloneTemplateResponse::class, $result); $this->assertSame(Http::STATUS_FORBIDDEN, $result->getStatus()); $this->assertSame('Please use original client', $result->getParams()['message']); } @@ -247,7 +249,7 @@ class ClientFlowLoginV2ControllerTest extends TestCase { $result = $this->controller->grantPage('stateToken'); - $this->assertInstanceOf(Http\StandaloneTemplateResponse::class, $result); + $this->assertInstanceOf(StandaloneTemplateResponse::class, $result); $this->assertSame(Http::STATUS_FORBIDDEN, $result->getStatus()); $this->assertSame('Please use original client', $result->getParams()['message']); } @@ -330,7 +332,7 @@ class ClientFlowLoginV2ControllerTest extends TestCase { $result = $this->controller->generateAppPassword('stateToken'); - $this->assertInstanceOf(Http\StandaloneTemplateResponse::class, $result); + $this->assertInstanceOf(StandaloneTemplateResponse::class, $result); $this->assertSame(Http::STATUS_FORBIDDEN, $result->getStatus()); $this->assertSame('Please use original client', $result->getParams()['message']); } @@ -355,7 +357,7 @@ class ClientFlowLoginV2ControllerTest extends TestCase { $clearedState = false; $clearedLogin = false; $this->session->method('remove') - ->willReturnCallback(function ($name) use (&$clearedLogin, &$clearedState) { + ->willReturnCallback(function ($name) use (&$clearedLogin, &$clearedState): void { if ($name === 'client.flow.v2.state.token') { $clearedState = true; } diff --git a/tests/Core/Controller/CssControllerTest.php b/tests/Core/Controller/CssControllerTest.php index cae6f7989c4..b4764d6ea3a 100644 --- a/tests/Core/Controller/CssControllerTest.php +++ b/tests/Core/Controller/CssControllerTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/tests/Core/Controller/GuestAvatarControllerTest.php b/tests/Core/Controller/GuestAvatarControllerTest.php index 1ad9e49f858..66a83098130 100644 --- a/tests/Core/Controller/GuestAvatarControllerTest.php +++ b/tests/Core/Controller/GuestAvatarControllerTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -7,6 +8,7 @@ namespace Core\Controller; use OC\Core\Controller\GuestAvatarController; use OCP\AppFramework\Http\FileDisplayResponse; +use OCP\Files\File; use OCP\Files\SimpleFS\ISimpleFile; use OCP\IAvatar; use OCP\IAvatarManager; @@ -38,7 +40,7 @@ class GuestAvatarControllerTest extends \Test\TestCase { private $avatar; /** - * @var \OCP\Files\File|\PHPUnit\Framework\MockObject\MockObject + * @var File|\PHPUnit\Framework\MockObject\MockObject */ private $file; diff --git a/tests/Core/Controller/JsControllerTest.php b/tests/Core/Controller/JsControllerTest.php index 1500ed6eacf..30bc02e8625 100644 --- a/tests/Core/Controller/JsControllerTest.php +++ b/tests/Core/Controller/JsControllerTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index d049203c302..18baaf5b08c 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -279,7 +279,7 @@ class LoginControllerTest extends TestCase { ]; $this->initialState->expects($this->exactly(13)) ->method('provideInitialState') - ->willReturnCallback(function () use (&$calls) { + ->willReturnCallback(function () use (&$calls): void { $expected = array_shift($calls); if (!empty($expected)) { $this->assertEquals($expected, func_get_args()); @@ -316,7 +316,7 @@ class LoginControllerTest extends TestCase { ]; $this->initialState->expects($this->exactly(14)) ->method('provideInitialState') - ->willReturnCallback(function () use (&$calls) { + ->willReturnCallback(function () use (&$calls): void { $expected = array_shift($calls); if (!empty($expected)) { $this->assertEquals($expected, func_get_args()); @@ -351,9 +351,7 @@ class LoginControllerTest extends TestCase { ]; } - /** - * @dataProvider passwordResetDataProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('passwordResetDataProvider')] public function testShowLoginFormWithPasswordResetOption($canChangePassword, $expectedResult): void { $this->userSession @@ -396,7 +394,7 @@ class LoginControllerTest extends TestCase { ]; $this->initialState->expects($this->exactly(13)) ->method('provideInitialState') - ->willReturnCallback(function () use (&$calls) { + ->willReturnCallback(function () use (&$calls): void { $expected = array_shift($calls); if (!empty($expected)) { $this->assertEquals($expected, func_get_args()); @@ -459,7 +457,7 @@ class LoginControllerTest extends TestCase { ]; $this->initialState->expects($this->exactly(13)) ->method('provideInitialState') - ->willReturnCallback(function () use (&$calls) { + ->willReturnCallback(function () use (&$calls): void { $expected = array_shift($calls); if (!empty($expected)) { $this->assertEquals($expected, func_get_args()); diff --git a/tests/Core/Controller/LostControllerTest.php b/tests/Core/Controller/LostControllerTest.php index ffe3eb3920d..bbb5f2c2e54 100644 --- a/tests/Core/Controller/LostControllerTest.php +++ b/tests/Core/Controller/LostControllerTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-only @@ -180,7 +181,7 @@ class LostControllerTest extends TestCase { $this->initialState ->expects($this->exactly(2)) ->method('provideInitialState') - ->willReturnCallback(function () use (&$calls) { + ->willReturnCallback(function () use (&$calls): void { $expected = array_shift($calls); $this->assertEquals($expected, func_get_args()); }); @@ -403,7 +404,7 @@ class LostControllerTest extends TestCase { ->expects($this->once()) ->method('send') ->with($message) - ->will($this->throwException(new \Exception())); + ->willThrowException(new \Exception()); $this->logger->expects($this->exactly(1)) ->method('error'); @@ -461,7 +462,7 @@ class LostControllerTest extends TestCase { $this->eventDispatcher ->expects($this->exactly(2)) ->method('dispatchTyped') - ->willReturnCallback(function () use (&$calls) { + ->willReturnCallback(function () use (&$calls): void { $expected = array_shift($calls); $this->assertEquals($expected, func_get_args()); }); @@ -686,10 +687,10 @@ class LostControllerTest extends TestCase { } /** - * @dataProvider dataTwoUsersWithSameEmailOneDisabled * @param bool $userEnabled1 * @param bool $userEnabled2 */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTwoUsersWithSameEmailOneDisabled')] public function testTwoUsersWithSameEmailOneDisabled(bool $userEnabled1, bool $userEnabled2): void { $user1 = $this->createMock(IUser::class); $user1->method('getEMailAddress') diff --git a/tests/Core/Controller/NavigationControllerTest.php b/tests/Core/Controller/NavigationControllerTest.php index 2df705c2296..d00976f18ec 100644 --- a/tests/Core/Controller/NavigationControllerTest.php +++ b/tests/Core/Controller/NavigationControllerTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -47,7 +48,7 @@ class NavigationControllerTest extends TestCase { [true], ]; } - /** @dataProvider dataGetNavigation */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetNavigation')] public function testGetAppNavigation(bool $absolute): void { $this->navigationManager->expects($this->once()) ->method('getAll') @@ -75,7 +76,7 @@ class NavigationControllerTest extends TestCase { } } - /** @dataProvider dataGetNavigation */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetNavigation')] public function testGetSettingsNavigation(bool $absolute): void { $this->navigationManager->expects($this->once()) ->method('getAll') diff --git a/tests/Core/Controller/OCSControllerTest.php b/tests/Core/Controller/OCSControllerTest.php index 142a15e2308..bd7e26d5e8f 100644 --- a/tests/Core/Controller/OCSControllerTest.php +++ b/tests/Core/Controller/OCSControllerTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -15,6 +16,7 @@ use OCP\IRequest; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; +use OCP\Server; use OCP\ServerVersion; use Test\TestCase; @@ -42,7 +44,7 @@ class OCSControllerTest extends TestCase { $this->userSession = $this->createMock(IUserSession::class); $this->userManager = $this->createMock(IUserManager::class); $this->keyManager = $this->createMock(Manager::class); - $serverVersion = \OCP\Server::get(ServerVersion::class); + $serverVersion = Server::get(ServerVersion::class); $this->controller = new OCSController( 'core', @@ -78,7 +80,7 @@ class OCSControllerTest extends TestCase { ->method('isLoggedIn') ->willReturn(true); - $serverVersion = \OCP\Server::get(ServerVersion::class); + $serverVersion = Server::get(ServerVersion::class); $result = []; $result['version'] = [ @@ -111,7 +113,7 @@ class OCSControllerTest extends TestCase { $this->userSession->expects($this->once()) ->method('isLoggedIn') ->willReturn(false); - $serverVersion = \OCP\Server::get(ServerVersion::class); + $serverVersion = Server::get(ServerVersion::class); $result = []; $result['version'] = [ diff --git a/tests/Core/Controller/PreviewControllerTest.php b/tests/Core/Controller/PreviewControllerTest.php index e7ecba27064..5a6cd1fba0a 100644 --- a/tests/Core/Controller/PreviewControllerTest.php +++ b/tests/Core/Controller/PreviewControllerTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -19,7 +20,6 @@ use OCP\Files\Storage\IStorage; use OCP\IPreview; use OCP\IRequest; use OCP\Preview\IMimeIconProvider; -use OCP\Share\IAttributes; use OCP\Share\IShare; use PHPUnit\Framework\MockObject\MockObject; @@ -196,15 +196,9 @@ class PreviewControllerTest extends \Test\TestCase { ->with($this->equalTo($file)) ->willReturn(true); - $shareAttributes = $this->createMock(IAttributes::class); - $shareAttributes->expects(self::atLeastOnce()) - ->method('getAttribute') - ->with('permissions', 'download') - ->willReturn(false); - $share = $this->createMock(IShare::class); - $share->method('getAttributes') - ->willReturn($shareAttributes); + $share->method('canSeeContent') + ->willReturn(false); $storage = $this->createMock(ISharedStorage::class); $storage->method('instanceOfStorage') @@ -242,14 +236,9 @@ class PreviewControllerTest extends \Test\TestCase { ->with($this->equalTo($file)) ->willReturn(true); - $shareAttributes = $this->createMock(IAttributes::class); - $shareAttributes->method('getAttribute') - ->with('permissions', 'download') - ->willReturn(false); - $share = $this->createMock(IShare::class); - $share->method('getAttributes') - ->willReturn($shareAttributes); + $share->method('canSeeContent') + ->willReturn(false); $storage = $this->createMock(ISharedStorage::class); $storage->method('instanceOfStorage') @@ -265,7 +254,7 @@ class PreviewControllerTest extends \Test\TestCase { $this->request ->method('getHeader') - ->with('X-NC-Preview') + ->with('x-nc-preview') ->willReturn('true'); $preview = $this->createMock(ISimpleFile::class); @@ -341,8 +330,8 @@ class PreviewControllerTest extends \Test\TestCase { // No attributes set -> download permitted $share = $this->createMock(IShare::class); - $share->method('getAttributes') - ->willReturn(null); + $share->method('canSeeContent') + ->willReturn(true); $storage = $this->createMock(ISharedStorage::class); $storage->method('instanceOfStorage') diff --git a/tests/Core/Controller/TwoFactorChallengeControllerTest.php b/tests/Core/Controller/TwoFactorChallengeControllerTest.php index 97900191199..d9ea1ca263f 100644 --- a/tests/Core/Controller/TwoFactorChallengeControllerTest.php +++ b/tests/Core/Controller/TwoFactorChallengeControllerTest.php @@ -301,14 +301,14 @@ class TwoFactorChallengeControllerTest extends TestCase { $this->twoFactorManager->expects($this->once()) ->method('verifyChallenge') ->with('myprovider', $user, 'token') - ->will($this->throwException($exception)); + ->willThrowException($exception); $calls = [ ['two_factor_auth_error_message', '2FA failed'], ['two_factor_auth_error', true], ]; $this->session->expects($this->exactly(2)) ->method('set') - ->willReturnCallback(function () use (&$calls) { + ->willReturnCallback(function () use (&$calls): void { $expected = array_shift($calls); $this->assertEquals($expected, func_get_args()); }); diff --git a/tests/Core/Controller/UserControllerTest.php b/tests/Core/Controller/UserControllerTest.php index 979c723dd85..2473f280580 100644 --- a/tests/Core/Controller/UserControllerTest.php +++ b/tests/Core/Controller/UserControllerTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/tests/Core/Controller/WipeControllerTest.php b/tests/Core/Controller/WipeControllerTest.php index fa5f98988e7..5330eb599e6 100644 --- a/tests/Core/Controller/WipeControllerTest.php +++ b/tests/Core/Controller/WipeControllerTest.php @@ -47,9 +47,8 @@ class WipeControllerTest extends TestCase { * @param bool $valid * @param bool $couldPerform * @param bool $result - * - * @dataProvider dataTest */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTest')] public function testCheckWipe(bool $valid, bool $couldPerform, bool $result): void { if (!$valid) { $this->remoteWipe->method('start') @@ -76,9 +75,8 @@ class WipeControllerTest extends TestCase { * @param bool $valid * @param bool $couldPerform * @param bool $result - * - * @dataProvider dataTest */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTest')] public function testWipeDone(bool $valid, bool $couldPerform, bool $result): void { if (!$valid) { $this->remoteWipe->method('finish') |