mirror of
https://github.com/nextcloud/server.git
synced 2026-02-03 20:41:22 -05:00
test: Add unit test for excluded groups in contacts menu
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
parent
53cc490c8f
commit
ca5b838181
1 changed files with 89 additions and 0 deletions
|
|
@ -188,6 +188,95 @@ class ContactsStoreTest extends TestCase {
|
|||
$this->assertEquals('https://photo', $entries[1]->getAvatar());
|
||||
}
|
||||
|
||||
public static function dataGetContactsWhenUserIsInExcludeGroups(): array {
|
||||
return [
|
||||
['yes', '[]', [], ['user123', 'user12345']],
|
||||
['yes', '["excludedGroup1"]', [], ['user123', 'user12345']],
|
||||
['yes', '["excludedGroup1"]', ['anotherGroup1'], ['user123', 'user12345']],
|
||||
['yes', '["excludedGroup1"]', ['anotherGroup1', 'anotherGroup2', 'anotherGroup3'], ['user123', 'user12345']],
|
||||
['yes', '["excludedGroup1"]', ['excludedGroup1'], []],
|
||||
['yes', '["excludedGroup1"]', ['anotherGroup1', 'excludedGroup1'], []],
|
||||
['yes', '["excludedGroup1"]', ['excludedGroup1', 'anotherGroup1', 'anotherGroup2', 'anotherGroup3'], []],
|
||||
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', [], ['user123', 'user12345']],
|
||||
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['anotherGroup1'], ['user123', 'user12345']],
|
||||
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['anotherGroup1', 'anotherGroup2', 'anotherGroup3'], ['user123', 'user12345']],
|
||||
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['excludedGroup1'], []],
|
||||
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['excludedGroup2'], []],
|
||||
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['excludedGroup3'], []],
|
||||
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['excludedGroup1', 'excludedGroup2', 'excludedGroup3'], []],
|
||||
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['anotherGroup1', 'excludedGroup1'], []],
|
||||
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['anotherGroup1', 'excludedGroup2', 'anotherGroup2', 'anotherGroup3'], []],
|
||||
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['excludedGroup3', 'anotherGroup1', 'anotherGroup2', 'anotherGroup3'], []],
|
||||
['allow', '[]', [], []],
|
||||
['allow', '["allowedGroup1"]', [], []],
|
||||
['allow', '["allowedGroup1"]', ['anotherGroup1'], []],
|
||||
['allow', '["allowedGroup1"]', ['anotherGroup1', 'anotherGroup2', 'anotherGroup3'], []],
|
||||
['allow', '["allowedGroup1"]', ['allowedGroup1'], ['user123', 'user12345']],
|
||||
['allow', '["allowedGroup1"]', ['anotherGroup1', 'allowedGroup1'], ['user123', 'user12345']],
|
||||
['allow', '["allowedGroup1"]', ['allowedGroup1', 'anotherGroup1', 'anotherGroup2', 'anotherGroup3'], ['user123', 'user12345']],
|
||||
['allow', '["allowedGroup1", "allowedGroup2", "allowedGroup3"]', [], []],
|
||||
['allow', '["allowedGroup1", "allowedGroup2", "allowedGroup3"]', ['anotherGroup1'], []],
|
||||
['allow', '["allowedGroup1", "allowedGroup2", "allowedGroup3"]', ['anotherGroup1', 'anotherGroup2', 'anotherGroup3'], []],
|
||||
['allow', '["allowedGroup1", "allowedGroup2", "allowedGroup3"]', ['allowedGroup1'], ['user123', 'user12345']],
|
||||
['allow', '["allowedGroup1", "allowedGroup2", "allowedGroup3"]', ['allowedGroup2'], ['user123', 'user12345']],
|
||||
['allow', '["allowedGroup1", "allowedGroup2", "allowedGroup3"]', ['allowedGroup3'], ['user123', 'user12345']],
|
||||
['allow', '["allowedGroup1", "allowedGroup2", "allowedGroup3"]', ['allowedGroup1', 'allowedGroup2', 'allowedGroup3'], ['user123', 'user12345']],
|
||||
['allow', '["allowedGroup1", "allowedGroup2", "allowedGroup3"]', ['anotherGroup1', 'allowedGroup1'], ['user123', 'user12345']],
|
||||
['allow', '["allowedGroup1", "allowedGroup2", "allowedGroup3"]', ['anotherGroup1', 'allowedGroup2', 'anotherGroup2', 'anotherGroup3'], ['user123', 'user12345']],
|
||||
['allow', '["allowedGroup1", "allowedGroup2", "allowedGroup3"]', ['allowedGroup3', 'anotherGroup1', 'anotherGroup2', 'anotherGroup3'], ['user123', 'user12345']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataGetContactsWhenUserIsInExcludeGroups
|
||||
*/
|
||||
public function testGetContactsWhenUserIsInExcludeGroups(string $excludeGroups, string $excludeGroupsList, array $currentUserGroupIds, array $expectedUids): void {
|
||||
$this->config
|
||||
->method('getAppValue')
|
||||
->willReturnMap([
|
||||
['core', 'shareapi_allow_share_dialog_user_enumeration', 'yes', 'yes'],
|
||||
['core', 'shareapi_restrict_user_enumeration_to_group', 'no', 'no'],
|
||||
['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
|
||||
['core', 'shareapi_exclude_groups', 'no', $excludeGroups],
|
||||
['core', 'shareapi_only_share_with_group_members', 'no', 'no'],
|
||||
['core', 'shareapi_exclude_groups_list', '', $excludeGroupsList],
|
||||
['core', 'shareapi_only_share_with_group_members_exclude_group_list', '', '[]'],
|
||||
]);
|
||||
|
||||
/** @var IUser|MockObject $currentUser */
|
||||
$currentUser = $this->createMock(IUser::class);
|
||||
$currentUser->expects($this->exactly(2))
|
||||
->method('getUID')
|
||||
->willReturn('user001');
|
||||
|
||||
$this->groupManager->expects($this->once())
|
||||
->method('getUserGroupIds')
|
||||
->with($this->equalTo($currentUser))
|
||||
->willReturn($currentUserGroupIds);
|
||||
|
||||
$this->contactsManager->expects($this->once())
|
||||
->method('search')
|
||||
->with($this->equalTo(''), $this->equalTo(['FN', 'EMAIL']))
|
||||
->willReturn([
|
||||
[
|
||||
'UID' => 'user123',
|
||||
'isLocalSystemBook' => true
|
||||
],
|
||||
[
|
||||
'UID' => 'user12345',
|
||||
'isLocalSystemBook' => true
|
||||
],
|
||||
]);
|
||||
|
||||
|
||||
$entries = $this->contactsStore->getContacts($currentUser, '');
|
||||
|
||||
$this->assertCount(count($expectedUids), $entries);
|
||||
for ($i = 0; $i < count($expectedUids); $i++) {
|
||||
$this->assertEquals($expectedUids[$i], $entries[$i]->getProperty('UID'));
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetContactsOnlyShareIfInTheSameGroupWhenUserIsInExcludeGroups(): void {
|
||||
$this->config
|
||||
->method('getAppValue')
|
||||
|
|
|
|||
Loading…
Reference in a new issue