CommentsPluginTest.php 20 KB

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