aboutsummaryrefslogtreecommitdiffstats
path: root/apps/federation/tests/Controller/SettingsControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/federation/tests/Controller/SettingsControllerTest.php')
-rw-r--r--apps/federation/tests/Controller/SettingsControllerTest.php131
1 files changed, 54 insertions, 77 deletions
diff --git a/apps/federation/tests/Controller/SettingsControllerTest.php b/apps/federation/tests/Controller/SettingsControllerTest.php
index fd072d841b5..b0a7a5e30c9 100644
--- a/apps/federation/tests/Controller/SettingsControllerTest.php
+++ b/apps/federation/tests/Controller/SettingsControllerTest.php
@@ -1,67 +1,50 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Björn Schießle <bjoern@schiessle.org>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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\Federation\Tests\Controller;
use OCA\Federation\Controller\SettingsController;
use OCA\Federation\TrustedServers;
use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\OCS\OCSException;
+use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\IL10N;
use OCP\IRequest;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
use Test\TestCase;
class SettingsControllerTest extends TestCase {
+ private SettingsController $controller;
- /** @var SettingsController */
- private $controller;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | \OCP\IRequest */
- private $request;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | \OCP\IL10N */
- private $l10n;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | \OCA\Federation\TrustedServers */
- private $trustedServers;
+ private IRequest&MockObject $request;
+ private IL10N&MockObject $l10n;
+ private TrustedServers&MockObject $trustedServers;
+ private LoggerInterface&MockObject $logger;
protected function setUp(): void {
parent::setUp();
- $this->request = $this->getMockBuilder(IRequest::class)->getMock();
- $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
- $this->trustedServers = $this->getMockBuilder(TrustedServers::class)
- ->disableOriginalConstructor()->getMock();
+ $this->request = $this->createMock(IRequest::class);
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->trustedServers = $this->createMock(TrustedServers::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
$this->controller = new SettingsController(
'SettingsControllerTest',
$this->request,
$this->l10n,
- $this->trustedServers
+ $this->trustedServers,
+ $this->logger,
);
}
- public function testAddServer() {
+ public function testAddServer(): void {
$this->trustedServers
->expects($this->once())
->method('isTrustedServer')
@@ -69,12 +52,12 @@ class SettingsControllerTest extends TestCase {
->willReturn(false);
$this->trustedServers
->expects($this->once())
- ->method('isOwnCloudServer')
+ ->method('isNextcloudServer')
->with('url')
->willReturn(true);
$result = $this->controller->addServer('url');
- $this->assertTrue($result instanceof DataResponse);
+ $this->assertInstanceOf(DataResponse::class, $result);
$data = $result->getData();
$this->assertSame(200, $result->getStatus());
@@ -82,15 +65,8 @@ class SettingsControllerTest extends TestCase {
$this->assertArrayHasKey('id', $data);
}
- /**
- * @dataProvider checkServerFails
- *
- * @param bool $isTrustedServer
- * @param bool $isOwnCloud
- */
- public function testAddServerFail($isTrustedServer, $isOwnCloud) {
- $this->expectException(\OC\HintException::class);
-
+ #[\PHPUnit\Framework\Attributes\DataProvider('checkServerFails')]
+ public function testAddServerFail(bool $isTrustedServer, bool $isNextcloud): void {
$this->trustedServers
->expects($this->any())
->method('isTrustedServer')
@@ -98,22 +74,29 @@ class SettingsControllerTest extends TestCase {
->willReturn($isTrustedServer);
$this->trustedServers
->expects($this->any())
- ->method('isOwnCloudServer')
+ ->method('isNextcloudServer')
->with('url')
- ->willReturn($isOwnCloud);
+ ->willReturn($isNextcloud);
+
+ if ($isTrustedServer) {
+ $this->expectException(OCSException::class);
+ } else {
+ $this->expectException(OCSNotFoundException::class);
+ }
$this->controller->addServer('url');
}
- public function testRemoveServer() {
- $this->trustedServers->expects($this->once())->method('removeServer')
- ->with('url');
- $result = $this->controller->removeServer('url');
+ public function testRemoveServer(): void {
+ $this->trustedServers->expects($this->once())
+ ->method('removeServer')
+ ->with(1);
+ $result = $this->controller->removeServer(1);
$this->assertTrue($result instanceof DataResponse);
$this->assertSame(200, $result->getStatus());
}
- public function testCheckServer() {
+ public function testCheckServer(): void {
$this->trustedServers
->expects($this->once())
->method('isTrustedServer')
@@ -121,24 +104,17 @@ class SettingsControllerTest extends TestCase {
->willReturn(false);
$this->trustedServers
->expects($this->once())
- ->method('isOwnCloudServer')
+ ->method('isNextcloudServer')
->with('url')
->willReturn(true);
- $this->assertTrue(
- $this->invokePrivate($this->controller, 'checkServer', ['url'])
+ $this->assertNull(
+ self::invokePrivate($this->controller, 'checkServer', ['url'])
);
}
- /**
- * @dataProvider checkServerFails
- *
- * @param bool $isTrustedServer
- * @param bool $isOwnCloud
- */
- public function testCheckServerFail($isTrustedServer, $isOwnCloud) {
- $this->expectException(\OC\HintException::class);
-
+ #[\PHPUnit\Framework\Attributes\DataProvider('checkServerFails')]
+ public function testCheckServerFail(bool $isTrustedServer, bool $isNextcloud): void {
$this->trustedServers
->expects($this->any())
->method('isTrustedServer')
@@ -146,21 +122,22 @@ class SettingsControllerTest extends TestCase {
->willReturn($isTrustedServer);
$this->trustedServers
->expects($this->any())
- ->method('isOwnCloudServer')
+ ->method('isNextcloudServer')
->with('url')
- ->willReturn($isOwnCloud);
+ ->willReturn($isNextcloud);
+
+ if ($isTrustedServer) {
+ $this->expectException(OCSException::class);
+ } else {
+ $this->expectException(OCSNotFoundException::class);
+ }
$this->assertTrue(
- $this->invokePrivate($this->controller, 'checkServer', ['url'])
+ self::invokePrivate($this->controller, 'checkServer', ['url'])
);
}
- /**
- * data to simulate checkServer fails
- *
- * @return array
- */
- public function checkServerFails() {
+ public static function checkServerFails(): array {
return [
[true, true],
[false, false]