2017-09-13 00:40:46 +03:00
< ? php
/**
* @ copyright Copyright ( c ) 2017 Arthur Schiwon < blizzz @ arthur - schiwon . de >
*
* @ author Arthur Schiwon < blizzz @ arthur - schiwon . de >
*
* @ license GNU AGPL version 3 or any later version
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation , either version 3 of the
* License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*
*/
namespace Test\Collaboration\Collaborators ;
use OC\Collaboration\Collaborators\MailPlugin ;
use OC\Collaboration\Collaborators\SearchResult ;
use OC\Federation\CloudIdManager ;
use OCP\Collaboration\Collaborators\SearchResultType ;
use OCP\Contacts\IManager ;
use OCP\Federation\ICloudIdManager ;
use OCP\IConfig ;
2017-12-16 10:46:03 +03:00
use OCP\IGroupManager ;
2018-03-07 13:48:14 +03:00
use OCP\IUser ;
2017-12-16 10:46:03 +03:00
use OCP\IUserSession ;
2017-09-13 00:40:46 +03:00
use OCP\Share ;
use Test\TestCase ;
class MailPluginTest extends TestCase {
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
protected $config ;
/** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
protected $contactsManager ;
/** @var ICloudIdManager|\PHPUnit_Framework_MockObject_MockObject */
protected $cloudIdManager ;
/** @var MailPlugin */
protected $plugin ;
/** @var SearchResult */
protected $searchResult ;
2017-12-16 10:46:03 +03:00
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
protected $groupManager ;
/** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
protected $userSession ;
2019-11-27 17:27:18 +03:00
protected function setUp () : void {
2017-09-13 00:40:46 +03:00
parent :: setUp ();
$this -> config = $this -> createMock ( IConfig :: class );
$this -> contactsManager = $this -> createMock ( IManager :: class );
2017-12-16 10:46:03 +03:00
$this -> groupManager = $this -> createMock ( IGroupManager :: class );
$this -> userSession = $this -> createMock ( IUserSession :: class );
2017-09-13 00:40:46 +03:00
$this -> cloudIdManager = new CloudIdManager ();
$this -> searchResult = new SearchResult ();
}
public function instantiatePlugin () {
2017-12-16 10:46:03 +03:00
$this -> plugin = new MailPlugin ( $this -> contactsManager , $this -> cloudIdManager , $this -> config , $this -> groupManager , $this -> userSession );
2017-09-13 00:40:46 +03:00
}
/**
* @ dataProvider dataGetEmail
*
* @ param string $searchTerm
* @ param array $contacts
* @ param bool $shareeEnumeration
* @ param array $expected
* @ param bool $reachedEnd
*/
public function testSearch ( $searchTerm , $contacts , $shareeEnumeration , $expected , $exactIdMatch , $reachedEnd ) {
$this -> config -> expects ( $this -> any ())
-> method ( 'getAppValue' )
-> willReturnCallback (
2020-04-09 14:53:40 +03:00
function ( $appName , $key , $default ) use ( $shareeEnumeration )
2017-09-13 00:40:46 +03:00
{
if ( $appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration' ) {
return $shareeEnumeration ? 'yes' : 'no' ;
}
return $default ;
}
);
$this -> instantiatePlugin ();
2018-03-07 13:48:14 +03:00
$currentUser = $this -> createMock ( IUser :: class );
$currentUser -> method ( 'getUID' )
-> willReturn ( 'current' );
$this -> userSession -> method ( 'getUser' )
-> willReturn ( $currentUser );
2017-09-13 00:40:46 +03:00
$this -> contactsManager -> expects ( $this -> any ())
-> method ( 'search' )
-> with ( $searchTerm , [ 'EMAIL' , 'FN' ])
-> willReturn ( $contacts );
2018-02-06 20:11:44 +03:00
$moreResults = $this -> plugin -> search ( $searchTerm , 2 , 0 , $this -> searchResult );
2017-09-13 00:40:46 +03:00
$result = $this -> searchResult -> asArray ();
$this -> assertSame ( $exactIdMatch , $this -> searchResult -> hasExactIdMatch ( new SearchResultType ( 'emails' )));
$this -> assertEquals ( $expected , $result );
$this -> assertSame ( $reachedEnd , $moreResults );
}
public function dataGetEmail () {
return [
2018-10-30 12:18:58 +03:00
// data set 0
2018-03-07 13:57:08 +03:00
[ 'test' , [], true , [ 'emails' => [], 'exact' => [ 'emails' => []]], false , false ],
2018-10-30 12:18:58 +03:00
// data set 1
2018-03-07 13:57:08 +03:00
[ 'test' , [], false , [ 'emails' => [], 'exact' => [ 'emails' => []]], false , false ],
2018-10-30 12:18:58 +03:00
// data set 2
2017-09-13 00:40:46 +03:00
[
'test@remote.com' ,
[],
true ,
2018-10-30 12:18:58 +03:00
[ 'emails' => [], 'exact' => [ 'emails' => [[ 'uuid' => 'test@remote.com' , 'label' => 'test@remote.com' , 'value' => [ 'shareType' => Share :: SHARE_TYPE_EMAIL , 'shareWith' => 'test@remote.com' ]]]]],
2017-09-13 00:40:46 +03:00
false ,
2018-03-07 13:57:08 +03:00
false ,
2017-09-13 00:40:46 +03:00
],
2018-10-30 12:18:58 +03:00
// data set 3
2017-09-13 00:40:46 +03:00
[ // no valid email address
'test@remote' ,
[],
true ,
[ 'emails' => [], 'exact' => [ 'emails' => []]],
false ,
2018-03-07 13:57:08 +03:00
false ,
2017-09-13 00:40:46 +03:00
],
2018-10-30 12:18:58 +03:00
// data set 4
2017-09-13 00:40:46 +03:00
[
'test@remote.com' ,
[],
false ,
2018-10-30 12:18:58 +03:00
[ 'emails' => [], 'exact' => [ 'emails' => [[ 'uuid' => 'test@remote.com' , 'label' => 'test@remote.com' , 'value' => [ 'shareType' => Share :: SHARE_TYPE_EMAIL , 'shareWith' => 'test@remote.com' ]]]]],
2017-09-13 00:40:46 +03:00
false ,
2018-03-07 13:57:08 +03:00
false ,
2017-09-13 00:40:46 +03:00
],
2018-10-30 12:18:58 +03:00
// data set 5
2017-09-13 00:40:46 +03:00
[
'test' ,
[
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid3' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User3 @ Localhost' ,
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid2' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User2 @ Localhost' ,
'EMAIL' => [
],
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid1' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User @ Localhost' ,
'EMAIL' => [
'username@localhost' ,
],
],
],
true ,
2018-10-30 12:18:58 +03:00
[ 'emails' => [[ 'uuid' => 'uid1' , 'name' => 'User @ Localhost' , 'type' => '' , 'label' => 'User @ Localhost (username@localhost)' , 'value' => [ 'shareType' => Share :: SHARE_TYPE_EMAIL , 'shareWith' => 'username@localhost' ]]], 'exact' => [ 'emails' => []]],
2017-09-13 00:40:46 +03:00
false ,
2018-03-07 13:57:08 +03:00
false ,
2017-09-13 00:40:46 +03:00
],
2018-10-30 12:18:58 +03:00
// data set 6
2017-09-13 00:40:46 +03:00
[
'test' ,
[
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid3' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User3 @ Localhost' ,
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid2' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User2 @ Localhost' ,
'EMAIL' => [
],
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid1' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User @ Localhost' ,
'EMAIL' => [
'username@localhost' ,
],
],
],
false ,
[ 'emails' => [], 'exact' => [ 'emails' => []]],
false ,
2018-03-07 13:57:08 +03:00
false ,
2017-09-13 00:40:46 +03:00
],
2018-10-30 12:18:58 +03:00
// data set 7
2017-09-13 00:40:46 +03:00
[
'test@remote.com' ,
[
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid3' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User3 @ Localhost' ,
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid2' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User2 @ Localhost' ,
'EMAIL' => [
],
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid1' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User @ Localhost' ,
'EMAIL' => [
'username@localhost' ,
],
],
],
true ,
2018-10-30 12:18:58 +03:00
[ 'emails' => [[ 'uuid' => 'uid1' , 'name' => 'User @ Localhost' , 'type' => '' , 'label' => 'User @ Localhost (username@localhost)' , 'value' => [ 'shareType' => Share :: SHARE_TYPE_EMAIL , 'shareWith' => 'username@localhost' ]]], 'exact' => [ 'emails' => [[ 'label' => 'test@remote.com' , 'uuid' => 'test@remote.com' , 'value' => [ 'shareType' => Share :: SHARE_TYPE_EMAIL , 'shareWith' => 'test@remote.com' ]]]]],
2017-09-13 00:40:46 +03:00
false ,
2018-03-07 13:57:08 +03:00
false ,
2017-09-13 00:40:46 +03:00
],
2018-10-30 12:18:58 +03:00
// data set 8
2017-09-13 00:40:46 +03:00
[
'test@remote.com' ,
[
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid3' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User3 @ Localhost' ,
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid2' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User2 @ Localhost' ,
'EMAIL' => [
],
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid1' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User @ Localhost' ,
'EMAIL' => [
'username@localhost' ,
],
],
],
false ,
2018-10-30 12:18:58 +03:00
[ 'emails' => [], 'exact' => [ 'emails' => [[ 'label' => 'test@remote.com' , 'uuid' => 'test@remote.com' , 'value' => [ 'shareType' => Share :: SHARE_TYPE_EMAIL , 'shareWith' => 'test@remote.com' ]]]]],
2017-09-13 00:40:46 +03:00
false ,
2018-03-07 13:57:08 +03:00
false ,
2017-09-13 00:40:46 +03:00
],
2018-10-30 12:18:58 +03:00
// data set 9
2017-09-13 00:40:46 +03:00
[
'username@localhost' ,
[
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid3' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User3 @ Localhost' ,
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid2' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User2 @ Localhost' ,
'EMAIL' => [
],
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid1' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User @ Localhost' ,
'EMAIL' => [
'username@localhost' ,
],
],
],
true ,
2018-10-30 12:18:58 +03:00
[ 'emails' => [], 'exact' => [ 'emails' => [[ 'name' => 'User @ Localhost' , 'uuid' => 'uid1' , 'type' => '' , 'label' => 'User @ Localhost (username@localhost)' , 'value' => [ 'shareType' => Share :: SHARE_TYPE_EMAIL , 'shareWith' => 'username@localhost' ]]]]],
2017-09-13 00:40:46 +03:00
true ,
2018-03-07 13:57:08 +03:00
false ,
2017-09-13 00:40:46 +03:00
],
2018-10-30 12:18:58 +03:00
// data set 10
2017-09-13 00:40:46 +03:00
[
'username@localhost' ,
[
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid1' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User3 @ Localhost' ,
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid2' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User2 @ Localhost' ,
'EMAIL' => [
],
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid1' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User @ Localhost' ,
'EMAIL' => [
'username@localhost' ,
],
],
],
false ,
2018-10-30 12:18:58 +03:00
[ 'emails' => [], 'exact' => [ 'emails' => [[ 'name' => 'User @ Localhost' , 'uuid' => 'uid1' , 'type' => '' , 'label' => 'User @ Localhost (username@localhost)' , 'value' => [ 'shareType' => Share :: SHARE_TYPE_EMAIL , 'shareWith' => 'username@localhost' ]]]]],
2017-09-13 00:40:46 +03:00
true ,
2018-03-07 13:57:08 +03:00
false ,
2017-09-13 00:40:46 +03:00
],
2018-10-30 12:18:58 +03:00
// data set 11
2017-09-13 00:40:46 +03:00
// contact with space
[
'user name@localhost' ,
[
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid3' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User3 @ Localhost' ,
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid2' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User2 @ Localhost' ,
'EMAIL' => [
],
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid1' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User Name @ Localhost' ,
'EMAIL' => [
'user name@localhost' ,
],
],
],
false ,
2018-10-30 12:18:58 +03:00
[ 'emails' => [], 'exact' => [ 'emails' => [[ 'name' => 'User Name @ Localhost' , 'uuid' => 'uid1' , 'type' => '' , 'label' => 'User Name @ Localhost (user name@localhost)' , 'value' => [ 'shareType' => Share :: SHARE_TYPE_EMAIL , 'shareWith' => 'user name@localhost' ]]]]],
2017-09-13 00:40:46 +03:00
true ,
2018-03-07 13:57:08 +03:00
false ,
2017-09-13 00:40:46 +03:00
],
2018-10-30 12:18:58 +03:00
// data set 12
2017-09-13 00:40:46 +03:00
// remote with space, no contact
[
'user space@remote.com' ,
[
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid3' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User3 @ Localhost' ,
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid2' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User2 @ Localhost' ,
'EMAIL' => [
],
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid1' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User @ Localhost' ,
'EMAIL' => [
'username@localhost' ,
],
],
],
false ,
[ 'emails' => [], 'exact' => [ 'emails' => []]],
false ,
2018-03-07 13:57:08 +03:00
false ,
2017-09-13 00:40:46 +03:00
],
2018-10-30 12:18:58 +03:00
// data set 13
2017-09-13 00:40:46 +03:00
// Local user found by email
[
'test@example.com' ,
[
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid1' ,
2017-09-13 00:40:46 +03:00
'FN' => 'User' ,
'EMAIL' => [ 'test@example.com' ],
'CLOUD' => [ 'test@localhost' ],
'isLocalSystemBook' => true ,
]
],
false ,
2018-10-30 12:18:58 +03:00
[ 'users' => [], 'exact' => [ 'users' => [[ 'uuid' => 'uid1' , 'name' => 'User' , 'label' => 'User (test@example.com)' , 'value' => [ 'shareType' => Share :: SHARE_TYPE_USER , 'shareWith' => 'test' ],]]]],
2017-09-13 00:40:46 +03:00
true ,
false ,
2018-03-07 13:48:14 +03:00
],
2018-10-30 12:18:58 +03:00
// data set 14
2018-03-07 13:48:14 +03:00
// Current local user found by email => no result
[
'test@example.com' ,
[
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid1' ,
2018-03-07 13:48:14 +03:00
'FN' => 'User' ,
'EMAIL' => [ 'test@example.com' ],
'CLOUD' => [ 'current@localhost' ],
'isLocalSystemBook' => true ,
]
],
true ,
[ 'exact' => []],
false ,
false ,
],
2018-10-30 12:18:58 +03:00
// data set 15
2018-03-07 13:48:14 +03:00
// Pagination and "more results" for user matches byyyyyyy emails
[
'test@example' ,
[
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid1' ,
2018-03-07 13:48:14 +03:00
'FN' => 'User1' ,
'EMAIL' => [ 'test@example.com' ],
'CLOUD' => [ 'test1@localhost' ],
'isLocalSystemBook' => true ,
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid2' ,
2018-03-07 13:48:14 +03:00
'FN' => 'User2' ,
'EMAIL' => [ 'test@example.de' ],
'CLOUD' => [ 'test2@localhost' ],
'isLocalSystemBook' => true ,
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid3' ,
2018-03-07 13:48:14 +03:00
'FN' => 'User3' ,
'EMAIL' => [ 'test@example.org' ],
'CLOUD' => [ 'test3@localhost' ],
'isLocalSystemBook' => true ,
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid4' ,
2018-03-07 13:48:14 +03:00
'FN' => 'User4' ,
'EMAIL' => [ 'test@example.net' ],
'CLOUD' => [ 'test4@localhost' ],
'isLocalSystemBook' => true ,
],
],
true ,
[ 'users' => [
2018-10-30 12:18:58 +03:00
[ 'uuid' => 'uid1' , 'name' => 'User1' , 'label' => 'User1 (test@example.com)' , 'value' => [ 'shareType' => Share :: SHARE_TYPE_USER , 'shareWith' => 'test1' ]],
[ 'uuid' => 'uid2' , 'name' => 'User2' , 'label' => 'User2 (test@example.de)' , 'value' => [ 'shareType' => Share :: SHARE_TYPE_USER , 'shareWith' => 'test2' ]],
2018-03-07 13:48:14 +03:00
], 'emails' => [], 'exact' => [ 'users' => [], 'emails' => []]],
false ,
true ,
],
2018-10-30 12:18:58 +03:00
// data set 16
2018-03-07 13:48:14 +03:00
// Pagination and "more results" for normal emails
[
'test@example' ,
[
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid1' ,
2018-03-07 13:48:14 +03:00
'FN' => 'User1' ,
'EMAIL' => [ 'test@example.com' ],
'CLOUD' => [ 'test1@localhost' ],
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid2' ,
2018-03-07 13:48:14 +03:00
'FN' => 'User2' ,
'EMAIL' => [ 'test@example.de' ],
'CLOUD' => [ 'test2@localhost' ],
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid3' ,
2018-03-07 13:48:14 +03:00
'FN' => 'User3' ,
'EMAIL' => [ 'test@example.org' ],
'CLOUD' => [ 'test3@localhost' ],
],
[
2018-10-30 12:18:58 +03:00
'UID' => 'uid4' ,
2018-03-07 13:48:14 +03:00
'FN' => 'User4' ,
'EMAIL' => [ 'test@example.net' ],
'CLOUD' => [ 'test4@localhost' ],
],
],
true ,
[ 'emails' => [
2018-10-30 12:18:58 +03:00
[ 'uuid' => 'uid1' , 'name' => 'User1' , 'type' => '' , 'label' => 'User1 (test@example.com)' , 'value' => [ 'shareType' => Share :: SHARE_TYPE_EMAIL , 'shareWith' => 'test@example.com' ]],
[ 'uuid' => 'uid2' , 'name' => 'User2' , 'type' => '' , 'label' => 'User2 (test@example.de)' , 'value' => [ 'shareType' => Share :: SHARE_TYPE_EMAIL , 'shareWith' => 'test@example.de' ]],
2018-03-07 13:48:14 +03:00
], 'exact' => [ 'emails' => []]],
false ,
true ,
],
2018-10-30 12:18:58 +03:00
// data set 17
// multiple email addresses with type
[
'User Name' ,
[
[
'UID' => 'uid3' ,
'FN' => 'User3' ,
],
[
'UID' => 'uid2' ,
'FN' => 'User2' ,
'EMAIL' => [
],
],
[
'UID' => 'uid1' ,
'FN' => 'User Name' ,
'EMAIL' => [
[ 'type' => 'HOME' , 'value' => 'username@localhost' ],
[ 'type' => 'WORK' , 'value' => 'username@other' ],
],
],
],
false ,
[ 'emails' => [
], 'exact' => [ 'emails' => [
[ 'name' => 'User Name' , 'uuid' => 'uid1' , 'type' => 'HOME' , 'label' => 'User Name (username@localhost)' , 'value' => [ 'shareType' => Share :: SHARE_TYPE_EMAIL , 'shareWith' => 'username@localhost' ]],
[ 'name' => 'User Name' , 'uuid' => 'uid1' , 'type' => 'WORK' , 'label' => 'User Name (username@other)' , 'value' => [ 'shareType' => Share :: SHARE_TYPE_EMAIL , 'shareWith' => 'username@other' ]]
]]],
false ,
false ,
],
2017-09-13 00:40:46 +03:00
];
}
2017-12-16 10:46:03 +03:00
/**
* @ dataProvider dataGetEmailGroupsOnly
*
* @ param string $searchTerm
* @ param array $contacts
* @ param array $expected
* @ param bool $exactIdMatch
* @ param bool $reachedEnd
* @ param array groups
*/
public function testSearchGroupsOnly ( $searchTerm , $contacts , $expected , $exactIdMatch , $reachedEnd , $userToGroupMapping ) {
$this -> config -> expects ( $this -> any ())
-> method ( 'getAppValue' )
-> willReturnCallback (
2020-04-09 14:53:40 +03:00
function ( $appName , $key , $default ) {
2017-12-16 10:46:03 +03:00
if ( $appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration' ) {
return 'yes' ;
2020-04-10 11:35:09 +03:00
} elseif ( $appName === 'core' && $key === 'shareapi_only_share_with_group_members' ) {
2017-12-16 10:46:03 +03:00
return 'yes' ;
}
return $default ;
}
);
$this -> instantiatePlugin ();
/** @var \OCP\IUser | \PHPUnit_Framework_MockObject_MockObject */
$currentUser = $this -> createMock ( '\OCP\IUser' );
$currentUser -> expects ( $this -> any ())
-> method ( 'getUID' )
-> willReturn ( 'currentUser' );
$this -> contactsManager -> expects ( $this -> any ())
-> method ( 'search' )
-> with ( $searchTerm , [ 'EMAIL' , 'FN' ])
-> willReturn ( $contacts );
$this -> userSession -> expects ( $this -> any ())
-> method ( 'getUser' )
-> willReturn ( $currentUser );
$this -> groupManager -> expects ( $this -> any ())
-> method ( 'getUserGroupIds' )
2020-04-09 14:53:40 +03:00
-> willReturnCallback ( function ( \OCP\IUser $user ) use ( $userToGroupMapping ) {
2017-12-16 10:46:03 +03:00
return $userToGroupMapping [ $user -> getUID ()];
});
$this -> groupManager -> expects ( $this -> any ())
-> method ( 'isInGroup' )
2020-04-09 14:53:40 +03:00
-> willReturnCallback ( function ( $userId , $group ) use ( $userToGroupMapping ) {
2017-12-16 10:46:03 +03:00
return in_array ( $group , $userToGroupMapping [ $userId ]);
});
2018-02-06 20:11:44 +03:00
$moreResults = $this -> plugin -> search ( $searchTerm , 2 , 0 , $this -> searchResult );
2017-12-16 10:46:03 +03:00
$result = $this -> searchResult -> asArray ();
$this -> assertSame ( $exactIdMatch , $this -> searchResult -> hasExactIdMatch ( new SearchResultType ( 'emails' )));
$this -> assertEquals ( $expected , $result );
$this -> assertSame ( $reachedEnd , $moreResults );
}
public function dataGetEmailGroupsOnly () {
return [
// The user `User` can share with the current user
[
'test' ,
[
[
'FN' => 'User' ,
'EMAIL' => [ 'test@example.com' ],
'CLOUD' => [ 'test@localhost' ],
'isLocalSystemBook' => true ,
'UID' => 'User'
]
],
2018-10-30 12:18:58 +03:00
[ 'users' => [[ 'label' => 'User (test@example.com)' , 'uuid' => 'User' , 'name' => 'User' , 'value' => [ 'shareType' => 0 , 'shareWith' => 'test' ],]], 'emails' => [], 'exact' => [ 'emails' => [], 'users' => []]],
2017-12-16 10:46:03 +03:00
false ,
2018-03-07 13:57:08 +03:00
false ,
2017-12-16 10:46:03 +03:00
[
" currentUser " => [ " group1 " ],
" User " => [ " group1 " ]
]
],
// The user `User` cannot share with the current user
[
2020-04-09 10:22:29 +03:00
'test' ,
2017-12-16 10:46:03 +03:00
[
[
'FN' => 'User' ,
'EMAIL' => [ 'test@example.com' ],
'CLOUD' => [ 'test@localhost' ],
'isLocalSystemBook' => true ,
'UID' => 'User'
]
],
[ 'emails' => [], 'exact' => [ 'emails' => []]],
false ,
2018-03-07 13:57:08 +03:00
false ,
2017-12-16 10:46:03 +03:00
[
" currentUser " => [ " group1 " ],
" User " => [ " group2 " ]
]
],
// The user `User` cannot share with the current user, but there is an exact match on the e-mail address -> share by e-mail
[
2020-04-09 10:22:29 +03:00
'test@example.com' ,
2017-12-16 10:46:03 +03:00
[
[
'FN' => 'User' ,
'EMAIL' => [ 'test@example.com' ],
'CLOUD' => [ 'test@localhost' ],
'isLocalSystemBook' => true ,
'UID' => 'User'
]
],
2018-10-30 12:18:58 +03:00
[ 'emails' => [], 'exact' => [ 'emails' => [[ 'label' => 'test@example.com' , 'uuid' => 'test@example.com' , 'value' => [ 'shareType' => 4 , 'shareWith' => 'test@example.com' ]]]]],
2017-12-16 10:46:03 +03:00
false ,
2018-03-07 13:57:08 +03:00
false ,
2017-12-16 10:46:03 +03:00
[
" currentUser " => [ " group1 " ],
" User " => [ " group2 " ]
]
]
];
}
2017-09-13 00:40:46 +03:00
}