You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommentsPluginTest.php 20KB

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