aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Contacts/ContactsMenu/ManagerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Contacts/ContactsMenu/ManagerTest.php')
-rw-r--r--tests/lib/Contacts/ContactsMenu/ManagerTest.php86
1 files changed, 31 insertions, 55 deletions
diff --git a/tests/lib/Contacts/ContactsMenu/ManagerTest.php b/tests/lib/Contacts/ContactsMenu/ManagerTest.php
index 2f5acf61644..dd6c634c740 100644
--- a/tests/lib/Contacts/ContactsMenu/ManagerTest.php
+++ b/tests/lib/Contacts/ContactsMenu/ManagerTest.php
@@ -1,56 +1,38 @@
<?php
/**
- * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @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/>.
- *
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Tests\Contacts\ContactsMenu;
use OC\Contacts\ContactsMenu\ActionProviderStore;
use OC\Contacts\ContactsMenu\ContactsStore;
+use OC\Contacts\ContactsMenu\Entry;
use OC\Contacts\ContactsMenu\Manager;
use OCP\App\IAppManager;
use OCP\Constants;
-use OCP\Contacts\ContactsMenu\IEntry;
use OCP\Contacts\ContactsMenu\IProvider;
use OCP\IConfig;
use OCP\IUser;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ManagerTest extends TestCase {
-
- /** @var ContactsStore|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var ContactsStore|MockObject */
private $contactsStore;
- /** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IAppManager|MockObject */
private $appManager;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IConfig|MockObject */
private $config;
- /** @var ActionProviderStore|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var ActionProviderStore|MockObject */
private $actionProviderStore;
- /** @var Manager */
- private $manager;
+ private Manager $manager;
protected function setUp(): void {
parent::setUp();
@@ -63,10 +45,10 @@ class ManagerTest extends TestCase {
$this->manager = new Manager($this->contactsStore, $this->actionProviderStore, $this->appManager, $this->config);
}
- private function generateTestEntries() {
+ private function generateTestEntries(): array {
$entries = [];
foreach (range('Z', 'A') as $char) {
- $entry = $this->createMock(IEntry::class);
+ $entry = $this->createMock(Entry::class);
$entry->expects($this->any())
->method('getFullName')
->willReturn('Contact ' . $char);
@@ -75,20 +57,18 @@ class ManagerTest extends TestCase {
return $entries;
}
- public function testGetFilteredEntries() {
+ public function testGetFilteredEntries(): void {
$filter = 'con';
$user = $this->createMock(IUser::class);
$entries = $this->generateTestEntries();
$provider = $this->createMock(IProvider::class);
- $this->config->expects($this->at(0))
- ->method('getSystemValueInt')
- ->with('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)
- ->willReturn(25);
- $this->config->expects($this->at(1))
+ $this->config->expects($this->exactly(2))
->method('getSystemValueInt')
- ->with('sharing.minSearchStringLength', 0)
- ->willReturn(0);
+ ->willReturnMap([
+ ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT, 25],
+ ['sharing.minSearchStringLength', 0, 0],
+ ]);
$this->contactsStore->expects($this->once())
->method('getContacts')
->with($user, $filter)
@@ -113,20 +93,18 @@ class ManagerTest extends TestCase {
$this->assertEquals($expected, $data);
}
- public function testGetFilteredEntriesLimit() {
+ public function testGetFilteredEntriesLimit(): void {
$filter = 'con';
$user = $this->createMock(IUser::class);
$entries = $this->generateTestEntries();
$provider = $this->createMock(IProvider::class);
- $this->config->expects($this->at(0))
+ $this->config->expects($this->exactly(2))
->method('getSystemValueInt')
- ->with('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)
- ->willReturn(3);
- $this->config->expects($this->at(1))
- ->method('getSystemValueInt')
- ->with('sharing.minSearchStringLength', 0)
- ->willReturn(0);
+ ->willReturnMap([
+ ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT, 3],
+ ['sharing.minSearchStringLength', 0, 0],
+ ]);
$this->contactsStore->expects($this->once())
->method('getContacts')
->with($user, $filter)
@@ -151,19 +129,17 @@ class ManagerTest extends TestCase {
$this->assertEquals($expected, $data);
}
- public function testGetFilteredEntriesMinSearchStringLength() {
+ public function testGetFilteredEntriesMinSearchStringLength(): void {
$filter = 'con';
$user = $this->createMock(IUser::class);
$provider = $this->createMock(IProvider::class);
- $this->config->expects($this->at(0))
- ->method('getSystemValueInt')
- ->with('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)
- ->willReturn(3);
- $this->config->expects($this->at(1))
+ $this->config->expects($this->exactly(2))
->method('getSystemValueInt')
- ->with('sharing.minSearchStringLength', 0)
- ->willReturn(4);
+ ->willReturnMap([
+ ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT, 3],
+ ['sharing.minSearchStringLength', 0, 4],
+ ]);
$this->appManager->expects($this->once())
->method('isEnabledForUser')
->with($this->equalTo('contacts'), $user)
@@ -178,7 +154,7 @@ class ManagerTest extends TestCase {
$this->assertEquals($expected, $data);
}
- public function testFindOne() {
+ public function testFindOne(): void {
$shareTypeFilter = 42;
$shareWithFilter = 'foobar';
@@ -201,7 +177,7 @@ class ManagerTest extends TestCase {
$this->assertEquals($entry, $data);
}
- public function testFindOne404() {
+ public function testFindOne404(): void {
$shareTypeFilter = 42;
$shareWithFilter = 'foobar';