aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2017-08-30 10:56:02 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2017-10-22 14:13:32 +0200
commitfd6daf8d195b985fcdec82c0c53e8ba230765f41 (patch)
treedbfbbfb8424604daeb0fba63a8e0d2b7cda9a3ac /tests
parent2b31b8289169e35be7bb1b129e9a978ddcd8f478 (diff)
downloadnextcloud-server-fd6daf8d195b985fcdec82c0c53e8ba230765f41.tar.gz
nextcloud-server-fd6daf8d195b985fcdec82c0c53e8ba230765f41.zip
AutoCompletion backend
* introduce a Controller for requests * introduce result sorting mechanism * extend Comments to retrieve commentors (actors) in a tree * add commenters sorter * add share recipients sorter Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/Core/Controller/AutoCompleteControllerTest.php84
-rw-r--r--tests/lib/Comments/FakeManager.php14
-rw-r--r--tests/lib/Comments/ManagerTest.php81
3 files changed, 156 insertions, 23 deletions
diff --git a/tests/Core/Controller/AutoCompleteControllerTest.php b/tests/Core/Controller/AutoCompleteControllerTest.php
new file mode 100644
index 00000000000..59dac58b952
--- /dev/null
+++ b/tests/Core/Controller/AutoCompleteControllerTest.php
@@ -0,0 +1,84 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @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/>.
+ *
+ */
+
+namespace Tests\Core\Controller;
+
+
+use OC\Core\Controller\AutoCompleteController;
+use OCP\Collaboration\AutoComplete\IManager;
+use OCP\Collaboration\Collaborators\ISearch;
+use OCP\IRequest;
+use Test\TestCase;
+
+class AutoCompleteControllerTest extends TestCase {
+ /** @var ISearch|\PHPUnit_Framework_MockObject_MockObject */
+ protected $collaboratorSearch;
+ /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
+ protected $autoCompleteManager;
+ /** @var AutoCompleteController */
+ protected $controller;
+
+ protected function setUp() {
+ parent::setUp();
+
+ /** @var IRequest $request */
+ $request = $this->createMock(IRequest::class);
+ $this->collaboratorSearch = $this->createMock(ISearch::class);
+ $this->autoCompleteManager = $this->createMock(IManager::class);
+
+ $this->controller = new AutoCompleteController(
+ 'core',
+ $request,
+ $this->collaboratorSearch,
+ $this->autoCompleteManager
+ );
+ }
+
+ public function testGet() {
+ $searchResults = [
+ 'exact' => [
+ 'users' => [],
+ 'robots' => [],
+ ],
+ 'users' => [
+ ['label' => 'Alice A.', 'value' => ['shareWith' => 'alice']],
+ ['label' => 'Bob Y.', 'value' => ['shareWith' => 'bob']],
+ ],
+ ];
+
+ $expected = [
+ [ 'id' => 'alice', 'label' => 'Alice A.', 'source' => 'users'],
+ [ 'id' => 'bob', 'label' => 'Bob Y.', 'source' => 'users'],
+ ];
+
+ $this->collaboratorSearch->expects($this->once())
+ ->method('search')
+ ->willReturn([$searchResults, false]);
+
+ $response = $this->controller->get('files', '42', null);
+
+ $list = $response->getData();
+ $this->assertEquals($expected, $list); // has better error output…
+ $this->assertSame($expected, $list);
+ }
+}
diff --git a/tests/lib/Comments/FakeManager.php b/tests/lib/Comments/FakeManager.php
index 840961fb901..d3dd1dfb58a 100644
--- a/tests/lib/Comments/FakeManager.php
+++ b/tests/lib/Comments/FakeManager.php
@@ -1,12 +1,14 @@
<?php
namespace Test\Comments;
+use OCP\Comments\IComment;
+use OCP\Comments\ICommentsManager;
use OCP\IUser;
/**
* Class FakeManager
*/
-class FakeManager implements \OCP\Comments\ICommentsManager {
+class FakeManager implements ICommentsManager {
public function get($id) {}
@@ -26,17 +28,17 @@ class FakeManager implements \OCP\Comments\ICommentsManager {
public function delete($id) {}
- public function save(\OCP\Comments\IComment $comment) {}
+ public function save(IComment $comment) {}
public function deleteReferencesOfActor($actorType, $actorId) {}
public function deleteCommentsAtObject($objectType, $objectId) {}
- public function setReadMark($objectType, $objectId, \DateTime $dateTime, \OCP\IUser $user) {}
+ public function setReadMark($objectType, $objectId, \DateTime $dateTime, IUser $user) {}
- public function getReadMark($objectType, $objectId, \OCP\IUser $user) {}
+ public function getReadMark($objectType, $objectId, IUser $user) {}
- public function deleteReadMarksFromUser(\OCP\IUser $user) {}
+ public function deleteReadMarksFromUser(IUser $user) {}
public function deleteReadMarksOnObject($objectType, $objectId) {}
@@ -47,4 +49,6 @@ class FakeManager implements \OCP\Comments\ICommentsManager {
public function resolveDisplayName($type, $id) {}
public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user) {}
+
+ public function getActorsInTree($id) {}
}
diff --git a/tests/lib/Comments/ManagerTest.php b/tests/lib/Comments/ManagerTest.php
index b04f3bd567e..df70581d6b4 100644
--- a/tests/lib/Comments/ManagerTest.php
+++ b/tests/lib/Comments/ManagerTest.php
@@ -3,12 +3,13 @@
namespace Test\Comments;
use OC\Comments\Comment;
-use OCP\Comments\CommentsEvent;
+use OC\Comments\ManagerFactory;
+use OCP\Comments\IComment;
use OCP\Comments\ICommentsEventHandler;
use OCP\Comments\ICommentsManager;
+use OCP\Comments\NotFoundException;
use OCP\IDBConnection;
use OCP\IUser;
-use Test\Files\Storage\DummyUser;
use Test\TestCase;
/**
@@ -62,7 +63,7 @@ class ManagerTest extends TestCase {
}
protected function getManager() {
- $factory = new \OC\Comments\ManagerFactory(\OC::$server);
+ $factory = new ManagerFactory(\OC::$server);
return $factory->getManager();
}
@@ -109,7 +110,7 @@ class ManagerTest extends TestCase {
$id = strval($qb->getLastInsertId());
$comment = $manager->get($id);
- $this->assertTrue($comment instanceof \OCP\Comments\IComment);
+ $this->assertTrue($comment instanceof IComment);
$this->assertSame($comment->getId(), $id);
$this->assertSame($comment->getParentId(), '2');
$this->assertSame($comment->getTopmostParentId(), '1');
@@ -152,14 +153,14 @@ class ManagerTest extends TestCase {
// Verifying the root comment
$this->assertTrue(isset($tree['comment']));
- $this->assertTrue($tree['comment'] instanceof \OCP\Comments\IComment);
+ $this->assertTrue($tree['comment'] instanceof IComment);
$this->assertSame($tree['comment']->getId(), strval($headId));
$this->assertTrue(isset($tree['replies']));
$this->assertSame(count($tree['replies']), 3);
// one level deep
foreach ($tree['replies'] as $reply) {
- $this->assertTrue($reply['comment'] instanceof \OCP\Comments\IComment);
+ $this->assertTrue($reply['comment'] instanceof IComment);
$this->assertSame($reply['comment']->getId(), strval($id));
$this->assertSame(count($reply['replies']), 0);
$id--;
@@ -174,7 +175,7 @@ class ManagerTest extends TestCase {
// Verifying the root comment
$this->assertTrue(isset($tree['comment']));
- $this->assertTrue($tree['comment'] instanceof \OCP\Comments\IComment);
+ $this->assertTrue($tree['comment'] instanceof IComment);
$this->assertSame($tree['comment']->getId(), strval($id));
$this->assertTrue(isset($tree['replies']));
$this->assertSame(count($tree['replies']), 0);
@@ -200,14 +201,14 @@ class ManagerTest extends TestCase {
// Verifying the root comment
$this->assertTrue(isset($tree['comment']));
- $this->assertTrue($tree['comment'] instanceof \OCP\Comments\IComment);
+ $this->assertTrue($tree['comment'] instanceof IComment);
$this->assertSame($tree['comment']->getId(), strval($headId));
$this->assertTrue(isset($tree['replies']));
$this->assertSame(count($tree['replies']), 2);
// one level deep
foreach ($tree['replies'] as $reply) {
- $this->assertTrue($reply['comment'] instanceof \OCP\Comments\IComment);
+ $this->assertTrue($reply['comment'] instanceof IComment);
$this->assertSame($reply['comment']->getId(), strval($idToVerify));
$this->assertSame(count($reply['replies']), 0);
$idToVerify--;
@@ -223,7 +224,7 @@ class ManagerTest extends TestCase {
$this->assertTrue(is_array($comments));
$this->assertSame(count($comments), 1);
- $this->assertTrue($comments[0] instanceof \OCP\Comments\IComment);
+ $this->assertTrue($comments[0] instanceof IComment);
$this->assertSame($comments[0]->getMessage(), 'nice one');
}
@@ -243,7 +244,7 @@ class ManagerTest extends TestCase {
$this->assertTrue(is_array($comments));
foreach ($comments as $comment) {
- $this->assertTrue($comment instanceof \OCP\Comments\IComment);
+ $this->assertTrue($comment instanceof IComment);
$this->assertSame($comment->getMessage(), 'nice one');
$this->assertSame($comment->getId(), strval($idToVerify));
$idToVerify--;
@@ -252,6 +253,37 @@ class ManagerTest extends TestCase {
} while (count($comments) > 0);
}
+ public function testGetActorsInTree() {
+ $manager = $this->getManager();
+
+ $headId = $this->addDatabaseEntry(0, 0);
+
+ $id = $this->addDatabaseEntry($headId, $headId, new \DateTime('-3 hours'));
+ $comment = $manager->get($id)->setActor('users', 'bob');
+ $manager->save($comment);
+
+ $this->addDatabaseEntry($headId, $headId, new \DateTime('-2 hours'));
+ $this->addDatabaseEntry($headId, $headId, new \DateTime('-2 hours'));
+
+ $id = $this->addDatabaseEntry($headId, $headId, new \DateTime('-1 hour'));
+ $comment = $manager->get($id)->setActor('users', 'bob');
+ $manager->save($comment);
+
+ $id = $this->addDatabaseEntry($headId, $headId, new \DateTime('-4 hour'));
+ $comment = $manager->get($id)->setActor('users', 'cynthia');
+ $manager->save($comment);
+
+ $actors = $manager->getActorsInTree($headId);
+ $this->assertTrue(isset($actors['users']));
+ $this->assertCount(3, $actors['users']);
+ $this->assertTrue(isset($actors['users']['alice']));
+ $this->assertTrue(isset($actors['users']['bob']));
+ $this->assertTrue(isset($actors['users']['cynthia']));
+ $this->assertSame(3, $actors['users']['alice']);
+ $this->assertSame(2, $actors['users']['bob']);
+ $this->assertSame(1, $actors['users']['cynthia']);
+ }
+
public function testGetForObjectWithDateTimeConstraint() {
$this->addDatabaseEntry(0, 0, new \DateTime('-6 hours'));
$this->addDatabaseEntry(0, 0, new \DateTime('-5 hours'));
@@ -282,7 +314,7 @@ class ManagerTest extends TestCase {
$this->assertTrue(is_array($comments));
foreach ($comments as $comment) {
- $this->assertTrue($comment instanceof \OCP\Comments\IComment);
+ $this->assertTrue($comment instanceof IComment);
$this->assertSame($comment->getMessage(), 'nice one');
$this->assertSame($comment->getId(), strval($idToVerify));
$this->assertTrue(intval($comment->getId()) >= 4);
@@ -334,6 +366,7 @@ class ManagerTest extends TestCase {
$this->addDatabaseEntry(0, 0, null, null, $fileIds[$i]);
}
$this->addDatabaseEntry(0, 0, (new \DateTime())->modify('-2 days'), null, $fileIds[0]);
+ /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
$user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
@@ -368,6 +401,10 @@ class ManagerTest extends TestCase {
/**
* @dataProvider invalidCreateArgsProvider
* @expectedException \InvalidArgumentException
+ * @param string $aType
+ * @param string $aId
+ * @param string $oType
+ * @param string $oId
*/
public function testCreateCommentInvalidArguments($aType, $aId, $oType, $oId) {
$manager = $this->getManager();
@@ -381,7 +418,7 @@ class ManagerTest extends TestCase {
$objectId = 'bielefeld';
$comment = $this->getManager()->create($actorType, $actorId, $objectType, $objectId);
- $this->assertTrue($comment instanceof \OCP\Comments\IComment);
+ $this->assertTrue($comment instanceof IComment);
$this->assertSame($comment->getActorType(), $actorType);
$this->assertSame($comment->getActorId(), $actorId);
$this->assertSame($comment->getObjectType(), $objectType);
@@ -405,7 +442,7 @@ class ManagerTest extends TestCase {
$id = strval($this->addDatabaseEntry(0, 0));
$comment = $manager->get($id);
- $this->assertTrue($comment instanceof \OCP\Comments\IComment);
+ $this->assertTrue($comment instanceof IComment);
$done = $manager->delete($id);
$this->assertTrue($done);
$manager->get($id);
@@ -515,6 +552,8 @@ class ManagerTest extends TestCase {
/**
* @dataProvider invalidActorArgsProvider
* @expectedException \InvalidArgumentException
+ * @param string $type
+ * @param string $id
*/
public function testDeleteReferencesOfActorInvalidInput($type, $id) {
$manager = $this->getManager();
@@ -551,7 +590,7 @@ class ManagerTest extends TestCase {
public function testDeleteReferencesOfActorWithUserManagement() {
$user = \OC::$server->getUserManager()->createUser('xenia', '123456');
- $this->assertTrue($user instanceof \OCP\IUser);
+ $this->assertTrue($user instanceof IUser);
$manager = \OC::$server->getCommentsManager();
$comment = $manager->create('users', $user->getUID(), 'files', 'file64');
@@ -565,8 +604,8 @@ class ManagerTest extends TestCase {
$user->delete();
$comment = $manager->get($commentID);
- $this->assertSame($comment->getActorType(), \OCP\Comments\ICommentsManager::DELETED_USER);
- $this->assertSame($comment->getActorId(), \OCP\Comments\ICommentsManager::DELETED_USER);
+ $this->assertSame($comment->getActorType(), ICommentsManager::DELETED_USER);
+ $this->assertSame($comment->getActorId(), ICommentsManager::DELETED_USER);
}
public function invalidObjectArgsProvider() {
@@ -581,6 +620,8 @@ class ManagerTest extends TestCase {
/**
* @dataProvider invalidObjectArgsProvider
* @expectedException \InvalidArgumentException
+ * @param string $type
+ * @param string $id
*/
public function testDeleteCommentsAtObjectInvalidInput($type, $id) {
$manager = $this->getManager();
@@ -607,7 +648,7 @@ class ManagerTest extends TestCase {
foreach ($ids as $id) {
try {
$manager->get(strval($id));
- } catch (\OCP\Comments\NotFoundException $e) {
+ } catch (NotFoundException $e) {
$verified++;
}
}
@@ -620,6 +661,7 @@ class ManagerTest extends TestCase {
}
public function testSetMarkRead() {
+ /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
$user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
@@ -636,6 +678,7 @@ class ManagerTest extends TestCase {
}
public function testSetMarkReadUpdate() {
+ /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
$user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
@@ -655,6 +698,7 @@ class ManagerTest extends TestCase {
}
public function testReadMarkDeleteUser() {
+ /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
$user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
@@ -672,6 +716,7 @@ class ManagerTest extends TestCase {
}
public function testReadMarkDeleteObject() {
+ /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
$user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')