diff options
Diffstat (limited to 'tests/lib/Collaboration')
9 files changed, 247 insertions, 379 deletions
diff --git a/tests/lib/Collaboration/Collaborators/GroupPluginTest.php b/tests/lib/Collaboration/Collaborators/GroupPluginTest.php index 1cbaa178445..a4ecd598562 100644 --- a/tests/lib/Collaboration/Collaborators/GroupPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/GroupPluginTest.php @@ -1,24 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @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: 2017 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\Collaboration\Collaborators; @@ -35,19 +19,19 @@ use OCP\Share\IShare; use Test\TestCase; class GroupPluginTest extends TestCase { - /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ protected $config; - /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ protected $groupManager; - /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */ protected $session; - /** @var ISearchResult */ + /** @var ISearchResult */ protected $searchResult; - /** @var GroupPlugin */ + /** @var GroupPlugin */ protected $plugin; /** @var int */ @@ -56,7 +40,7 @@ class GroupPluginTest extends TestCase { /** @var int */ protected $offset = 0; - /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */ protected $user; protected function setUp(): void { @@ -434,7 +418,6 @@ class GroupPluginTest extends TestCase { } /** - * @dataProvider dataGetGroups * * @param string $searchTerm * @param bool $shareWithGroupOnly @@ -447,6 +430,7 @@ class GroupPluginTest extends TestCase { * @param bool $reachedEnd * @param bool|IGroup $singleGroup */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetGroups')] public function testSearch( string $searchTerm, bool $shareWithGroupOnly, @@ -457,8 +441,8 @@ class GroupPluginTest extends TestCase { array $exactExpected, array $expected, bool $reachedEnd, - $singleGroup - ) { + $singleGroup, + ): void { $this->config->expects($this->any()) ->method('getAppValue') ->willReturnCallback( diff --git a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php index 1d856252745..ac9b196ea1e 100644 --- a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php @@ -1,24 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @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: 2017 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\Collaboration\Collaborators; @@ -41,16 +25,15 @@ use Psr\Log\LoggerInterface; use Test\TestCase; class LookupPluginTest extends TestCase { - - /** @var IConfig|MockObject */ + /** @var IConfig|MockObject */ protected $config; - /** @var IClientService|MockObject */ + /** @var IClientService|MockObject */ protected $clientService; /** @var IUserSession|MockObject */ protected $userSession; /** @var ICloudIdManager|MockObject */ protected $cloudIdManager; - /** @var LookupPlugin */ + /** @var LookupPlugin */ protected $plugin; /** @var LoggerInterface|MockObject */ protected $logger; @@ -87,22 +70,20 @@ class LookupPluginTest extends TestCase { ); } - public function testSearchNoLookupServerURI() { + public function testSearchNoLookupServerURI(): void { $this->config->expects($this->once()) ->method('getAppValue') - ->with('files_sharing', 'lookupServerEnabled', 'yes') + ->with('files_sharing', 'lookupServerEnabled', 'no') ->willReturn('yes'); - $this->config->expects($this->at(0)) - ->method('getSystemValue') - ->with('gs.enabled', false) - ->willReturn(false); - - $this->config->expects($this->at(2)) + $this->config->expects($this->exactly(2)) ->method('getSystemValueBool') - ->with('has_internet_connection', true) - ->willReturn(true); - $this->config->expects($this->at(3)) - ->method('getSystemValue') + ->willReturnMap([ + ['gs.enabled', false, true], + ['has_internet_connection', true, true], + ]); + + $this->config->expects($this->once()) + ->method('getSystemValueString') ->with('lookup_server', 'https://lookup.nextcloud.com') ->willReturn(''); @@ -115,20 +96,17 @@ class LookupPluginTest extends TestCase { $this->plugin->search('foobar', 10, 0, $searchResult); } - public function testSearchNoInternet() { + public function testSearchNoInternet(): void { $this->config->expects($this->once()) ->method('getAppValue') - ->with('files_sharing', 'lookupServerEnabled', 'yes') + ->with('files_sharing', 'lookupServerEnabled', 'no') ->willReturn('yes'); - $this->config->expects($this->at(0)) - ->method('getSystemValue') - ->with('gs.enabled', false) - ->willReturn(false); - - $this->config->expects($this->at(2)) + $this->config->expects($this->exactly(2)) ->method('getSystemValueBool') - ->with('has_internet_connection', true) - ->willReturn(false); + ->willReturnMap([ + ['gs.enabled', false, false], + ['has_internet_connection', true, false], + ]); $this->clientService->expects($this->never()) ->method('newClient'); @@ -140,10 +118,10 @@ class LookupPluginTest extends TestCase { } /** - * @dataProvider searchDataProvider * @param array $searchParams */ - public function testSearch(array $searchParams) { + #[\PHPUnit\Framework\Attributes\DataProvider('searchDataProvider')] + public function testSearch(array $searchParams): void { $type = new SearchResultType('lookup'); /** @var ISearchResult|MockObject $searchResult */ @@ -154,19 +132,17 @@ class LookupPluginTest extends TestCase { $this->config->expects($this->once()) ->method('getAppValue') - ->with('files_sharing', 'lookupServerEnabled', 'yes') + ->with('files_sharing', 'lookupServerEnabled', 'no') ->willReturn('yes'); - $this->config->expects($this->at(0)) - ->method('getSystemValue') - ->with('gs.enabled', false) - ->willReturn(false); - - $this->config->expects($this->at(2)) + $this->config->expects($this->exactly(2)) ->method('getSystemValueBool') - ->with('has_internet_connection', true) - ->willReturn(true); - $this->config->expects($this->at(3)) - ->method('getSystemValue') + ->willReturnMap([ + ['gs.enabled', false, true], + ['has_internet_connection', true, true], + ]); + + $this->config->expects($this->once()) + ->method('getSystemValueString') ->with('lookup_server', 'https://lookup.nextcloud.com') ->willReturn($searchParams['server']); @@ -200,12 +176,12 @@ class LookupPluginTest extends TestCase { /** - * @dataProvider dataSearchEnableDisableLookupServer * @param array $searchParams * @param bool $GSEnabled * @param bool $LookupEnabled */ - public function testSearchEnableDisableLookupServer(array $searchParams, $GSEnabled, $LookupEnabled) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataSearchEnableDisableLookupServer')] + public function testSearchEnableDisableLookupServer(array $searchParams, $GSEnabled, $LookupEnabled): void { $type = new SearchResultType('lookup'); /** @var ISearchResult|MockObject $searchResult */ @@ -213,23 +189,21 @@ class LookupPluginTest extends TestCase { $this->config->expects($this->once()) ->method('getAppValue') - ->with('files_sharing', 'lookupServerEnabled', 'yes') + ->with('files_sharing', 'lookupServerEnabled', 'no') ->willReturn($LookupEnabled ? 'yes' : 'no'); - $this->config->expects($this->at(0)) - ->method('getSystemValue') - ->with('gs.enabled', false) - ->willReturn($GSEnabled); - if ($GSEnabled || $LookupEnabled) { + if ($GSEnabled) { $searchResult->expects($this->once()) ->method('addResultSet') ->with($type, $searchParams['expectedResult'], []); - $this->config->expects($this->at(2)) + $this->config->expects($this->exactly(2)) ->method('getSystemValueBool') - ->with('has_internet_connection', true) - ->willReturn(true); - $this->config->expects($this->at(3)) - ->method('getSystemValue') + ->willReturnMap([ + ['gs.enabled', false, $GSEnabled], + ['has_internet_connection', true, true], + ]); + $this->config->expects($this->once()) + ->method('getSystemValueString') ->with('lookup_server', 'https://lookup.nextcloud.com') ->willReturn($searchParams['server']); @@ -252,6 +226,12 @@ class LookupPluginTest extends TestCase { ->willReturn($client); } else { $searchResult->expects($this->never())->method('addResultSet'); + $this->config->expects($this->exactly(2)) + ->method('getSystemValueBool') + ->willReturnMap([ + ['gs.enabled', false, $GSEnabled], + ['has_internet_connection', true, true], + ]); } $moreResults = $this->plugin->search( $searchParams['search'], @@ -264,11 +244,13 @@ class LookupPluginTest extends TestCase { } - public function testSearchLookupServerDisabled() { - $this->config->expects($this->once()) - ->method('getAppValue') - ->with('files_sharing', 'lookupServerEnabled', 'yes') - ->willReturn('no'); + public function testSearchGSDisabled(): void { + $this->config->expects($this->atLeastOnce()) + ->method('getSystemValueBool') + ->willReturnMap([ + ['has_internet_connection', true, true], + ['gs.enabled', false, false], + ]); /** @var ISearchResult|MockObject $searchResult */ $searchResult = $this->createMock(ISearchResult::class); @@ -280,7 +262,7 @@ class LookupPluginTest extends TestCase { $this->assertFalse($this->plugin->search('irr', 10, 0, $searchResult)); } - public function dataSearchEnableDisableLookupServer() { + public static function dataSearchEnableDisableLookupServer(): array { $fedIDs = [ 'foo@enceladus.moon', 'foobar@enceladus.moon', @@ -387,7 +369,6 @@ class LookupPluginTest extends TestCase { 'label' => $fedIDs[0], 'value' => [ 'shareType' => IShare::TYPE_REMOTE, - 'globalScale' => false, 'shareWith' => $fedIDs[0] ], 'extra' => ['federationId' => $fedIDs[0]], @@ -396,7 +377,6 @@ class LookupPluginTest extends TestCase { 'label' => $fedIDs[1], 'value' => [ 'shareType' => IShare::TYPE_REMOTE, - 'globalScale' => false, 'shareWith' => $fedIDs[1] ], 'extra' => ['federationId' => $fedIDs[1]], @@ -405,7 +385,6 @@ class LookupPluginTest extends TestCase { 'label' => $fedIDs[2], 'value' => [ 'shareType' => IShare::TYPE_REMOTE, - 'globalScale' => false, 'shareWith' => $fedIDs[2] ], 'extra' => ['federationId' => $fedIDs[2]], @@ -456,7 +435,7 @@ class LookupPluginTest extends TestCase { ]; } - public function searchDataProvider() { + public static function searchDataProvider(): array { $fedIDs = [ 'foo@enceladus.moon', 'foobar@enceladus.moon', @@ -480,7 +459,7 @@ class LookupPluginTest extends TestCase { 'label' => $fedIDs[0], 'value' => [ 'shareType' => IShare::TYPE_REMOTE, - 'globalScale' => false, + 'globalScale' => true, 'shareWith' => $fedIDs[0] ], 'extra' => ['federationId' => $fedIDs[0]], @@ -489,7 +468,7 @@ class LookupPluginTest extends TestCase { 'label' => $fedIDs[1], 'value' => [ 'shareType' => IShare::TYPE_REMOTE, - 'globalScale' => false, + 'globalScale' => true, 'shareWith' => $fedIDs[1] ], 'extra' => ['federationId' => $fedIDs[1]], @@ -498,7 +477,7 @@ class LookupPluginTest extends TestCase { 'label' => $fedIDs[2], 'value' => [ 'shareType' => IShare::TYPE_REMOTE, - 'globalScale' => false, + 'globalScale' => true, 'shareWith' => $fedIDs[2] ], 'extra' => ['federationId' => $fedIDs[2]], diff --git a/tests/lib/Collaboration/Collaborators/MailPluginTest.php b/tests/lib/Collaboration/Collaborators/MailPluginTest.php index 702c1d6be6e..b38b961a512 100644 --- a/tests/lib/Collaboration/Collaborators/MailPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/MailPluginTest.php @@ -1,24 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @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: 2017 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\Collaboration\Collaborators; @@ -29,40 +13,42 @@ use OC\Federation\CloudIdManager; use OC\KnownUser\KnownUserService; use OCP\Collaboration\Collaborators\SearchResultType; use OCP\Contacts\IManager; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\ICloudIdManager; +use OCP\ICacheFactory; use OCP\IConfig; use OCP\IGroupManager; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; -use OCP\Share\IShare; use OCP\Mail\IMailer; +use OCP\Share\IShare; use Test\TestCase; class MailPluginTest extends TestCase { - /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ protected $config; - /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ protected $contactsManager; - /** @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject */ protected $cloudIdManager; - /** @var MailPlugin */ + /** @var MailPlugin */ protected $plugin; - /** @var SearchResult */ + /** @var SearchResult */ protected $searchResult; - /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ protected $groupManager; - /** @var KnownUserService|\PHPUnit\Framework\MockObject\MockObject */ + /** @var KnownUserService|\PHPUnit\Framework\MockObject\MockObject */ protected $knownUserService; - /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */ protected $userSession; /** @var IMailer|\PHPUnit\Framework\MockObject\MockObject */ @@ -77,7 +63,13 @@ class MailPluginTest extends TestCase { $this->knownUserService = $this->createMock(KnownUserService::class); $this->userSession = $this->createMock(IUserSession::class); $this->mailer = $this->createMock(IMailer::class); - $this->cloudIdManager = new CloudIdManager($this->contactsManager, $this->createMock(IURLGenerator::class), $this->createMock(IUserManager::class)); + $this->cloudIdManager = new CloudIdManager( + $this->createMock(ICacheFactory::class), + $this->createMock(IEventDispatcher::class), + $this->contactsManager, + $this->createMock(IURLGenerator::class), + $this->createMock(IUserManager::class), + ); $this->searchResult = new SearchResult(); } @@ -95,7 +87,6 @@ class MailPluginTest extends TestCase { } /** - * @dataProvider dataGetEmail * * @param string $searchTerm * @param array $contacts @@ -103,7 +94,8 @@ class MailPluginTest extends TestCase { * @param array $expected * @param bool $reachedEnd */ - public function testSearch($searchTerm, $contacts, $shareeEnumeration, $expected, $exactIdMatch, $reachedEnd, $validEmail) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetEmail')] + public function testSearch($searchTerm, $contacts, $shareeEnumeration, $expected, $exactIdMatch, $reachedEnd, $validEmail): void { $this->config->expects($this->any()) ->method('getAppValue') ->willReturnCallback( @@ -143,7 +135,7 @@ class MailPluginTest extends TestCase { $this->assertSame($reachedEnd, $moreResults); } - public function dataGetEmail() { + public static function dataGetEmail(): array { return [ // data set 0 ['test', [], true, ['emails' => [], 'exact' => ['emails' => []]], false, false, false], @@ -197,12 +189,12 @@ class MailPluginTest extends TestCase { 'UID' => 'uid1', 'FN' => 'User @ Localhost', 'EMAIL' => [ - 'username@localhost', + 'username@example.com', ], ], ], true, - ['emails' => [['uuid' => 'uid1', 'name' => 'User @ Localhost', 'type' => '', 'label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@localhost']]], 'exact' => ['emails' => []]], + ['emails' => [['uuid' => 'uid1', 'name' => 'User @ Localhost', 'type' => '', 'label' => 'User @ Localhost (username@example.com)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@example.com']]], 'exact' => ['emails' => []]], false, false, false, @@ -242,24 +234,24 @@ class MailPluginTest extends TestCase { [ [ 'UID' => 'uid3', - 'FN' => 'User3 @ Localhost', + 'FN' => 'User3 @ example.com', ], [ 'UID' => 'uid2', - 'FN' => 'User2 @ Localhost', + 'FN' => 'User2 @ example.com', 'EMAIL' => [ ], ], [ 'UID' => 'uid1', - 'FN' => 'User @ Localhost', + 'FN' => 'User @ example.com', 'EMAIL' => [ - 'username@localhost', + 'username@example.com', ], ], ], true, - ['emails' => [['uuid' => 'uid1', 'name' => 'User @ Localhost', 'type' => '', 'label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@localhost']]], 'exact' => ['emails' => [['label' => 'test@remote.com', 'uuid' => 'test@remote.com', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]], + ['emails' => [['uuid' => 'uid1', 'name' => 'User @ example.com', 'type' => '', 'label' => 'User @ example.com (username@example.com)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@example.com']]], 'exact' => ['emails' => [['label' => 'test@remote.com', 'uuid' => 'test@remote.com', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]], false, false, true, @@ -295,56 +287,56 @@ class MailPluginTest extends TestCase { ], // data set 9 [ - 'username@localhost', + 'username@example.com', [ [ 'UID' => 'uid3', - 'FN' => 'User3 @ Localhost', + 'FN' => 'User3 @ example.com', ], [ 'UID' => 'uid2', - 'FN' => 'User2 @ Localhost', + 'FN' => 'User2 @ example.com', 'EMAIL' => [ ], ], [ 'UID' => 'uid1', - 'FN' => 'User @ Localhost', + 'FN' => 'User @ example.com', 'EMAIL' => [ - 'username@localhost', + 'username@example.com', ], ], ], true, - ['emails' => [], 'exact' => ['emails' => [['name' => 'User @ Localhost', 'uuid' => 'uid1', 'type' => '', 'label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@localhost']]]]], + ['emails' => [], 'exact' => ['emails' => [['name' => 'User @ example.com', 'uuid' => 'uid1', 'type' => '', 'label' => 'User @ example.com (username@example.com)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@example.com']]]]], true, false, false, ], // data set 10 [ - 'username@localhost', + 'username@example.com', [ [ 'UID' => 'uid1', - 'FN' => 'User3 @ Localhost', + 'FN' => 'User3 @ example.com', ], [ 'UID' => 'uid2', - 'FN' => 'User2 @ Localhost', + 'FN' => 'User2 @ example.com', 'EMAIL' => [ ], ], [ 'UID' => 'uid1', - 'FN' => 'User @ Localhost', + 'FN' => 'User @ example.com', 'EMAIL' => [ - 'username@localhost', + 'username@example.com', ], ], ], false, - ['emails' => [], 'exact' => ['emails' => [['name' => 'User @ Localhost', 'uuid' => 'uid1', 'type' => '', 'label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@localhost']]]]], + ['emails' => [], 'exact' => ['emails' => [['name' => 'User @ example.com', 'uuid' => 'uid1', 'type' => '', 'label' => 'User @ example.com (username@example.com)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@example.com']]]]], true, false, false, @@ -373,8 +365,8 @@ class MailPluginTest extends TestCase { ], ], false, - ['emails' => [], 'exact' => ['emails' => [['name' => 'User Name @ Localhost', 'uuid' => 'uid1', 'type' => '', 'label' => 'User Name @ Localhost (user name@localhost)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'user name@localhost']]]]], - true, + ['emails' => [], 'exact' => ['emails' => []]], + false, false, false, ], @@ -547,16 +539,16 @@ class MailPluginTest extends TestCase { 'UID' => 'uid1', 'FN' => 'User Name', 'EMAIL' => [ - ['type' => 'HOME', 'value' => 'username@localhost'], - ['type' => 'WORK', 'value' => 'username@other'], + ['type' => 'HOME', 'value' => 'username@example.com'], + ['type' => 'WORK', 'value' => 'other@example.com'], ], ], ], false, ['emails' => [ ], 'exact' => ['emails' => [ - ['name' => 'User Name', 'uuid' => 'uid1', 'type' => 'HOME', 'label' => 'User Name (username@localhost)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@localhost']], - ['name' => 'User Name', 'uuid' => 'uid1', 'type' => 'WORK', 'label' => 'User Name (username@other)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@other']] + ['name' => 'User Name', 'uuid' => 'uid1', 'type' => 'HOME', 'label' => 'User Name (username@example.com)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@example.com']], + ['name' => 'User Name', 'uuid' => 'uid1', 'type' => 'WORK', 'label' => 'User Name (other@example.com)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'other@example.com']] ]]], false, false, @@ -577,7 +569,6 @@ class MailPluginTest extends TestCase { } /** - * @dataProvider dataGetEmailGroupsOnly * * @param string $searchTerm * @param array $contacts @@ -586,7 +577,8 @@ class MailPluginTest extends TestCase { * @param bool $reachedEnd * @param array groups */ - public function testSearchGroupsOnly($searchTerm, $contacts, $expected, $exactIdMatch, $reachedEnd, $userToGroupMapping, $validEmail) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetEmailGroupsOnly')] + public function testSearchGroupsOnly($searchTerm, $contacts, $expected, $exactIdMatch, $reachedEnd, $userToGroupMapping, $validEmail): void { $this->config->expects($this->any()) ->method('getAppValue') ->willReturnCallback( @@ -602,7 +594,7 @@ class MailPluginTest extends TestCase { $this->instantiatePlugin(); - /** @var \OCP\IUser | \PHPUnit\Framework\MockObject\MockObject */ + /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */ $currentUser = $this->createMock('\OCP\IUser'); $currentUser->expects($this->any()) @@ -627,7 +619,7 @@ class MailPluginTest extends TestCase { $this->groupManager->expects($this->any()) ->method('getUserGroupIds') - ->willReturnCallback(function (\OCP\IUser $user) use ($userToGroupMapping) { + ->willReturnCallback(function (IUser $user) use ($userToGroupMapping) { return $userToGroupMapping[$user->getUID()]; }); @@ -645,7 +637,7 @@ class MailPluginTest extends TestCase { $this->assertSame($reachedEnd, $moreResults); } - public function dataGetEmailGroupsOnly() { + public static function dataGetEmailGroupsOnly(): array { return [ // The user `User` can share with the current user [ @@ -663,8 +655,8 @@ class MailPluginTest extends TestCase { false, false, [ - "currentUser" => ["group1"], - "User" => ["group1"] + 'currentUser' => ['group1'], + 'User' => ['group1'] ], false, ], @@ -684,8 +676,8 @@ class MailPluginTest extends TestCase { false, false, [ - "currentUser" => ["group1"], - "User" => ["group2"] + 'currentUser' => ['group1'], + 'User' => ['group2'] ], false, ], @@ -705,8 +697,8 @@ class MailPluginTest extends TestCase { false, false, [ - "currentUser" => ["group1"], - "User" => ["group2"] + 'currentUser' => ['group1'], + 'User' => ['group2'] ], true, ] diff --git a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php index 4072f3ecde1..a9a5e05dfe4 100644 --- a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php +++ b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php @@ -1,24 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @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: 2017 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\Collaboration\Collaborators; @@ -28,7 +12,9 @@ use OC\Collaboration\Collaborators\SearchResult; use OC\Federation\CloudIdManager; use OCP\Collaboration\Collaborators\SearchResultType; use OCP\Contacts\IManager; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\ICloudIdManager; +use OCP\ICacheFactory; use OCP\IConfig; use OCP\IURLGenerator; use OCP\IUser; @@ -38,23 +24,22 @@ use OCP\Share\IShare; use Test\TestCase; class RemotePluginTest extends TestCase { - /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ protected $userManager; - /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ protected $config; - /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ protected $contactsManager; - /** @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject */ protected $cloudIdManager; - /** @var RemotePlugin */ + /** @var RemotePlugin */ protected $plugin; - /** @var SearchResult */ + /** @var SearchResult */ protected $searchResult; protected function setUp(): void { @@ -63,7 +48,13 @@ class RemotePluginTest extends TestCase { $this->userManager = $this->createMock(IUserManager::class); $this->config = $this->createMock(IConfig::class); $this->contactsManager = $this->createMock(IManager::class); - $this->cloudIdManager = new CloudIdManager($this->contactsManager, $this->createMock(IURLGenerator::class), $this->createMock(IUserManager::class)); + $this->cloudIdManager = new CloudIdManager( + $this->createMock(ICacheFactory::class), + $this->createMock(IEventDispatcher::class), + $this->contactsManager, + $this->createMock(IURLGenerator::class), + $this->createMock(IUserManager::class), + ); $this->searchResult = new SearchResult(); } @@ -80,7 +71,6 @@ class RemotePluginTest extends TestCase { } /** - * @dataProvider dataGetRemote * * @param string $searchTerm * @param array $contacts @@ -89,7 +79,8 @@ class RemotePluginTest extends TestCase { * @param bool $exactIdMatch * @param bool $reachedEnd */ - public function testSearch($searchTerm, array $contacts, $shareeEnumeration, array $expected, $exactIdMatch, $reachedEnd) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetRemote')] + public function testSearch($searchTerm, array $contacts, $shareeEnumeration, array $expected, $exactIdMatch, $reachedEnd): void { $this->config->expects($this->any()) ->method('getAppValue') ->willReturnCallback( @@ -121,13 +112,13 @@ class RemotePluginTest extends TestCase { } /** - * @dataProvider dataTestSplitUserRemote * * @param string $remote * @param string $expectedUser * @param string $expectedUrl */ - public function testSplitUserRemote($remote, $expectedUser, $expectedUrl) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSplitUserRemote')] + public function testSplitUserRemote($remote, $expectedUser, $expectedUrl): void { $this->instantiatePlugin(); $this->contactsManager->expects($this->any()) @@ -140,18 +131,17 @@ class RemotePluginTest extends TestCase { } /** - * @dataProvider dataTestSplitUserRemoteError - * * @param string $id */ - public function testSplitUserRemoteError($id) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSplitUserRemoteError')] + public function testSplitUserRemoteError($id): void { $this->expectException(\Exception::class); $this->instantiatePlugin(); $this->plugin->splitUserRemote($id); } - public function dataGetRemote() { + public static function dataGetRemote() { return [ ['test', [], true, ['remotes' => [], 'exact' => ['remotes' => []]], false, true], ['test', [], false, ['remotes' => [], 'exact' => ['remotes' => []]], false, true], @@ -384,7 +374,7 @@ class RemotePluginTest extends TestCase { ]; } - public function dataTestSplitUserRemote() { + public static function dataTestSplitUserRemote(): array { $userPrefix = ['user@name', 'username']; $protocols = ['', 'http://', 'https://']; $remotes = [ @@ -405,6 +395,11 @@ class RemotePluginTest extends TestCase { foreach ($protocols as $protocol) { $baseUrl = $user . '@' . $protocol . $remote; + if ($protocol === 'https://') { + // https:// protocol is not expected in the final result + $protocol = ''; + } + $testCases[] = [$baseUrl, $user, $protocol . $remote]; $testCases[] = [$baseUrl . '/', $user, $protocol . $remote]; $testCases[] = [$baseUrl . '/index.php', $user, $protocol . $remote]; @@ -415,7 +410,7 @@ class RemotePluginTest extends TestCase { return $testCases; } - public function dataTestSplitUserRemoteError() { + public static function dataTestSplitUserRemoteError(): array { return [ // Invalid path ['user@'], diff --git a/tests/lib/Collaboration/Collaborators/SearchResultTest.php b/tests/lib/Collaboration/Collaborators/SearchResultTest.php index 98e454f2834..687901c47a6 100644 --- a/tests/lib/Collaboration/Collaborators/SearchResultTest.php +++ b/tests/lib/Collaboration/Collaborators/SearchResultTest.php @@ -1,24 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2017 Joas Schilling - * - * @author Joas Schilling <coding@schilljs.com> - * - * @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: 2017 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\Collaboration\Collaborators; @@ -31,9 +15,9 @@ use OCP\IContainer; use Test\TestCase; class SearchResultTest extends TestCase { - /** @var IContainer|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IContainer|\PHPUnit\Framework\MockObject\MockObject */ protected $container; - /** @var ISearch */ + /** @var ISearch */ protected $search; protected function setUp(): void { @@ -44,7 +28,7 @@ class SearchResultTest extends TestCase { $this->search = new Search($this->container); } - public function dataAddResultSet() { + public static function dataAddResultSet(): array { return [ [[], ['exact' => []]], [['users' => ['exact' => null, 'loose' => []]], ['exact' => ['users' => []], 'users' => []]], @@ -54,11 +38,11 @@ class SearchResultTest extends TestCase { } /** - * @dataProvider dataAddResultSet * @param array $toAdd * @param array $expected */ - public function testAddResultSet(array $toAdd, array $expected) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataAddResultSet')] + public function testAddResultSet(array $toAdd, array $expected): void { $result = new SearchResult(); foreach ($toAdd as $type => $results) { @@ -68,7 +52,7 @@ class SearchResultTest extends TestCase { $this->assertEquals($expected, $result->asArray()); } - public function dataHasResult() { + public static function dataHasResult(): array { $result = ['value' => ['shareWith' => 'l1']]; return [ [[],'users', 'n1', false], @@ -83,13 +67,13 @@ class SearchResultTest extends TestCase { } /** - * @dataProvider dataHasResult * @param array $toAdd * @param string $type * @param string $id * @param bool $expected */ - public function testHasResult(array $toAdd, $type, $id, $expected) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataHasResult')] + public function testHasResult(array $toAdd, $type, $id, $expected): void { $result = new SearchResult(); foreach ($toAdd as $addType => $results) { diff --git a/tests/lib/Collaboration/Collaborators/SearchTest.php b/tests/lib/Collaboration/Collaborators/SearchTest.php index 1d55ee6dd22..ade995ea526 100644 --- a/tests/lib/Collaboration/Collaborators/SearchTest.php +++ b/tests/lib/Collaboration/Collaborators/SearchTest.php @@ -1,24 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @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: 2017 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\Collaboration\Collaborators; @@ -33,9 +17,9 @@ use OCP\Share\IShare; use Test\TestCase; class SearchTest extends TestCase { - /** @var IContainer|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IContainer|\PHPUnit\Framework\MockObject\MockObject */ protected $container; - /** @var ISearch */ + /** @var ISearch */ protected $search; protected function setUp(): void { @@ -46,9 +30,7 @@ class SearchTest extends TestCase { $this->search = new Search($this->container); } - /** - * @dataProvider dataSearchSharees - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSearchSharees')] public function testSearch( string $searchTerm, array $shareTypes, @@ -59,8 +41,8 @@ class SearchTest extends TestCase { array $mockedRemotesResult, array $mockedMailResult, array $expected, - bool $expectedMoreResults - ) { + bool $expectedMoreResults, + ): void { $searchResult = new SearchResult(); $userPlugin = $this->createMock(ISearchPlugin::class); @@ -132,7 +114,7 @@ class SearchTest extends TestCase { $this->assertSame($expectedMoreResults, $moreResults); } - public function dataSearchSharees() { + public static function dataSearchSharees(): array { return [ // #0 [ diff --git a/tests/lib/Collaboration/Collaborators/UserPluginTest.php b/tests/lib/Collaboration/Collaborators/UserPluginTest.php index 20e1ed898ad..cb4949fb86d 100644 --- a/tests/lib/Collaboration/Collaborators/UserPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/UserPluginTest.php @@ -1,24 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @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: 2017 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\Collaboration\Collaborators; @@ -35,40 +19,39 @@ use OCP\IUserManager; use OCP\IUserSession; use OCP\Share\IShare; use OCP\UserStatus\IManager as IUserStatusManager; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class UserPluginTest extends TestCase { - /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IConfig|MockObject */ protected $config; - /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUserManager|MockObject */ protected $userManager; - /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IGroupManager|MockObject */ protected $groupManager; - /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUserSession|MockObject */ protected $session; - /** @var KnownUserService|\PHPUnit\Framework\MockObject\MockObject */ + /** @var KnownUserService|MockObject */ protected $knownUserService; - /** @var IUserStatusManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUserStatusManager|MockObject */ protected $userStatusManager; - /** @var UserPlugin */ + /** @var UserPlugin */ protected $plugin; - /** @var ISearchResult */ + /** @var ISearchResult */ protected $searchResult; - /** @var int */ - protected $limit = 2; + protected int $limit = 2; - /** @var int */ - protected $offset = 0; + protected int $offset = 0; - /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUser|MockObject */ protected $user; protected function setUp(): void { @@ -142,7 +125,7 @@ class UserPluginTest extends TestCase { return $group; } - public function dataGetUsers() { + public function dataGetUsers(): array { return [ ['test', false, true, [], [], [], [], true, false], ['test', false, false, [], [], [], [], true, false], @@ -435,7 +418,6 @@ class UserPluginTest extends TestCase { } /** - * @dataProvider dataGetUsers * * @param string $searchTerm * @param bool $shareWithGroupOnly @@ -448,6 +430,7 @@ class UserPluginTest extends TestCase { * @param bool|IUser $singleUser * @param array $users */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetUsers')] public function testSearch( $searchTerm, $shareWithGroupOnly, @@ -459,9 +442,9 @@ class UserPluginTest extends TestCase { $reachedEnd, $singleUser, array $users = [], - $shareeEnumerationPhone = false - ) { - $this->mockConfig(["core" => [ + $shareeEnumerationPhone = false, + ): void { + $this->mockConfig(['core' => [ 'shareapi_only_share_with_group_members' => $shareWithGroupOnly ? 'yes' : 'no', 'shareapi_allow_share_dialog_user_enumeration' => $shareeEnumeration? 'yes' : 'no', 'shareapi_restrict_user_enumeration_to_group' => false ? 'yes' : 'no', @@ -526,7 +509,7 @@ class UserPluginTest extends TestCase { $this->assertSame($reachedEnd, $moreResults); } - public function takeOutCurrentUserProvider() { + public static function takeOutCurrentUserProvider(): array { $inputUsers = [ 'alice' => 'Alice', 'bob' => 'Bob', @@ -552,12 +535,12 @@ class UserPluginTest extends TestCase { } /** - * @dataProvider takeOutCurrentUserProvider * @param array $users * @param array $expectedUIDs * @param $currentUserId */ - public function testTakeOutCurrentUser(array $users, array $expectedUIDs, $currentUserId) { + #[\PHPUnit\Framework\Attributes\DataProvider('takeOutCurrentUserProvider')] + public function testTakeOutCurrentUser(array $users, array $expectedUIDs, $currentUserId): void { $this->instantiatePlugin(); $this->session->expects($this->once()) @@ -573,7 +556,7 @@ class UserPluginTest extends TestCase { $this->assertSame($expectedUIDs, array_keys($users)); } - public function dataSearchEnumeration() { + public static function dataSearchEnumeration(): array { return [ [ 'test', @@ -657,7 +640,7 @@ class UserPluginTest extends TestCase { [ 'core' => [ 'shareapi_allow_share_dialog_user_enumeration' => 'no', - 'shareapi_restrict_user_enumeration_full_match_ignore_second_display_name' => 'yes', + 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn' => 'yes', ], ] ], @@ -734,10 +717,8 @@ class UserPluginTest extends TestCase { ]; } - /** - * @dataProvider dataSearchEnumeration - */ - public function testSearchEnumerationLimit($search, $userGroups, $matchingUsers, $result, $mockedSettings) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataSearchEnumeration')] + public function testSearchEnumerationLimit($search, $userGroups, $matchingUsers, $result, $mockedSettings): void { $this->mockConfig($mockedSettings); $userResults = []; @@ -780,16 +761,16 @@ class UserPluginTest extends TestCase { return null; }); $this->userManager - ->method('searchDisplayName') - ->willReturnCallback(function ($search) use ($matchingUsers) { - $users = array_filter( - $matchingUsers, - fn ($user) => str_contains(strtolower($user['displayName']), strtolower($search)) - ); - return array_map( - fn ($user) => $this->getUserMock($user['uid'], $user['displayName']), - $users); - }); + ->method('searchDisplayName') + ->willReturnCallback(function ($search) use ($matchingUsers) { + $users = array_filter( + $matchingUsers, + fn ($user) => str_contains(strtolower($user['displayName']), strtolower($search)) + ); + return array_map( + fn ($user) => $this->getUserMock($user['uid'], $user['displayName']), + $users); + }); $this->groupManager->method('displayNamesInGroup') ->willReturn($userResults); @@ -798,13 +779,15 @@ class UserPluginTest extends TestCase { $this->session->expects($this->any()) ->method('getUser') ->willReturn($this->getUserMock('test', 'foo')); - // current user - $this->groupManager->expects($this->at(0)) - ->method('getUserGroupIds') - ->willReturn($userGroups); $this->groupManager->expects($this->any()) ->method('getUserGroupIds') - ->willReturnCallback(function ($user) use ($matchingUsers) { + ->willReturnCallback(function ($user) use ($matchingUsers, $userGroups) { + static $firstCall = true; + if ($firstCall) { + $firstCall = false; + // current user + return $userGroups; + } $neededObject = array_filter( $matchingUsers, function ($e) use ($user) { diff --git a/tests/lib/Collaboration/Resources/ManagerTest.php b/tests/lib/Collaboration/Resources/ManagerTest.php index 01a39660a7c..0e4e42458e2 100644 --- a/tests/lib/Collaboration/Resources/ManagerTest.php +++ b/tests/lib/Collaboration/Resources/ManagerTest.php @@ -2,23 +2,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2019 Daniel Kesselberg <mail@danielkesselberg.de> - * - * @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: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\Collaboration\Resources; @@ -27,17 +12,15 @@ use OC\Collaboration\Resources\Manager; use OCP\Collaboration\Resources\IManager; use OCP\Collaboration\Resources\IProviderManager; use OCP\IDBConnection; +use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use Test\TestCase; class ManagerTest extends TestCase { - /** @var LoggerInterface */ - protected $logger; - /** @var IProviderManager */ - protected $providerManager; - /** @var IManager */ - protected $manager; + protected LoggerInterface&MockObject $logger; + protected IProviderManager&MockObject $providerManager; + protected IManager $manager; protected function setUp(): void { parent::setUp(); diff --git a/tests/lib/Collaboration/Resources/ProviderManagerTest.php b/tests/lib/Collaboration/Resources/ProviderManagerTest.php index 01e45de9fdf..b063d89f06e 100644 --- a/tests/lib/Collaboration/Resources/ProviderManagerTest.php +++ b/tests/lib/Collaboration/Resources/ProviderManagerTest.php @@ -2,23 +2,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2019 Daniel Kesselberg <mail@danielkesselberg.de> - * - * @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: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\Collaboration\Resources; @@ -32,7 +17,6 @@ use Psr\Log\LoggerInterface; use Test\TestCase; class ProviderManagerTest extends TestCase { - /** @var IServerContainer */ protected $serverContainer; /** @var LoggerInterface */ @@ -91,14 +75,16 @@ class ProviderManagerTest extends TestCase { } public function testGetResourceProvidersValidAndInvalidProvider(): void { - $this->serverContainer->expects($this->at(0)) - ->method('query') - ->with($this->equalTo('InvalidResourceProvider')) - ->willThrowException(new QueryException('A meaningful error message')); - $this->serverContainer->expects($this->at(1)) + $this->serverContainer->expects($this->exactly(2)) ->method('query') - ->with($this->equalTo(ResourceProvider::class)) - ->willReturn($this->createMock(ResourceProvider::class)); + ->willReturnCallback(function (string $service) { + if ($service === 'InvalidResourceProvider') { + throw new QueryException('A meaningful error message'); + } + if ($service === ResourceProvider::class) { + return $this->createMock(ResourceProvider::class); + } + }); $this->logger->expects($this->once()) ->method('error'); |