2016-01-11 20:09:00 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2016-01-11 20:09:00 +03:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2016-01-11 20:09:00 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-05-25 17:04:15 +03:00
|
|
|
namespace OCA\DAV\Tests\unit\Comments;
|
2016-01-11 20:09:00 +03:00
|
|
|
|
|
|
|
use OCA\DAV\Comments\CommentNode;
|
2017-10-24 16:26:53 +03:00
|
|
|
use OCP\Comments\IComment;
|
2016-10-16 21:28:36 +03:00
|
|
|
use OCP\Comments\ICommentsManager;
|
2016-02-09 15:59:13 +03:00
|
|
|
use OCP\Comments\MessageTooLongException;
|
2017-10-24 16:26:53 +03:00
|
|
|
use OCP\ILogger;
|
|
|
|
use OCP\IUser;
|
|
|
|
use OCP\IUserManager;
|
|
|
|
use OCP\IUserSession;
|
2017-10-25 01:03:28 +03:00
|
|
|
use Sabre\DAV\PropPatch;
|
2016-01-11 20:09:00 +03:00
|
|
|
|
2016-05-25 17:04:15 +03:00
|
|
|
class CommentsNodeTest extends \Test\TestCase {
|
2016-01-11 20:09:00 +03:00
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var ICommentsManager|\PHPUnit\Framework\MockObject\MockObject */
|
2016-01-11 20:09:00 +03:00
|
|
|
protected $commentsManager;
|
2016-10-16 21:28:36 +03:00
|
|
|
|
2016-01-11 20:09:00 +03:00
|
|
|
protected $comment;
|
|
|
|
protected $node;
|
|
|
|
protected $userManager;
|
|
|
|
protected $logger;
|
2016-01-30 01:23:16 +03:00
|
|
|
protected $userSession;
|
2016-01-11 20:09:00 +03:00
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2016-01-11 20:09:00 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->commentsManager = $this->getMockBuilder(ICommentsManager::class)
|
2016-07-15 10:52:46 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->comment = $this->getMockBuilder(IComment::class)
|
2016-07-15 10:52:46 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->userManager = $this->getMockBuilder(IUserManager::class)
|
2016-07-15 10:52:46 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->userSession = $this->getMockBuilder(IUserSession::class)
|
2016-07-15 10:52:46 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->logger = $this->getMockBuilder(ILogger::class)
|
2016-07-15 10:52:46 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-01-11 20:09:00 +03:00
|
|
|
|
2016-01-30 01:23:16 +03:00
|
|
|
$this->node = new CommentNode(
|
|
|
|
$this->commentsManager,
|
|
|
|
$this->comment,
|
|
|
|
$this->userManager,
|
|
|
|
$this->userSession,
|
|
|
|
$this->logger
|
|
|
|
);
|
2016-01-11 20:09:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDelete() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$user = $this->getMockBuilder(IUser::class)
|
2016-07-15 10:52:46 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$user->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('alice');
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($user);
|
2016-02-04 14:57:48 +03:00
|
|
|
|
2016-01-11 20:09:00 +03:00
|
|
|
$this->comment->expects($this->once())
|
|
|
|
->method('getId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('19');
|
2016-01-11 20:09:00 +03:00
|
|
|
|
2016-02-04 14:57:48 +03:00
|
|
|
$this->comment->expects($this->any())
|
|
|
|
->method('getActorType')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('users');
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->any())
|
|
|
|
->method('getActorId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('alice');
|
2016-02-04 14:57:48 +03:00
|
|
|
|
2016-01-11 20:09:00 +03:00
|
|
|
$this->commentsManager->expects($this->once())
|
|
|
|
->method('delete')
|
|
|
|
->with('19');
|
|
|
|
|
|
|
|
$this->node->delete();
|
|
|
|
}
|
|
|
|
|
2020-04-02 10:59:44 +03:00
|
|
|
|
2016-02-04 14:57:48 +03:00
|
|
|
public function testDeleteForbidden() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$user = $this->getMockBuilder(IUser::class)
|
2016-07-15 10:52:46 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$user->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('mallory');
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($user);
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->never())
|
|
|
|
->method('getId');
|
|
|
|
|
|
|
|
$this->comment->expects($this->any())
|
|
|
|
->method('getActorType')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('users');
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->any())
|
|
|
|
->method('getActorId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('alice');
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$this->commentsManager->expects($this->never())
|
|
|
|
->method('delete');
|
|
|
|
|
|
|
|
$this->node->delete();
|
|
|
|
}
|
|
|
|
|
2016-01-11 20:09:00 +03:00
|
|
|
public function testGetName() {
|
|
|
|
$id = '19';
|
|
|
|
$this->comment->expects($this->once())
|
|
|
|
->method('getId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($id);
|
2016-01-11 20:09:00 +03:00
|
|
|
|
|
|
|
$this->assertSame($this->node->getName(), $id);
|
|
|
|
}
|
|
|
|
|
2020-04-02 10:59:44 +03:00
|
|
|
|
2016-01-11 20:09:00 +03:00
|
|
|
public function testSetName() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class);
|
|
|
|
|
2016-01-11 20:09:00 +03:00
|
|
|
$this->node->setName('666');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetLastModified() {
|
2016-01-26 15:16:14 +03:00
|
|
|
$this->assertSame($this->node->getLastModified(), null);
|
2016-01-11 20:09:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateComment() {
|
|
|
|
$msg = 'Hello Earth';
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$user = $this->getMockBuilder(IUser::class)
|
2016-07-15 10:52:46 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$user->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('alice');
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($user);
|
2016-02-04 14:57:48 +03:00
|
|
|
|
2016-01-11 20:09:00 +03:00
|
|
|
$this->comment->expects($this->once())
|
|
|
|
->method('setMessage')
|
|
|
|
->with($msg);
|
|
|
|
|
2016-02-04 14:57:48 +03:00
|
|
|
$this->comment->expects($this->any())
|
|
|
|
->method('getActorType')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('users');
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->any())
|
|
|
|
->method('getActorId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('alice');
|
2016-02-04 14:57:48 +03:00
|
|
|
|
2016-01-11 20:09:00 +03:00
|
|
|
$this->commentsManager->expects($this->once())
|
|
|
|
->method('save')
|
|
|
|
->with($this->comment);
|
|
|
|
|
|
|
|
$this->assertTrue($this->node->updateComment($msg));
|
|
|
|
}
|
|
|
|
|
2020-04-02 10:59:44 +03:00
|
|
|
|
2016-02-04 14:57:48 +03:00
|
|
|
public function testUpdateCommentLogException() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
$this->expectExceptionMessage('buh!');
|
|
|
|
|
2016-01-11 20:09:00 +03:00
|
|
|
$msg = null;
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$user = $this->getMockBuilder(IUser::class)
|
2016-07-15 10:52:46 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$user->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('alice');
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($user);
|
2016-02-04 14:57:48 +03:00
|
|
|
|
2016-01-11 20:09:00 +03:00
|
|
|
$this->comment->expects($this->once())
|
|
|
|
->method('setMessage')
|
|
|
|
->with($msg)
|
|
|
|
->will($this->throwException(new \Exception('buh!')));
|
|
|
|
|
2016-02-04 14:57:48 +03:00
|
|
|
$this->comment->expects($this->any())
|
|
|
|
->method('getActorType')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('users');
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->any())
|
|
|
|
->method('getActorId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('alice');
|
2016-02-04 14:57:48 +03:00
|
|
|
|
2016-01-11 20:09:00 +03:00
|
|
|
$this->commentsManager->expects($this->never())
|
|
|
|
->method('save');
|
|
|
|
|
|
|
|
$this->logger->expects($this->once())
|
|
|
|
->method('logException');
|
|
|
|
|
2016-06-24 11:10:10 +03:00
|
|
|
$this->node->updateComment($msg);
|
2016-01-11 20:09:00 +03:00
|
|
|
}
|
|
|
|
|
2020-04-02 10:59:44 +03:00
|
|
|
|
2016-02-09 15:59:13 +03:00
|
|
|
public function testUpdateCommentMessageTooLongException() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Sabre\DAV\Exception\BadRequest::class);
|
|
|
|
$this->expectExceptionMessage('Message exceeds allowed character limit of');
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$user = $this->getMockBuilder(IUser::class)
|
2016-07-15 10:52:46 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-02-09 15:59:13 +03:00
|
|
|
|
|
|
|
$user->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('alice');
|
2016-02-09 15:59:13 +03:00
|
|
|
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($user);
|
2016-02-09 15:59:13 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->once())
|
|
|
|
->method('setMessage')
|
|
|
|
->will($this->throwException(new MessageTooLongException()));
|
|
|
|
|
|
|
|
$this->comment->expects($this->any())
|
|
|
|
->method('getActorType')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('users');
|
2016-02-09 15:59:13 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->any())
|
|
|
|
->method('getActorId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('alice');
|
2016-02-09 15:59:13 +03:00
|
|
|
|
|
|
|
$this->commentsManager->expects($this->never())
|
|
|
|
->method('save');
|
|
|
|
|
|
|
|
$this->logger->expects($this->once())
|
|
|
|
->method('logException');
|
|
|
|
|
|
|
|
// imagine 'foo' has >1k characters. comment is mocked anyway.
|
|
|
|
$this->node->updateComment('foo');
|
|
|
|
}
|
|
|
|
|
2020-04-02 10:59:44 +03:00
|
|
|
|
2016-02-04 14:57:48 +03:00
|
|
|
public function testUpdateForbiddenByUser() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
|
|
|
|
|
2016-02-04 14:57:48 +03:00
|
|
|
$msg = 'HaXX0r';
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$user = $this->getMockBuilder(IUser::class)
|
2016-07-15 10:52:46 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$user->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('mallory');
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($user);
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->never())
|
|
|
|
->method('setMessage');
|
|
|
|
|
|
|
|
$this->comment->expects($this->any())
|
|
|
|
->method('getActorType')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('users');
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->any())
|
|
|
|
->method('getActorId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('alice');
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$this->commentsManager->expects($this->never())
|
|
|
|
->method('save');
|
|
|
|
|
|
|
|
$this->node->updateComment($msg);
|
|
|
|
}
|
|
|
|
|
2020-04-02 10:59:44 +03:00
|
|
|
|
2016-02-04 14:57:48 +03:00
|
|
|
public function testUpdateForbiddenByType() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
|
|
|
|
|
2016-02-04 14:57:48 +03:00
|
|
|
$msg = 'HaXX0r';
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$user = $this->getMockBuilder(IUser::class)
|
2016-07-15 10:52:46 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$user->expects($this->never())
|
|
|
|
->method('getUID');
|
|
|
|
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($user);
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->never())
|
|
|
|
->method('setMessage');
|
|
|
|
|
|
|
|
$this->comment->expects($this->any())
|
|
|
|
->method('getActorType')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('bots');
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$this->commentsManager->expects($this->never())
|
|
|
|
->method('save');
|
|
|
|
|
|
|
|
$this->node->updateComment($msg);
|
|
|
|
}
|
|
|
|
|
2020-04-02 10:59:44 +03:00
|
|
|
|
2016-02-04 14:57:48 +03:00
|
|
|
public function testUpdateForbiddenByNotLoggedIn() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
|
|
|
|
|
2016-02-04 14:57:48 +03:00
|
|
|
$msg = 'HaXX0r';
|
|
|
|
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(null);
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->never())
|
|
|
|
->method('setMessage');
|
|
|
|
|
|
|
|
$this->comment->expects($this->any())
|
|
|
|
->method('getActorType')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('users');
|
2016-02-04 14:57:48 +03:00
|
|
|
|
|
|
|
$this->commentsManager->expects($this->never())
|
|
|
|
->method('save');
|
|
|
|
|
|
|
|
$this->node->updateComment($msg);
|
|
|
|
}
|
|
|
|
|
2016-01-11 20:09:00 +03:00
|
|
|
public function testPropPatch() {
|
2017-10-25 01:03:28 +03:00
|
|
|
$propPatch = $this->getMockBuilder(PropPatch::class)
|
2016-01-11 20:09:00 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$propPatch->expects($this->once())
|
|
|
|
->method('handle')
|
|
|
|
->with('{http://owncloud.org/ns}message');
|
|
|
|
|
|
|
|
$this->node->propPatch($propPatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetProperties() {
|
|
|
|
$ns = '{http://owncloud.org/ns}';
|
|
|
|
$expected = [
|
|
|
|
$ns . 'id' => '123',
|
|
|
|
$ns . 'parentId' => '12',
|
|
|
|
$ns . 'topmostParentId' => '2',
|
|
|
|
$ns . 'childrenCount' => 3,
|
|
|
|
$ns . 'message' => 'such a nice file you have…',
|
2016-10-14 01:19:31 +03:00
|
|
|
$ns . 'mentions' => [
|
2016-10-16 21:28:36 +03:00
|
|
|
[ $ns . 'mention' => [
|
|
|
|
$ns . 'mentionType' => 'user',
|
|
|
|
$ns . 'mentionId' => 'alice',
|
|
|
|
$ns . 'mentionDisplayName' => 'Alice Al-Isson',
|
|
|
|
] ],
|
|
|
|
[ $ns . 'mention' => [
|
|
|
|
$ns . 'mentionType' => 'user',
|
|
|
|
$ns . 'mentionId' => 'bob',
|
|
|
|
$ns . 'mentionDisplayName' => 'Unknown user',
|
|
|
|
] ],
|
2016-10-14 01:19:31 +03:00
|
|
|
],
|
2016-01-11 20:09:00 +03:00
|
|
|
$ns . 'verb' => 'comment',
|
|
|
|
$ns . 'actorType' => 'users',
|
|
|
|
$ns . 'actorId' => 'alice',
|
|
|
|
$ns . 'actorDisplayName' => 'Alice of Wonderland',
|
|
|
|
$ns . 'creationDateTime' => new \DateTime('2016-01-10 18:48:00'),
|
|
|
|
$ns . 'latestChildDateTime' => new \DateTime('2016-01-12 18:48:00'),
|
|
|
|
$ns . 'objectType' => 'files',
|
|
|
|
$ns . 'objectId' => '1848',
|
2020-04-02 10:59:44 +03:00
|
|
|
$ns . 'referenceId' => 'ref',
|
2016-01-30 01:23:16 +03:00
|
|
|
$ns . 'isUnread' => null,
|
2016-01-11 20:09:00 +03:00
|
|
|
];
|
|
|
|
|
2016-10-16 21:28:36 +03:00
|
|
|
$this->commentsManager->expects($this->exactly(2))
|
|
|
|
->method('resolveDisplayName')
|
|
|
|
->withConsecutive(
|
|
|
|
[$this->equalTo('user'), $this->equalTo('alice')],
|
|
|
|
[$this->equalTo('user'), $this->equalTo('bob')]
|
|
|
|
)
|
|
|
|
->willReturnOnConsecutiveCalls('Alice Al-Isson', 'Unknown user');
|
|
|
|
|
2016-01-11 20:09:00 +03:00
|
|
|
$this->comment->expects($this->once())
|
|
|
|
->method('getId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($expected[$ns . 'id']);
|
2016-01-11 20:09:00 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->once())
|
|
|
|
->method('getParentId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($expected[$ns . 'parentId']);
|
2016-01-11 20:09:00 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->once())
|
|
|
|
->method('getTopmostParentId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($expected[$ns . 'topmostParentId']);
|
2016-01-11 20:09:00 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->once())
|
|
|
|
->method('getChildrenCount')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($expected[$ns . 'childrenCount']);
|
2016-01-11 20:09:00 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->once())
|
|
|
|
->method('getMessage')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($expected[$ns . 'message']);
|
2016-01-11 20:09:00 +03:00
|
|
|
|
2016-10-14 01:19:31 +03:00
|
|
|
$this->comment->expects($this->once())
|
|
|
|
->method('getMentions')
|
|
|
|
->willReturn([
|
|
|
|
['type' => 'user', 'id' => 'alice'],
|
|
|
|
['type' => 'user', 'id' => 'bob'],
|
|
|
|
]);
|
|
|
|
|
2016-01-11 20:09:00 +03:00
|
|
|
$this->comment->expects($this->once())
|
|
|
|
->method('getVerb')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($expected[$ns . 'verb']);
|
2016-01-11 20:09:00 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->exactly(2))
|
|
|
|
->method('getActorType')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($expected[$ns . 'actorType']);
|
2016-01-11 20:09:00 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->exactly(2))
|
|
|
|
->method('getActorId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($expected[$ns . 'actorId']);
|
2016-01-11 20:09:00 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->once())
|
|
|
|
->method('getCreationDateTime')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($expected[$ns . 'creationDateTime']);
|
2016-01-11 20:09:00 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->once())
|
|
|
|
->method('getLatestChildDateTime')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($expected[$ns . 'latestChildDateTime']);
|
2016-01-11 20:09:00 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->once())
|
|
|
|
->method('getObjectType')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($expected[$ns . 'objectType']);
|
2016-01-11 20:09:00 +03:00
|
|
|
|
|
|
|
$this->comment->expects($this->once())
|
|
|
|
->method('getObjectId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($expected[$ns . 'objectId']);
|
2016-01-11 20:09:00 +03:00
|
|
|
|
2020-04-02 10:59:44 +03:00
|
|
|
$this->comment->expects($this->once())
|
|
|
|
->method('getReferenceId')
|
|
|
|
->willReturn($expected[$ns . 'referenceId']);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$user = $this->getMockBuilder(IUser::class)
|
2016-01-11 20:09:00 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$user->expects($this->once())
|
|
|
|
->method('getDisplayName')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($expected[$ns . 'actorDisplayName']);
|
2016-01-11 20:09:00 +03:00
|
|
|
|
|
|
|
$this->userManager->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('alice')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($user);
|
2016-01-11 20:09:00 +03:00
|
|
|
|
|
|
|
$properties = $this->node->getProperties(null);
|
|
|
|
|
2020-04-10 15:19:56 +03:00
|
|
|
foreach ($properties as $name => $value) {
|
2020-04-02 10:59:44 +03:00
|
|
|
$this->assertArrayHasKey($name, $expected);
|
2016-01-11 20:09:00 +03:00
|
|
|
$this->assertSame($expected[$name], $value);
|
|
|
|
unset($expected[$name]);
|
|
|
|
}
|
|
|
|
$this->assertTrue(empty($expected));
|
|
|
|
}
|
2016-01-30 01:23:16 +03:00
|
|
|
|
|
|
|
public function readCommentProvider() {
|
|
|
|
$creationDT = new \DateTime('2016-01-19 18:48:00');
|
|
|
|
$diff = new \DateInterval('PT2H');
|
2020-04-10 15:19:56 +03:00
|
|
|
$readDT1 = clone $creationDT;
|
|
|
|
$readDT1->sub($diff);
|
|
|
|
$readDT2 = clone $creationDT;
|
|
|
|
$readDT2->add($diff);
|
2016-01-30 01:23:16 +03:00
|
|
|
return [
|
|
|
|
[$creationDT, $readDT1, 'true'],
|
|
|
|
[$creationDT, $readDT2, 'false'],
|
|
|
|
[$creationDT, null, 'true'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider readCommentProvider
|
|
|
|
* @param $expected
|
|
|
|
*/
|
|
|
|
public function testGetPropertiesUnreadProperty($creationDT, $readDT, $expected) {
|
|
|
|
$this->comment->expects($this->any())
|
|
|
|
->method('getCreationDateTime')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($creationDT);
|
2016-01-30 01:23:16 +03:00
|
|
|
|
2016-10-14 01:19:31 +03:00
|
|
|
$this->comment->expects($this->any())
|
|
|
|
->method('getMentions')
|
|
|
|
->willReturn([]);
|
|
|
|
|
2016-01-30 01:23:16 +03:00
|
|
|
$this->commentsManager->expects($this->once())
|
|
|
|
->method('getReadMark')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($readDT);
|
2016-01-30 01:23:16 +03:00
|
|
|
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->getMockBuilder(IUser::class)
|
2016-07-15 10:52:46 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock()
|
2020-03-26 00:21:27 +03:00
|
|
|
);
|
2016-01-30 01:23:16 +03:00
|
|
|
|
|
|
|
$properties = $this->node->getProperties(null);
|
|
|
|
|
|
|
|
$this->assertTrue(array_key_exists(CommentNode::PROPERTY_NAME_UNREAD, $properties));
|
|
|
|
$this->assertSame($properties[CommentNode::PROPERTY_NAME_UNREAD], $expected);
|
|
|
|
}
|
2016-01-11 20:09:00 +03:00
|
|
|
}
|