2016-05-09 11:02:07 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
*
|
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-05-09 11:02:07 +03:00
|
|
|
*
|
|
|
|
* @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
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-05-09 11:02:07 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Comments\Tests\Unit\Notification;
|
|
|
|
|
|
|
|
use OCA\Comments\Notification\Notifier;
|
|
|
|
use OCP\Comments\IComment;
|
|
|
|
use OCP\Comments\ICommentsManager;
|
|
|
|
use OCP\Comments\NotFoundException;
|
|
|
|
use OCP\Files\Folder;
|
2017-03-03 15:12:24 +03:00
|
|
|
use OCP\Files\IRootFolder;
|
2016-05-09 11:02:07 +03:00
|
|
|
use OCP\Files\Node;
|
|
|
|
use OCP\IL10N;
|
2016-11-23 13:31:35 +03:00
|
|
|
use OCP\IURLGenerator;
|
2016-05-09 11:02:07 +03:00
|
|
|
use OCP\IUser;
|
|
|
|
use OCP\IUserManager;
|
|
|
|
use OCP\L10N\IFactory;
|
|
|
|
use OCP\Notification\INotification;
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class NotifierTest extends TestCase {
|
|
|
|
|
|
|
|
/** @var Notifier */
|
|
|
|
protected $notifier;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
|
2016-05-09 11:02:07 +03:00
|
|
|
protected $l10nFactory;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
|
2017-03-03 15:12:24 +03:00
|
|
|
protected $l;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject */
|
2016-05-09 11:02:07 +03:00
|
|
|
protected $folder;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var ICommentsManager|\PHPUnit\Framework\MockObject\MockObject */
|
2016-05-09 11:02:07 +03:00
|
|
|
protected $commentsManager;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
|
2016-11-23 13:31:35 +03:00
|
|
|
protected $url;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
|
2016-05-09 11:02:07 +03:00
|
|
|
protected $userManager;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var INotification|\PHPUnit\Framework\MockObject\MockObject */
|
2016-05-09 11:02:07 +03:00
|
|
|
protected $notification;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IComment|\PHPUnit\Framework\MockObject\MockObject */
|
2016-05-09 11:02:07 +03:00
|
|
|
protected $comment;
|
2017-03-03 15:12:24 +03:00
|
|
|
/** @var string */
|
|
|
|
protected $lc = 'tlh_KX';
|
2016-05-09 11:02:07 +03:00
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2016-05-09 11:02:07 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2017-03-03 15:12:24 +03:00
|
|
|
$this->l10nFactory = $this->createMock(IFactory::class);
|
|
|
|
$this->folder = $this->createMock(IRootFolder::class);
|
|
|
|
$this->commentsManager = $this->createMock(ICommentsManager::class);
|
2016-11-23 13:31:35 +03:00
|
|
|
$this->url = $this->createMock(IURLGenerator::class);
|
2017-03-03 15:12:24 +03:00
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
2016-05-09 11:02:07 +03:00
|
|
|
|
|
|
|
$this->notifier = new Notifier(
|
|
|
|
$this->l10nFactory,
|
|
|
|
$this->folder,
|
|
|
|
$this->commentsManager,
|
2016-11-23 13:31:35 +03:00
|
|
|
$this->url,
|
2016-05-09 11:02:07 +03:00
|
|
|
$this->userManager
|
|
|
|
);
|
|
|
|
|
2016-11-23 13:31:35 +03:00
|
|
|
$this->l = $this->createMock(IL10N::class);
|
|
|
|
$this->l->expects($this->any())
|
|
|
|
->method('t')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function ($text, $parameters = []) {
|
2016-11-23 13:31:35 +03:00
|
|
|
return vsprintf($text, $parameters);
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2016-11-23 13:31:35 +03:00
|
|
|
|
2017-03-03 15:12:24 +03:00
|
|
|
$this->notification = $this->createMock(INotification::class);
|
|
|
|
$this->comment = $this->createMock(IComment::class);
|
2016-05-09 11:02:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testPrepareSuccess() {
|
|
|
|
$fileName = 'Gre\'thor.odp';
|
|
|
|
$displayName = 'Huraga';
|
2018-11-08 13:54:41 +03:00
|
|
|
$message = '@Huraga mentioned you in a comment on “Gre\'thor.odp”';
|
2016-05-09 11:02:07 +03:00
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
|
2017-03-03 15:12:24 +03:00
|
|
|
$user = $this->createMock(IUser::class);
|
2016-05-09 11:02:07 +03:00
|
|
|
$user->expects($this->once())
|
|
|
|
->method('getDisplayName')
|
|
|
|
->willReturn($displayName);
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $you */
|
2018-11-08 13:54:41 +03:00
|
|
|
$you = $this->createMock(IUser::class);
|
2016-05-09 11:02:07 +03:00
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var Node|\PHPUnit\Framework\MockObject\MockObject $node */
|
2017-03-03 15:12:24 +03:00
|
|
|
$node = $this->createMock(Node::class);
|
2016-05-09 11:02:07 +03:00
|
|
|
$node
|
2016-11-23 13:31:35 +03:00
|
|
|
->expects($this->atLeastOnce())
|
2016-05-09 11:02:07 +03:00
|
|
|
->method('getName')
|
|
|
|
->willReturn($fileName);
|
2018-11-08 13:54:41 +03:00
|
|
|
$node
|
|
|
|
->expects($this->atLeastOnce())
|
|
|
|
->method('getPath')
|
|
|
|
->willReturn('/you/files/' . $fileName);
|
2016-05-09 11:02:07 +03:00
|
|
|
|
2017-03-03 15:12:24 +03:00
|
|
|
$userFolder = $this->createMock(Folder::class);
|
|
|
|
$this->folder->expects($this->once())
|
|
|
|
->method('getUserFolder')
|
|
|
|
->with('you')
|
|
|
|
->willReturn($userFolder);
|
|
|
|
$userFolder->expects($this->once())
|
2016-05-09 11:02:07 +03:00
|
|
|
->method('getById')
|
|
|
|
->with('678')
|
|
|
|
->willReturn([$node]);
|
|
|
|
|
2018-11-08 13:54:41 +03:00
|
|
|
$this->notification->expects($this->exactly(2))
|
2017-03-03 15:12:24 +03:00
|
|
|
->method('getUser')
|
|
|
|
->willReturn('you');
|
2016-05-09 11:02:07 +03:00
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getApp')
|
|
|
|
->willReturn('comments');
|
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubject')
|
|
|
|
->willReturn('mention');
|
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubjectParameters')
|
|
|
|
->willReturn(['files', '678']);
|
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('setParsedSubject')
|
2016-11-23 13:31:35 +03:00
|
|
|
->with($message)
|
|
|
|
->willReturnSelf();
|
|
|
|
$this->notification
|
2016-05-09 11:02:07 +03:00
|
|
|
->expects($this->once())
|
2016-11-23 13:31:35 +03:00
|
|
|
->method('setRichSubject')
|
|
|
|
->with('{user} mentioned you in a comment on “{file}”', $this->anything())
|
|
|
|
->willReturnSelf();
|
2018-11-08 13:54:41 +03:00
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('setRichMessage')
|
|
|
|
->with('Hi {mention-user1}!', ['mention-user1' => ['type' => 'user', 'id' => 'you', 'name' => 'Your name']])
|
|
|
|
->willReturnSelf();
|
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('setParsedMessage')
|
|
|
|
->with('Hi @Your name!')
|
|
|
|
->willReturnSelf();
|
2016-11-23 13:31:35 +03:00
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('setIcon')
|
|
|
|
->with('absolute-image-path')
|
|
|
|
->willReturnSelf();
|
|
|
|
|
|
|
|
$this->url->expects($this->once())
|
|
|
|
->method('imagePath')
|
|
|
|
->with('core', 'actions/comment.svg')
|
|
|
|
->willReturn('image-path');
|
|
|
|
$this->url->expects($this->once())
|
|
|
|
->method('getAbsoluteURL')
|
|
|
|
->with('image-path')
|
|
|
|
->willReturn('absolute-image-path');
|
2016-05-09 11:02:07 +03:00
|
|
|
|
|
|
|
$this->l10nFactory
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->willReturn($this->l);
|
|
|
|
|
|
|
|
$this->comment
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getActorId')
|
|
|
|
->willReturn('huraga');
|
|
|
|
$this->comment
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getActorType')
|
|
|
|
->willReturn('users');
|
2018-11-08 13:54:41 +03:00
|
|
|
$this->comment
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getMessage')
|
|
|
|
->willReturn('Hi @you!');
|
|
|
|
$this->comment
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getMentions')
|
|
|
|
->willReturn([['type' => 'user', 'id' => 'you']]);
|
2019-07-16 14:32:44 +03:00
|
|
|
$this->comment->expects($this->atLeastOnce())
|
|
|
|
->method('getId')
|
|
|
|
->willReturn('1234');
|
2016-05-09 11:02:07 +03:00
|
|
|
|
|
|
|
$this->commentsManager
|
2017-03-03 15:12:24 +03:00
|
|
|
->expects($this->once())
|
2016-05-09 11:02:07 +03:00
|
|
|
->method('get')
|
|
|
|
->willReturn($this->comment);
|
2018-11-08 13:54:41 +03:00
|
|
|
$this->commentsManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('resolveDisplayName')
|
|
|
|
->with('user', 'you')
|
|
|
|
->willReturn('Your name');
|
2016-05-09 11:02:07 +03:00
|
|
|
|
|
|
|
$this->userManager
|
2018-11-08 13:54:41 +03:00
|
|
|
->expects($this->exactly(2))
|
2016-05-09 11:02:07 +03:00
|
|
|
->method('get')
|
2018-11-08 13:54:41 +03:00
|
|
|
->willReturnMap([
|
|
|
|
['huraga', $user],
|
|
|
|
['you', $you],
|
|
|
|
]);
|
2016-05-09 11:02:07 +03:00
|
|
|
|
|
|
|
$this->notifier->prepare($this->notification, $this->lc);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPrepareSuccessDeletedUser() {
|
|
|
|
$fileName = 'Gre\'thor.odp';
|
2017-11-24 14:10:04 +03:00
|
|
|
$message = 'You were mentioned on “Gre\'thor.odp”, in a comment by a user that has since been deleted';
|
2016-05-09 11:02:07 +03:00
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $you */
|
2018-11-08 13:54:41 +03:00
|
|
|
$you = $this->createMock(IUser::class);
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var Node|\PHPUnit\Framework\MockObject\MockObject $node */
|
2017-03-03 15:12:24 +03:00
|
|
|
$node = $this->createMock(Node::class);
|
2016-05-09 11:02:07 +03:00
|
|
|
$node
|
2016-11-23 13:31:35 +03:00
|
|
|
->expects($this->atLeastOnce())
|
2016-05-09 11:02:07 +03:00
|
|
|
->method('getName')
|
|
|
|
->willReturn($fileName);
|
2018-11-08 13:54:41 +03:00
|
|
|
$node
|
|
|
|
->expects($this->atLeastOnce())
|
|
|
|
->method('getPath')
|
|
|
|
->willReturn('/you/files/' . $fileName);
|
2016-05-09 11:02:07 +03:00
|
|
|
|
2017-03-03 15:12:24 +03:00
|
|
|
$userFolder = $this->createMock(Folder::class);
|
|
|
|
$this->folder->expects($this->once())
|
|
|
|
->method('getUserFolder')
|
|
|
|
->with('you')
|
|
|
|
->willReturn($userFolder);
|
|
|
|
$userFolder->expects($this->once())
|
2016-05-09 11:02:07 +03:00
|
|
|
->method('getById')
|
|
|
|
->with('678')
|
|
|
|
->willReturn([$node]);
|
|
|
|
|
2018-11-08 13:54:41 +03:00
|
|
|
$this->notification->expects($this->exactly(2))
|
2017-03-03 15:12:24 +03:00
|
|
|
->method('getUser')
|
|
|
|
->willReturn('you');
|
2016-05-09 11:02:07 +03:00
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getApp')
|
|
|
|
->willReturn('comments');
|
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubject')
|
|
|
|
->willReturn('mention');
|
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubjectParameters')
|
|
|
|
->willReturn(['files', '678']);
|
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('setParsedSubject')
|
2016-11-23 13:31:35 +03:00
|
|
|
->with($message)
|
|
|
|
->willReturnSelf();
|
|
|
|
$this->notification
|
2016-05-09 11:02:07 +03:00
|
|
|
->expects($this->once())
|
2016-11-23 13:31:35 +03:00
|
|
|
->method('setRichSubject')
|
2017-11-24 14:10:04 +03:00
|
|
|
->with('You were mentioned on “{file}”, in a comment by a user that has since been deleted', $this->anything())
|
2016-11-23 13:31:35 +03:00
|
|
|
->willReturnSelf();
|
2018-11-08 13:54:41 +03:00
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('setRichMessage')
|
|
|
|
->with('Hi {mention-user1}!', ['mention-user1' => ['type' => 'user', 'id' => 'you', 'name' => 'Your name']])
|
|
|
|
->willReturnSelf();
|
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('setParsedMessage')
|
|
|
|
->with('Hi @Your name!')
|
|
|
|
->willReturnSelf();
|
2016-11-23 13:31:35 +03:00
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('setIcon')
|
|
|
|
->with('absolute-image-path')
|
|
|
|
->willReturnSelf();
|
|
|
|
|
|
|
|
$this->url->expects($this->once())
|
|
|
|
->method('imagePath')
|
|
|
|
->with('core', 'actions/comment.svg')
|
|
|
|
->willReturn('image-path');
|
|
|
|
$this->url->expects($this->once())
|
|
|
|
->method('getAbsoluteURL')
|
|
|
|
->with('image-path')
|
|
|
|
->willReturn('absolute-image-path');
|
2016-05-09 11:02:07 +03:00
|
|
|
|
|
|
|
$this->l10nFactory
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->willReturn($this->l);
|
|
|
|
|
|
|
|
$this->comment
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getActorId')
|
|
|
|
->willReturn('huraga');
|
|
|
|
$this->comment
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getActorType')
|
|
|
|
->willReturn(ICommentsManager::DELETED_USER);
|
2018-11-08 13:54:41 +03:00
|
|
|
$this->comment
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getMessage')
|
|
|
|
->willReturn('Hi @you!');
|
|
|
|
$this->comment
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getMentions')
|
|
|
|
->willReturn([['type' => 'user', 'id' => 'you']]);
|
2016-05-09 11:02:07 +03:00
|
|
|
|
|
|
|
$this->commentsManager
|
2017-03-03 15:12:24 +03:00
|
|
|
->expects($this->once())
|
2016-05-09 11:02:07 +03:00
|
|
|
->method('get')
|
|
|
|
->willReturn($this->comment);
|
2018-11-08 13:54:41 +03:00
|
|
|
$this->commentsManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('resolveDisplayName')
|
|
|
|
->with('user', 'you')
|
|
|
|
->willReturn('Your name');
|
2016-05-09 11:02:07 +03:00
|
|
|
|
|
|
|
$this->userManager
|
2018-11-08 13:54:41 +03:00
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('you')
|
|
|
|
->willReturn($you);
|
2016-05-09 11:02:07 +03:00
|
|
|
|
|
|
|
$this->notifier->prepare($this->notification, $this->lc);
|
|
|
|
}
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
|
2016-05-09 11:02:07 +03:00
|
|
|
public function testPrepareDifferentApp() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
2016-05-09 11:02:07 +03:00
|
|
|
$this->folder
|
|
|
|
->expects($this->never())
|
|
|
|
->method('getById');
|
|
|
|
|
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getApp')
|
|
|
|
->willReturn('constructions');
|
|
|
|
$this->notification
|
|
|
|
->expects($this->never())
|
|
|
|
->method('getSubject');
|
|
|
|
$this->notification
|
|
|
|
->expects($this->never())
|
|
|
|
->method('getSubjectParameters');
|
|
|
|
$this->notification
|
|
|
|
->expects($this->never())
|
|
|
|
->method('setParsedSubject');
|
|
|
|
|
|
|
|
$this->l10nFactory
|
|
|
|
->expects($this->never())
|
|
|
|
->method('get');
|
|
|
|
|
|
|
|
$this->commentsManager
|
2017-03-03 15:12:24 +03:00
|
|
|
->expects($this->never())
|
2016-05-09 11:02:07 +03:00
|
|
|
->method('get');
|
|
|
|
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->never())
|
|
|
|
->method('get');
|
|
|
|
|
|
|
|
$this->notifier->prepare($this->notification, $this->lc);
|
|
|
|
}
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
|
2016-05-09 11:02:07 +03:00
|
|
|
public function testPrepareNotFound() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
2016-05-09 11:02:07 +03:00
|
|
|
$this->folder
|
|
|
|
->expects($this->never())
|
|
|
|
->method('getById');
|
|
|
|
|
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getApp')
|
|
|
|
->willReturn('comments');
|
|
|
|
$this->notification
|
|
|
|
->expects($this->never())
|
|
|
|
->method('getSubject');
|
|
|
|
$this->notification
|
|
|
|
->expects($this->never())
|
|
|
|
->method('getSubjectParameters');
|
|
|
|
$this->notification
|
|
|
|
->expects($this->never())
|
|
|
|
->method('setParsedSubject');
|
|
|
|
|
|
|
|
$this->l10nFactory
|
|
|
|
->expects($this->never())
|
|
|
|
->method('get');
|
|
|
|
|
|
|
|
$this->commentsManager
|
2017-03-03 15:12:24 +03:00
|
|
|
->expects($this->once())
|
2016-05-09 11:02:07 +03:00
|
|
|
->method('get')
|
|
|
|
->willThrowException(new NotFoundException());
|
|
|
|
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->never())
|
|
|
|
->method('get');
|
|
|
|
|
|
|
|
$this->notifier->prepare($this->notification, $this->lc);
|
|
|
|
}
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
|
2016-05-09 11:02:07 +03:00
|
|
|
public function testPrepareDifferentSubject() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
2016-05-09 11:02:07 +03:00
|
|
|
$displayName = 'Huraga';
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
|
2017-03-03 15:12:24 +03:00
|
|
|
$user = $this->createMock(IUser::class);
|
2016-05-09 11:02:07 +03:00
|
|
|
$user->expects($this->once())
|
|
|
|
->method('getDisplayName')
|
|
|
|
->willReturn($displayName);
|
|
|
|
|
|
|
|
$this->folder
|
|
|
|
->expects($this->never())
|
|
|
|
->method('getById');
|
|
|
|
|
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getApp')
|
|
|
|
->willReturn('comments');
|
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubject')
|
|
|
|
->willReturn('unlike');
|
|
|
|
$this->notification
|
|
|
|
->expects($this->never())
|
|
|
|
->method('getSubjectParameters');
|
|
|
|
$this->notification
|
|
|
|
->expects($this->never())
|
|
|
|
->method('setParsedSubject');
|
|
|
|
|
|
|
|
$this->l
|
|
|
|
->expects($this->never())
|
|
|
|
->method('t');
|
|
|
|
|
|
|
|
$this->l10nFactory
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->willReturn($this->l);
|
|
|
|
|
|
|
|
$this->comment
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getActorId')
|
|
|
|
->willReturn('huraga');
|
|
|
|
$this->comment
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getActorType')
|
|
|
|
->willReturn('users');
|
|
|
|
|
|
|
|
$this->commentsManager
|
2017-03-03 15:12:24 +03:00
|
|
|
->expects($this->once())
|
2016-05-09 11:02:07 +03:00
|
|
|
->method('get')
|
|
|
|
->willReturn($this->comment);
|
|
|
|
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('huraga')
|
|
|
|
->willReturn($user);
|
|
|
|
|
|
|
|
$this->notifier->prepare($this->notification, $this->lc);
|
|
|
|
}
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
|
2016-05-09 11:02:07 +03:00
|
|
|
public function testPrepareNotFiles() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
2016-05-09 11:02:07 +03:00
|
|
|
$displayName = 'Huraga';
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
|
2017-03-03 15:12:24 +03:00
|
|
|
$user = $this->createMock(IUser::class);
|
2016-05-09 11:02:07 +03:00
|
|
|
$user->expects($this->once())
|
|
|
|
->method('getDisplayName')
|
|
|
|
->willReturn($displayName);
|
|
|
|
|
|
|
|
$this->folder
|
|
|
|
->expects($this->never())
|
|
|
|
->method('getById');
|
|
|
|
|
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getApp')
|
|
|
|
->willReturn('comments');
|
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubject')
|
|
|
|
->willReturn('mention');
|
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubjectParameters')
|
|
|
|
->willReturn(['ships', '678']);
|
|
|
|
$this->notification
|
|
|
|
->expects($this->never())
|
|
|
|
->method('setParsedSubject');
|
|
|
|
|
|
|
|
$this->l
|
|
|
|
->expects($this->never())
|
|
|
|
->method('t');
|
|
|
|
|
|
|
|
$this->l10nFactory
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->willReturn($this->l);
|
|
|
|
|
|
|
|
$this->comment
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getActorId')
|
|
|
|
->willReturn('huraga');
|
|
|
|
$this->comment
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getActorType')
|
|
|
|
->willReturn('users');
|
|
|
|
|
|
|
|
$this->commentsManager
|
2017-03-03 15:12:24 +03:00
|
|
|
->expects($this->once())
|
2016-05-09 11:02:07 +03:00
|
|
|
->method('get')
|
|
|
|
->willReturn($this->comment);
|
|
|
|
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('huraga')
|
|
|
|
->willReturn($user);
|
|
|
|
|
|
|
|
$this->notifier->prepare($this->notification, $this->lc);
|
|
|
|
}
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
|
2016-05-09 11:02:07 +03:00
|
|
|
public function testPrepareUnresolvableFileID() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\Notification\AlreadyProcessedException::class);
|
|
|
|
|
2016-05-09 11:02:07 +03:00
|
|
|
$displayName = 'Huraga';
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
|
2017-03-03 15:12:24 +03:00
|
|
|
$user = $this->createMock(IUser::class);
|
2016-05-09 11:02:07 +03:00
|
|
|
$user->expects($this->once())
|
|
|
|
->method('getDisplayName')
|
|
|
|
->willReturn($displayName);
|
|
|
|
|
2017-03-03 15:12:24 +03:00
|
|
|
$userFolder = $this->createMock(Folder::class);
|
|
|
|
$this->folder->expects($this->once())
|
|
|
|
->method('getUserFolder')
|
|
|
|
->with('you')
|
|
|
|
->willReturn($userFolder);
|
|
|
|
$userFolder->expects($this->once())
|
2016-05-09 11:02:07 +03:00
|
|
|
->method('getById')
|
|
|
|
->with('678')
|
|
|
|
->willReturn([]);
|
|
|
|
|
2017-03-03 15:12:24 +03:00
|
|
|
$this->notification->expects($this->once())
|
|
|
|
->method('getUser')
|
|
|
|
->willReturn('you');
|
2016-05-09 11:02:07 +03:00
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getApp')
|
|
|
|
->willReturn('comments');
|
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubject')
|
|
|
|
->willReturn('mention');
|
|
|
|
$this->notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubjectParameters')
|
|
|
|
->willReturn(['files', '678']);
|
|
|
|
$this->notification
|
|
|
|
->expects($this->never())
|
|
|
|
->method('setParsedSubject');
|
|
|
|
|
|
|
|
$this->l
|
|
|
|
->expects($this->never())
|
|
|
|
->method('t');
|
|
|
|
|
|
|
|
$this->l10nFactory
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->willReturn($this->l);
|
|
|
|
|
|
|
|
$this->comment
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getActorId')
|
|
|
|
->willReturn('huraga');
|
|
|
|
$this->comment
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getActorType')
|
|
|
|
->willReturn('users');
|
|
|
|
|
|
|
|
$this->commentsManager
|
2017-03-03 15:12:24 +03:00
|
|
|
->expects($this->once())
|
2016-05-09 11:02:07 +03:00
|
|
|
->method('get')
|
|
|
|
->willReturn($this->comment);
|
|
|
|
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('huraga')
|
|
|
|
->willReturn($user);
|
|
|
|
|
|
|
|
$this->notifier->prepare($this->notification, $this->lc);
|
|
|
|
}
|
|
|
|
}
|