diff options
author | Vitor Mattos <vitor@php.rio> | 2021-10-13 07:37:26 -0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-03-13 11:16:04 +0100 |
commit | 37565a09839f0511512f6dedb56287c85cfc526a (patch) | |
tree | 28c2620ef5093b6d1f98a06e7b67aee40a61d1d6 /tests | |
parent | 332345e2e6e4159aea38f257e59804ffeed62714 (diff) |
Implement tests on method searchGroups
Signed-off-by: Vitor Mattos <vitor@php.rio>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/php/Chat/AutoComplete/SearchPluginTest.php | 52 | ||||
-rw-r--r-- | tests/php/Chat/Parser/UserMentionTest.php | 5 |
2 files changed, 57 insertions, 0 deletions
diff --git a/tests/php/Chat/AutoComplete/SearchPluginTest.php b/tests/php/Chat/AutoComplete/SearchPluginTest.php index 6f7b90b7b..441007e10 100644 --- a/tests/php/Chat/AutoComplete/SearchPluginTest.php +++ b/tests/php/Chat/AutoComplete/SearchPluginTest.php @@ -21,6 +21,7 @@ namespace OCA\Talk\Tests\php\Chat\AutoComplete; +use OC\Collaboration\Collaborators\SearchResult; use OCA\Talk\Chat\AutoComplete\SearchPlugin; use OCA\Talk\Files\Util; use OCA\Talk\GuestManager; @@ -31,6 +32,7 @@ use OCA\Talk\Room; use OCA\Talk\Service\ParticipantService; use OCA\Talk\TalkSession; use OCP\Collaboration\Collaborators\ISearchResult; +use OCP\IGroup; use OCP\IGroupManager; use OCP\IL10N; use OCP\IUser; @@ -319,4 +321,54 @@ class SearchPluginTest extends TestCase { $plugin = $this->getPlugin(); $this->assertEquals($expected, self::invokePrivate($plugin, 'createGuestResult', [$actorId, $name])); } + + /** + * @dataProvider dataSearchGroups + */ + public function testSearchGroups($search, $groupIds, $isGroup, $displayName, $totalMatches, $totalExactMatches): void { + $this->groupManager + ->method('get') + ->willReturnCallback(function ($groupId) use ($isGroup, $displayName) { + if ($isGroup) { + $group = $this->createMock(IGroup::class); + $group + ->method('getDisplayName') + ->willReturn($displayName); + $group + ->method('getGID') + ->willReturn($groupId); + return $group; + } + }); + $plugin = $this->getPlugin(['createGroupResult']); + $plugin->expects($this->any()) + ->method('createGroupResult') + ->willReturnCallback(function ($groupId) { + return [ + 'label' => $groupId, + 'value' => [ + 'shareType' => 'group', + 'shareWith' => 'group/' . $groupId, + ], + ]; + }); + $searchResult = new SearchResult(); + self::invokePrivate($plugin, 'searchGroups', [$search, $groupIds, $searchResult]); + $actual = $searchResult->asArray(); + $this->assertCount($totalMatches, $actual['groups']); + $this->assertCount($totalExactMatches, $actual['exact']['groups']); + } + + public function dataSearchGroups(): array { + return [ + // $search, $groupIds, $isGroup, $displayName, $totalMatches, $totalExactMatches + ['', ['groupid'], true, 'group', 1, 0], + ['groupid', ['groupid'], true, 'group', 0, 1], + ['gro', ['groupid'], true, 'group', 1, 0], + ['not', ['groupid'], false, 'group', 0, 0], + ['name', ['groupid'], true, 'name', 0, 1], + ['na', ['groupid'], true, 'name', 1, 0], + ['not', ['groupid'], true, 'group', 0, 0], + ]; + } } diff --git a/tests/php/Chat/Parser/UserMentionTest.php b/tests/php/Chat/Parser/UserMentionTest.php index 462704112..ea86699bf 100644 --- a/tests/php/Chat/Parser/UserMentionTest.php +++ b/tests/php/Chat/Parser/UserMentionTest.php @@ -34,6 +34,7 @@ use OCA\Talk\Room; use OCA\Talk\Service\ParticipantService; use OCP\Comments\IComment; use OCP\Comments\ICommentsManager; +use OCP\IGroupManager; use OCP\IL10N; use OCP\IUserManager; use PHPUnit\Framework\MockObject\MockObject; @@ -44,6 +45,8 @@ class UserMentionTest extends TestCase { protected $commentsManager; /** @var IUserManager|MockObject */ protected $userManager; + /** @var IGroupManager */ + protected $groupManager; /** @var GuestManager|MockObject */ protected $guestManager; /** @var ParticipantService|MockObject */ @@ -58,6 +61,7 @@ class UserMentionTest extends TestCase { $this->commentsManager = $this->createMock(ICommentsManager::class); $this->userManager = $this->createMock(IUserManager::class); + $this->groupManager = $this->createMock(IGroupManager::class); $this->guestManager = $this->createMock(GuestManager::class); $this->participantService = $this->createMock(ParticipantService::class); $this->l = $this->createMock(IL10N::class); @@ -65,6 +69,7 @@ class UserMentionTest extends TestCase { $this->parser = new UserMention( $this->commentsManager, $this->userManager, + $this->groupManager, $this->guestManager, $this->participantService, $this->l); |