aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Contacts/ContactsMenu
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Contacts/ContactsMenu')
-rw-r--r--tests/lib/Contacts/ContactsMenu/ActionFactoryTest.php25
-rw-r--r--tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php27
-rw-r--r--tests/lib/Contacts/ContactsMenu/Actions/LinkActionTest.php33
-rw-r--r--tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php210
-rw-r--r--tests/lib/Contacts/ContactsMenu/EntryTest.php33
-rw-r--r--tests/lib/Contacts/ContactsMenu/ManagerTest.php58
-rw-r--r--tests/lib/Contacts/ContactsMenu/Providers/EMailproviderTest.php25
-rw-r--r--tests/lib/Contacts/ContactsMenu/Providers/LocalTimeProviderTest.php129
8 files changed, 221 insertions, 319 deletions
diff --git a/tests/lib/Contacts/ContactsMenu/ActionFactoryTest.php b/tests/lib/Contacts/ContactsMenu/ActionFactoryTest.php
index 7102ed80129..09e0e11bd5e 100644
--- a/tests/lib/Contacts/ContactsMenu/ActionFactoryTest.php
+++ b/tests/lib/Contacts/ContactsMenu/ActionFactoryTest.php
@@ -1,25 +1,8 @@
<?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;
@@ -37,7 +20,7 @@ class ActionFactoryTest extends TestCase {
$this->actionFactory = new ActionFactory();
}
- public function testNewLinkAction() {
+ public function testNewLinkAction(): void {
$icon = 'icon-test';
$name = 'Test';
$href = 'some/url';
@@ -49,7 +32,7 @@ class ActionFactoryTest extends TestCase {
$this->assertEquals(10, $action->getPriority());
}
- public function testNewEMailAction() {
+ public function testNewEMailAction(): void {
$icon = 'icon-test';
$name = 'Test';
$href = 'user@example.com';
diff --git a/tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php b/tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php
index 549bfd8670d..84de6ec88e2 100644
--- a/tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php
+++ b/tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php
@@ -1,25 +1,8 @@
<?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;
@@ -57,7 +40,7 @@ class ActionProviderStoreTest extends TestCase {
$this->actionProviderStore = new ActionProviderStore($this->serverContainer, $this->appManager, $logger);
}
- public function testGetProviders() {
+ public function testGetProviders(): void {
$user = $this->createMock(IUser::class);
$provider1 = $this->createMock(ProfileProvider::class);
$provider2 = $this->createMock(LocalTimeProvider::class);
@@ -93,7 +76,7 @@ class ActionProviderStoreTest extends TestCase {
$this->assertInstanceOf(EMailProvider::class, $providers[2]);
}
- public function testGetProvidersOfAppWithIncompleInfo() {
+ public function testGetProvidersOfAppWithIncompleInfo(): void {
$user = $this->createMock(IUser::class);
$provider1 = $this->createMock(ProfileProvider::class);
$provider2 = $this->createMock(LocalTimeProvider::class);
@@ -124,7 +107,7 @@ class ActionProviderStoreTest extends TestCase {
}
- public function testGetProvidersWithQueryException() {
+ public function testGetProvidersWithQueryException(): void {
$this->expectException(\Exception::class);
$user = $this->createMock(IUser::class);
diff --git a/tests/lib/Contacts/ContactsMenu/Actions/LinkActionTest.php b/tests/lib/Contacts/ContactsMenu/Actions/LinkActionTest.php
index 497cf992e95..5e2b416a66b 100644
--- a/tests/lib/Contacts/ContactsMenu/Actions/LinkActionTest.php
+++ b/tests/lib/Contacts/ContactsMenu/Actions/LinkActionTest.php
@@ -1,25 +1,8 @@
<?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\Actions;
@@ -36,7 +19,7 @@ class LinkActionTest extends TestCase {
$this->action = new LinkAction();
}
- public function testSetIcon() {
+ public function testSetIcon(): void {
$icon = 'icon-test';
$this->action->setIcon($icon);
@@ -46,7 +29,7 @@ class LinkActionTest extends TestCase {
$this->assertEquals($json['icon'], $icon);
}
- public function testGetSetName() {
+ public function testGetSetName(): void {
$name = 'Jane Doe';
$this->assertEmpty($this->action->getName());
@@ -54,7 +37,7 @@ class LinkActionTest extends TestCase {
$this->assertEquals($name, $this->action->getName());
}
- public function testGetSetPriority() {
+ public function testGetSetPriority(): void {
$prio = 50;
$this->assertEquals(10, $this->action->getPriority());
@@ -62,7 +45,7 @@ class LinkActionTest extends TestCase {
$this->assertEquals($prio, $this->action->getPriority());
}
- public function testSetHref() {
+ public function testSetHref(): void {
$this->action->setHref('/some/url');
$json = $this->action->jsonSerialize();
@@ -70,7 +53,7 @@ class LinkActionTest extends TestCase {
$this->assertEquals('/some/url', $json['hyperlink']);
}
- public function testJsonSerialize() {
+ public function testJsonSerialize(): void {
$this->action->setIcon('icon-contacts');
$this->action->setName('Nickie Works');
$this->action->setPriority(33);
@@ -88,7 +71,7 @@ class LinkActionTest extends TestCase {
$this->assertEquals($expected, $json);
}
- public function testJsonSerializeNoAppName() {
+ public function testJsonSerializeNoAppName(): void {
$this->action->setIcon('icon-contacts');
$this->action->setName('Nickie Works');
$this->action->setPriority(33);
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())
diff --git a/tests/lib/Contacts/ContactsMenu/EntryTest.php b/tests/lib/Contacts/ContactsMenu/EntryTest.php
index 253ec321365..15f5b60b948 100644
--- a/tests/lib/Contacts/ContactsMenu/EntryTest.php
+++ b/tests/lib/Contacts/ContactsMenu/EntryTest.php
@@ -1,25 +1,8 @@
<?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;
@@ -37,25 +20,25 @@ class EntryTest extends TestCase {
$this->entry = new Entry();
}
- public function testSetId() {
+ public function testSetId(): void {
$this->entry->setId(123);
$this->addToAssertionCount(1);
}
- public function testSetGetFullName() {
+ public function testSetGetFullName(): void {
$fn = 'Danette Chaille';
$this->assertEquals('', $this->entry->getFullName());
$this->entry->setFullName($fn);
$this->assertEquals($fn, $this->entry->getFullName());
}
- public function testAddGetEMailAddresses() {
+ public function testAddGetEMailAddresses(): void {
$this->assertEmpty($this->entry->getEMailAddresses());
$this->entry->addEMailAddress('user@example.com');
$this->assertEquals(['user@example.com'], $this->entry->getEMailAddresses());
}
- public function testAddAndSortAction() {
+ public function testAddAndSortAction(): void {
// Three actions, two with equal priority
$action1 = new LinkAction();
$action2 = new LinkAction();
@@ -79,7 +62,7 @@ class EntryTest extends TestCase {
$this->assertSame($action2, $sorted[2]);
}
- public function testSetGetProperties() {
+ public function testSetGetProperties(): void {
$props = [
'prop1' => 123,
'prop2' => 'string',
@@ -92,7 +75,7 @@ class EntryTest extends TestCase {
$this->assertEquals('string', $this->entry->getProperty('prop2'));
}
- public function testJsonSerialize() {
+ public function testJsonSerialize(): void {
$expectedJson = [
'id' => '123',
'fullName' => 'Guadalupe Frisbey',
diff --git a/tests/lib/Contacts/ContactsMenu/ManagerTest.php b/tests/lib/Contacts/ContactsMenu/ManagerTest.php
index 2ea3966ad4f..dd6c634c740 100644
--- a/tests/lib/Contacts/ContactsMenu/ManagerTest.php
+++ b/tests/lib/Contacts/ContactsMenu/ManagerTest.php
@@ -1,25 +1,8 @@
<?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;
@@ -74,7 +57,7 @@ class ManagerTest extends TestCase {
return $entries;
}
- public function testGetFilteredEntries() {
+ public function testGetFilteredEntries(): void {
$filter = 'con';
$user = $this->createMock(IUser::class);
$entries = $this->generateTestEntries();
@@ -82,11 +65,10 @@ class ManagerTest extends TestCase {
$this->config->expects($this->exactly(2))
->method('getSystemValueInt')
- ->withConsecutive(
- ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT],
- ['sharing.minSearchStringLength', 0]
- )
- ->willReturnOnConsecutiveCalls(25, 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)
@@ -111,7 +93,7 @@ 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();
@@ -119,11 +101,10 @@ class ManagerTest extends TestCase {
$this->config->expects($this->exactly(2))
->method('getSystemValueInt')
- ->withConsecutive(
- ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT],
- ['sharing.minSearchStringLength', 0]
- )
- ->willReturnOnConsecutiveCalls(3, 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)
@@ -148,18 +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->exactly(2))
->method('getSystemValueInt')
- ->withConsecutive(
- ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT],
- ['sharing.minSearchStringLength', 0]
- )
- ->willReturnOnConsecutiveCalls(3, 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)
@@ -174,7 +154,7 @@ class ManagerTest extends TestCase {
$this->assertEquals($expected, $data);
}
- public function testFindOne() {
+ public function testFindOne(): void {
$shareTypeFilter = 42;
$shareWithFilter = 'foobar';
@@ -197,7 +177,7 @@ class ManagerTest extends TestCase {
$this->assertEquals($entry, $data);
}
- public function testFindOne404() {
+ public function testFindOne404(): void {
$shareTypeFilter = 42;
$shareWithFilter = 'foobar';
diff --git a/tests/lib/Contacts/ContactsMenu/Providers/EMailproviderTest.php b/tests/lib/Contacts/ContactsMenu/Providers/EMailproviderTest.php
index e9eb41ad397..648351c2ca9 100644
--- a/tests/lib/Contacts/ContactsMenu/Providers/EMailproviderTest.php
+++ b/tests/lib/Contacts/ContactsMenu/Providers/EMailproviderTest.php
@@ -1,25 +1,8 @@
<?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\Providers;
@@ -50,7 +33,7 @@ class EMailproviderTest extends TestCase {
$this->provider = new EMailProvider($this->actionFactory, $this->urlGenerator);
}
- public function testProcess() {
+ public function testProcess(): void {
$entry = $this->createMock(IEntry::class);
$action = $this->createMock(ILinkAction::class);
$iconUrl = 'https://example.com/img/actions/icon.svg';
@@ -77,7 +60,7 @@ class EMailproviderTest extends TestCase {
$this->provider->process($entry);
}
- public function testProcessEmptyAddress() {
+ public function testProcessEmptyAddress(): void {
$entry = $this->createMock(IEntry::class);
$iconUrl = 'https://example.com/img/actions/icon.svg';
$this->urlGenerator->expects($this->once())
diff --git a/tests/lib/Contacts/ContactsMenu/Providers/LocalTimeProviderTest.php b/tests/lib/Contacts/ContactsMenu/Providers/LocalTimeProviderTest.php
index 5b4589de317..cc53c0bcfcf 100644
--- a/tests/lib/Contacts/ContactsMenu/Providers/LocalTimeProviderTest.php
+++ b/tests/lib/Contacts/ContactsMenu/Providers/LocalTimeProviderTest.php
@@ -3,25 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2023, Joas Schilling <coding@schilljs.com>
- *
- * @author Joas Schilling <coding@schilljs.com>
- *
- * @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: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace lib\Contacts\ContactsMenu\Providers;
@@ -37,27 +20,22 @@ use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
+use OCP\IUserSession;
use OCP\L10N\IFactory as IL10NFactory;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class LocalTimeProviderTest extends TestCase {
- /** @var IActionFactory|MockObject */
- private $actionFactory;
- /** @var IL10N|MockObject */
- private $l;
- /** @var IL10NFactory|MockObject */
- private $l10nFactory;
- /** @var IURLGenerator|MockObject */
- private $urlGenerator;
- /** @var IUserManager|MockObject */
- private $userManager;
- /** @var ITimeFactory|MockObject */
- private $timeFactory;
- /** @var IDateTimeFormatter|MockObject */
- private $dateTimeFormatter;
- /** @var IConfig|MockObject */
- private $config;
+
+ private IActionFactory&MockObject $actionFactory;
+ private IL10N&MockObject $l;
+ private IL10NFactory&MockObject $l10nFactory;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IUserManager&MockObject $userManager;
+ private ITimeFactory&MockObject $timeFactory;
+ private IUserSession&MockObject $userSession;
+ private IDateTimeFormatter&MockObject $dateTimeFormatter;
+ private IConfig&MockObject $config;
private LocalTimeProvider $provider;
@@ -69,14 +47,21 @@ class LocalTimeProviderTest extends TestCase {
$this->l = $this->createMock(IL10N::class);
$this->l->expects($this->any())
->method('t')
- ->will($this->returnCallback(function ($text, $parameters = []) {
+ ->willReturnCallback(function ($text, $parameters = []) {
return vsprintf($text, $parameters);
- }));
+ });
+ $this->l->expects($this->any())
+ ->method('n')
+ ->willReturnCallback(function ($text, $textPlural, $n, $parameters = []) {
+ $formatted = str_replace('%n', (string)$n, $n === 1 ? $text : $textPlural);
+ return vsprintf($formatted, $parameters);
+ });
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->dateTimeFormatter = $this->createMock(IDateTimeFormatter::class);
$this->config = $this->createMock(IConfig::class);
+ $this->userSession = $this->createMock(IUserSession::class);
$this->provider = new LocalTimeProvider(
$this->actionFactory,
@@ -85,11 +70,48 @@ class LocalTimeProviderTest extends TestCase {
$this->userManager,
$this->timeFactory,
$this->dateTimeFormatter,
- $this->config
+ $this->config,
+ $this->userSession,
);
}
- public function testProcess(): void {
+ public static function dataTestProcess(): array {
+ return [
+ 'no current user' => [
+ false,
+ null,
+ null,
+ 'Local time: 10:24',
+ ],
+ 'both UTC' => [
+ true,
+ null,
+ null,
+ '10:24 • same time',
+ ],
+ 'both same time zone' => [
+ true,
+ 'Europe/Berlin',
+ 'Europe/Berlin',
+ '11:24 • same time',
+ ],
+ '1h behind' => [
+ true,
+ 'Europe/Berlin',
+ 'Europe/London',
+ '10:24 • 1h behind',
+ ],
+ '4:45h ahead' => [
+ true,
+ 'Europe/Berlin',
+ 'Asia/Kathmandu',
+ '16:09 • 4h45m ahead',
+ ],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestProcess')]
+ public function testProcess(bool $hasCurrentUser, ?string $currentUserTZ, ?string $targetUserTZ, string $expected): void {
$entry = $this->createMock(IEntry::class);
$entry->expects($this->once())
->method('getProperty')
@@ -108,18 +130,29 @@ class LocalTimeProviderTest extends TestCase {
->with('lib')
->willReturn($this->l);
- $this->config->method('getUserValue')
- ->with('user1', 'core', 'timezone')
- ->willReturn('America/Los_Angeles');
+ $this->config->method('getSystemValueString')
+ ->with('default_timezone', 'UTC')
+ ->willReturn('UTC');
+ $this->config
+ ->method('getUserValue')
+ ->willReturnMap([
+ ['user1', 'core', 'timezone', '', $targetUserTZ],
+ ['currentUser', 'core', 'timezone', '', $currentUserTZ],
+ ]);
+
+ if ($hasCurrentUser) {
+ $currentUser = $this->createMock(IUser::class);
+ $currentUser->method('getUID')
+ ->willReturn('currentUser');
+ $this->userSession->method('getUser')
+ ->willReturn($currentUser);
+ }
- $now = new \DateTime('2023-01-04 10:24:43');
$this->timeFactory->method('getDateTime')
- ->willReturn($now);
+ ->willReturnCallback(fn ($time, $tz) => (new \DateTime('2023-01-04 10:24:43', new \DateTimeZone('UTC')))->setTimezone($tz));
- $now = new \DateTime('2023-01-04 10:24:43');
$this->dateTimeFormatter->method('formatTime')
- ->with($now, 'short', $this->anything())
- ->willReturn('01:24');
+ ->willReturnCallback(fn (\DateTime $time) => $time->format('H:i'));
$this->urlGenerator->method('imagePath')
->willReturn('actions/recent.svg');
@@ -132,7 +165,7 @@ class LocalTimeProviderTest extends TestCase {
->method('newLinkAction')
->with(
'https://localhost/actions/recent.svg',
- 'Local time: 01:24',
+ $expected,
'#',
'timezone'
)