summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/comments
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2016-01-11 18:09:00 +0100
committerArthur Schiwon <blizzz@owncloud.com>2016-01-26 12:10:14 +0100
commited546bd2a591d0d9029e9f3989e159f8b1e4e8c5 (patch)
treef0d0126c7f43cea0191b2dda78d5a832767cc822 /apps/dav/tests/unit/comments
parent3da78c8f1c9355a726f289e834fa237366c3df20 (diff)
downloadnextcloud-server-ed546bd2a591d0d9029e9f3989e159f8b1e4e8c5.tar.gz
nextcloud-server-ed546bd2a591d0d9029e9f3989e159f8b1e4e8c5.zip
Comments DAV implementation
Diffstat (limited to 'apps/dav/tests/unit/comments')
-rw-r--r--apps/dav/tests/unit/comments/commentnode.php215
-rw-r--r--apps/dav/tests/unit/comments/commentsplugin.php631
-rw-r--r--apps/dav/tests/unit/comments/entitycollection.php113
-rw-r--r--apps/dav/tests/unit/comments/entitytypecollection.php94
-rw-r--r--apps/dav/tests/unit/comments/rootcollection.php160
5 files changed, 1213 insertions, 0 deletions
diff --git a/apps/dav/tests/unit/comments/commentnode.php b/apps/dav/tests/unit/comments/commentnode.php
new file mode 100644
index 00000000000..b224bee9098
--- /dev/null
+++ b/apps/dav/tests/unit/comments/commentnode.php
@@ -0,0 +1,215 @@
+<?php
+/**
+ * @author Arthur Schiwon <blizzz@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\DAV\Tests\Unit\Comments;
+
+use OCA\DAV\Comments\CommentNode;
+
+class CommentsNode extends \Test\TestCase {
+
+ protected $commentsManager;
+ protected $comment;
+ protected $node;
+ protected $userManager;
+ protected $logger;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->commentsManager = $this->getMock('\OCP\Comments\ICommentsManager');
+ $this->comment = $this->getMock('\OCP\Comments\IComment');
+ $this->userManager = $this->getMock('\OCP\IUserManager');
+ $this->logger = $this->getMock('\OCP\ILogger');
+
+ $this->node = new CommentNode($this->commentsManager, $this->comment, $this->userManager, $this->logger);
+ }
+
+ public function testDelete() {
+ $this->comment->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue('19'));
+
+ $this->commentsManager->expects($this->once())
+ ->method('delete')
+ ->with('19');
+
+ $this->node->delete();
+ }
+
+ public function testGetName() {
+ $id = '19';
+ $this->comment->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue($id));
+
+ $this->assertSame($this->node->getName(), $id);
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\MethodNotAllowed
+ */
+ public function testSetName() {
+ $this->node->setName('666');
+ }
+
+ public function testGetLastModified() {
+ $dateTime = new \DateTime('2016-01-10 18:48:00');
+ $this->comment->expects($this->once())
+ ->method('getCreationDateTime')
+ ->will($this->returnValue($dateTime));
+
+ $this->assertSame($this->node->getLastModified(), $dateTime->getTimestamp());
+ }
+
+ public function testUpdateComment() {
+ $msg = 'Hello Earth';
+
+ $this->comment->expects($this->once())
+ ->method('setMessage')
+ ->with($msg);
+
+ $this->commentsManager->expects($this->once())
+ ->method('save')
+ ->with($this->comment);
+
+ $this->assertTrue($this->node->updateComment($msg));
+ }
+
+ public function testUpdateCommentException() {
+ $msg = null;
+
+ $this->comment->expects($this->once())
+ ->method('setMessage')
+ ->with($msg)
+ ->will($this->throwException(new \Exception('buh!')));
+
+ $this->commentsManager->expects($this->never())
+ ->method('save');
+
+ $this->logger->expects($this->once())
+ ->method('logException');
+
+ $this->assertFalse($this->node->updateComment($msg));
+ }
+
+ public function testPropPatch() {
+ $propPatch = $this->getMockBuilder('Sabre\DAV\PropPatch')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $propPatch->expects($this->once())
+ ->method('handle')
+ ->with('{http://owncloud.org/ns}message');
+
+ $propPatch->expects($this->once())
+ ->method('commit');
+
+ $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ā€¦',
+ $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',
+ ];
+
+ $this->comment->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue($expected[$ns . 'id']));
+
+ $this->comment->expects($this->once())
+ ->method('getParentId')
+ ->will($this->returnValue($expected[$ns . 'parentId']));
+
+ $this->comment->expects($this->once())
+ ->method('getTopmostParentId')
+ ->will($this->returnValue($expected[$ns . 'topmostParentId']));
+
+ $this->comment->expects($this->once())
+ ->method('getChildrenCount')
+ ->will($this->returnValue($expected[$ns . 'childrenCount']));
+
+ $this->comment->expects($this->once())
+ ->method('getMessage')
+ ->will($this->returnValue($expected[$ns . 'message']));
+
+ $this->comment->expects($this->once())
+ ->method('getVerb')
+ ->will($this->returnValue($expected[$ns . 'verb']));
+
+ $this->comment->expects($this->exactly(2))
+ ->method('getActorType')
+ ->will($this->returnValue($expected[$ns . 'actorType']));
+
+ $this->comment->expects($this->exactly(2))
+ ->method('getActorId')
+ ->will($this->returnValue($expected[$ns . 'actorId']));
+
+ $this->comment->expects($this->once())
+ ->method('getCreationDateTime')
+ ->will($this->returnValue($expected[$ns . 'creationDateTime']));
+
+ $this->comment->expects($this->once())
+ ->method('getLatestChildDateTime')
+ ->will($this->returnValue($expected[$ns . 'latestChildDateTime']));
+
+ $this->comment->expects($this->once())
+ ->method('getObjectType')
+ ->will($this->returnValue($expected[$ns . 'objectType']));
+
+ $this->comment->expects($this->once())
+ ->method('getObjectId')
+ ->will($this->returnValue($expected[$ns . 'objectId']));
+
+ $user = $this->getMockBuilder('\OCP\IUser')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $user->expects($this->once())
+ ->method('getDisplayName')
+ ->will($this->returnValue($expected[$ns . 'actorDisplayName']));
+
+ $this->userManager->expects($this->once())
+ ->method('get')
+ ->with('alice')
+ ->will($this->returnValue($user));
+
+ $properties = $this->node->getProperties(null);
+
+ foreach($properties as $name => $value) {
+ $this->assertTrue(isset($expected[$name]));
+ $this->assertSame($expected[$name], $value);
+ unset($expected[$name]);
+ }
+ $this->assertTrue(empty($expected));
+ }
+}
diff --git a/apps/dav/tests/unit/comments/commentsplugin.php b/apps/dav/tests/unit/comments/commentsplugin.php
new file mode 100644
index 00000000000..5fcccab90b7
--- /dev/null
+++ b/apps/dav/tests/unit/comments/commentsplugin.php
@@ -0,0 +1,631 @@
+<?php
+/**
+ * @author Arthur Schiwon <blizzz@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\DAV\Tests\Unit\Comments;
+
+use OC\Comments\Comment;
+use OCA\DAV\Comments\CommentsPlugin as CommentsPluginImplementation;
+
+class CommentsPlugin extends \Test\TestCase {
+ /** @var \Sabre\DAV\Server */
+ private $server;
+
+ /** @var \Sabre\DAV\Tree */
+ private $tree;
+
+ /** @var \OCP\Comments\ICommentsManager */
+ private $commentsManager;
+
+ /** @var \OCP\IUserSession */
+ private $userSession;
+
+ /** @var CommentsPluginImplementation */
+ private $plugin;
+
+ public function setUp() {
+ parent::setUp();
+ $this->tree = $this->getMockBuilder('\Sabre\DAV\Tree')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->server = $this->getMockBuilder('\Sabre\DAV\Server')
+ ->setConstructorArgs([$this->tree])
+ ->setMethods(['getRequestUri'])
+ ->getMock();
+
+ $this->commentsManager = $this->getMock('\OCP\Comments\ICommentsManager');
+ $this->userSession = $this->getMock('\OCP\IUserSession');
+
+ $this->plugin = new CommentsPluginImplementation($this->commentsManager, $this->userSession);
+ }
+
+ public function testCreateComment() {
+ $commentData = [
+ 'actorType' => 'users',
+ 'verb' => 'comment',
+ 'message' => 'my first comment',
+ ];
+
+ $comment = new Comment([
+ 'objectType' => 'files',
+ 'objectId' => '42',
+ 'actorType' => 'users',
+ 'actorId' => 'alice'
+ ] + $commentData);
+ $comment->setId('23');
+
+ $path = 'comments/files/42';
+
+ $requestData = json_encode($commentData);
+
+ $user = $this->getMock('OCP\IUser');
+ $user->expects($this->once())
+ ->method('getUID')
+ ->will($this->returnValue('alice'));
+
+ $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $node->expects($this->once())
+ ->method('getName')
+ ->will($this->returnValue('files'));
+ $node->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue('42'));
+
+ $this->commentsManager->expects($this->once())
+ ->method('create')
+ ->with('users', 'alice', 'files', '42')
+ ->will($this->returnValue($comment));
+
+ $this->userSession->expects($this->once())
+ ->method('getUser')
+ ->will($this->returnValue($user));
+
+ // technically, this is a shortcut. Inbetween EntityTypeCollection would
+ // be returned, but doing it exactly right would not be really
+ // unit-testing like, as it would require to haul in a lot of other
+ // things.
+ $this->tree->expects($this->any())
+ ->method('getNodeForPath')
+ ->with('/' . $path)
+ ->will($this->returnValue($node));
+
+ $request = $this->getMockBuilder('Sabre\HTTP\RequestInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $response = $this->getMockBuilder('Sabre\HTTP\ResponseInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $request->expects($this->once())
+ ->method('getPath')
+ ->will($this->returnValue('/' . $path));
+
+ $request->expects($this->once())
+ ->method('getBodyAsString')
+ ->will($this->returnValue($requestData));
+
+ $request->expects($this->once())
+ ->method('getHeader')
+ ->with('Content-Type')
+ ->will($this->returnValue('application/json'));
+
+ $request->expects($this->once())
+ ->method('getUrl')
+ ->will($this->returnValue('http://example.com/dav/' . $path));
+
+ $response->expects($this->once())
+ ->method('setHeader')
+ ->with('Content-Location', 'http://example.com/dav/' . $path . '/23');
+
+ $this->server->expects($this->any())
+ ->method('getRequestUri')
+ ->will($this->returnValue($path));
+ $this->plugin->initialize($this->server);
+
+ $this->plugin->httpPost($request, $response);
+ }
+
+ public function testCreateCommentInvalidObject() {
+ $commentData = [
+ 'actorType' => 'users',
+ 'verb' => 'comment',
+ 'message' => 'my first comment',
+ ];
+
+ $comment = new Comment([
+ 'objectType' => 'files',
+ 'objectId' => '666',
+ 'actorType' => 'users',
+ 'actorId' => 'alice'
+ ] + $commentData);
+ $comment->setId('23');
+
+ $path = 'comments/files/666';
+
+ $user = $this->getMock('OCP\IUser');
+ $user->expects($this->never())
+ ->method('getUID');
+
+ $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $node->expects($this->never())
+ ->method('getName');
+ $node->expects($this->never())
+ ->method('getId');
+
+ $this->commentsManager->expects($this->never())
+ ->method('create');
+
+ $this->userSession->expects($this->never())
+ ->method('getUser');
+
+ // technically, this is a shortcut. Inbetween EntityTypeCollection would
+ // be returned, but doing it exactly right would not be really
+ // unit-testing like, as it would require to haul in a lot of other
+ // things.
+ $this->tree->expects($this->any())
+ ->method('getNodeForPath')
+ ->with('/' . $path)
+ ->will($this->throwException(new \Sabre\DAV\Exception\NotFound()));
+
+ $request = $this->getMockBuilder('Sabre\HTTP\RequestInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $response = $this->getMockBuilder('Sabre\HTTP\ResponseInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $request->expects($this->once())
+ ->method('getPath')
+ ->will($this->returnValue('/' . $path));
+
+ $request->expects($this->never())
+ ->method('getBodyAsString');
+
+ $request->expects($this->never())
+ ->method('getHeader')
+ ->with('Content-Type');
+
+ $request->expects($this->never())
+ ->method('getUrl');
+
+ $response->expects($this->never())
+ ->method('setHeader');
+
+ $this->server->expects($this->any())
+ ->method('getRequestUri')
+ ->will($this->returnValue($path));
+ $this->plugin->initialize($this->server);
+
+ $this->plugin->httpPost($request, $response);
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\BadRequest
+ */
+ public function testCreateCommentInvalidActor() {
+ $commentData = [
+ 'actorType' => 'robots',
+ 'verb' => 'comment',
+ 'message' => 'my first comment',
+ ];
+
+ $comment = new Comment([
+ 'objectType' => 'files',
+ 'objectId' => '42',
+ 'actorType' => 'users',
+ 'actorId' => 'alice'
+ ] + $commentData);
+ $comment->setId('23');
+
+ $path = 'comments/files/42';
+
+ $requestData = json_encode($commentData);
+
+ $user = $this->getMock('OCP\IUser');
+ $user->expects($this->never())
+ ->method('getUID');
+
+ $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $node->expects($this->once())
+ ->method('getName')
+ ->will($this->returnValue('files'));
+ $node->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue('42'));
+
+ $this->commentsManager->expects($this->never())
+ ->method('create');
+
+ $this->userSession->expects($this->never())
+ ->method('getUser');
+
+ // technically, this is a shortcut. Inbetween EntityTypeCollection would
+ // be returned, but doing it exactly right would not be really
+ // unit-testing like, as it would require to haul in a lot of other
+ // things.
+ $this->tree->expects($this->any())
+ ->method('getNodeForPath')
+ ->with('/' . $path)
+ ->will($this->returnValue($node));
+
+ $request = $this->getMockBuilder('Sabre\HTTP\RequestInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $response = $this->getMockBuilder('Sabre\HTTP\ResponseInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $request->expects($this->once())
+ ->method('getPath')
+ ->will($this->returnValue('/' . $path));
+
+ $request->expects($this->once())
+ ->method('getBodyAsString')
+ ->will($this->returnValue($requestData));
+
+ $request->expects($this->once())
+ ->method('getHeader')
+ ->with('Content-Type')
+ ->will($this->returnValue('application/json'));
+
+ $request->expects($this->never())
+ ->method('getUrl');
+
+ $response->expects($this->never())
+ ->method('setHeader');
+
+ $this->server->expects($this->any())
+ ->method('getRequestUri')
+ ->will($this->returnValue($path));
+ $this->plugin->initialize($this->server);
+
+ $this->plugin->httpPost($request, $response);
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\UnsupportedMediaType
+ */
+ public function testCreateCommentUnsupportedMediaType() {
+ $commentData = [
+ 'actorType' => 'users',
+ 'verb' => 'comment',
+ 'message' => 'my first comment',
+ ];
+
+ $comment = new Comment([
+ 'objectType' => 'files',
+ 'objectId' => '42',
+ 'actorType' => 'users',
+ 'actorId' => 'alice'
+ ] + $commentData);
+ $comment->setId('23');
+
+ $path = 'comments/files/42';
+
+ $requestData = json_encode($commentData);
+
+ $user = $this->getMock('OCP\IUser');
+ $user->expects($this->never())
+ ->method('getUID');
+
+ $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $node->expects($this->once())
+ ->method('getName')
+ ->will($this->returnValue('files'));
+ $node->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue('42'));
+
+ $this->commentsManager->expects($this->never())
+ ->method('create');
+
+ $this->userSession->expects($this->never())
+ ->method('getUser');
+
+ // technically, this is a shortcut. Inbetween EntityTypeCollection would
+ // be returned, but doing it exactly right would not be really
+ // unit-testing like, as it would require to haul in a lot of other
+ // things.
+ $this->tree->expects($this->any())
+ ->method('getNodeForPath')
+ ->with('/' . $path)
+ ->will($this->returnValue($node));
+
+ $request = $this->getMockBuilder('Sabre\HTTP\RequestInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $response = $this->getMockBuilder('Sabre\HTTP\ResponseInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $request->expects($this->once())
+ ->method('getPath')
+ ->will($this->returnValue('/' . $path));
+
+ $request->expects($this->once())
+ ->method('getBodyAsString')
+ ->will($this->returnValue($requestData));
+
+ $request->expects($this->once())
+ ->method('getHeader')
+ ->with('Content-Type')
+ ->will($this->returnValue('application/trumpscript'));
+
+ $request->expects($this->never())
+ ->method('getUrl');
+
+ $response->expects($this->never())
+ ->method('setHeader');
+
+ $this->server->expects($this->any())
+ ->method('getRequestUri')
+ ->will($this->returnValue($path));
+ $this->plugin->initialize($this->server);
+
+ $this->plugin->httpPost($request, $response);
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\BadRequest
+ */
+ public function testCreateCommentInvalidPayload() {
+ $commentData = [
+ 'actorType' => 'users',
+ 'verb' => '',
+ 'message' => '',
+ ];
+
+ $comment = new Comment([
+ 'objectType' => 'files',
+ 'objectId' => '42',
+ 'actorType' => 'users',
+ 'actorId' => 'alice',
+ 'message' => 'dummy',
+ 'verb' => 'dummy'
+ ]);
+ $comment->setId('23');
+
+ $path = 'comments/files/42';
+
+ $requestData = json_encode($commentData);
+
+ $user = $this->getMock('OCP\IUser');
+ $user->expects($this->once())
+ ->method('getUID')
+ ->will($this->returnValue('alice'));
+
+ $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $node->expects($this->once())
+ ->method('getName')
+ ->will($this->returnValue('files'));
+ $node->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue('42'));
+
+ $this->commentsManager->expects($this->once())
+ ->method('create')
+ ->with('users', 'alice', 'files', '42')
+ ->will($this->returnValue($comment));
+
+ $this->commentsManager->expects($this->any())
+ ->method('setMessage')
+ ->with('')
+ ->will($this->throwException(new \InvalidArgumentException()));
+
+ $this->commentsManager->expects($this->any())
+ ->method('setVerb')
+ ->with('')
+ ->will($this->throwException(new \InvalidArgumentException()));
+
+ $this->userSession->expects($this->once())
+ ->method('getUser')
+ ->will($this->returnValue($user));
+
+ // technically, this is a shortcut. Inbetween EntityTypeCollection would
+ // be returned, but doing it exactly right would not be really
+ // unit-testing like, as it would require to haul in a lot of other
+ // things.
+ $this->tree->expects($this->any())
+ ->method('getNodeForPath')
+ ->with('/' . $path)
+ ->will($this->returnValue($node));
+
+ $request = $this->getMockBuilder('Sabre\HTTP\RequestInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $response = $this->getMockBuilder('Sabre\HTTP\ResponseInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $request->expects($this->once())
+ ->method('getPath')
+ ->will($this->returnValue('/' . $path));
+
+ $request->expects($this->once())
+ ->method('getBodyAsString')
+ ->will($this->returnValue($requestData));
+
+ $request->expects($this->once())
+ ->method('getHeader')
+ ->with('Content-Type')
+ ->will($this->returnValue('application/json'));
+
+ $request->expects($this->never())
+ ->method('getUrl');
+
+ $response->expects($this->never())
+ ->method('setHeader');
+
+ $this->server->expects($this->any())
+ ->method('getRequestUri')
+ ->will($this->returnValue($path));
+ $this->plugin->initialize($this->server);
+
+ $this->plugin->httpPost($request, $response);
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\ReportNotSupported
+ */
+ public function testOnReportInvalidNode() {
+ $path = 'totally/unrelated/13';
+
+ $this->tree->expects($this->any())
+ ->method('getNodeForPath')
+ ->with('/' . $path)
+ ->will($this->returnValue($this->getMock('\Sabre\DAV\INode')));
+
+ $this->server->expects($this->any())
+ ->method('getRequestUri')
+ ->will($this->returnValue($path));
+ $this->plugin->initialize($this->server);
+
+ $this->plugin->onReport('', [], '/' . $path);
+ }
+
+ public function testOnReportDateTimeEmpty() {
+ $path = 'comments/files/42';
+
+ $parameters = [
+ [
+ 'name' => '{http://owncloud.org/ns}limit',
+ 'value' => 5,
+ ],
+ [
+ 'name' => '{http://owncloud.org/ns}offset',
+ 'value' => 10,
+ ],
+ [
+ 'name' => '{http://owncloud.org/ns}datetime',
+ 'value' => '',
+ ]
+ ];
+
+ $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $node->expects($this->once())
+ ->method('findChildren')
+ ->with(5, 10, null)
+ ->will($this->returnValue([]));
+
+ $response = $this->getMockBuilder('Sabre\HTTP\ResponseInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $response->expects($this->once())
+ ->method('setHeader')
+ ->with('Content-Type', 'application/xml; charset=utf-8');
+
+ $response->expects($this->once())
+ ->method('setStatus')
+ ->with(207);
+
+ $response->expects($this->once())
+ ->method('setBody');
+
+ $this->tree->expects($this->any())
+ ->method('getNodeForPath')
+ ->with('/' . $path)
+ ->will($this->returnValue($node));
+
+ $this->server->expects($this->any())
+ ->method('getRequestUri')
+ ->will($this->returnValue($path));
+ $this->server->httpResponse = $response;
+ $this->plugin->initialize($this->server);
+
+ $this->plugin->onReport('', $parameters, '/' . $path);
+ }
+
+ public function testOnReport() {
+ $path = 'comments/files/42';
+
+ $parameters = [
+ [
+ 'name' => '{http://owncloud.org/ns}limit',
+ 'value' => 5,
+ ],
+ [
+ 'name' => '{http://owncloud.org/ns}offset',
+ 'value' => 10,
+ ],
+ [
+ 'name' => '{http://owncloud.org/ns}datetime',
+ 'value' => '2016-01-10 18:48:00',
+ ]
+ ];
+
+ $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $node->expects($this->once())
+ ->method('findChildren')
+ ->with(5, 10, new \DateTime($parameters[2]['value']))
+ ->will($this->returnValue([]));
+
+ $response = $this->getMockBuilder('Sabre\HTTP\ResponseInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $response->expects($this->once())
+ ->method('setHeader')
+ ->with('Content-Type', 'application/xml; charset=utf-8');
+
+ $response->expects($this->once())
+ ->method('setStatus')
+ ->with(207);
+
+ $response->expects($this->once())
+ ->method('setBody');
+
+ $this->tree->expects($this->any())
+ ->method('getNodeForPath')
+ ->with('/' . $path)
+ ->will($this->returnValue($node));
+
+ $this->server->expects($this->any())
+ ->method('getRequestUri')
+ ->will($this->returnValue($path));
+ $this->server->httpResponse = $response;
+ $this->plugin->initialize($this->server);
+
+ $this->plugin->onReport('', $parameters, '/' . $path);
+ }
+
+
+
+}
diff --git a/apps/dav/tests/unit/comments/entitycollection.php b/apps/dav/tests/unit/comments/entitycollection.php
new file mode 100644
index 00000000000..81442c7a873
--- /dev/null
+++ b/apps/dav/tests/unit/comments/entitycollection.php
@@ -0,0 +1,113 @@
+<?php
+/**
+ * @author Arthur Schiwon <blizzz@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\DAV\Tests\Unit\Comments;
+
+class EntityCollection extends \Test\TestCase {
+
+ protected $commentsManager;
+ protected $folder;
+ protected $userManager;
+ protected $logger;
+ protected $collection;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->commentsManager = $this->getMock('\OCP\Comments\ICommentsManager');
+ $this->folder = $this->getMock('\OCP\Files\Folder');
+ $this->userManager = $this->getMock('\OCP\IUserManager');
+ $this->logger = $this->getMock('\OCP\ILogger');
+
+ $this->collection = new \OCA\DAV\Comments\EntityCollection(
+ '19',
+ 'files',
+ $this->commentsManager,
+ $this->folder,
+ $this->userManager,
+ $this->logger
+ );
+ }
+
+ public function testGetId() {
+ $this->assertSame($this->collection->getId(), '19');
+ }
+
+ public function testGetChild() {
+ $this->commentsManager->expects($this->once())
+ ->method('get')
+ ->with('55')
+ ->will($this->returnValue($this->getMock('\OCP\Comments\IComment')));
+
+ $node = $this->collection->getChild('55');
+ $this->assertTrue($node instanceof \OCA\DAV\Comments\CommentNode);
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\NotFound
+ */
+ public function testGetChildException() {
+ $this->commentsManager->expects($this->once())
+ ->method('get')
+ ->with('55')
+ ->will($this->throwException(new \OCP\Comments\NotFoundException()));
+
+ $this->collection->getChild('55');
+ }
+
+ public function testGetChildren() {
+ $this->commentsManager->expects($this->once())
+ ->method('getForObject')
+ ->with('files', '19')
+ ->will($this->returnValue([$this->getMock('\OCP\Comments\IComment')]));
+
+ $result = $this->collection->getChildren();
+
+ $this->assertSame(count($result), 1);
+ $this->assertTrue($result[0] instanceof \OCA\DAV\Comments\CommentNode);
+ }
+
+ public function testFindChildren() {
+ $dt = new \DateTime('2016-01-10 18:48:00');
+ $this->commentsManager->expects($this->once())
+ ->method('getForObject')
+ ->with('files', '19', 5, 15, $dt)
+ ->will($this->returnValue([$this->getMock('\OCP\Comments\IComment')]));
+
+ $result = $this->collection->findChildren(5, 15, $dt);
+
+ $this->assertSame(count($result), 1);
+ $this->assertTrue($result[0] instanceof \OCA\DAV\Comments\CommentNode);
+ }
+
+ public function testChildExistsTrue() {
+ $this->assertTrue($this->collection->childExists('44'));
+ }
+
+ public function testChildExistsFalse() {
+ $this->commentsManager->expects($this->once())
+ ->method('get')
+ ->with('44')
+ ->will($this->throwException(new \OCP\Comments\NotFoundException()));
+
+ $this->assertFalse($this->collection->childExists('44'));
+ }
+}
diff --git a/apps/dav/tests/unit/comments/entitytypecollection.php b/apps/dav/tests/unit/comments/entitytypecollection.php
new file mode 100644
index 00000000000..72e90a57134
--- /dev/null
+++ b/apps/dav/tests/unit/comments/entitytypecollection.php
@@ -0,0 +1,94 @@
+<?php
+/**
+ * @author Arthur Schiwon <blizzz@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\DAV\Tests\Unit\Comments;
+
+use OCA\DAV\Comments\EntityCollection as EntityCollectionImplemantation;
+
+class EntityTypeCollection extends \Test\TestCase {
+
+ protected $commentsManager;
+ protected $folder;
+ protected $userManager;
+ protected $logger;
+ protected $collection;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->commentsManager = $this->getMock('\OCP\Comments\ICommentsManager');
+ $this->folder = $this->getMock('\OCP\Files\Folder');
+ $this->userManager = $this->getMock('\OCP\IUserManager');
+ $this->logger = $this->getMock('\OCP\ILogger');
+
+ $this->collection = new \OCA\DAV\Comments\EntityTypeCollection(
+ 'files',
+ $this->commentsManager,
+ $this->folder,
+ $this->userManager,
+ $this->logger
+ );
+ }
+
+ public function testChildExistsYes() {
+ $this->folder->expects($this->once())
+ ->method('getById')
+ ->with('17')
+ ->will($this->returnValue([$this->getMock('\OCP\Files\Node')]));
+ $this->assertTrue($this->collection->childExists('17'));
+ }
+
+ public function testChildExistsNo() {
+ $this->folder->expects($this->once())
+ ->method('getById')
+ ->will($this->returnValue([]));
+ $this->assertFalse($this->collection->childExists('17'));
+ }
+
+ public function testGetChild() {
+ $this->folder->expects($this->once())
+ ->method('getById')
+ ->with('17')
+ ->will($this->returnValue([$this->getMock('\OCP\Files\Node')]));
+
+ $ec = $this->collection->getChild('17');
+ $this->assertTrue($ec instanceof EntityCollectionImplemantation);
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\Forbidden
+ */
+ public function testGetChildException() {
+ $this->folder->expects($this->once())
+ ->method('getById')
+ ->with('17')
+ ->will($this->returnValue([]));
+
+ $this->collection->getChild('17');
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\MethodNotAllowed
+ */
+ public function testGetChildren() {
+ $this->collection->getChildren();
+ }
+}
diff --git a/apps/dav/tests/unit/comments/rootcollection.php b/apps/dav/tests/unit/comments/rootcollection.php
new file mode 100644
index 00000000000..369006e7159
--- /dev/null
+++ b/apps/dav/tests/unit/comments/rootcollection.php
@@ -0,0 +1,160 @@
+<?php
+/**
+ * @author Arthur Schiwon <blizzz@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\DAV\Tests\Unit\Comments;
+
+use OCA\DAV\Comments\EntityTypeCollection as EntityTypeCollectionImplementation;
+
+class RootCollection extends \Test\TestCase {
+
+ protected $commentsManager;
+ protected $userManager;
+ protected $logger;
+ protected $collection;
+ protected $userSession;
+ protected $rootFolder;
+ protected $user;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->user = $this->getMock('\OCP\IUser');
+
+ $this->commentsManager = $this->getMock('\OCP\Comments\ICommentsManager');
+ $this->userManager = $this->getMock('\OCP\IUserManager');
+ $this->userSession = $this->getMock('\OCP\IUserSession');
+ $this->rootFolder = $this->getMock('\OCP\Files\IRootFolder');
+ $this->logger = $this->getMock('\OCP\ILogger');
+
+ $this->collection = new \OCA\DAV\Comments\RootCollection(
+ $this->commentsManager,
+ $this->userManager,
+ $this->userSession,
+ $this->rootFolder,
+ $this->logger
+ );
+ }
+
+ protected function prepareForInitCollections() {
+ $this->user->expects($this->any())
+ ->method('getUID')
+ ->will($this->returnValue('alice'));
+
+ $this->userSession->expects($this->once())
+ ->method('getUser')
+ ->will($this->returnValue($this->user));
+
+ $this->rootFolder->expects($this->once())
+ ->method('getUserFolder')
+ ->with('alice')
+ ->will($this->returnValue($this->getMock('\OCP\Files\Folder')));
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\Forbidden
+ */
+ public function testCreateFile() {
+ $this->collection->createFile('foo');
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\Forbidden
+ */
+ public function testCreateDirectory() {
+ $this->collection->createDirectory('foo');
+ }
+
+ public function testGetChild() {
+ $this->prepareForInitCollections();
+ $etc = $this->collection->getChild('files');
+ $this->assertTrue($etc instanceof EntityTypeCollectionImplementation);
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\NotFound
+ */
+ public function testGetChildInvalid() {
+ $this->prepareForInitCollections();
+ $this->collection->getChild('robots');
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\NotAuthenticated
+ */
+ public function testGetChildNoAuth() {
+ $this->collection->getChild('files');
+ }
+
+ public function testGetChildren() {
+ $this->prepareForInitCollections();
+ $children = $this->collection->getChildren();
+ $this->assertFalse(empty($children));
+ foreach($children as $child) {
+ $this->assertTrue($child instanceof EntityTypeCollectionImplementation);
+ }
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\NotAuthenticated
+ */
+ public function testGetChildrenNoAuth() {
+ $this->collection->getChildren();
+ }
+
+ public function testChildExistsYes() {
+ $this->prepareForInitCollections();
+ $this->assertTrue($this->collection->childExists('files'));
+ }
+
+ public function testChildExistsNo() {
+ $this->prepareForInitCollections();
+ $this->assertFalse($this->collection->childExists('robots'));
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\NotAuthenticated
+ */
+ public function testChildExistsNoAuth() {
+ $this->collection->childExists('files');
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\Forbidden
+ */
+ public function testDelete() {
+ $this->collection->delete();
+ }
+
+ public function testGetName() {
+ $this->assertSame('comments', $this->collection->getName());
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\Forbidden
+ */
+ public function testSetName() {
+ $this->collection->setName('foobar');
+ }
+
+ public function testGetLastModified() {
+ $this->assertSame(null, $this->collection->getLastModified());
+ }
+}