Add tests for ContactsStore filtering
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
78beb9e6d4
commit
0ef53ebc08
|
@ -177,16 +177,21 @@ class ContactsStoreTest extends TestCase {
|
||||||
->willReturn('yes');
|
->willReturn('yes');
|
||||||
|
|
||||||
$this->config->expects($this->at(1))
|
$this->config->expects($this->at(1))
|
||||||
|
->method('getAppValue')
|
||||||
|
->with($this->equalTo('core'), $this->equalTo('shareapi_restrict_user_enumeration_to_group'), $this->equalTo('yes'))
|
||||||
|
->willReturn('no');
|
||||||
|
|
||||||
|
$this->config->expects($this->at(2))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with($this->equalTo('core'), $this->equalTo('shareapi_exclude_groups'), $this->equalTo('no'))
|
->with($this->equalTo('core'), $this->equalTo('shareapi_exclude_groups'), $this->equalTo('no'))
|
||||||
->willReturn('yes');
|
->willReturn('yes');
|
||||||
|
|
||||||
$this->config->expects($this->at(2))
|
$this->config->expects($this->at(3))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with($this->equalTo('core'), $this->equalTo('shareapi_only_share_with_group_members'), $this->equalTo('no'))
|
->with($this->equalTo('core'), $this->equalTo('shareapi_only_share_with_group_members'), $this->equalTo('no'))
|
||||||
->willReturn('yes');
|
->willReturn('yes');
|
||||||
|
|
||||||
$this->config->expects($this->at(3))
|
$this->config->expects($this->at(4))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with($this->equalTo('core'), $this->equalTo('shareapi_exclude_groups_list'), $this->equalTo(''))
|
->with($this->equalTo('core'), $this->equalTo('shareapi_exclude_groups_list'), $this->equalTo(''))
|
||||||
->willReturn('["group1", "group5", "group6"]');
|
->willReturn('["group1", "group5", "group6"]');
|
||||||
|
@ -223,16 +228,20 @@ class ContactsStoreTest extends TestCase {
|
||||||
$this->assertCount(0, $entries);
|
$this->assertCount(0, $entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetContactsOnlyIfInTheSameGroup() {
|
public function testGetContactsOnlyShareIfInTheSameGroup() {
|
||||||
$this->config->expects($this->at(0))->method('getAppValue')
|
$this->config->expects($this->at(0))->method('getAppValue')
|
||||||
->with($this->equalTo('core'), $this->equalTo('shareapi_allow_share_dialog_user_enumeration'), $this->equalTo('yes'))
|
->with($this->equalTo('core'), $this->equalTo('shareapi_allow_share_dialog_user_enumeration'), $this->equalTo('yes'))
|
||||||
->willReturn('yes');
|
->willReturn('yes');
|
||||||
|
|
||||||
$this->config->expects($this->at(1)) ->method('getAppValue')
|
$this->config->expects($this->at(1)) ->method('getAppValue')
|
||||||
|
->with($this->equalTo('core'), $this->equalTo('shareapi_restrict_user_enumeration_to_group'), $this->equalTo('yes'))
|
||||||
|
->willReturn('no');
|
||||||
|
|
||||||
|
$this->config->expects($this->at(2)) ->method('getAppValue')
|
||||||
->with($this->equalTo('core'), $this->equalTo('shareapi_exclude_groups'), $this->equalTo('no'))
|
->with($this->equalTo('core'), $this->equalTo('shareapi_exclude_groups'), $this->equalTo('no'))
|
||||||
->willReturn('no');
|
->willReturn('no');
|
||||||
|
|
||||||
$this->config->expects($this->at(2))
|
$this->config->expects($this->at(3))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with($this->equalTo('core'), $this->equalTo('shareapi_only_share_with_group_members'), $this->equalTo('no'))
|
->with($this->equalTo('core'), $this->equalTo('shareapi_only_share_with_group_members'), $this->equalTo('no'))
|
||||||
->willReturn('yes');
|
->willReturn('yes');
|
||||||
|
@ -305,6 +314,92 @@ class ContactsStoreTest extends TestCase {
|
||||||
$this->assertEquals('contact', $entries[2]->getProperty('UID'));
|
$this->assertEquals('contact', $entries[2]->getProperty('UID'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetContactsOnlyEnumerateIfInTheSameGroup() {
|
||||||
|
$this->config->expects($this->at(0))->method('getAppValue')
|
||||||
|
->with($this->equalTo('core'), $this->equalTo('shareapi_allow_share_dialog_user_enumeration'), $this->equalTo('yes'))
|
||||||
|
->willReturn('yes');
|
||||||
|
|
||||||
|
$this->config->expects($this->at(1)) ->method('getAppValue')
|
||||||
|
->with($this->equalTo('core'), $this->equalTo('shareapi_restrict_user_enumeration_to_group'), $this->equalTo('yes'))
|
||||||
|
->willReturn('yes');
|
||||||
|
|
||||||
|
$this->config->expects($this->at(2)) ->method('getAppValue')
|
||||||
|
->with($this->equalTo('core'), $this->equalTo('shareapi_exclude_groups'), $this->equalTo('no'))
|
||||||
|
->willReturn('no');
|
||||||
|
|
||||||
|
$this->config->expects($this->at(3))
|
||||||
|
->method('getAppValue')
|
||||||
|
->with($this->equalTo('core'), $this->equalTo('shareapi_only_share_with_group_members'), $this->equalTo('no'))
|
||||||
|
->willReturn('no');
|
||||||
|
|
||||||
|
/** @var IUser|PHPUnit_Framework_MockObject_MockObject $currentUser */
|
||||||
|
$currentUser = $this->createMock(IUser::class);
|
||||||
|
$currentUser->expects($this->once())
|
||||||
|
->method('getUID')
|
||||||
|
->willReturn('user001');
|
||||||
|
|
||||||
|
$this->groupManager->expects($this->at(0))
|
||||||
|
->method('getUserGroupIds')
|
||||||
|
->with($this->equalTo($currentUser))
|
||||||
|
->willReturn(['group1', 'group2', 'group3']);
|
||||||
|
|
||||||
|
$user1 = $this->createMock(IUser::class);
|
||||||
|
$this->userManager->expects($this->at(0))
|
||||||
|
->method('get')
|
||||||
|
->with('user1')
|
||||||
|
->willReturn($user1);
|
||||||
|
$this->groupManager->expects($this->at(1))
|
||||||
|
->method('getUserGroupIds')
|
||||||
|
->with($this->equalTo($user1))
|
||||||
|
->willReturn(['group1']);
|
||||||
|
$user2 = $this->createMock(IUser::class);
|
||||||
|
$this->userManager->expects($this->at(1))
|
||||||
|
->method('get')
|
||||||
|
->with('user2')
|
||||||
|
->willReturn($user2);
|
||||||
|
$this->groupManager->expects($this->at(2))
|
||||||
|
->method('getUserGroupIds')
|
||||||
|
->with($this->equalTo($user2))
|
||||||
|
->willReturn(['group2', 'group3']);
|
||||||
|
$user3 = $this->createMock(IUser::class);
|
||||||
|
$this->userManager->expects($this->at(2))
|
||||||
|
->method('get')
|
||||||
|
->with('user3')
|
||||||
|
->willReturn($user3);
|
||||||
|
$this->groupManager->expects($this->at(3))
|
||||||
|
->method('getUserGroupIds')
|
||||||
|
->with($this->equalTo($user3))
|
||||||
|
->willReturn(['group8', 'group9']);
|
||||||
|
|
||||||
|
$this->contactsManager->expects($this->once())
|
||||||
|
->method('search')
|
||||||
|
->with($this->equalTo(''), $this->equalTo(['FN', 'EMAIL']))
|
||||||
|
->willReturn([
|
||||||
|
[
|
||||||
|
'UID' => 'user1',
|
||||||
|
'isLocalSystemBook' => true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'UID' => 'user2',
|
||||||
|
'isLocalSystemBook' => true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'UID' => 'user3',
|
||||||
|
'isLocalSystemBook' => true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'UID' => 'contact',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$entries = $this->contactsStore->getContacts($currentUser, '');
|
||||||
|
|
||||||
|
$this->assertCount(3, $entries);
|
||||||
|
$this->assertEquals('user1', $entries[0]->getProperty('UID'));
|
||||||
|
$this->assertEquals('user2', $entries[1]->getProperty('UID'));
|
||||||
|
$this->assertEquals('contact', $entries[2]->getProperty('UID'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetContactsWithFilter() {
|
public function testGetContactsWithFilter() {
|
||||||
$this->config->expects($this->at(0))->method('getAppValue')
|
$this->config->expects($this->at(0))->method('getAppValue')
|
||||||
->with($this->equalTo('core'), $this->equalTo('shareapi_allow_share_dialog_user_enumeration'), $this->equalTo('yes'))
|
->with($this->equalTo('core'), $this->equalTo('shareapi_allow_share_dialog_user_enumeration'), $this->equalTo('yes'))
|
||||||
|
|
Loading…
Reference in New Issue