CommentsPluginTest.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Vincent Petry <pvince81@owncloud.com>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\DAV\Tests\unit\Comments;
  26. use OC\Comments\Comment;
  27. use OCA\DAV\Comments\CommentsPlugin as CommentsPluginImplementation;
  28. use OCP\Comments\IComment;
  29. use Sabre\DAV\Exception\NotFound;
  30. class CommentsPluginTest extends \Test\TestCase {
  31. /** @var \Sabre\DAV\Server */
  32. private $server;
  33. /** @var \Sabre\DAV\Tree */
  34. private $tree;
  35. /** @var \OCP\Comments\ICommentsManager */
  36. private $commentsManager;
  37. /** @var \OCP\IUserSession */
  38. private $userSession;
  39. /** @var CommentsPluginImplementation */
  40. private $plugin;
  41. public function setUp() {
  42. parent::setUp();
  43. $this->tree = $this->getMockBuilder('\Sabre\DAV\Tree')
  44. ->disableOriginalConstructor()
  45. ->getMock();
  46. $this->server = $this->getMockBuilder('\Sabre\DAV\Server')
  47. ->setConstructorArgs([$this->tree])
  48. ->setMethods(['getRequestUri'])
  49. ->getMock();
  50. $this->commentsManager = $this->getMockBuilder('\OCP\Comments\ICommentsManager')
  51. ->disableOriginalConstructor()
  52. ->getMock();
  53. $this->userSession = $this->getMockBuilder('\OCP\IUserSession')
  54. ->disableOriginalConstructor()
  55. ->getMock();
  56. $this->plugin = new CommentsPluginImplementation($this->commentsManager, $this->userSession);
  57. }
  58. public function testCreateComment() {
  59. $commentData = [
  60. 'actorType' => 'users',
  61. 'verb' => 'comment',
  62. 'message' => 'my first comment',
  63. ];
  64. $comment = new Comment([
  65. 'objectType' => 'files',
  66. 'objectId' => '42',
  67. 'actorType' => 'users',
  68. 'actorId' => 'alice'
  69. ] + $commentData);
  70. $comment->setId('23');
  71. $path = 'comments/files/42';
  72. $requestData = json_encode($commentData);
  73. $user = $this->getMockBuilder('OCP\IUser')
  74. ->disableOriginalConstructor()
  75. ->getMock();
  76. $user->expects($this->once())
  77. ->method('getUID')
  78. ->will($this->returnValue('alice'));
  79. $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection')
  80. ->disableOriginalConstructor()
  81. ->getMock();
  82. $node->expects($this->once())
  83. ->method('getName')
  84. ->will($this->returnValue('files'));
  85. $node->expects($this->once())
  86. ->method('getId')
  87. ->will($this->returnValue('42'));
  88. $node->expects($this->once())
  89. ->method('setReadMarker')
  90. ->with(null);
  91. $this->commentsManager->expects($this->once())
  92. ->method('create')
  93. ->with('users', 'alice', 'files', '42')
  94. ->will($this->returnValue($comment));
  95. $this->userSession->expects($this->once())
  96. ->method('getUser')
  97. ->will($this->returnValue($user));
  98. // technically, this is a shortcut. Inbetween EntityTypeCollection would
  99. // be returned, but doing it exactly right would not be really
  100. // unit-testing like, as it would require to haul in a lot of other
  101. // things.
  102. $this->tree->expects($this->any())
  103. ->method('getNodeForPath')
  104. ->with('/' . $path)
  105. ->will($this->returnValue($node));
  106. $request = $this->getMockBuilder('Sabre\HTTP\RequestInterface')
  107. ->disableOriginalConstructor()
  108. ->getMock();
  109. $response = $this->getMockBuilder('Sabre\HTTP\ResponseInterface')
  110. ->disableOriginalConstructor()
  111. ->getMock();
  112. $request->expects($this->once())
  113. ->method('getPath')
  114. ->will($this->returnValue('/' . $path));
  115. $request->expects($this->once())
  116. ->method('getBodyAsString')
  117. ->will($this->returnValue($requestData));
  118. $request->expects($this->once())
  119. ->method('getHeader')
  120. ->with('Content-Type')
  121. ->will($this->returnValue('application/json'));
  122. $request->expects($this->once())
  123. ->method('getUrl')
  124. ->will($this->returnValue('http://example.com/dav/' . $path));
  125. $response->expects($this->once())
  126. ->method('setHeader')
  127. ->with('Content-Location', 'http://example.com/dav/' . $path . '/23');
  128. $this->server->expects($this->any())
  129. ->method('getRequestUri')
  130. ->will($this->returnValue($path));
  131. $this->plugin->initialize($this->server);
  132. $this->plugin->httpPost($request, $response);
  133. }
  134. /**
  135. * @expectedException \Sabre\DAV\Exception\NotFound
  136. */
  137. public function testCreateCommentInvalidObject() {
  138. $commentData = [
  139. 'actorType' => 'users',
  140. 'verb' => 'comment',
  141. 'message' => 'my first comment',
  142. ];
  143. $comment = new Comment([
  144. 'objectType' => 'files',
  145. 'objectId' => '666',
  146. 'actorType' => 'users',
  147. 'actorId' => 'alice'
  148. ] + $commentData);
  149. $comment->setId('23');
  150. $path = 'comments/files/666';
  151. $user = $this->getMockBuilder('OCP\IUser')
  152. ->disableOriginalConstructor()
  153. ->getMock();
  154. $user->expects($this->never())
  155. ->method('getUID');
  156. $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection')
  157. ->disableOriginalConstructor()
  158. ->getMock();
  159. $node->expects($this->never())
  160. ->method('getName');
  161. $node->expects($this->never())
  162. ->method('getId');
  163. $this->commentsManager->expects($this->never())
  164. ->method('create');
  165. $this->userSession->expects($this->never())
  166. ->method('getUser');
  167. // technically, this is a shortcut. Inbetween EntityTypeCollection would
  168. // be returned, but doing it exactly right would not be really
  169. // unit-testing like, as it would require to haul in a lot of other
  170. // things.
  171. $this->tree->expects($this->any())
  172. ->method('getNodeForPath')
  173. ->with('/' . $path)
  174. ->will($this->throwException(new \Sabre\DAV\Exception\NotFound()));
  175. $request = $this->getMockBuilder('Sabre\HTTP\RequestInterface')
  176. ->disableOriginalConstructor()
  177. ->getMock();
  178. $response = $this->getMockBuilder('Sabre\HTTP\ResponseInterface')
  179. ->disableOriginalConstructor()
  180. ->getMock();
  181. $request->expects($this->once())
  182. ->method('getPath')
  183. ->will($this->returnValue('/' . $path));
  184. $request->expects($this->never())
  185. ->method('getBodyAsString');
  186. $request->expects($this->never())
  187. ->method('getHeader')
  188. ->with('Content-Type');
  189. $request->expects($this->never())
  190. ->method('getUrl');
  191. $response->expects($this->never())
  192. ->method('setHeader');
  193. $this->server->expects($this->any())
  194. ->method('getRequestUri')
  195. ->will($this->returnValue($path));
  196. $this->plugin->initialize($this->server);
  197. $this->plugin->httpPost($request, $response);
  198. }
  199. /**
  200. * @expectedException \Sabre\DAV\Exception\BadRequest
  201. */
  202. public function testCreateCommentInvalidActor() {
  203. $commentData = [
  204. 'actorType' => 'robots',
  205. 'verb' => 'comment',
  206. 'message' => 'my first comment',
  207. ];
  208. $comment = new Comment([
  209. 'objectType' => 'files',
  210. 'objectId' => '42',
  211. 'actorType' => 'users',
  212. 'actorId' => 'alice'
  213. ] + $commentData);
  214. $comment->setId('23');
  215. $path = 'comments/files/42';
  216. $requestData = json_encode($commentData);
  217. $user = $this->getMockBuilder('OCP\IUser')
  218. ->disableOriginalConstructor()
  219. ->getMock();
  220. $user->expects($this->never())
  221. ->method('getUID');
  222. $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection')
  223. ->disableOriginalConstructor()
  224. ->getMock();
  225. $node->expects($this->once())
  226. ->method('getName')
  227. ->will($this->returnValue('files'));
  228. $node->expects($this->once())
  229. ->method('getId')
  230. ->will($this->returnValue('42'));
  231. $this->commentsManager->expects($this->never())
  232. ->method('create');
  233. $this->userSession->expects($this->never())
  234. ->method('getUser');
  235. // technically, this is a shortcut. Inbetween EntityTypeCollection would
  236. // be returned, but doing it exactly right would not be really
  237. // unit-testing like, as it would require to haul in a lot of other
  238. // things.
  239. $this->tree->expects($this->any())
  240. ->method('getNodeForPath')
  241. ->with('/' . $path)
  242. ->will($this->returnValue($node));
  243. $request = $this->getMockBuilder('Sabre\HTTP\RequestInterface')
  244. ->disableOriginalConstructor()
  245. ->getMock();
  246. $response = $this->getMockBuilder('Sabre\HTTP\ResponseInterface')
  247. ->disableOriginalConstructor()
  248. ->getMock();
  249. $request->expects($this->once())
  250. ->method('getPath')
  251. ->will($this->returnValue('/' . $path));
  252. $request->expects($this->once())
  253. ->method('getBodyAsString')
  254. ->will($this->returnValue($requestData));
  255. $request->expects($this->once())
  256. ->method('getHeader')
  257. ->with('Content-Type')
  258. ->will($this->returnValue('application/json'));
  259. $request->expects($this->never())
  260. ->method('getUrl');
  261. $response->expects($this->never())
  262. ->method('setHeader');
  263. $this->server->expects($this->any())
  264. ->method('getRequestUri')
  265. ->will($this->returnValue($path));
  266. $this->plugin->initialize($this->server);
  267. $this->plugin->httpPost($request, $response);
  268. }
  269. /**
  270. * @expectedException \Sabre\DAV\Exception\UnsupportedMediaType
  271. */
  272. public function testCreateCommentUnsupportedMediaType() {
  273. $commentData = [
  274. 'actorType' => 'users',
  275. 'verb' => 'comment',
  276. 'message' => 'my first comment',
  277. ];
  278. $comment = new Comment([
  279. 'objectType' => 'files',
  280. 'objectId' => '42',
  281. 'actorType' => 'users',
  282. 'actorId' => 'alice'
  283. ] + $commentData);
  284. $comment->setId('23');
  285. $path = 'comments/files/42';
  286. $requestData = json_encode($commentData);
  287. $user = $this->getMockBuilder('OCP\IUser')
  288. ->disableOriginalConstructor()
  289. ->getMock();
  290. $user->expects($this->never())
  291. ->method('getUID');
  292. $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection')
  293. ->disableOriginalConstructor()
  294. ->getMock();
  295. $node->expects($this->once())
  296. ->method('getName')
  297. ->will($this->returnValue('files'));
  298. $node->expects($this->once())
  299. ->method('getId')
  300. ->will($this->returnValue('42'));
  301. $this->commentsManager->expects($this->never())
  302. ->method('create');
  303. $this->userSession->expects($this->never())
  304. ->method('getUser');
  305. // technically, this is a shortcut. Inbetween EntityTypeCollection would
  306. // be returned, but doing it exactly right would not be really
  307. // unit-testing like, as it would require to haul in a lot of other
  308. // things.
  309. $this->tree->expects($this->any())
  310. ->method('getNodeForPath')
  311. ->with('/' . $path)
  312. ->will($this->returnValue($node));
  313. $request = $this->getMockBuilder('Sabre\HTTP\RequestInterface')
  314. ->disableOriginalConstructor()
  315. ->getMock();
  316. $response = $this->getMockBuilder('Sabre\HTTP\ResponseInterface')
  317. ->disableOriginalConstructor()
  318. ->getMock();
  319. $request->expects($this->once())
  320. ->method('getPath')
  321. ->will($this->returnValue('/' . $path));
  322. $request->expects($this->once())
  323. ->method('getBodyAsString')
  324. ->will($this->returnValue($requestData));
  325. $request->expects($this->once())
  326. ->method('getHeader')
  327. ->with('Content-Type')
  328. ->will($this->returnValue('application/trumpscript'));
  329. $request->expects($this->never())
  330. ->method('getUrl');
  331. $response->expects($this->never())
  332. ->method('setHeader');
  333. $this->server->expects($this->any())
  334. ->method('getRequestUri')
  335. ->will($this->returnValue($path));
  336. $this->plugin->initialize($this->server);
  337. $this->plugin->httpPost($request, $response);
  338. }
  339. /**
  340. * @expectedException \Sabre\DAV\Exception\BadRequest
  341. */
  342. public function testCreateCommentInvalidPayload() {
  343. $commentData = [
  344. 'actorType' => 'users',
  345. 'verb' => '',
  346. 'message' => '',
  347. ];
  348. $comment = new Comment([
  349. 'objectType' => 'files',
  350. 'objectId' => '42',
  351. 'actorType' => 'users',
  352. 'actorId' => 'alice',
  353. 'message' => 'dummy',
  354. 'verb' => 'dummy'
  355. ]);
  356. $comment->setId('23');
  357. $path = 'comments/files/42';
  358. $requestData = json_encode($commentData);
  359. $user = $this->getMockBuilder('OCP\IUser')
  360. ->disableOriginalConstructor()
  361. ->getMock();
  362. $user->expects($this->once())
  363. ->method('getUID')
  364. ->will($this->returnValue('alice'));
  365. $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection')
  366. ->disableOriginalConstructor()
  367. ->getMock();
  368. $node->expects($this->once())
  369. ->method('getName')
  370. ->will($this->returnValue('files'));
  371. $node->expects($this->once())
  372. ->method('getId')
  373. ->will($this->returnValue('42'));
  374. $this->commentsManager->expects($this->once())
  375. ->method('create')
  376. ->with('users', 'alice', 'files', '42')
  377. ->will($this->returnValue($comment));
  378. $this->userSession->expects($this->once())
  379. ->method('getUser')
  380. ->will($this->returnValue($user));
  381. // technically, this is a shortcut. Inbetween EntityTypeCollection would
  382. // be returned, but doing it exactly right would not be really
  383. // unit-testing like, as it would require to haul in a lot of other
  384. // things.
  385. $this->tree->expects($this->any())
  386. ->method('getNodeForPath')
  387. ->with('/' . $path)
  388. ->will($this->returnValue($node));
  389. $request = $this->getMockBuilder('Sabre\HTTP\RequestInterface')
  390. ->disableOriginalConstructor()
  391. ->getMock();
  392. $response = $this->getMockBuilder('Sabre\HTTP\ResponseInterface')
  393. ->disableOriginalConstructor()
  394. ->getMock();
  395. $request->expects($this->once())
  396. ->method('getPath')
  397. ->will($this->returnValue('/' . $path));
  398. $request->expects($this->once())
  399. ->method('getBodyAsString')
  400. ->will($this->returnValue($requestData));
  401. $request->expects($this->once())
  402. ->method('getHeader')
  403. ->with('Content-Type')
  404. ->will($this->returnValue('application/json'));
  405. $request->expects($this->never())
  406. ->method('getUrl');
  407. $response->expects($this->never())
  408. ->method('setHeader');
  409. $this->server->expects($this->any())
  410. ->method('getRequestUri')
  411. ->will($this->returnValue($path));
  412. $this->plugin->initialize($this->server);
  413. $this->plugin->httpPost($request, $response);
  414. }
  415. /**
  416. * @expectedException \Sabre\DAV\Exception\BadRequest
  417. * @expectedExceptionMessage Message exceeds allowed character limit of
  418. */
  419. public function testCreateCommentMessageTooLong() {
  420. $commentData = [
  421. 'actorType' => 'users',
  422. 'verb' => 'comment',
  423. 'message' => str_pad('', IComment::MAX_MESSAGE_LENGTH + 1, 'x'),
  424. ];
  425. $comment = new Comment([
  426. 'objectType' => 'files',
  427. 'objectId' => '42',
  428. 'actorType' => 'users',
  429. 'actorId' => 'alice',
  430. 'verb' => 'comment',
  431. ]);
  432. $comment->setId('23');
  433. $path = 'comments/files/42';
  434. $requestData = json_encode($commentData);
  435. $user = $this->getMockBuilder('OCP\IUser')
  436. ->disableOriginalConstructor()
  437. ->getMock();
  438. $user->expects($this->once())
  439. ->method('getUID')
  440. ->will($this->returnValue('alice'));
  441. $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection')
  442. ->disableOriginalConstructor()
  443. ->getMock();
  444. $node->expects($this->once())
  445. ->method('getName')
  446. ->will($this->returnValue('files'));
  447. $node->expects($this->once())
  448. ->method('getId')
  449. ->will($this->returnValue('42'));
  450. $node->expects($this->never())
  451. ->method('setReadMarker');
  452. $this->commentsManager->expects($this->once())
  453. ->method('create')
  454. ->with('users', 'alice', 'files', '42')
  455. ->will($this->returnValue($comment));
  456. $this->userSession->expects($this->once())
  457. ->method('getUser')
  458. ->will($this->returnValue($user));
  459. // technically, this is a shortcut. Inbetween EntityTypeCollection would
  460. // be returned, but doing it exactly right would not be really
  461. // unit-testing like, as it would require to haul in a lot of other
  462. // things.
  463. $this->tree->expects($this->any())
  464. ->method('getNodeForPath')
  465. ->with('/' . $path)
  466. ->will($this->returnValue($node));
  467. $request = $this->getMockBuilder('Sabre\HTTP\RequestInterface')
  468. ->disableOriginalConstructor()
  469. ->getMock();
  470. $response = $this->getMockBuilder('Sabre\HTTP\ResponseInterface')
  471. ->disableOriginalConstructor()
  472. ->getMock();
  473. $request->expects($this->once())
  474. ->method('getPath')
  475. ->will($this->returnValue('/' . $path));
  476. $request->expects($this->once())
  477. ->method('getBodyAsString')
  478. ->will($this->returnValue($requestData));
  479. $request->expects($this->once())
  480. ->method('getHeader')
  481. ->with('Content-Type')
  482. ->will($this->returnValue('application/json'));
  483. $response->expects($this->never())
  484. ->method('setHeader');
  485. $this->server->expects($this->any())
  486. ->method('getRequestUri')
  487. ->will($this->returnValue($path));
  488. $this->plugin->initialize($this->server);
  489. $this->plugin->httpPost($request, $response);
  490. }
  491. /**
  492. * @expectedException \Sabre\DAV\Exception\ReportNotSupported
  493. */
  494. public function testOnReportInvalidNode() {
  495. $path = 'totally/unrelated/13';
  496. $this->tree->expects($this->any())
  497. ->method('getNodeForPath')
  498. ->with('/' . $path)
  499. ->will($this->returnValue(
  500. $this->getMockBuilder('\Sabre\DAV\INode')
  501. ->disableOriginalConstructor()
  502. ->getMock()
  503. ));
  504. $this->server->expects($this->any())
  505. ->method('getRequestUri')
  506. ->will($this->returnValue($path));
  507. $this->plugin->initialize($this->server);
  508. $this->plugin->onReport(CommentsPluginImplementation::REPORT_NAME, [], '/' . $path);
  509. }
  510. /**
  511. * @expectedException \Sabre\DAV\Exception\ReportNotSupported
  512. */
  513. public function testOnReportInvalidReportName() {
  514. $path = 'comments/files/42';
  515. $this->tree->expects($this->any())
  516. ->method('getNodeForPath')
  517. ->with('/' . $path)
  518. ->will($this->returnValue(
  519. $this->getMockBuilder('\Sabre\DAV\INode')
  520. ->disableOriginalConstructor()
  521. ->getMock()
  522. ));
  523. $this->server->expects($this->any())
  524. ->method('getRequestUri')
  525. ->will($this->returnValue($path));
  526. $this->plugin->initialize($this->server);
  527. $this->plugin->onReport('{whoever}whatever', [], '/' . $path);
  528. }
  529. public function testOnReportDateTimeEmpty() {
  530. $path = 'comments/files/42';
  531. $parameters = [
  532. [
  533. 'name' => '{http://owncloud.org/ns}limit',
  534. 'value' => 5,
  535. ],
  536. [
  537. 'name' => '{http://owncloud.org/ns}offset',
  538. 'value' => 10,
  539. ],
  540. [
  541. 'name' => '{http://owncloud.org/ns}datetime',
  542. 'value' => '',
  543. ]
  544. ];
  545. $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection')
  546. ->disableOriginalConstructor()
  547. ->getMock();
  548. $node->expects($this->once())
  549. ->method('findChildren')
  550. ->with(5, 10, null)
  551. ->will($this->returnValue([]));
  552. $response = $this->getMockBuilder('Sabre\HTTP\ResponseInterface')
  553. ->disableOriginalConstructor()
  554. ->getMock();
  555. $response->expects($this->once())
  556. ->method('setHeader')
  557. ->with('Content-Type', 'application/xml; charset=utf-8');
  558. $response->expects($this->once())
  559. ->method('setStatus')
  560. ->with(207);
  561. $response->expects($this->once())
  562. ->method('setBody');
  563. $this->tree->expects($this->any())
  564. ->method('getNodeForPath')
  565. ->with('/' . $path)
  566. ->will($this->returnValue($node));
  567. $this->server->expects($this->any())
  568. ->method('getRequestUri')
  569. ->will($this->returnValue($path));
  570. $this->server->httpResponse = $response;
  571. $this->plugin->initialize($this->server);
  572. $this->plugin->onReport(CommentsPluginImplementation::REPORT_NAME, $parameters, '/' . $path);
  573. }
  574. public function testOnReport() {
  575. $path = 'comments/files/42';
  576. $parameters = [
  577. [
  578. 'name' => '{http://owncloud.org/ns}limit',
  579. 'value' => 5,
  580. ],
  581. [
  582. 'name' => '{http://owncloud.org/ns}offset',
  583. 'value' => 10,
  584. ],
  585. [
  586. 'name' => '{http://owncloud.org/ns}datetime',
  587. 'value' => '2016-01-10 18:48:00',
  588. ]
  589. ];
  590. $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection')
  591. ->disableOriginalConstructor()
  592. ->getMock();
  593. $node->expects($this->once())
  594. ->method('findChildren')
  595. ->with(5, 10, new \DateTime($parameters[2]['value']))
  596. ->will($this->returnValue([]));
  597. $response = $this->getMockBuilder('Sabre\HTTP\ResponseInterface')
  598. ->disableOriginalConstructor()
  599. ->getMock();
  600. $response->expects($this->once())
  601. ->method('setHeader')
  602. ->with('Content-Type', 'application/xml; charset=utf-8');
  603. $response->expects($this->once())
  604. ->method('setStatus')
  605. ->with(207);
  606. $response->expects($this->once())
  607. ->method('setBody');
  608. $this->tree->expects($this->any())
  609. ->method('getNodeForPath')
  610. ->with('/' . $path)
  611. ->will($this->returnValue($node));
  612. $this->server->expects($this->any())
  613. ->method('getRequestUri')
  614. ->will($this->returnValue($path));
  615. $this->server->httpResponse = $response;
  616. $this->plugin->initialize($this->server);
  617. $this->plugin->onReport(CommentsPluginImplementation::REPORT_NAME, $parameters, '/' . $path);
  618. }
  619. }