diff options
Diffstat (limited to 'tests/lib/AppFramework/Controller')
5 files changed, 81 insertions, 159 deletions
diff --git a/tests/lib/AppFramework/Controller/ApiControllerTest.php b/tests/lib/AppFramework/Controller/ApiControllerTest.php index 975b92c5b96..9dd980f975f 100644 --- a/tests/lib/AppFramework/Controller/ApiControllerTest.php +++ b/tests/lib/AppFramework/Controller/ApiControllerTest.php @@ -1,24 +1,9 @@ <?php /** - * ownCloud - App Framework - * - * @author Bernhard Posselt - * @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE - * License as published by the Free Software Foundation; either - * version 3 of the License, or any later version. - * - * This library 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 library. 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-or-later */ namespace Test\AppFramework\Controller; @@ -36,7 +21,7 @@ class ApiControllerTest extends \Test\TestCase { /** @var ChildApiController */ protected $controller; - public function testCors() { + public function testCors(): void { $request = new Request( ['server' => ['HTTP_ORIGIN' => 'test']], $this->createMock(IRequestId::class), diff --git a/tests/lib/AppFramework/Controller/AuthPublicShareControllerTest.php b/tests/lib/AppFramework/Controller/AuthPublicShareControllerTest.php index e996f287c16..4efcac2dccf 100644 --- a/tests/lib/AppFramework/Controller/AuthPublicShareControllerTest.php +++ b/tests/lib/AppFramework/Controller/AuthPublicShareControllerTest.php @@ -1,24 +1,8 @@ <?php + /** - * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl> - * - * @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: 2018 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\AppFramework\Controller; @@ -55,7 +39,7 @@ class AuthPublicShareControllerTest extends \Test\TestCase { $this->request, $this->session, $this->urlGenerator - ])->setMethods([ + ])->onlyMethods([ 'authFailed', 'getPasswordHash', 'isAuthenticated', @@ -68,20 +52,22 @@ class AuthPublicShareControllerTest extends \Test\TestCase { ])->getMock(); } - public function testShowAuthenticate() { + public function testShowAuthenticate(): void { $expects = new TemplateResponse('core', 'publicshareauth', [], 'guest'); $this->assertEquals($expects, $this->controller->showAuthenticate()); } - public function testAuthenticateAuthenticated() { + public function testAuthenticateAuthenticated(): void { $this->controller->method('isAuthenticated') ->willReturn(true); $this->controller->setToken('myToken'); $this->session->method('get') - ->willReturnMap(['public_link_authenticate_redirect', ['foo' => 'bar']]); + ->willReturnMap([ + ['public_link_authenticate_redirect', json_encode(['foo' => 'bar'])], + ]); $this->urlGenerator->method('linkToRoute') ->willReturn('myLink!'); @@ -91,7 +77,7 @@ class AuthPublicShareControllerTest extends \Test\TestCase { $this->assertSame('myLink!', $result->getRedirectURL()); } - public function testAuthenticateInvalidPassword() { + public function testAuthenticateInvalidPassword(): void { $this->controller->setToken('token'); $this->controller->method('isPasswordProtected') ->willReturn(true); @@ -111,7 +97,7 @@ class AuthPublicShareControllerTest extends \Test\TestCase { $this->assertEquals($expects, $result); } - public function testAuthenticateValidPassword() { + public function testAuthenticateValidPassword(): void { $this->controller->setToken('token'); $this->controller->method('isPasswordProtected') ->willReturn(true); @@ -124,7 +110,9 @@ class AuthPublicShareControllerTest extends \Test\TestCase { $this->session->expects($this->once()) ->method('regenerateId'); $this->session->method('get') - ->willReturnMap(['public_link_authenticate_redirect', ['foo' => 'bar']]); + ->willReturnMap([ + ['public_link_authenticate_redirect', json_encode(['foo' => 'bar'])], + ]); $tokenSet = false; $hashSet = false; diff --git a/tests/lib/AppFramework/Controller/ControllerTest.php b/tests/lib/AppFramework/Controller/ControllerTest.php index 1f347cea535..aa016872847 100644 --- a/tests/lib/AppFramework/Controller/ControllerTest.php +++ b/tests/lib/AppFramework/Controller/ControllerTest.php @@ -1,28 +1,14 @@ <?php /** - * ownCloud - App Framework - * - * @author Bernhard Posselt - * @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE - * License as published by the Free Software Foundation; either - * version 3 of the License, or any later version. - * - * This library 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 library. 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-or-later */ namespace Test\AppFramework\Controller; +use OC\AppFramework\DependencyInjection\DIContainer; use OC\AppFramework\Http\Request; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\DataResponse; @@ -30,7 +16,6 @@ use OCP\AppFramework\Http\JSONResponse; use OCP\IConfig; use OCP\IRequest; use OCP\IRequestId; -use OC\AppFramework\DependencyInjection\DIContainer; class ChildController extends Controller { public function __construct($appName, $request) { @@ -81,12 +66,12 @@ class ControllerTest extends \Test\TestCase { ); $this->app = $this->getMockBuilder(DIContainer::class) - ->setMethods(['getAppName']) + ->onlyMethods(['getAppName']) ->setConstructorArgs(['test']) ->getMock(); $this->app->expects($this->any()) - ->method('getAppName') - ->willReturn('apptemplate_advanced'); + ->method('getAppName') + ->willReturn('apptemplate_advanced'); $this->controller = new ChildController($this->app, $request); $this->overwriteService(IRequest::class, $request); @@ -94,21 +79,21 @@ class ControllerTest extends \Test\TestCase { } - public function testFormatResonseInvalidFormat() { + public function testFormatResonseInvalidFormat(): void { $this->expectException(\DomainException::class); $this->controller->buildResponse(null, 'test'); } - public function testFormat() { + public function testFormat(): void { $response = $this->controller->buildResponse(['hi'], 'json'); $this->assertEquals(['hi'], $response->getData()); } - public function testFormatDataResponseJSON() { + public function testFormatDataResponseJSON(): void { $expectedHeaders = [ 'test' => 'something', 'Cache-Control' => 'no-cache, no-store, must-revalidate', @@ -116,7 +101,7 @@ class ControllerTest extends \Test\TestCase { 'Content-Security-Policy' => "default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'", 'Feature-Policy' => "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'", 'X-Request-Id' => $this->request->getId(), - 'X-Robots-Tag' => 'none', + 'X-Robots-Tag' => 'noindex, nofollow', ]; $response = $this->controller->customDataResponse(['hi']); @@ -128,7 +113,7 @@ class ControllerTest extends \Test\TestCase { } - public function testCustomFormatter() { + public function testCustomFormatter(): void { $response = $this->controller->custom('hi'); $response = $this->controller->buildResponse($response, 'json'); @@ -136,14 +121,14 @@ class ControllerTest extends \Test\TestCase { } - public function testDefaultResponderToJSON() { + public function testDefaultResponderToJSON(): void { $responder = $this->controller->getResponderByHTTPHeader('*/*'); $this->assertEquals('json', $responder); } - public function testResponderAcceptHeaderParsed() { + public function testResponderAcceptHeaderParsed(): void { $responder = $this->controller->getResponderByHTTPHeader( '*/*, application/tom, application/json' ); @@ -152,7 +137,7 @@ class ControllerTest extends \Test\TestCase { } - public function testResponderAcceptHeaderParsedUpperCase() { + public function testResponderAcceptHeaderParsedUpperCase(): void { $responder = $this->controller->getResponderByHTTPHeader( '*/*, apPlication/ToM, application/json' ); diff --git a/tests/lib/AppFramework/Controller/OCSControllerTest.php b/tests/lib/AppFramework/Controller/OCSControllerTest.php index ce110f435ef..4ab45ad6b06 100644 --- a/tests/lib/AppFramework/Controller/OCSControllerTest.php +++ b/tests/lib/AppFramework/Controller/OCSControllerTest.php @@ -1,24 +1,9 @@ <?php /** - * ownCloud - App Framework - * - * @author Bernhard Posselt - * @copyright 2015 Bernhard Posselt <dev@bernhard-posselt.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE - * License as published by the Free Software Foundation; either - * version 3 of the License, or any later version. - * - * This library 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 library. 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-or-later */ namespace Test\AppFramework\Controller; @@ -35,7 +20,7 @@ class ChildOCSController extends OCSController { class OCSControllerTest extends \Test\TestCase { - public function testCors() { + public function testCors(): void { $request = new Request( [ 'server' => [ @@ -60,7 +45,7 @@ class OCSControllerTest extends \Test\TestCase { } - public function testXML() { + public function testXML(): void { $controller = new ChildOCSController('app', new Request( [], $this->createMock(IRequestId::class), @@ -68,19 +53,19 @@ class OCSControllerTest extends \Test\TestCase { )); $controller->setOCSVersion(1); - $expected = "<?xml version=\"1.0\"?>\n" . - "<ocs>\n" . - " <meta>\n" . - " <status>ok</status>\n" . - " <statuscode>100</statuscode>\n" . - " <message>OK</message>\n" . - " <totalitems></totalitems>\n" . - " <itemsperpage></itemsperpage>\n" . - " </meta>\n" . - " <data>\n" . - " <test>hi</test>\n" . - " </data>\n" . - "</ocs>\n"; + $expected = "<?xml version=\"1.0\"?>\n" + . "<ocs>\n" + . " <meta>\n" + . " <status>ok</status>\n" + . " <statuscode>100</statuscode>\n" + . " <message>OK</message>\n" + . " <totalitems></totalitems>\n" + . " <itemsperpage></itemsperpage>\n" + . " </meta>\n" + . " <data>\n" + . " <test>hi</test>\n" + . " </data>\n" + . "</ocs>\n"; $params = new DataResponse(['test' => 'hi']); @@ -89,15 +74,15 @@ class OCSControllerTest extends \Test\TestCase { $this->assertEquals($expected, $response->render()); } - public function testJSON() { + public function testJSON(): void { $controller = new ChildOCSController('app', new Request( [], $this->createMock(IRequestId::class), $this->createMock(IConfig::class) )); $controller->setOCSVersion(1); - $expected = '{"ocs":{"meta":{"status":"ok","statuscode":100,"message":"OK",' . - '"totalitems":"","itemsperpage":""},"data":{"test":"hi"}}}'; + $expected = '{"ocs":{"meta":{"status":"ok","statuscode":100,"message":"OK",' + . '"totalitems":"","itemsperpage":""},"data":{"test":"hi"}}}'; $params = new DataResponse(['test' => 'hi']); $response = $controller->buildResponse($params, 'json'); @@ -106,7 +91,7 @@ class OCSControllerTest extends \Test\TestCase { $this->assertEquals($expected, $response->render()); } - public function testXMLV2() { + public function testXMLV2(): void { $controller = new ChildOCSController('app', new Request( [], $this->createMock(IRequestId::class), @@ -114,17 +99,17 @@ class OCSControllerTest extends \Test\TestCase { )); $controller->setOCSVersion(2); - $expected = "<?xml version=\"1.0\"?>\n" . - "<ocs>\n" . - " <meta>\n" . - " <status>ok</status>\n" . - " <statuscode>200</statuscode>\n" . - " <message>OK</message>\n" . - " </meta>\n" . - " <data>\n" . - " <test>hi</test>\n" . - " </data>\n" . - "</ocs>\n"; + $expected = "<?xml version=\"1.0\"?>\n" + . "<ocs>\n" + . " <meta>\n" + . " <status>ok</status>\n" + . " <statuscode>200</statuscode>\n" + . " <message>OK</message>\n" + . " </meta>\n" + . " <data>\n" + . " <test>hi</test>\n" + . " </data>\n" + . "</ocs>\n"; $params = new DataResponse(['test' => 'hi']); @@ -133,7 +118,7 @@ class OCSControllerTest extends \Test\TestCase { $this->assertEquals($expected, $response->render()); } - public function testJSONV2() { + public function testJSONV2(): void { $controller = new ChildOCSController('app', new Request( [], $this->createMock(IRequestId::class), diff --git a/tests/lib/AppFramework/Controller/PublicShareControllerTest.php b/tests/lib/AppFramework/Controller/PublicShareControllerTest.php index 9c03ba4cb6e..e676b8a0d7e 100644 --- a/tests/lib/AppFramework/Controller/PublicShareControllerTest.php +++ b/tests/lib/AppFramework/Controller/PublicShareControllerTest.php @@ -1,24 +1,8 @@ <?php + /** - * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl> - * - * @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: 2018 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\AppFramework\Controller; @@ -28,17 +12,14 @@ use OCP\IRequest; use OCP\ISession; class TestController extends PublicShareController { - /** @var string */ - private $hash; - - /** @var bool */ - private $isProtected; - - public function __construct(string $appName, IRequest $request, ISession $session, string $hash, bool $isProtected) { + public function __construct( + string $appName, + IRequest $request, + ISession $session, + private string $hash, + private bool $isProtected, + ) { parent::__construct($appName, $request, $session); - - $this->hash = $hash; - $this->isProtected = $isProtected; } protected function getPasswordHash(): string { @@ -67,14 +48,14 @@ class PublicShareControllerTest extends \Test\TestCase { $this->session = $this->createMock(ISession::class); } - public function testGetToken() { + public function testGetToken(): void { $controller = new TestController('app', $this->request, $this->session, 'hash', false); $controller->setToken('test'); $this->assertEquals('test', $controller->getToken()); } - public function dataIsAuthenticated() { + public static function dataIsAuthenticated(): array { return [ [false, 'token1', 'token1', 'hash1', 'hash1', true], [false, 'token1', 'token1', 'hash1', 'hash2', true], @@ -87,10 +68,8 @@ class PublicShareControllerTest extends \Test\TestCase { ]; } - /** - * @dataProvider dataIsAuthenticated - */ - public function testIsAuthenticatedNotPasswordProtected(bool $protected, string $token1, string $token2, string $hash1, string $hash2, bool $expected) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataIsAuthenticated')] + public function testIsAuthenticatedNotPasswordProtected(bool $protected, string $token1, string $token2, string $hash1, string $hash2, bool $expected): void { $controller = new TestController('app', $this->request, $this->session, $hash2, $protected); $this->session->method('get') |