aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2017-09-14 23:41:04 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2017-09-26 23:10:25 +0200
commit3db3e65121e5908c7a5729dfef965a747da61cca (patch)
tree8c97f7cea5a873a8483474cb555c836116d15eee
parentc43685e6fc142da72a0a77587739986f29635447 (diff)
downloadnextcloud-server-3db3e65121e5908c7a5729dfef965a747da61cca.tar.gz
nextcloud-server-3db3e65121e5908c7a5729dfef965a747da61cca.zip
add tests for Lookup Plugin
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
-rw-r--r--lib/private/Collaboration/Collaborators/LookupPlugin.php3
-rw-r--r--tests/lib/Collaboration/Collaborators/LookupPluginTest.php180
-rw-r--r--tests/lib/Collaboration/Collaborators/MailPluginTest.php1
-rw-r--r--tests/lib/Collaboration/Collaborators/RemotePluginTest.php1
4 files changed, 181 insertions, 4 deletions
diff --git a/lib/private/Collaboration/Collaborators/LookupPlugin.php b/lib/private/Collaboration/Collaborators/LookupPlugin.php
index e3a04fb7dde..3a6a0943772 100644
--- a/lib/private/Collaboration/Collaborators/LookupPlugin.php
+++ b/lib/private/Collaboration/Collaborators/LookupPlugin.php
@@ -50,7 +50,7 @@ class LookupPlugin implements ISearchPlugin {
$lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com');
$lookupServerUrl = rtrim($lookupServerUrl, '/');
- $result = ['wide' => [], 'exact' => []];
+ $result = [];
try {
$client = $this->clientService->newClient();
@@ -64,7 +64,6 @@ class LookupPlugin implements ISearchPlugin {
$body = json_decode($response->getBody(), true);
- $result = [];
foreach ($body as $lookup) {
$result[] = [
'label' => $lookup['federationId'],
diff --git a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php
new file mode 100644
index 00000000000..83d366cf467
--- /dev/null
+++ b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php
@@ -0,0 +1,180 @@
+<?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\LookupPlugin;
+use OCP\Collaboration\Collaborators\ISearchResult;
+use OCP\Collaboration\Collaborators\SearchResultType;
+use OCP\Http\Client\IClient;
+use OCP\Http\Client\IClientService;
+use OCP\Http\Client\IResponse;
+use OCP\IConfig;
+use OCP\Share;
+use Test\TestCase;
+
+class LookupPluginTest extends TestCase {
+
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
+ protected $config;
+ /** @var IClientService|\PHPUnit_Framework_MockObject_MockObject */
+ protected $clientService;
+ /** @var LookupPlugin */
+ protected $plugin;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->config = $this->createMock(IConfig::class);
+ $this->clientService = $this->createMock(IClientService::class);
+
+ $this->plugin = new LookupPlugin($this->config, $this->clientService);
+ }
+
+ /**
+ * @dataProvider searchDataProvider
+ * @param array $searchParams
+ */
+ public function testSearch(array $searchParams) {
+ $type = new SearchResultType('lookup');
+
+ /** @var ISearchResult|\PHPUnit_Framework_MockObject_MockObject $searchResult */
+ $searchResult = $this->createMock(ISearchResult::class);
+ $searchResult->expects($this->once())
+ ->method('addResultSet')
+ ->with($type, $searchParams['expectedResult'], []);
+
+ $this->config->expects($this->once())
+ ->method('getAppValue')
+ ->with('files_sharing', 'lookupServerEnabled', 'no')
+ ->willReturn('yes');
+ $this->config->expects($this->once())
+ ->method('getSystemValue')
+ ->with('lookup_server', 'https://lookup.nextcloud.com')
+ ->willReturn($searchParams['server']);
+
+ $response = $this->createMock(IResponse::class);
+ $response->expects($this->once())
+ ->method('getBody')
+ ->willReturn(json_encode($searchParams['resultBody']));
+
+ $client = $this->createMock(IClient::class);
+ $client->expects($this->once())
+ ->method('get')
+ ->willReturnCallback(function($url) use ($searchParams, $response) {
+ $this->assertSame(strpos($url, $searchParams['server'] . '/users?search='), 0);
+ $this->assertNotFalse(strpos($url, urlencode($searchParams['search'])));
+ return $response;
+ });
+
+ $this->clientService->expects($this->once())
+ ->method('newClient')
+ ->willReturn($client);
+
+ $moreResults = $this->plugin->search(
+ $searchParams['search'],
+ $searchParams['limit'],
+ $searchParams['offset'],
+ $searchResult
+ );
+
+
+
+ $this->assertFalse($moreResults);
+ }
+
+ public function testSearchLookupServerDisabled() {
+ $this->config->expects($this->once())
+ ->method('getAppValue')
+ ->with('files_sharing', 'lookupServerEnabled', 'no')
+ ->willReturn('no');
+
+ /** @var ISearchResult|\PHPUnit_Framework_MockObject_MockObject $searchResult */
+ $searchResult = $this->createMock(ISearchResult::class);
+ $searchResult->expects($this->never())
+ ->method('addResultSet');
+ $searchResult->expects($this->never())
+ ->method('markExactIdMatch');
+
+ $this->assertFalse($this->plugin->search('irr', 10, 0, $searchResult));
+ }
+
+ public function searchDataProvider() {
+ $fedIDs = [
+ 'foo@enceladus.moon',
+ 'foobar@enceladus.moon',
+ 'foongus@enceladus.moon',
+ ];
+
+ return [
+ // #0, standard search with results
+ [[
+ 'search' => 'foo',
+ 'limit' => 10,
+ 'offset' => 0,
+ 'server' => 'https://lookup.example.io',
+ 'resultBody' => [
+ [ 'federationId' => $fedIDs[0] ],
+ [ 'federationId' => $fedIDs[1] ],
+ [ 'federationId' => $fedIDs[2] ],
+ ],
+ 'expectedResult' => [
+ [
+ 'label' => $fedIDs[0],
+ 'value' => [
+ 'shareType' => Share::SHARE_TYPE_REMOTE,
+ 'shareWith' => $fedIDs[0]
+ ],
+ 'extra' => ['federationId' => $fedIDs[0]],
+ ],
+ [
+ 'label' => $fedIDs[1],
+ 'value' => [
+ 'shareType' => Share::SHARE_TYPE_REMOTE,
+ 'shareWith' => $fedIDs[1]
+ ],
+ 'extra' => ['federationId' => $fedIDs[1]],
+ ],
+ [
+ 'label' => $fedIDs[2],
+ 'value' => [
+ 'shareType' => Share::SHARE_TYPE_REMOTE,
+ 'shareWith' => $fedIDs[2]
+ ],
+ 'extra' => ['federationId' => $fedIDs[2]],
+ ],
+ ]
+ ]],
+ // #1, search without results
+ [[
+ 'search' => 'foo',
+ 'limit' => 10,
+ 'offset' => 0,
+ 'server' => 'https://lookup.example.io',
+ 'resultBody' => [],
+ 'expectedResult' => [],
+ ]],
+ ];
+ }
+}
diff --git a/tests/lib/Collaboration/Collaborators/MailPluginTest.php b/tests/lib/Collaboration/Collaborators/MailPluginTest.php
index af6e0680526..9c9d9cff909 100644
--- a/tests/lib/Collaboration/Collaborators/MailPluginTest.php
+++ b/tests/lib/Collaboration/Collaborators/MailPluginTest.php
@@ -55,7 +55,6 @@ class MailPluginTest extends TestCase {
$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();
}
diff --git a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php
index 78ef45d0146..5c4b3af5e70 100644
--- a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php
+++ b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php
@@ -55,7 +55,6 @@ class RemotePluginTest extends TestCase {
$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();
}