nextcloud/apps/federatedfilesharing/tests/Settings/AdminTest.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

128 lines
3.9 KiB
PHP
Raw Permalink Normal View History

2016-08-15 10:24:56 -04:00
<?php
declare(strict_types=1);
2016-08-15 10:24:56 -04:00
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
2016-08-15 10:24:56 -04:00
*/
namespace OCA\FederatedFileSharing\Tests\Settings;
use OCA\FederatedFileSharing\FederatedShareProvider;
2016-08-15 10:24:56 -04:00
use OCA\FederatedFileSharing\Settings\Admin;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\GlobalScale\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use PHPUnit\Framework\MockObject\MockObject;
2016-08-15 10:24:56 -04:00
use Test\TestCase;
class AdminTest extends TestCase {
private FederatedShareProvider&MockObject $federatedShareProvider;
private IConfig $gsConfig;
private IInitialState&MockObject $initialState;
private Admin $admin;
2016-08-15 10:24:56 -04:00
protected function setUp(): void {
2016-08-15 10:24:56 -04:00
parent::setUp();
$this->federatedShareProvider = $this->createMock(FederatedShareProvider::class);
$this->gsConfig = $this->createMock(IConfig::class);
$this->initialState = $this->createMock(IInitialState::class);
$urlGenerator = $this->createMock(IURLGenerator::class);
$urlGenerator->expects($this->any())
->method('linkToDocs')
->willReturn('doc-link');
2016-08-15 10:24:56 -04:00
$this->admin = new Admin(
$this->federatedShareProvider,
$this->gsConfig,
$this->createMock(IL10N::class),
$urlGenerator,
$this->initialState
2016-08-15 10:24:56 -04:00
);
}
public static function sharingStateProvider(): array {
2016-08-15 10:24:56 -04:00
return [
[
true,
],
[
false,
]
];
}
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'sharingStateProvider')]
public function testGetForm(bool $state): void {
2016-08-15 10:24:56 -04:00
$this->federatedShareProvider
->expects($this->once())
->method('isOutgoingServer2serverShareEnabled')
->willReturn($state);
$this->federatedShareProvider
->expects($this->once())
->method('isIncomingServer2serverShareEnabled')
->willReturn($state);
$this->federatedShareProvider
->expects($this->once())
->method('isIncomingServer2serverShareEnabled')
->willReturn($state);
$this->federatedShareProvider
->expects($this->once())
->method('isLookupServerQueriesEnabled')
->willReturn($state);
$this->federatedShareProvider
->expects($this->once())
->method('isLookupServerUploadEnabled')
->willReturn($state);
$this->federatedShareProvider
->expects($this->once())
->method('isFederatedGroupSharingSupported')
->willReturn($state);
$this->federatedShareProvider
->expects($this->once())
->method('isOutgoingServer2serverGroupShareEnabled')
->willReturn($state);
$this->federatedShareProvider
->expects($this->once())
->method('isIncomingServer2serverGroupShareEnabled')
->willReturn($state);
$this->federatedShareProvider
->expects($this->once())
->method('isFederatedTrustedShareAutoAccept')
->willReturn($state);
$this->gsConfig->expects($this->once())->method('onlyInternalFederation')
->willReturn($state);
2016-08-15 10:24:56 -04:00
$calls = [
['internalOnly', $state],
['sharingFederatedDocUrl', 'doc-link'],
['outgoingServer2serverShareEnabled', $state],
['incomingServer2serverShareEnabled', $state],
['federatedGroupSharingSupported', $state],
['outgoingServer2serverGroupShareEnabled', $state],
['incomingServer2serverGroupShareEnabled', $state],
['lookupServerEnabled', $state],
['lookupServerUploadEnabled', $state],
['federatedTrustedShareAutoAccept', $state],
];
$this->initialState->expects($this->exactly(10))
->method('provideInitialState')
->willReturnCallback(function () use (&$calls): void {
$expected = array_shift($calls);
$this->assertSame($expected, func_get_args());
});
$expected = new TemplateResponse('federatedfilesharing', 'settings-admin', [], '');
2016-08-15 10:24:56 -04:00
$this->assertEquals($expected, $this->admin->getForm());
}
public function testGetSection(): void {
$this->assertSame('sharing', $this->admin->getSection());
}
public function testGetPriority(): void {
$this->assertSame(20, $this->admin->getPriority());
}
}