diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-09-12 23:40:46 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-09-26 23:10:24 +0200 |
commit | 3d1d03a51175e0e52b506764bc7d96ddeae4cb65 (patch) | |
tree | 8da6d6a6fd004b6c6783223b3de21a549c947592 | |
parent | c92f7ee7674541f1e899e0f5077d79907d21df4c (diff) | |
download | nextcloud-server-3d1d03a51175e0e52b506764bc7d96ddeae4cb65.tar.gz nextcloud-server-3d1d03a51175e0e52b506764bc7d96ddeae4cb65.zip |
split off getEmail tests
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
3 files changed, 338 insertions, 245 deletions
diff --git a/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php index 7b321678908..928a151c420 100644 --- a/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php @@ -116,250 +116,6 @@ class ShareesAPIControllerTest extends TestCase { ); } - - /** - * @dataProvider dataGetEmail - * - * @param string $searchTerm - * @param array $contacts - * @param bool $shareeEnumeration - * @param array $expected - * @param bool $reachedEnd - */ - public function testGetEmail($searchTerm, $contacts, $shareeEnumeration, $expected, $reachedEnd) { - $this->invokePrivate($this->sharees, 'shareeEnumeration', [$shareeEnumeration]); - $this->contactsManager->expects($this->any()) - ->method('search') - ->with($searchTerm, ['EMAIL', 'FN']) - ->willReturn($contacts); - - $result = $this->invokePrivate($this->sharees, 'getEmail', [$searchTerm]); - - $this->assertEquals($expected, $result); - $this->assertCount((int) $reachedEnd, $this->invokePrivate($this->sharees, 'reachedEndFor')); - } - - public function dataGetEmail() { - return [ - ['test', [], true, ['results' => [], 'exact' => [], 'exactIdMatch' => false], true], - ['test', [], false, ['results' => [], 'exact' => [], 'exactIdMatch' => false], true], - [ - 'test@remote.com', - [], - true, - ['results' => [], 'exact' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]], 'exactIdMatch' => false], - true, - ], - [ // no valid email address - 'test@remote', - [], - true, - ['results' => [], 'exact' => [], 'exactIdMatch' => false], - true, - ], - [ - 'test@remote.com', - [], - false, - ['results' => [], 'exact' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]], 'exactIdMatch' => false], - true, - ], - [ - 'test', - [ - [ - 'FN' => 'User3 @ Localhost', - ], - [ - 'FN' => 'User2 @ Localhost', - 'EMAIL' => [ - ], - ], - [ - 'FN' => 'User @ Localhost', - 'EMAIL' => [ - 'username@localhost', - ], - ], - ], - true, - ['results' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]], 'exact' => [], 'exactIdMatch' => false], - true, - ], - [ - 'test', - [ - [ - 'FN' => 'User3 @ Localhost', - ], - [ - 'FN' => 'User2 @ Localhost', - 'EMAIL' => [ - ], - ], - [ - 'FN' => 'User @ Localhost', - 'EMAIL' => [ - 'username@localhost', - ], - ], - ], - false, - ['results' => [], 'exact' => [], 'exactIdMatch' => false], - true, - ], - [ - 'test@remote.com', - [ - [ - 'FN' => 'User3 @ Localhost', - ], - [ - 'FN' => 'User2 @ Localhost', - 'EMAIL' => [ - ], - ], - [ - 'FN' => 'User @ Localhost', - 'EMAIL' => [ - 'username@localhost', - ], - ], - ], - true, - ['results' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]], 'exact' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]], 'exactIdMatch' => false], - true, - ], - [ - 'test@remote.com', - [ - [ - 'FN' => 'User3 @ Localhost', - ], - [ - 'FN' => 'User2 @ Localhost', - 'EMAIL' => [ - ], - ], - [ - 'FN' => 'User @ Localhost', - 'EMAIL' => [ - 'username@localhost', - ], - ], - ], - false, - ['results' => [], 'exact' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]], 'exactIdMatch' => false], - true, - ], - [ - 'username@localhost', - [ - [ - 'FN' => 'User3 @ Localhost', - ], - [ - 'FN' => 'User2 @ Localhost', - 'EMAIL' => [ - ], - ], - [ - 'FN' => 'User @ Localhost', - 'EMAIL' => [ - 'username@localhost', - ], - ], - ], - true, - ['results' => [], 'exact' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]], 'exactIdMatch' => true], - true, - ], - [ - 'username@localhost', - [ - [ - 'FN' => 'User3 @ Localhost', - ], - [ - 'FN' => 'User2 @ Localhost', - 'EMAIL' => [ - ], - ], - [ - 'FN' => 'User @ Localhost', - 'EMAIL' => [ - 'username@localhost', - ], - ], - ], - false, - ['results' => [], 'exact' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]], 'exactIdMatch' => true], - true, - ], - // contact with space - [ - 'user name@localhost', - [ - [ - 'FN' => 'User3 @ Localhost', - ], - [ - 'FN' => 'User2 @ Localhost', - 'EMAIL' => [ - ], - ], - [ - 'FN' => 'User Name @ Localhost', - 'EMAIL' => [ - 'user name@localhost', - ], - ], - ], - false, - ['results' => [], 'exact' => [['label' => 'User Name @ Localhost (user name@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'user name@localhost']]], 'exactIdMatch' => true], - true, - ], - // remote with space, no contact - [ - 'user space@remote.com', - [ - [ - 'FN' => 'User3 @ Localhost', - ], - [ - 'FN' => 'User2 @ Localhost', - 'EMAIL' => [ - ], - ], - [ - 'FN' => 'User @ Localhost', - 'EMAIL' => [ - 'username@localhost', - ], - ], - ], - false, - ['results' => [], 'exact' => [], 'exactIdMatch' => false], - true, - ], - // Local user found by email - [ - 'test@example.com', - [ - [ - 'FN' => 'User', - 'EMAIL' => ['test@example.com'], - 'CLOUD' => ['test@localhost'], - 'isLocalSystemBook' => true, - ] - ], - false, - ['results' => [], 'exact' => [], 'exactIdMatch' => true], - false, - ] - ]; - } - public function dataSearch() { $noRemote = [Share::SHARE_TYPE_USER, Share::SHARE_TYPE_GROUP, Share::SHARE_TYPE_EMAIL]; $allTypes = [Share::SHARE_TYPE_USER, Share::SHARE_TYPE_GROUP, Share::SHARE_TYPE_REMOTE, Share::SHARE_TYPE_EMAIL]; diff --git a/lib/private/Collaboration/Collaborators/MailPlugin.php b/lib/private/Collaboration/Collaborators/MailPlugin.php index e6bda176566..d28bd3692a4 100644 --- a/lib/private/Collaboration/Collaborators/MailPlugin.php +++ b/lib/private/Collaboration/Collaborators/MailPlugin.php @@ -159,6 +159,6 @@ class MailPlugin implements ISearchPlugin { $searchResult->addResultSet($emailType, $result['wide'], $result['exact']); - return false; + return true; } } diff --git a/tests/lib/Collaboration/Collaborators/MailPluginTest.php b/tests/lib/Collaboration/Collaborators/MailPluginTest.php new file mode 100644 index 00000000000..af6e0680526 --- /dev/null +++ b/tests/lib/Collaboration/Collaborators/MailPluginTest.php @@ -0,0 +1,337 @@ +<?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; +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; + + public function setUp() { + parent::setUp(); + + $this->config = $this->createMock(IConfig::class); + $this->contactsManager = $this->createMock(IManager::class); + //$this->cloudIdManager = $this->createMock(ICloudIdManager::class); + $this->cloudIdManager = new CloudIdManager(); + $this->searchResult = new SearchResult(); + } + + public function instantiatePlugin() { + $this->plugin = new MailPlugin($this->contactsManager, $this->cloudIdManager, $this->config); + } + + /** + * @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( + function($appName, $key, $default) + use ($shareeEnumeration) + { + if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') { + return $shareeEnumeration ? 'yes' : 'no'; + } + return $default; + } + ); + + $this->instantiatePlugin(); + + $this->contactsManager->expects($this->any()) + ->method('search') + ->with($searchTerm, ['EMAIL', 'FN']) + ->willReturn($contacts); + + $moreResults = $this->plugin->search($searchTerm, 0, 0, $this->searchResult); + $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 [ + ['test', [], true, ['emails' => [], 'exact' => ['emails' => []]], false, true], + ['test', [], false, ['emails' => [], 'exact' => ['emails' => []]], false, true], + [ + 'test@remote.com', + [], + true, + ['emails' => [], 'exact' => ['emails' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]], + false, + true, + ], + [ // no valid email address + 'test@remote', + [], + true, + ['emails' => [], 'exact' => ['emails' => []]], + false, + true, + ], + [ + 'test@remote.com', + [], + false, + ['emails' => [], 'exact' => ['emails' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]], + false, + true, + ], + [ + 'test', + [ + [ + 'FN' => 'User3 @ Localhost', + ], + [ + 'FN' => 'User2 @ Localhost', + 'EMAIL' => [ + ], + ], + [ + 'FN' => 'User @ Localhost', + 'EMAIL' => [ + 'username@localhost', + ], + ], + ], + true, + ['emails' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]], 'exact' => ['emails' => []]], + false, + true, + ], + [ + 'test', + [ + [ + 'FN' => 'User3 @ Localhost', + ], + [ + 'FN' => 'User2 @ Localhost', + 'EMAIL' => [ + ], + ], + [ + 'FN' => 'User @ Localhost', + 'EMAIL' => [ + 'username@localhost', + ], + ], + ], + false, + ['emails' => [], 'exact' => ['emails' => []]], + false, + true, + ], + [ + 'test@remote.com', + [ + [ + 'FN' => 'User3 @ Localhost', + ], + [ + 'FN' => 'User2 @ Localhost', + 'EMAIL' => [ + ], + ], + [ + 'FN' => 'User @ Localhost', + 'EMAIL' => [ + 'username@localhost', + ], + ], + ], + true, + ['emails' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]], 'exact' => ['emails' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]], + false, + true, + ], + [ + 'test@remote.com', + [ + [ + 'FN' => 'User3 @ Localhost', + ], + [ + 'FN' => 'User2 @ Localhost', + 'EMAIL' => [ + ], + ], + [ + 'FN' => 'User @ Localhost', + 'EMAIL' => [ + 'username@localhost', + ], + ], + ], + false, + ['emails' => [], 'exact' => ['emails' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]], + false, + true, + ], + [ + 'username@localhost', + [ + [ + 'FN' => 'User3 @ Localhost', + ], + [ + 'FN' => 'User2 @ Localhost', + 'EMAIL' => [ + ], + ], + [ + 'FN' => 'User @ Localhost', + 'EMAIL' => [ + 'username@localhost', + ], + ], + ], + true, + ['emails' => [], 'exact' => ['emails' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]]]], + true, + true, + ], + [ + 'username@localhost', + [ + [ + 'FN' => 'User3 @ Localhost', + ], + [ + 'FN' => 'User2 @ Localhost', + 'EMAIL' => [ + ], + ], + [ + 'FN' => 'User @ Localhost', + 'EMAIL' => [ + 'username@localhost', + ], + ], + ], + false, + ['emails' => [], 'exact' => ['emails' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]]]], + true, + true, + ], + // contact with space + [ + 'user name@localhost', + [ + [ + 'FN' => 'User3 @ Localhost', + ], + [ + 'FN' => 'User2 @ Localhost', + 'EMAIL' => [ + ], + ], + [ + 'FN' => 'User Name @ Localhost', + 'EMAIL' => [ + 'user name@localhost', + ], + ], + ], + false, + ['emails' => [], 'exact' => ['emails' => [['label' => 'User Name @ Localhost (user name@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'user name@localhost']]]]], + true, + true, + ], + // remote with space, no contact + [ + 'user space@remote.com', + [ + [ + 'FN' => 'User3 @ Localhost', + ], + [ + 'FN' => 'User2 @ Localhost', + 'EMAIL' => [ + ], + ], + [ + 'FN' => 'User @ Localhost', + 'EMAIL' => [ + 'username@localhost', + ], + ], + ], + false, + ['emails' => [], 'exact' => ['emails' => []]], + false, + true, + ], + // Local user found by email + [ + 'test@example.com', + [ + [ + 'FN' => 'User', + 'EMAIL' => ['test@example.com'], + 'CLOUD' => ['test@localhost'], + 'isLocalSystemBook' => true, + ] + ], + false, + ['users' => [], 'exact' => ['users' => [['label' => 'User (test@example.com)','value' => ['shareType' => 0, 'shareWith' => 'test'],]]]], + true, + false, + ] + ]; + } +} |