diff options
Diffstat (limited to 'apps/files/tests/Activity')
-rw-r--r-- | apps/files/tests/Activity/Filter/GenericTest.php | 104 | ||||
-rw-r--r-- | apps/files/tests/Activity/ProviderTest.php | 197 | ||||
-rw-r--r-- | apps/files/tests/Activity/Setting/GenericTest.php | 123 |
3 files changed, 159 insertions, 265 deletions
diff --git a/apps/files/tests/Activity/Filter/GenericTest.php b/apps/files/tests/Activity/Filter/GenericTest.php index f2b1acba3b3..40e2f9848b5 100644 --- a/apps/files/tests/Activity/Filter/GenericTest.php +++ b/apps/files/tests/Activity/Filter/GenericTest.php @@ -1,32 +1,16 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @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: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OCA\Files\Tests\Activity\Filter; - use OCA\Files\Activity\Filter\Favorites; use OCA\Files\Activity\Filter\FileChanges; use OCP\Activity\IFilter; +use OCP\Server; use Test\TestCase; /** @@ -36,84 +20,62 @@ use Test\TestCase; * @group DB */ class GenericTest extends TestCase { - - public function dataFilters() { + public static function dataFilters(): array { return [ [Favorites::class], [FileChanges::class], ]; } - /** - * @dataProvider dataFilters - * @param string $filterClass - */ - public function testImplementsInterface($filterClass) { - $filter = \OC::$server->query($filterClass); + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] + public function testImplementsInterface(string $filterClass): void { + $filter = Server::get($filterClass); $this->assertInstanceOf(IFilter::class, $filter); } - /** - * @dataProvider dataFilters - * @param string $filterClass - */ - public function testGetIdentifier($filterClass) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] + public function testGetIdentifier(string $filterClass): void { /** @var IFilter $filter */ - $filter = \OC::$server->query($filterClass); - $this->assertInternalType('string', $filter->getIdentifier()); + $filter = Server::get($filterClass); + $this->assertIsString($filter->getIdentifier()); } - /** - * @dataProvider dataFilters - * @param string $filterClass - */ - public function testGetName($filterClass) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] + public function testGetName(string $filterClass): void { /** @var IFilter $filter */ - $filter = \OC::$server->query($filterClass); - $this->assertInternalType('string', $filter->getName()); + $filter = Server::get($filterClass); + $this->assertIsString($filter->getName()); } - /** - * @dataProvider dataFilters - * @param string $filterClass - */ - public function testGetPriority($filterClass) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] + public function testGetPriority(string $filterClass): void { /** @var IFilter $filter */ - $filter = \OC::$server->query($filterClass); + $filter = Server::get($filterClass); $priority = $filter->getPriority(); - $this->assertInternalType('int', $filter->getPriority()); + $this->assertIsInt($filter->getPriority()); $this->assertGreaterThanOrEqual(0, $priority); $this->assertLessThanOrEqual(100, $priority); } - /** - * @dataProvider dataFilters - * @param string $filterClass - */ - public function testGetIcon($filterClass) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] + public function testGetIcon(string $filterClass): void { /** @var IFilter $filter */ - $filter = \OC::$server->query($filterClass); - $this->assertInternalType('string', $filter->getIcon()); + $filter = Server::get($filterClass); + $this->assertIsString($filter->getIcon()); $this->assertStringStartsWith('http', $filter->getIcon()); } - /** - * @dataProvider dataFilters - * @param string $filterClass - */ - public function testFilterTypes($filterClass) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] + public function testFilterTypes(string $filterClass): void { /** @var IFilter $filter */ - $filter = \OC::$server->query($filterClass); - $this->assertInternalType('array', $filter->filterTypes([])); + $filter = Server::get($filterClass); + $this->assertIsArray($filter->filterTypes([])); } - /** - * @dataProvider dataFilters - * @param string $filterClass - */ - public function testAllowedApps($filterClass) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] + public function testAllowedApps(string $filterClass): void { /** @var IFilter $filter */ - $filter = \OC::$server->query($filterClass); - $this->assertInternalType('array', $filter->allowedApps()); + $filter = Server::get($filterClass); + $this->assertIsArray($filter->allowedApps()); } } diff --git a/apps/files/tests/Activity/ProviderTest.php b/apps/files/tests/Activity/ProviderTest.php index 4a835f42d75..b6ba095ecfe 100644 --- a/apps/files/tests/Activity/ProviderTest.php +++ b/apps/files/tests/Activity/ProviderTest.php @@ -1,37 +1,25 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com> - * - * @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 OCA\Files\Tests\Activity; - use OCA\Files\Activity\Provider; +use OCP\Activity\Exceptions\UnknownActivityException; use OCP\Activity\IEvent; use OCP\Activity\IEventMerger; use OCP\Activity\IManager; +use OCP\Contacts\IManager as IContactsManager; +use OCP\Federation\ICloudId; +use OCP\Federation\ICloudIdManager; +use OCP\Files\IRootFolder; use OCP\IURLGenerator; -use OCP\IUser; use OCP\IUserManager; use OCP\L10N\IFactory; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; /** @@ -40,31 +28,31 @@ use Test\TestCase; * @package OCA\Files\Tests\Activity */ class ProviderTest extends TestCase { - - /** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $l10nFactory; - /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */ - protected $url; - /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */ - protected $activityManager; - /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ - protected $userManager; - /** @var IEventMerger|\PHPUnit_Framework_MockObject_MockObject */ - protected $eventMerger; - - public function setUp() { + protected IFactory&MockObject $l10nFactory; + protected IURLGenerator&MockObject $url; + protected IManager&MockObject $activityManager; + protected IUserManager&MockObject $userManager; + protected IRootFolder&MockObject $rootFolder; + protected ICloudIdManager&MockObject $cloudIdManager; + protected IContactsManager&MockObject $contactsManager; + protected IEventMerger&MockObject $eventMerger; + + protected function setUp(): void { parent::setUp(); $this->l10nFactory = $this->createMock(IFactory::class); $this->url = $this->createMock(IURLGenerator::class); $this->activityManager = $this->createMock(IManager::class); $this->userManager = $this->createMock(IUserManager::class); + $this->rootFolder = $this->createMock(IRootFolder::class); + $this->cloudIdManager = $this->createMock(ICloudIdManager::class); + $this->contactsManager = $this->createMock(IContactsManager::class); $this->eventMerger = $this->createMock(IEventMerger::class); } /** * @param string[] $methods - * @return Provider|\PHPUnit_Framework_MockObject_MockObject + * @return Provider|MockObject */ protected function getProvider(array $methods = []) { if (!empty($methods)) { @@ -74,9 +62,12 @@ class ProviderTest extends TestCase { $this->url, $this->activityManager, $this->userManager, + $this->rootFolder, + $this->cloudIdManager, + $this->contactsManager, $this->eventMerger, ]) - ->setMethods($methods) + ->onlyMethods($methods) ->getMock(); } return new Provider( @@ -84,27 +75,23 @@ class ProviderTest extends TestCase { $this->url, $this->activityManager, $this->userManager, + $this->rootFolder, + $this->cloudIdManager, + $this->contactsManager, $this->eventMerger ); } - public function dataGetFile() { + public static function dataGetFile(): array { return [ [[42 => '/FortyTwo.txt'], null, '42', 'FortyTwo.txt', 'FortyTwo.txt'], [['23' => '/Twenty/Three.txt'], null, '23', 'Three.txt', 'Twenty/Three.txt'], - ['/Foo/Bar.txt', '128', '128', 'Bar.txt', 'Foo/Bar.txt'], // Legacy from ownCloud 8.2 and before + ['/Foo/Bar.txt', 128, '128', 'Bar.txt', 'Foo/Bar.txt'], // Legacy from ownCloud 8.2 and before ]; } - /** - * @dataProvider dataGetFile - * @param mixed $parameter - * @param mixed $eventId - * @param int $id - * @param string $name - * @param string $path - */ - public function testGetFile($parameter, $eventId, $id, $name, $path) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetFile')] + public function testGetFile(array|string $parameter, ?int $eventId, string $id, string $name, string $path): void { $provider = $this->getProvider(); if ($eventId !== null) { @@ -130,81 +117,73 @@ class ProviderTest extends TestCase { $this->assertSame('link-' . $id, $result['link']); } - /** - * @expectedException \InvalidArgumentException - */ - public function testGetFileThrows() { - $provider = $this->getProvider(); - self::invokePrivate($provider, 'getFile', ['/Foo/Bar.txt', null]); - } - public function dataGetUser() { - return [ - ['test', [], false, 'Test'], - ['foo', ['admin' => 'Admin'], false, 'Bar'], - ['admin', ['admin' => 'Administrator'], true, 'Administrator'], - ]; - } + public function testGetFileThrows(): void { + $this->expectException(UnknownActivityException::class); - /** - * @dataProvider dataGetUser - * @param string $uid - * @param array $cache - * @param bool $cacheHit - * @param string $name - */ - public function testGetUser($uid, $cache, $cacheHit, $name) { - $provider = $this->getProvider(['getDisplayName']); - - self::invokePrivate($provider, 'displayNames', [$cache]); - - if (!$cacheHit) { - $provider->expects($this->once()) - ->method('getDisplayName') - ->with($uid) - ->willReturn($name); - } else { - $provider->expects($this->never()) - ->method('getDisplayName'); - } - - $result = self::invokePrivate($provider, 'getUser', [$uid]); - $this->assertSame('user', $result['type']); - $this->assertSame($uid, $result['id']); - $this->assertSame($name, $result['name']); + $provider = $this->getProvider(); + self::invokePrivate($provider, 'getFile', ['/Foo/Bar.txt', null]); } - public function dataGetDisplayName() { + public static function dataGetUser(): array { return [ - ['test', true, 'Test'], - ['foo', false, 'foo'], + ['test', 'Test user', null, ['type' => 'user', 'id' => 'test', 'name' => 'Test user']], + ['test@http://localhost', null, ['user' => 'test', 'displayId' => 'test@localhost', 'remote' => 'localhost', 'name' => null], ['type' => 'user', 'id' => 'test', 'name' => 'test@localhost', 'server' => 'localhost']], + ['test@http://localhost', null, ['user' => 'test', 'displayId' => 'test@localhost', 'remote' => 'localhost', 'name' => 'Remote user'], ['type' => 'user', 'id' => 'test', 'name' => 'Remote user (test@localhost)', 'server' => 'localhost']], + ['test', null, null, ['type' => 'user', 'id' => 'test', 'name' => 'test']], ]; } - /** - * @dataProvider dataGetDisplayName - * @param string $uid - * @param string $name - */ - public function testGetDisplayNamer($uid, $validUser, $name) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetUser')] + public function testGetUser(string $uid, ?string $userDisplayName, ?array $cloudIdData, array $expected): void { $provider = $this->getProvider(); - if ($validUser) { - $user = $this->createMock(IUser::class); - $user->expects($this->once()) - ->method('getDisplayName') - ->willReturn($name); + if ($userDisplayName !== null) { $this->userManager->expects($this->once()) - ->method('get') + ->method('getDisplayName') ->with($uid) - ->willReturn($user); - } else { - $this->userManager->expects($this->once()) - ->method('get') + ->willReturn($userDisplayName); + } + if ($cloudIdData !== null) { + $this->cloudIdManager->expects($this->once()) + ->method('isValidCloudId') + ->willReturn(true); + + $cloudId = $this->createMock(ICloudId::class); + $cloudId->expects($this->once()) + ->method('getUser') + ->willReturn($cloudIdData['user']); + $cloudId->expects($this->once()) + ->method('getDisplayId') + ->willReturn($cloudIdData['displayId']); + $cloudId->expects($this->once()) + ->method('getRemote') + ->willReturn($cloudIdData['remote']); + + $this->cloudIdManager->expects($this->once()) + ->method('resolveCloudId') ->with($uid) - ->willReturn(null); + ->willReturn($cloudId); + + if ($cloudIdData['name'] !== null) { + $this->contactsManager->expects($this->once()) + ->method('search') + ->with($cloudIdData['displayId'], ['CLOUD']) + ->willReturn([ + [ + 'CLOUD' => $cloudIdData['displayId'], + 'FN' => $cloudIdData['name'], + ] + ]); + } else { + $this->contactsManager->expects($this->once()) + ->method('search') + ->with($cloudIdData['displayId'], ['CLOUD']) + ->willReturn([]); + } } - $this->assertSame($name, self::invokePrivate($provider, 'getDisplayName', [$uid])); + $result = self::invokePrivate($provider, 'getUser', [$uid]); + $this->assertEquals($expected, $result); } } diff --git a/apps/files/tests/Activity/Setting/GenericTest.php b/apps/files/tests/Activity/Setting/GenericTest.php index a8df291cb80..df6b1e0f6d4 100644 --- a/apps/files/tests/Activity/Setting/GenericTest.php +++ b/apps/files/tests/Activity/Setting/GenericTest.php @@ -1,129 +1,82 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @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: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OCA\Files\Tests\Activity\Setting; use OCA\Files\Activity\Settings\FavoriteAction; use OCA\Files\Activity\Settings\FileChanged; -use OCA\Files\Activity\Settings\FileCreated; -use OCA\Files\Activity\Settings\FileDeleted; -use OCA\Files\Activity\Settings\FileFavorite; -use OCA\Files\Activity\Settings\FileRestored; use OCP\Activity\ISetting; +use OCP\Server; use Test\TestCase; class GenericTest extends TestCase { - - public function dataSettings() { + public static function dataSettings(): array { return [ [FavoriteAction::class], [FileChanged::class], - [FileCreated::class], - [FileDeleted::class], - [FileFavorite::class], - [FileRestored::class], + [FileChanged::class], ]; } - /** - * @dataProvider dataSettings - * @param string $settingClass - */ - public function testImplementsInterface($settingClass) { - $setting = \OC::$server->query($settingClass); + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] + public function testImplementsInterface(string $settingClass): void { + $setting = Server::get($settingClass); $this->assertInstanceOf(ISetting::class, $setting); } - /** - * @dataProvider dataSettings - * @param string $settingClass - */ - public function testGetIdentifier($settingClass) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] + public function testGetIdentifier(string $settingClass): void { /** @var ISetting $setting */ - $setting = \OC::$server->query($settingClass); - $this->assertInternalType('string', $setting->getIdentifier()); + $setting = Server::get($settingClass); + $this->assertIsString($setting->getIdentifier()); } - /** - * @dataProvider dataSettings - * @param string $settingClass - */ - public function testGetName($settingClass) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] + public function testGetName(string $settingClass): void { /** @var ISetting $setting */ - $setting = \OC::$server->query($settingClass); - $this->assertInternalType('string', $setting->getName()); + $setting = Server::get($settingClass); + $this->assertIsString($setting->getName()); } - /** - * @dataProvider dataSettings - * @param string $settingClass - */ - public function testGetPriority($settingClass) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] + public function testGetPriority(string $settingClass): void { /** @var ISetting $setting */ - $setting = \OC::$server->query($settingClass); + $setting = Server::get($settingClass); $priority = $setting->getPriority(); - $this->assertInternalType('int', $setting->getPriority()); + $this->assertIsInt($setting->getPriority()); $this->assertGreaterThanOrEqual(0, $priority); $this->assertLessThanOrEqual(100, $priority); } - /** - * @dataProvider dataSettings - * @param string $settingClass - */ - public function testCanChangeStream($settingClass) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] + public function testCanChangeStream(string $settingClass): void { /** @var ISetting $setting */ - $setting = \OC::$server->query($settingClass); - $this->assertInternalType('bool', $setting->canChangeStream()); + $setting = Server::get($settingClass); + $this->assertIsBool($setting->canChangeStream()); } - /** - * @dataProvider dataSettings - * @param string $settingClass - */ - public function testIsDefaultEnabledStream($settingClass) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] + public function testIsDefaultEnabledStream(string $settingClass): void { /** @var ISetting $setting */ - $setting = \OC::$server->query($settingClass); - $this->assertInternalType('bool', $setting->isDefaultEnabledStream()); + $setting = Server::get($settingClass); + $this->assertIsBool($setting->isDefaultEnabledStream()); } - /** - * @dataProvider dataSettings - * @param string $settingClass - */ - public function testCanChangeMail($settingClass) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] + public function testCanChangeMail(string $settingClass): void { /** @var ISetting $setting */ - $setting = \OC::$server->query($settingClass); - $this->assertInternalType('bool', $setting->canChangeMail()); + $setting = Server::get($settingClass); + $this->assertIsBool($setting->canChangeMail()); } - /** - * @dataProvider dataSettings - * @param string $settingClass - */ - public function testIsDefaultEnabledMail($settingClass) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] + public function testIsDefaultEnabledMail(string $settingClass): void { /** @var ISetting $setting */ - $setting = \OC::$server->query($settingClass); - $this->assertInternalType('bool', $setting->isDefaultEnabledMail()); + $setting = Server::get($settingClass); + $this->assertIsBool($setting->isDefaultEnabledMail()); } } |