diff options
Diffstat (limited to 'apps/files_sharing/tests/Middleware')
3 files changed, 42 insertions, 100 deletions
diff --git a/apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php b/apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php index 7a579c9cddb..efc6b3f7f7f 100644 --- a/apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php +++ b/apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php @@ -1,27 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2016 Roeland Jago Douma <roeland@famdouma.nl> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\Files_Sharing\Tests\Middleware; @@ -92,13 +73,13 @@ class OCSShareAPIMiddlewareTest extends \Test\TestCase { } /** - * @dataProvider dataBeforeController * * @param Controller $controller * @param bool $enabled * @param bool $exception */ - public function testBeforeController(Controller $controller, $enabled, $exception) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataBeforeController')] + public function testBeforeController(Controller $controller, $enabled, $exception): void { $this->shareManager->method('shareApiEnabled')->willReturn($enabled); try { @@ -124,12 +105,12 @@ class OCSShareAPIMiddlewareTest extends \Test\TestCase { } /** - * @dataProvider dataAfterController * * @param Controller $controller * @param bool $called */ - public function testAfterController(Controller $controller) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataAfterController')] + public function testAfterController(Controller $controller): void { if ($controller instanceof ShareAPIController) { $controller->expects($this->once())->method('cleanup'); } diff --git a/apps/files_sharing/tests/Middleware/ShareInfoMiddlewareTest.php b/apps/files_sharing/tests/Middleware/ShareInfoMiddlewareTest.php index 41f104fe20b..631b6a0f51c 100644 --- a/apps/files_sharing/tests/Middleware/ShareInfoMiddlewareTest.php +++ b/apps/files_sharing/tests/Middleware/ShareInfoMiddlewareTest.php @@ -1,25 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2016 Roeland Jago Douma <roeland@famdouma.nl> - * - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\Files_Sharing\Tests\Middleware; @@ -29,6 +12,7 @@ use OCA\Files_Sharing\Middleware\ShareInfoMiddleware; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\Http\Response; use OCP\Share\IManager as ShareManager; use Test\TestCase; @@ -47,14 +31,14 @@ class ShareInfoMiddlewareTest extends TestCase { $this->middleware = new ShareInfoMiddleware($this->shareManager); } - public function testBeforeControllerNoShareInfo() { + public function testBeforeControllerNoShareInfo(): void { $this->shareManager->expects($this->never()) ->method($this->anything()); $this->middleware->beforeController($this->createMock(ShareInfoMiddlewareTestController::class), 'foo'); } - public function testBeforeControllerShareInfoNoS2s() { + public function testBeforeControllerShareInfoNoS2s(): void { $this->shareManager->expects($this->once()) ->method('outgoingServer2ServerSharesAllowed') ->willReturn(false); @@ -63,7 +47,7 @@ class ShareInfoMiddlewareTest extends TestCase { $this->middleware->beforeController($this->createMock(ShareInfoController::class), 'foo'); } - public function testBeforeControllerShareInfo() { + public function testBeforeControllerShareInfo(): void { $this->shareManager->expects($this->once()) ->method('outgoingServer2ServerSharesAllowed') ->willReturn(true); @@ -71,7 +55,7 @@ class ShareInfoMiddlewareTest extends TestCase { $this->middleware->beforeController($this->createMock(ShareInfoController::class), 'foo'); } - public function testAfterExceptionNoShareInfo() { + public function testAfterExceptionNoShareInfo(): void { $exeption = new \Exception(); try { @@ -83,7 +67,7 @@ class ShareInfoMiddlewareTest extends TestCase { } - public function testAfterExceptionNoS2S() { + public function testAfterExceptionNoS2S(): void { $exeption = new \Exception(); try { @@ -94,7 +78,7 @@ class ShareInfoMiddlewareTest extends TestCase { } } - public function testAfterExceptionS2S() { + public function testAfterExceptionS2S(): void { $expected = new JSONResponse([], Http::STATUS_NOT_FOUND); $this->assertEquals( @@ -103,8 +87,8 @@ class ShareInfoMiddlewareTest extends TestCase { ); } - public function testAfterControllerNoShareInfo() { - $response = $this->createMock(Http\Response::class); + public function testAfterControllerNoShareInfo(): void { + $response = $this->createMock(Response::class); $this->assertEquals( $response, @@ -112,8 +96,8 @@ class ShareInfoMiddlewareTest extends TestCase { ); } - public function testAfterControllerNoJSON() { - $response = $this->createMock(Http\Response::class); + public function testAfterControllerNoJSON(): void { + $response = $this->createMock(Response::class); $this->assertEquals( $response, @@ -121,7 +105,7 @@ class ShareInfoMiddlewareTest extends TestCase { ); } - public function testAfterControllerJSONok() { + public function testAfterControllerJSONok(): void { $data = ['foo' => 'bar']; $response = new JSONResponse($data); @@ -136,7 +120,7 @@ class ShareInfoMiddlewareTest extends TestCase { ); } - public function testAfterControllerJSONerror() { + public function testAfterControllerJSONerror(): void { $data = ['foo' => 'bar']; $response = new JSONResponse($data, Http::STATUS_FORBIDDEN); diff --git a/apps/files_sharing/tests/Middleware/SharingCheckMiddlewareTest.php b/apps/files_sharing/tests/Middleware/SharingCheckMiddlewareTest.php index 379cb88567e..3d86007a54c 100644 --- a/apps/files_sharing/tests/Middleware/SharingCheckMiddlewareTest.php +++ b/apps/files_sharing/tests/Middleware/SharingCheckMiddlewareTest.php @@ -1,28 +1,9 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Bjoern Schiessle <bjoern@schiessle.org> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ namespace OCA\Files_Sharing\Middleware; @@ -55,9 +36,9 @@ class SharingCheckMiddlewareTest extends \Test\TestCase { private $controllerMock; /** @var IControllerMethodReflector|\PHPUnit\Framework\MockObject\MockObject */ private $reflector; - /** @var IManager | \PHPUnit\Framework\MockObject\MockObject */ + /** @var IManager | \PHPUnit\Framework\MockObject\MockObject */ private $shareManager; - /** @var IRequest | \PHPUnit\Framework\MockObject\MockObject */ + /** @var IRequest | \PHPUnit\Framework\MockObject\MockObject */ private $request; protected function setUp(): void { @@ -79,7 +60,7 @@ class SharingCheckMiddlewareTest extends \Test\TestCase { $this->request); } - public function testIsSharingEnabledWithAppEnabled() { + public function testIsSharingEnabledWithAppEnabled(): void { $this->appManager ->expects($this->once()) ->method('isEnabledForUser') @@ -89,7 +70,7 @@ class SharingCheckMiddlewareTest extends \Test\TestCase { $this->assertTrue(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled')); } - public function testIsSharingEnabledWithAppDisabled() { + public function testIsSharingEnabledWithAppDisabled(): void { $this->appManager ->expects($this->once()) ->method('isEnabledForUser') @@ -99,7 +80,7 @@ class SharingCheckMiddlewareTest extends \Test\TestCase { $this->assertFalse(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled')); } - public function externalSharesChecksDataProvider() { + public static function externalSharesChecksDataProvider() { $data = []; foreach ([false, true] as $annIn) { @@ -134,10 +115,8 @@ class SharingCheckMiddlewareTest extends \Test\TestCase { return $data; } - /** - * @dataProvider externalSharesChecksDataProvider - */ - public function testExternalSharesChecks($annotations, $config, $expectedResult) { + #[\PHPUnit\Framework\Attributes\DataProvider('externalSharesChecksDataProvider')] + public function testExternalSharesChecks($annotations, $config, $expectedResult): void { $this->reflector ->expects($this->atLeastOnce()) ->method('hasAnnotation') @@ -150,10 +129,8 @@ class SharingCheckMiddlewareTest extends \Test\TestCase { $this->assertEquals($expectedResult, self::invokePrivate($this->sharingCheckMiddleware, 'externalSharesChecks')); } - /** - * @dataProvider externalSharesChecksDataProvider - */ - public function testBeforeControllerWithExternalShareControllerWithSharingEnabled($annotations, $config, $noException) { + #[\PHPUnit\Framework\Attributes\DataProvider('externalSharesChecksDataProvider')] + public function testBeforeControllerWithExternalShareControllerWithSharingEnabled($annotations, $config, $noException): void { $this->appManager ->expects($this->once()) ->method('isEnabledForUser') @@ -182,7 +159,7 @@ class SharingCheckMiddlewareTest extends \Test\TestCase { $this->assertNotEquals($noException, $exceptionThrown); } - public function testBeforeControllerWithShareControllerWithSharingEnabled() { + public function testBeforeControllerWithShareControllerWithSharingEnabled(): void { $share = $this->createMock(IShare::class); $this->appManager @@ -197,8 +174,8 @@ class SharingCheckMiddlewareTest extends \Test\TestCase { } - public function testBeforeControllerWithSharingDisabled() { - $this->expectException(\OCP\Files\NotFoundException::class); + public function testBeforeControllerWithSharingDisabled(): void { + $this->expectException(NotFoundException::class); $this->expectExceptionMessage('Sharing is disabled.'); $this->appManager @@ -211,18 +188,18 @@ class SharingCheckMiddlewareTest extends \Test\TestCase { } - public function testAfterExceptionWithRegularException() { + public function testAfterExceptionWithRegularException(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage('My Exception message'); $this->sharingCheckMiddleware->afterException($this->controllerMock, 'myMethod', new \Exception('My Exception message')); } - public function testAfterExceptionWithNotFoundException() { + public function testAfterExceptionWithNotFoundException(): void { $this->assertEquals(new NotFoundResponse(), $this->sharingCheckMiddleware->afterException($this->controllerMock, 'myMethod', new NotFoundException('My Exception message'))); } - public function testAfterExceptionWithS2SException() { + public function testAfterExceptionWithS2SException(): void { $this->assertEquals(new JSONResponse('My Exception message', 405), $this->sharingCheckMiddleware->afterException($this->controllerMock, 'myMethod', new S2SException('My Exception message'))); } } |