2017-08-30 11:56:02 +03:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
|
*
|
|
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2020-04-29 12:57:22 +03:00
|
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2020-08-24 15:54:25 +03:00
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2019-12-03 21:57:53 +03:00
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2017-08-30 11:56:02 +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/>.
|
2017-08-30 11:56:02 +03:00
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace OCA\Comments\Tests\Unit\Collaboration;
|
|
|
|
|
|
|
|
|
|
use OCA\Comments\Collaboration\CommentersSorter;
|
|
|
|
|
use OCP\Comments\IComment;
|
|
|
|
|
use OCP\Comments\ICommentsManager;
|
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
|
|
class CommentersSorterTest extends TestCase {
|
2020-08-11 22:32:18 +03:00
|
|
|
|
/** @var ICommentsManager|\PHPUnit\Framework\MockObject\MockObject */
|
2017-08-30 11:56:02 +03:00
|
|
|
|
protected $commentsManager;
|
|
|
|
|
/** @var CommentersSorter */
|
|
|
|
|
protected $sorter;
|
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
protected function setUp(): void {
|
2017-08-30 11:56:02 +03:00
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$this->commentsManager = $this->createMock(ICommentsManager::class);
|
|
|
|
|
|
|
|
|
|
$this->sorter = new CommentersSorter($this->commentsManager);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider sortDataProvider
|
|
|
|
|
* @param $data
|
|
|
|
|
*/
|
|
|
|
|
public function testSort($data) {
|
2017-10-30 17:10:21 +03:00
|
|
|
|
$commentMocks = [];
|
2020-04-10 15:19:56 +03:00
|
|
|
|
foreach ($data['actors'] as $actorType => $actors) {
|
2017-10-30 17:10:21 +03:00
|
|
|
|
foreach ($actors as $actorId => $noOfComments) {
|
2020-10-05 16:12:57 +03:00
|
|
|
|
for ($i = 0;$i < $noOfComments;$i++) {
|
2017-10-30 17:10:21 +03:00
|
|
|
|
$mock = $this->createMock(IComment::class);
|
|
|
|
|
$mock->expects($this->atLeastOnce())
|
|
|
|
|
->method('getActorType')
|
|
|
|
|
->willReturn($actorType);
|
|
|
|
|
$mock->expects($this->atLeastOnce())
|
|
|
|
|
->method('getActorId')
|
|
|
|
|
->willReturn($actorId);
|
|
|
|
|
$commentMocks[] = $mock;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-30 11:56:02 +03:00
|
|
|
|
|
|
|
|
|
$this->commentsManager->expects($this->once())
|
2017-10-30 17:10:21 +03:00
|
|
|
|
->method('getForObject')
|
|
|
|
|
->willReturn($commentMocks);
|
2017-08-30 11:56:02 +03:00
|
|
|
|
|
|
|
|
|
$workArray = $data['input'];
|
|
|
|
|
$this->sorter->sort($workArray, ['itemType' => 'files', 'itemId' => '24']);
|
|
|
|
|
|
2017-10-11 18:25:21 +03:00
|
|
|
|
$this->assertEquals($data['expected'], $workArray);
|
2017-08-30 11:56:02 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function sortDataProvider() {
|
|
|
|
|
return [[
|
|
|
|
|
[
|
|
|
|
|
#1 – sort properly and otherwise keep existing order
|
|
|
|
|
'actors' => ['users' => ['celia' => 3, 'darius' => 7, 'faruk' => 5, 'gail' => 5], 'bots' => ['r2-d2' => 8]],
|
|
|
|
|
'input' => [
|
|
|
|
|
'users' =>
|
|
|
|
|
[
|
|
|
|
|
['value' => ['shareWith' => 'alice']],
|
|
|
|
|
['value' => ['shareWith' => 'bob']],
|
|
|
|
|
['value' => ['shareWith' => 'celia']],
|
|
|
|
|
['value' => ['shareWith' => 'darius']],
|
|
|
|
|
['value' => ['shareWith' => 'elena']],
|
|
|
|
|
['value' => ['shareWith' => 'faruk']],
|
|
|
|
|
['value' => ['shareWith' => 'gail']],
|
|
|
|
|
],
|
|
|
|
|
'bots' => [
|
|
|
|
|
['value' => ['shareWith' => 'c-3po']],
|
|
|
|
|
['value' => ['shareWith' => 'r2-d2']],
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'users' =>
|
|
|
|
|
[
|
|
|
|
|
['value' => ['shareWith' => 'darius']],
|
|
|
|
|
['value' => ['shareWith' => 'faruk']],
|
|
|
|
|
['value' => ['shareWith' => 'gail']],
|
|
|
|
|
['value' => ['shareWith' => 'celia']],
|
|
|
|
|
['value' => ['shareWith' => 'alice']],
|
|
|
|
|
['value' => ['shareWith' => 'bob']],
|
|
|
|
|
['value' => ['shareWith' => 'elena']],
|
|
|
|
|
],
|
|
|
|
|
'bots' => [
|
|
|
|
|
['value' => ['shareWith' => 'r2-d2']],
|
|
|
|
|
['value' => ['shareWith' => 'c-3po']],
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
#2 – no commentors, input equals output
|
|
|
|
|
'actors' => [],
|
|
|
|
|
'input' => [
|
|
|
|
|
'users' =>
|
|
|
|
|
[
|
|
|
|
|
['value' => ['shareWith' => 'alice']],
|
|
|
|
|
['value' => ['shareWith' => 'bob']],
|
|
|
|
|
['value' => ['shareWith' => 'celia']],
|
|
|
|
|
['value' => ['shareWith' => 'darius']],
|
|
|
|
|
['value' => ['shareWith' => 'elena']],
|
|
|
|
|
['value' => ['shareWith' => 'faruk']],
|
|
|
|
|
['value' => ['shareWith' => 'gail']],
|
|
|
|
|
],
|
|
|
|
|
'bots' => [
|
|
|
|
|
['value' => ['shareWith' => 'c-3po']],
|
|
|
|
|
['value' => ['shareWith' => 'r2-d2']],
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'users' =>
|
|
|
|
|
[
|
|
|
|
|
['value' => ['shareWith' => 'alice']],
|
|
|
|
|
['value' => ['shareWith' => 'bob']],
|
|
|
|
|
['value' => ['shareWith' => 'celia']],
|
|
|
|
|
['value' => ['shareWith' => 'darius']],
|
|
|
|
|
['value' => ['shareWith' => 'elena']],
|
|
|
|
|
['value' => ['shareWith' => 'faruk']],
|
|
|
|
|
['value' => ['shareWith' => 'gail']],
|
|
|
|
|
],
|
|
|
|
|
'bots' => [
|
|
|
|
|
['value' => ['shareWith' => 'c-3po']],
|
|
|
|
|
['value' => ['shareWith' => 'r2-d2']],
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
#3 – no nothing
|
|
|
|
|
'actors' => [],
|
|
|
|
|
'input' => [],
|
|
|
|
|
'expected' => [],
|
|
|
|
|
],
|
|
|
|
|
]];
|
|
|
|
|
}
|
|
|
|
|
}
|