summaryrefslogtreecommitdiffstats
path: root/tests/php
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-08-18 09:58:22 +0200
committerJoas Schilling <coding@schilljs.com>2022-08-19 12:06:21 +0200
commit1c29d7714f899b44507306dd4b3b05e0c4e02dfc (patch)
tree13676e5184cfbe968cc04662df14b839cb344577 /tests/php
parentfa2dfc51e6d4f75950f777bb7b2d607004c1f2f7 (diff)
Use user displayname cache in notification rendering
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests/php')
-rw-r--r--tests/php/Notification/NotifierTest.php83
1 files changed, 34 insertions, 49 deletions
diff --git a/tests/php/Notification/NotifierTest.php b/tests/php/Notification/NotifierTest.php
index 2192b3de9..2cf02639c 100644
--- a/tests/php/Notification/NotifierTest.php
+++ b/tests/php/Notification/NotifierTest.php
@@ -19,7 +19,7 @@
*
*/
-namespace OCA\Talk\Tests\php\Notifications;
+namespace OCA\Talk\Tests\php\Notification;
use OCA\FederatedFileSharing\AddressHandler;
use OCA\Talk\Chat\CommentsManager;
@@ -113,7 +113,7 @@ class NotifierTest extends TestCase {
);
}
- public function dataPrepareOne2One() {
+ public function dataPrepareOne2One(): array {
return [
['admin', 'Admin', 'Admin invited you to a private conversation'],
['test', 'Test user', 'Test user invited you to a private conversation'],
@@ -126,7 +126,7 @@ class NotifierTest extends TestCase {
* @param string $displayName
* @param string $parsedSubject
*/
- public function testPrepareOne2One($uid, $displayName, $parsedSubject) {
+ public function testPrepareOne2One(string $uid, string $displayName, string $parsedSubject): void {
/** @var INotification|MockObject $n */
$n = $this->createMock(INotification::class);
$l = $this->createMock(IL10N::class);
@@ -158,20 +158,15 @@ class NotifierTest extends TestCase {
->willReturn($l);
$recipient = $this->createMock(IUser::class);
- $u = $this->createMock(IUser::class);
- $u->expects($this->exactly(2))
+ $this->userManager->expects($this->once())
+ ->method('get')
+ ->with('recipient')
+ ->willReturn($recipient);
+
+ $this->userManager->expects($this->once())
->method('getDisplayName')
+ ->with($uid)
->willReturn($displayName);
- $this->userManager->expects($this->exactly(2))
- ->method('get')
- ->withConsecutive(
- ['recipient'],
- [$uid]
- )
- ->willReturnOnConsecutiveCalls(
- $recipient,
- $u
- );
$n->expects($this->once())
->method('setIcon')
@@ -264,16 +259,15 @@ class NotifierTest extends TestCase {
->willReturn($l);
$recipient = $this->createMock(IUser::class);
- $u = $this->createMock(IUser::class);
- $u->expects($this->exactly($numNotifications * 2))
- ->method('getDisplayName')
- ->willReturn($displayName);
$this->userManager->expects($this->any())
->method('get')
- ->willReturnMap([
- ['recipient', $recipient],
- [$uid, $u],
- ]);
+ ->with('recipient')
+ ->willReturn($recipient);
+
+ $this->userManager->expects($this->any())
+ ->method('getDisplayName')
+ ->with($uid)
+ ->willReturn($displayName);
$n = $this->getNotificationMock($parsedSubject, $uid, $displayName);
$this->notifier->prepare($n, 'de');
@@ -315,7 +309,6 @@ class NotifierTest extends TestCase {
])
->willReturnSelf();
-
$n->expects($this->exactly(2))
->method('getUser')
->willReturn('recipient');
@@ -381,20 +374,15 @@ class NotifierTest extends TestCase {
->willReturn($l);
$recipient = $this->createMock(IUser::class);
- $u = $this->createMock(IUser::class);
- $u->expects($this->exactly(2))
+ $this->userManager->expects($this->once())
+ ->method('get')
+ ->with('recipient')
+ ->willReturn($recipient);
+
+ $this->userManager->expects($this->once())
->method('getDisplayName')
+ ->with($uid)
->willReturn($displayName);
- $this->userManager->expects($this->exactly(2))
- ->method('get')
- ->withConsecutive(
- ['recipient'],
- [$uid]
- )
- ->willReturnOnConsecutiveCalls(
- $recipient,
- $u
- );
$n->expects($this->once())
->method('setIcon')
@@ -902,27 +890,24 @@ class NotifierTest extends TestCase {
->willReturn($l);
$recipient = $this->createMock(IUser::class);
- $userManagerGet['with'][] = ['recipient'];
- $userManagerGet['willReturn'][] = $recipient;
+ $this->userManager->expects($this->once())
+ ->method('get')
+ ->with('recipient')
+ ->willReturn($recipient);
- $user = $this->createMock(IUser::class);
+ $userManagerGet = [
+ 'with' => [],
+ 'willReturn' => [],
+ ];
if ($subjectParameters['userType'] === 'users' && !$deletedUser) {
- $user->expects($this->once())
- ->method('getDisplayName')
- ->willReturn($displayName);
$userManagerGet['with'][] = [$subjectParameters['userId']];
- $userManagerGet['willReturn'][] = $user;
+ $userManagerGet['willReturn'][] = $displayName;
} elseif ($subjectParameters['userType'] === 'users' && $deletedUser) {
- $user->expects($this->never())
- ->method('getDisplayName');
$userManagerGet['with'][] = [$subjectParameters['userId']];
$userManagerGet['willReturn'][] = null;
- } else {
- $user->expects($this->never())
- ->method('getDisplayName');
}
$this->userManager->expects($this->exactly(count($userManagerGet['with'])))
- ->method('get')
+ ->method('getDisplayName')
->withConsecutive(...$userManagerGet['with'])
->willReturnOnConsecutiveCalls(...$userManagerGet['willReturn']);