diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2023-11-08 22:21:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-08 22:21:18 +0100 |
commit | 734b11dc86c7f54eff7557271aba1e4530cbcc23 (patch) | |
tree | bdeabbf7460a5ed509e6476fa55257a637d13a18 /tests | |
parent | b29bc59e8b4a0683b6e6af289fbeffad332cfcc5 (diff) | |
parent | 71080a8d20d5e7ee9e77768cdfa47ec07a200393 (diff) | |
download | nextcloud-server-734b11dc86c7f54eff7557271aba1e4530cbcc23.tar.gz nextcloud-server-734b11dc86c7f54eff7557271aba1e4530cbcc23.zip |
Merge pull request #41266 from nextcloud/feat/contactsmenu/user-status-sorting
feat(contactsmenu): Sort by user status
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php | 124 | ||||
-rw-r--r-- | tests/lib/Contacts/ContactsMenu/EntryTest.php | 1 | ||||
-rw-r--r-- | tests/lib/Contacts/ContactsMenu/ManagerTest.php | 4 |
3 files changed, 126 insertions, 3 deletions
diff --git a/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php b/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php index ccb888a6c3d..e3d6ea99226 100644 --- a/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php +++ b/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at> * @copyright 2017 Lukas Reschke <lukas@statuscode.ch> @@ -28,6 +31,8 @@ namespace Tests\Contacts\ContactsMenu; use OC\Contacts\ContactsMenu\ContactsStore; use OC\KnownUser\KnownUserService; use OC\Profile\ProfileManager; +use OCA\UserStatus\Db\UserStatus; +use OCA\UserStatus\Service\StatusService; use OCP\Contacts\IManager; use OCP\IConfig; use OCP\IGroupManager; @@ -40,6 +45,7 @@ use Test\TestCase; class ContactsStoreTest extends TestCase { private ContactsStore $contactsStore; + private StatusService|MockObject $statusService; /** @var IManager|MockObject */ private $contactsManager; /** @var ProfileManager */ @@ -61,6 +67,7 @@ class ContactsStoreTest extends TestCase { parent::setUp(); $this->contactsManager = $this->createMock(IManager::class); + $this->statusService = $this->createMock(StatusService::class); $this->userManager = $this->createMock(IUserManager::class); $this->profileManager = $this->createMock(ProfileManager::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); @@ -70,13 +77,14 @@ class ContactsStoreTest extends TestCase { $this->l10nFactory = $this->createMock(IL10NFactory::class); $this->contactsStore = new ContactsStore( $this->contactsManager, + $this->statusService, $this->config, $this->profileManager, $this->userManager, $this->urlGenerator, $this->groupManager, $this->knownUserService, - $this->l10nFactory + $this->l10nFactory, ); } @@ -964,4 +972,118 @@ class ContactsStoreTest extends TestCase { $this->assertEquals(null, $entry); } + + public function testGetRecentStatusFirst(): void { + $user = $this->createMock(IUser::class); + $status1 = new UserStatus(); + $status1->setUserId('user1'); + $status2 = new UserStatus(); + $status2->setUserId('user2'); + $this->statusService->expects(self::once()) + ->method('findAllRecentStatusChanges') + ->willReturn([ + $status1, + $status2, + ]); + $user1 = $this->createMock(IUser::class); + $user1->method('getCloudId')->willReturn('user1@localcloud'); + $user2 = $this->createMock(IUser::class); + $user2->method('getCloudId')->willReturn('user2@localcloud'); + $this->userManager->expects(self::exactly(2)) + ->method('get') + ->willReturnCallback(function ($uid) use ($user1, $user2) { + return match ($uid) { + 'user1' => $user1, + 'user2' => $user2, + }; + }); + $this->contactsManager + ->expects(self::exactly(3)) + ->method('search') + ->willReturnCallback(function ($uid, $searchProps, $options) { + return match ([$uid, $options['limit'] ?? null]) { + ['user1@localcloud', 1] => [ + [ + 'UID' => 'user1', + 'URI' => 'user1.vcf', + ], + ], + ['user2@localcloud' => [], 1], // Simulate not found + ['', 4] => [ + [ + 'UID' => 'contact1', + 'URI' => 'contact1.vcf', + ], + [ + 'UID' => 'contact2', + 'URI' => 'contact2.vcf', + ], + ], + default => [], + }; + }); + + $contacts = $this->contactsStore->getContacts( + $user, + null, + 5, + ); + + self::assertCount(3, $contacts); + self::assertEquals('user1', $contacts[0]->getProperty('UID')); + self::assertEquals('contact1', $contacts[1]->getProperty('UID')); + self::assertEquals('contact2', $contacts[2]->getProperty('UID')); + } + + public function testPaginateRecentStatus(): void { + $user = $this->createMock(IUser::class); + $status1 = new UserStatus(); + $status1->setUserId('user1'); + $status2 = new UserStatus(); + $status2->setUserId('user2'); + $status3 = new UserStatus(); + $status3->setUserId('user3'); + $this->statusService->expects(self::never()) + ->method('findAllRecentStatusChanges'); + $this->contactsManager + ->expects(self::exactly(2)) + ->method('search') + ->willReturnCallback(function ($uid, $searchProps, $options) { + return match ([$uid, $options['limit'] ?? null, $options['offset'] ?? null]) { + ['', 2, 0] => [ + [ + 'UID' => 'contact1', + 'URI' => 'contact1.vcf', + ], + [ + 'UID' => 'contact2', + 'URI' => 'contact2.vcf', + ], + ], + ['', 2, 3] => [ + [ + 'UID' => 'contact3', + 'URI' => 'contact3.vcf', + ], + ], + default => [], + }; + }); + + $page1 = $this->contactsStore->getContacts( + $user, + null, + 2, + 0, + ); + $page2 = $this->contactsStore->getContacts( + $user, + null, + 2, + 3, + ); + + self::assertCount(2, $page1); + self::assertCount(1, $page2); + } } diff --git a/tests/lib/Contacts/ContactsMenu/EntryTest.php b/tests/lib/Contacts/ContactsMenu/EntryTest.php index 7b1ca5d5320..253ec321365 100644 --- a/tests/lib/Contacts/ContactsMenu/EntryTest.php +++ b/tests/lib/Contacts/ContactsMenu/EntryTest.php @@ -105,6 +105,7 @@ class EntryTest extends TestCase { 'profileUrl' => null, 'status' => null, 'statusMessage' => null, + 'statusMessageTimestamp' => null, 'statusIcon' => null, 'isUser' => false, 'uid' => null, diff --git a/tests/lib/Contacts/ContactsMenu/ManagerTest.php b/tests/lib/Contacts/ContactsMenu/ManagerTest.php index eb776a6e39d..2ea3966ad4f 100644 --- a/tests/lib/Contacts/ContactsMenu/ManagerTest.php +++ b/tests/lib/Contacts/ContactsMenu/ManagerTest.php @@ -26,10 +26,10 @@ namespace Tests\Contacts\ContactsMenu; use OC\Contacts\ContactsMenu\ActionProviderStore; use OC\Contacts\ContactsMenu\ContactsStore; +use OC\Contacts\ContactsMenu\Entry; use OC\Contacts\ContactsMenu\Manager; use OCP\App\IAppManager; use OCP\Constants; -use OCP\Contacts\ContactsMenu\IEntry; use OCP\Contacts\ContactsMenu\IProvider; use OCP\IConfig; use OCP\IUser; @@ -65,7 +65,7 @@ class ManagerTest extends TestCase { private function generateTestEntries(): array { $entries = []; foreach (range('Z', 'A') as $char) { - $entry = $this->createMock(IEntry::class); + $entry = $this->createMock(Entry::class); $entry->expects($this->any()) ->method('getFullName') ->willReturn('Contact ' . $char); |