aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/tests/Activity
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/tests/Activity')
-rw-r--r--apps/files/tests/Activity/Filter/GenericTest.php81
-rw-r--r--apps/files/tests/Activity/ProviderTest.php189
-rw-r--r--apps/files/tests/Activity/Setting/GenericTest.php82
3 files changed, 352 insertions, 0 deletions
diff --git a/apps/files/tests/Activity/Filter/GenericTest.php b/apps/files/tests/Activity/Filter/GenericTest.php
new file mode 100644
index 00000000000..40e2f9848b5
--- /dev/null
+++ b/apps/files/tests/Activity/Filter/GenericTest.php
@@ -0,0 +1,81 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * 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;
+
+/**
+ * Class GenericTest
+ *
+ * @package OCA\Files\Tests\Activity\Filter
+ * @group DB
+ */
+class GenericTest extends TestCase {
+ public static function dataFilters(): array {
+ return [
+ [Favorites::class],
+ [FileChanges::class],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')]
+ public function testImplementsInterface(string $filterClass): void {
+ $filter = Server::get($filterClass);
+ $this->assertInstanceOf(IFilter::class, $filter);
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')]
+ public function testGetIdentifier(string $filterClass): void {
+ /** @var IFilter $filter */
+ $filter = Server::get($filterClass);
+ $this->assertIsString($filter->getIdentifier());
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')]
+ public function testGetName(string $filterClass): void {
+ /** @var IFilter $filter */
+ $filter = Server::get($filterClass);
+ $this->assertIsString($filter->getName());
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')]
+ public function testGetPriority(string $filterClass): void {
+ /** @var IFilter $filter */
+ $filter = Server::get($filterClass);
+ $priority = $filter->getPriority();
+ $this->assertIsInt($filter->getPriority());
+ $this->assertGreaterThanOrEqual(0, $priority);
+ $this->assertLessThanOrEqual(100, $priority);
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')]
+ public function testGetIcon(string $filterClass): void {
+ /** @var IFilter $filter */
+ $filter = Server::get($filterClass);
+ $this->assertIsString($filter->getIcon());
+ $this->assertStringStartsWith('http', $filter->getIcon());
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')]
+ public function testFilterTypes(string $filterClass): void {
+ /** @var IFilter $filter */
+ $filter = Server::get($filterClass);
+ $this->assertIsArray($filter->filterTypes([]));
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')]
+ public function testAllowedApps(string $filterClass): void {
+ /** @var IFilter $filter */
+ $filter = Server::get($filterClass);
+ $this->assertIsArray($filter->allowedApps());
+ }
+}
diff --git a/apps/files/tests/Activity/ProviderTest.php b/apps/files/tests/Activity/ProviderTest.php
new file mode 100644
index 00000000000..b6ba095ecfe
--- /dev/null
+++ b/apps/files/tests/Activity/ProviderTest.php
@@ -0,0 +1,189 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * 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\IUserManager;
+use OCP\L10N\IFactory;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+/**
+ * Class ProviderTest
+ *
+ * @package OCA\Files\Tests\Activity
+ */
+class ProviderTest extends TestCase {
+ 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|MockObject
+ */
+ protected function getProvider(array $methods = []) {
+ if (!empty($methods)) {
+ return $this->getMockBuilder(Provider::class)
+ ->setConstructorArgs([
+ $this->l10nFactory,
+ $this->url,
+ $this->activityManager,
+ $this->userManager,
+ $this->rootFolder,
+ $this->cloudIdManager,
+ $this->contactsManager,
+ $this->eventMerger,
+ ])
+ ->onlyMethods($methods)
+ ->getMock();
+ }
+ return new Provider(
+ $this->l10nFactory,
+ $this->url,
+ $this->activityManager,
+ $this->userManager,
+ $this->rootFolder,
+ $this->cloudIdManager,
+ $this->contactsManager,
+ $this->eventMerger
+ );
+ }
+
+ 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
+ ];
+ }
+
+ #[\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) {
+ $event = $this->createMock(IEvent::class);
+ $event->expects($this->once())
+ ->method('getObjectId')
+ ->willReturn($eventId);
+ } else {
+ $event = null;
+ }
+
+ $this->url->expects($this->once())
+ ->method('linkToRouteAbsolute')
+ ->with('files.viewcontroller.showFile', ['fileid' => $id])
+ ->willReturn('link-' . $id);
+
+ $result = self::invokePrivate($provider, 'getFile', [$parameter, $event]);
+
+ $this->assertSame('file', $result['type']);
+ $this->assertSame($id, $result['id']);
+ $this->assertSame($name, $result['name']);
+ $this->assertSame($path, $result['path']);
+ $this->assertSame('link-' . $id, $result['link']);
+ }
+
+
+ public function testGetFileThrows(): void {
+ $this->expectException(UnknownActivityException::class);
+
+ $provider = $this->getProvider();
+ self::invokePrivate($provider, 'getFile', ['/Foo/Bar.txt', null]);
+ }
+
+ public static function dataGetUser(): array {
+ return [
+ ['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']],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetUser')]
+ public function testGetUser(string $uid, ?string $userDisplayName, ?array $cloudIdData, array $expected): void {
+ $provider = $this->getProvider();
+
+ if ($userDisplayName !== null) {
+ $this->userManager->expects($this->once())
+ ->method('getDisplayName')
+ ->with($uid)
+ ->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($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([]);
+ }
+ }
+
+ $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
new file mode 100644
index 00000000000..df6b1e0f6d4
--- /dev/null
+++ b/apps/files/tests/Activity/Setting/GenericTest.php
@@ -0,0 +1,82 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * 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 OCP\Activity\ISetting;
+use OCP\Server;
+use Test\TestCase;
+
+class GenericTest extends TestCase {
+ public static function dataSettings(): array {
+ return [
+ [FavoriteAction::class],
+ [FileChanged::class],
+ [FileChanged::class],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')]
+ public function testImplementsInterface(string $settingClass): void {
+ $setting = Server::get($settingClass);
+ $this->assertInstanceOf(ISetting::class, $setting);
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')]
+ public function testGetIdentifier(string $settingClass): void {
+ /** @var ISetting $setting */
+ $setting = Server::get($settingClass);
+ $this->assertIsString($setting->getIdentifier());
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')]
+ public function testGetName(string $settingClass): void {
+ /** @var ISetting $setting */
+ $setting = Server::get($settingClass);
+ $this->assertIsString($setting->getName());
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')]
+ public function testGetPriority(string $settingClass): void {
+ /** @var ISetting $setting */
+ $setting = Server::get($settingClass);
+ $priority = $setting->getPriority();
+ $this->assertIsInt($setting->getPriority());
+ $this->assertGreaterThanOrEqual(0, $priority);
+ $this->assertLessThanOrEqual(100, $priority);
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')]
+ public function testCanChangeStream(string $settingClass): void {
+ /** @var ISetting $setting */
+ $setting = Server::get($settingClass);
+ $this->assertIsBool($setting->canChangeStream());
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')]
+ public function testIsDefaultEnabledStream(string $settingClass): void {
+ /** @var ISetting $setting */
+ $setting = Server::get($settingClass);
+ $this->assertIsBool($setting->isDefaultEnabledStream());
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')]
+ public function testCanChangeMail(string $settingClass): void {
+ /** @var ISetting $setting */
+ $setting = Server::get($settingClass);
+ $this->assertIsBool($setting->canChangeMail());
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')]
+ public function testIsDefaultEnabledMail(string $settingClass): void {
+ /** @var ISetting $setting */
+ $setting = Server::get($settingClass);
+ $this->assertIsBool($setting->isDefaultEnabledMail());
+ }
+}