aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php')
-rw-r--r--tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php210
1 files changed, 92 insertions, 118 deletions
diff --git a/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php b/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php
index 69805bf81f2..9097ee779d2 100644
--- a/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php
+++ b/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php
@@ -3,27 +3,8 @@
declare(strict_types=1);
/**
- * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
- * @copyright 2017 Lukas Reschke <lukas@statuscode.ch>
- *
- * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author 2017 Lukas Reschke <lukas@statuscode.ch>
- *
- * @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;
@@ -88,7 +69,7 @@ class ContactsStoreTest extends TestCase {
);
}
- public function testGetContactsWithoutFilter() {
+ public function testGetContactsWithoutFilter(): void {
/** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
@@ -118,7 +99,7 @@ class ContactsStoreTest extends TestCase {
], $entries[1]->getEMailAddresses());
}
- public function testGetContactsHidesOwnEntry() {
+ public function testGetContactsHidesOwnEntry(): void {
/** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
@@ -145,7 +126,7 @@ class ContactsStoreTest extends TestCase {
$this->assertCount(1, $entries);
}
- public function testGetContactsWithoutBinaryImage() {
+ public function testGetContactsWithoutBinaryImage(): void {
/** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->urlGenerator->expects($this->any())
@@ -178,7 +159,7 @@ class ContactsStoreTest extends TestCase {
$this->assertSame('https://urlToNcAvatar.test', $entries[1]->getAvatar());
}
- public function testGetContactsWithoutAvatarURI() {
+ public function testGetContactsWithoutAvatarURI(): void {
/** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
@@ -207,7 +188,7 @@ class ContactsStoreTest extends TestCase {
$this->assertEquals('https://photo', $entries[1]->getAvatar());
}
- public function testGetContactsWhenUserIsInExcludeGroups() {
+ public function testGetContactsWhenUserIsInExcludeGroups(): void {
$this->config
->method('getAppValue')
->willReturnMap([
@@ -252,7 +233,7 @@ class ContactsStoreTest extends TestCase {
$this->assertCount(0, $entries);
}
- public function testGetContactsOnlyShareIfInTheSameGroup() {
+ public function testGetContactsOnlyShareIfInTheSameGroup(): void {
$this->config
->method('getAppValue')
->willReturnMap([
@@ -274,29 +255,27 @@ class ContactsStoreTest extends TestCase {
$user2 = $this->createMock(IUser::class);
$user3 = $this->createMock(IUser::class);
+ $calls = [
+ [[$currentUser], ['group1', 'group2', 'group3']],
+ [[$user1], ['group1']],
+ [[$user2], ['group2', 'group3']],
+ [[$user3], ['group8', 'group9']],
+ ];
$this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
- ->withConsecutive(
- [$this->equalTo($currentUser)],
- [$this->equalTo($user1)],
- [$this->equalTo($user2)],
- [$this->equalTo($user3)]
- )
- ->willReturnOnConsecutiveCalls(
- ['group1', 'group2', 'group3'],
- ['group1'],
- ['group2', 'group3'],
- ['group8', 'group9']
- );
+ ->willReturnCallback(function () use (&$calls): array {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected[0], func_get_args());
+ return $expected[1];
+ });
$this->userManager->expects($this->exactly(3))
->method('get')
- ->withConsecutive(
- ['user1'],
- ['user2'],
- ['user3']
- )
- ->willReturnOnConsecutiveCalls($user1, $user2, $user3);
+ ->willReturnMap([
+ ['user1', $user1],
+ ['user2', $user2],
+ ['user3', $user3],
+ ]);
$this->contactsManager->expects($this->once())
->method('search')
@@ -327,7 +306,7 @@ class ContactsStoreTest extends TestCase {
$this->assertEquals('contact', $entries[2]->getProperty('UID'));
}
- public function testGetContactsOnlyEnumerateIfInTheSameGroup() {
+ public function testGetContactsOnlyEnumerateIfInTheSameGroup(): void {
$this->config
->method('getAppValue')
->willReturnMap([
@@ -349,29 +328,27 @@ class ContactsStoreTest extends TestCase {
$user2 = $this->createMock(IUser::class);
$user3 = $this->createMock(IUser::class);
+ $calls = [
+ [[$currentUser], ['group1', 'group2', 'group3']],
+ [[$user1], ['group1']],
+ [[$user2], ['group2', 'group3']],
+ [[$user3], ['group8', 'group9']],
+ ];
$this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
- ->withConsecutive(
- [$this->equalTo($currentUser)],
- [$this->equalTo($user1)],
- [$this->equalTo($user2)],
- [$this->equalTo($user3)]
- )
- ->willReturnOnConsecutiveCalls(
- ['group1', 'group2', 'group3'],
- ['group1'],
- ['group2', 'group3'],
- ['group8', 'group9']
- );
+ ->willReturnCallback(function () use (&$calls): array {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected[0], func_get_args());
+ return $expected[1];
+ });
$this->userManager->expects($this->exactly(3))
->method('get')
- ->withConsecutive(
- ['user1'],
- ['user2'],
- ['user3']
- )
- ->willReturn($user1, $user2, $user3);
+ ->willReturnMap([
+ ['user1', $user1],
+ ['user2', $user2],
+ ['user3', $user3],
+ ]);
$this->contactsManager->expects($this->once())
->method('search')
@@ -402,7 +379,7 @@ class ContactsStoreTest extends TestCase {
$this->assertEquals('contact', $entries[2]->getProperty('UID'));
}
- public function testGetContactsOnlyEnumerateIfPhoneBookMatch() {
+ public function testGetContactsOnlyEnumerateIfPhoneBookMatch(): void {
$this->config
->method('getAppValue')
->willReturnMap([
@@ -460,7 +437,7 @@ class ContactsStoreTest extends TestCase {
$this->assertEquals('contact', $entries[2]->getProperty('UID'));
}
- public function testGetContactsOnlyEnumerateIfPhoneBookMatchWithOwnGroupsOnly() {
+ public function testGetContactsOnlyEnumerateIfPhoneBookMatchWithOwnGroupsOnly(): void {
$this->config
->method('getAppValue')
->willReturnMap([
@@ -482,29 +459,27 @@ class ContactsStoreTest extends TestCase {
$user2 = $this->createMock(IUser::class);
$user3 = $this->createMock(IUser::class);
+ $calls = [
+ [[$currentUser], ['group1', 'group2', 'group3']],
+ [[$user1], ['group1']],
+ [[$user2], ['group2', 'group3']],
+ [[$user3], ['group8', 'group9']],
+ ];
$this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
- ->withConsecutive(
- [$this->equalTo($currentUser)],
- [$this->equalTo($user1)],
- [$this->equalTo($user2)],
- [$this->equalTo($user3)]
- )
- ->willReturnOnConsecutiveCalls(
- ['group1', 'group2', 'group3'],
- ['group1'],
- ['group2', 'group3'],
- ['group8', 'group9']
- );
+ ->willReturnCallback(function () use (&$calls): array {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected[0], func_get_args());
+ return $expected[1];
+ });
$this->userManager->expects($this->exactly(3))
->method('get')
- ->withConsecutive(
- ['user1'],
- ['user2'],
- ['user3']
- )
- ->willReturnOnConsecutiveCalls($user1, $user2, $user3);
+ ->willReturnMap([
+ ['user1', $user1],
+ ['user2', $user2],
+ ['user3', $user3],
+ ]);
$this->knownUserService->method('isKnownToUser')
->willReturnMap([
@@ -542,7 +517,7 @@ class ContactsStoreTest extends TestCase {
$this->assertEquals('contact', $entries[2]->getProperty('UID'));
}
- public function testGetContactsOnlyEnumerateIfPhoneBookOrSameGroup() {
+ public function testGetContactsOnlyEnumerateIfPhoneBookOrSameGroup(): void {
$this->config
->method('getAppValue')
->willReturnMap([
@@ -561,16 +536,17 @@ class ContactsStoreTest extends TestCase {
$user1 = $this->createMock(IUser::class);
+ $calls = [
+ [[$currentUser], ['group1', 'group2', 'group3']],
+ [[$user1], ['group1']],
+ ];
$this->groupManager->expects($this->exactly(2))
->method('getUserGroupIds')
- ->withConsecutive(
- [$this->equalTo($currentUser)],
- [$this->equalTo($user1)]
- )
- ->willReturnOnConsecutiveCalls(
- ['group1', 'group2', 'group3'],
- ['group1']
- );
+ ->willReturnCallback(function () use (&$calls): array {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected[0], func_get_args());
+ return $expected[1];
+ });
$this->userManager->expects($this->once())
->method('get')
@@ -614,7 +590,7 @@ class ContactsStoreTest extends TestCase {
$this->assertEquals('contact', $entries[3]->getProperty('UID'));
}
- public function testGetContactsOnlyEnumerateIfPhoneBookOrSameGroupInOwnGroupsOnly() {
+ public function testGetContactsOnlyEnumerateIfPhoneBookOrSameGroupInOwnGroupsOnly(): void {
$this->config
->method('getAppValue')
->willReturnMap([
@@ -636,29 +612,27 @@ class ContactsStoreTest extends TestCase {
$user2 = $this->createMock(IUser::class);
$user3 = $this->createMock(IUser::class);
+ $calls = [
+ [[$currentUser], ['group1', 'group2', 'group3']],
+ [[$user1], ['group1']],
+ [[$user2], ['group2', 'group3']],
+ [[$user3], ['group8', 'group9']],
+ ];
$this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
- ->withConsecutive(
- [$this->equalTo($currentUser)],
- [$this->equalTo($user1)],
- [$this->equalTo($user2)],
- [$this->equalTo($user3)]
- )
- ->willReturnOnConsecutiveCalls(
- ['group1', 'group2', 'group3'],
- ['group1'],
- ['group2', 'group3'],
- ['group8', 'group9']
- );
+ ->willReturnCallback(function () use (&$calls): array {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected[0], func_get_args());
+ return $expected[1];
+ });
$this->userManager->expects($this->exactly(3))
->method('get')
- ->withConsecutive(
- ['user1'],
- ['user2'],
- ['user3']
- )
- ->willReturnOnConsecutiveCalls($user1, $user2, $user3);
+ ->willReturnMap([
+ ['user1', $user1],
+ ['user2', $user2],
+ ['user3', $user3],
+ ]);
$this->knownUserService->method('isKnownToUser')
->willReturnMap([
@@ -696,7 +670,7 @@ class ContactsStoreTest extends TestCase {
$this->assertEquals('contact', $entries[2]->getProperty('UID'));
}
- public function testGetContactsWithFilter() {
+ public function testGetContactsWithFilter(): void {
$this->config
->method('getAppValue')
->willReturnMap([
@@ -783,7 +757,7 @@ class ContactsStoreTest extends TestCase {
], $entry[0]->getEMailAddresses());
}
- public function testGetContactsWithFilterWithoutFullMatch() {
+ public function testGetContactsWithFilterWithoutFullMatch(): void {
$this->config
->method('getAppValue')
->willReturnMap([
@@ -867,7 +841,7 @@ class ContactsStoreTest extends TestCase {
], $entry[0]->getEMailAddresses());
}
- public function testFindOneUser() {
+ public function testFindOneUser(): void {
$this->config
->method('getAppValue')
->willReturnMap([
@@ -910,7 +884,7 @@ class ContactsStoreTest extends TestCase {
], $entry->getEMailAddresses());
}
- public function testFindOneEMail() {
+ public function testFindOneEMail(): void {
/** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
@@ -941,7 +915,7 @@ class ContactsStoreTest extends TestCase {
], $entry->getEMailAddresses());
}
- public function testFindOneNotSupportedType() {
+ public function testFindOneNotSupportedType(): void {
/** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
@@ -950,7 +924,7 @@ class ContactsStoreTest extends TestCase {
$this->assertEquals(null, $entry);
}
- public function testFindOneNoMatches() {
+ public function testFindOneNoMatches(): void {
/** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())