1
0

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. protected function setUp(): void {
  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. ->willReturn('alice');
  87. $node = $this->getMockBuilder(EntityCollection::class)
  88. ->disableOriginalConstructor()
  89. ->getMock();
  90. $node->expects($this->once())
  91. ->method('getName')
  92. ->willReturn('files');
  93. $node->expects($this->once())
  94. ->method('getId')
  95. ->willReturn('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. ->willReturn($comment);
  103. $this->userSession->expects($this->once())
  104. ->method('getUser')
  105. ->willReturn($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. ->willReturn($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. ->willReturn('/' . $path);
  123. $request->expects($this->once())
  124. ->method('getBodyAsString')
  125. ->willReturn($requestData);
  126. $request->expects($this->once())
  127. ->method('getHeader')
  128. ->with('Content-Type')
  129. ->willReturn('application/json');
  130. $request->expects($this->once())
  131. ->method('getUrl')
  132. ->willReturn('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. ->willReturn($path);
  139. $this->plugin->initialize($this->server);
  140. $this->plugin->httpPost($request, $response);
  141. }
  142. public function testCreateCommentInvalidObject() {
  143. $this->expectException(\Sabre\DAV\Exception\NotFound::class);
  144. $commentData = [
  145. 'actorType' => 'users',
  146. 'verb' => 'comment',
  147. 'message' => 'my first comment',
  148. ];
  149. $comment = new Comment([
  150. 'objectType' => 'files',
  151. 'objectId' => '666',
  152. 'actorType' => 'users',
  153. 'actorId' => 'alice'
  154. ] + $commentData);
  155. $comment->setId('23');
  156. $path = 'comments/files/666';
  157. $user = $this->getMockBuilder(IUser::class)
  158. ->disableOriginalConstructor()
  159. ->getMock();
  160. $user->expects($this->never())
  161. ->method('getUID');
  162. $node = $this->getMockBuilder(EntityCollection::class)
  163. ->disableOriginalConstructor()
  164. ->getMock();
  165. $node->expects($this->never())
  166. ->method('getName');
  167. $node->expects($this->never())
  168. ->method('getId');
  169. $this->commentsManager->expects($this->never())
  170. ->method('create');
  171. $this->userSession->expects($this->never())
  172. ->method('getUser');
  173. // technically, this is a shortcut. Inbetween EntityTypeCollection would
  174. // be returned, but doing it exactly right would not be really
  175. // unit-testing like, as it would require to haul in a lot of other
  176. // things.
  177. $this->tree->expects($this->any())
  178. ->method('getNodeForPath')
  179. ->with('/' . $path)
  180. ->will($this->throwException(new \Sabre\DAV\Exception\NotFound()));
  181. $request = $this->getMockBuilder(RequestInterface::class)
  182. ->disableOriginalConstructor()
  183. ->getMock();
  184. $response = $this->getMockBuilder(ResponseInterface::class)
  185. ->disableOriginalConstructor()
  186. ->getMock();
  187. $request->expects($this->once())
  188. ->method('getPath')
  189. ->willReturn('/' . $path);
  190. $request->expects($this->never())
  191. ->method('getBodyAsString');
  192. $request->expects($this->never())
  193. ->method('getHeader')
  194. ->with('Content-Type');
  195. $request->expects($this->never())
  196. ->method('getUrl');
  197. $response->expects($this->never())
  198. ->method('setHeader');
  199. $this->server->expects($this->any())
  200. ->method('getRequestUri')
  201. ->willReturn($path);
  202. $this->plugin->initialize($this->server);
  203. $this->plugin->httpPost($request, $response);
  204. }
  205. public function testCreateCommentInvalidActor() {
  206. $this->expectException(\Sabre\DAV\Exception\BadRequest::class);
  207. $commentData = [
  208. 'actorType' => 'robots',
  209. 'verb' => 'comment',
  210. 'message' => 'my first comment',
  211. ];
  212. $comment = new Comment([
  213. 'objectType' => 'files',
  214. 'objectId' => '42',
  215. 'actorType' => 'users',
  216. 'actorId' => 'alice'
  217. ] + $commentData);
  218. $comment->setId('23');
  219. $path = 'comments/files/42';
  220. $requestData = json_encode($commentData);
  221. $user = $this->getMockBuilder(IUser::class)
  222. ->disableOriginalConstructor()
  223. ->getMock();
  224. $user->expects($this->never())
  225. ->method('getUID');
  226. $node = $this->getMockBuilder(EntityCollection::class)
  227. ->disableOriginalConstructor()
  228. ->getMock();
  229. $node->expects($this->once())
  230. ->method('getName')
  231. ->willReturn('files');
  232. $node->expects($this->once())
  233. ->method('getId')
  234. ->willReturn('42');
  235. $this->commentsManager->expects($this->never())
  236. ->method('create');
  237. $this->userSession->expects($this->never())
  238. ->method('getUser');
  239. // technically, this is a shortcut. Inbetween EntityTypeCollection would
  240. // be returned, but doing it exactly right would not be really
  241. // unit-testing like, as it would require to haul in a lot of other
  242. // things.
  243. $this->tree->expects($this->any())
  244. ->method('getNodeForPath')
  245. ->with('/' . $path)
  246. ->willReturn($node);
  247. $request = $this->getMockBuilder(RequestInterface::class)
  248. ->disableOriginalConstructor()
  249. ->getMock();
  250. $response = $this->getMockBuilder(ResponseInterface::class)
  251. ->disableOriginalConstructor()
  252. ->getMock();
  253. $request->expects($this->once())
  254. ->method('getPath')
  255. ->willReturn('/' . $path);
  256. $request->expects($this->once())
  257. ->method('getBodyAsString')
  258. ->willReturn($requestData);
  259. $request->expects($this->once())
  260. ->method('getHeader')
  261. ->with('Content-Type')
  262. ->willReturn('application/json');
  263. $request->expects($this->never())
  264. ->method('getUrl');
  265. $response->expects($this->never())
  266. ->method('setHeader');
  267. $this->server->expects($this->any())
  268. ->method('getRequestUri')
  269. ->willReturn($path);
  270. $this->plugin->initialize($this->server);
  271. $this->plugin->httpPost($request, $response);
  272. }
  273. public function testCreateCommentUnsupportedMediaType() {
  274. $this->expectException(\Sabre\DAV\Exception\UnsupportedMediaType::class);
  275. $commentData = [
  276. 'actorType' => 'users',
  277. 'verb' => 'comment',
  278. 'message' => 'my first comment',
  279. ];
  280. $comment = new Comment([
  281. 'objectType' => 'files',
  282. 'objectId' => '42',
  283. 'actorType' => 'users',
  284. 'actorId' => 'alice'
  285. ] + $commentData);
  286. $comment->setId('23');
  287. $path = 'comments/files/42';
  288. $requestData = json_encode($commentData);
  289. $user = $this->getMockBuilder(IUser::class)
  290. ->disableOriginalConstructor()
  291. ->getMock();
  292. $user->expects($this->never())
  293. ->method('getUID');
  294. $node = $this->getMockBuilder(EntityCollection::class)
  295. ->disableOriginalConstructor()
  296. ->getMock();
  297. $node->expects($this->once())
  298. ->method('getName')
  299. ->willReturn('files');
  300. $node->expects($this->once())
  301. ->method('getId')
  302. ->willReturn('42');
  303. $this->commentsManager->expects($this->never())
  304. ->method('create');
  305. $this->userSession->expects($this->never())
  306. ->method('getUser');
  307. // technically, this is a shortcut. Inbetween EntityTypeCollection would
  308. // be returned, but doing it exactly right would not be really
  309. // unit-testing like, as it would require to haul in a lot of other
  310. // things.
  311. $this->tree->expects($this->any())
  312. ->method('getNodeForPath')
  313. ->with('/' . $path)
  314. ->willReturn($node);
  315. $request = $this->getMockBuilder(RequestInterface::class)
  316. ->disableOriginalConstructor()
  317. ->getMock();
  318. $response = $this->getMockBuilder(ResponseInterface::class)
  319. ->disableOriginalConstructor()
  320. ->getMock();
  321. $request->expects($this->once())
  322. ->method('getPath')
  323. ->willReturn('/' . $path);
  324. $request->expects($this->once())
  325. ->method('getBodyAsString')
  326. ->willReturn($requestData);
  327. $request->expects($this->once())
  328. ->method('getHeader')
  329. ->with('Content-Type')
  330. ->willReturn('application/trumpscript');
  331. $request->expects($this->never())
  332. ->method('getUrl');
  333. $response->expects($this->never())
  334. ->method('setHeader');
  335. $this->server->expects($this->any())
  336. ->method('getRequestUri')
  337. ->willReturn($path);
  338. $this->plugin->initialize($this->server);
  339. $this->plugin->httpPost($request, $response);
  340. }
  341. public function testCreateCommentInvalidPayload() {
  342. $this->expectException(\Sabre\DAV\Exception\BadRequest::class);
  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(IUser::class)
  360. ->disableOriginalConstructor()
  361. ->getMock();
  362. $user->expects($this->once())
  363. ->method('getUID')
  364. ->willReturn('alice');
  365. $node = $this->getMockBuilder(EntityCollection::class)
  366. ->disableOriginalConstructor()
  367. ->getMock();
  368. $node->expects($this->once())
  369. ->method('getName')
  370. ->willReturn('files');
  371. $node->expects($this->once())
  372. ->method('getId')
  373. ->willReturn('42');
  374. $this->commentsManager->expects($this->once())
  375. ->method('create')
  376. ->with('users', 'alice', 'files', '42')
  377. ->willReturn($comment);
  378. $this->userSession->expects($this->once())
  379. ->method('getUser')
  380. ->willReturn($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. ->willReturn($node);
  389. $request = $this->getMockBuilder(RequestInterface::class)
  390. ->disableOriginalConstructor()
  391. ->getMock();
  392. $response = $this->getMockBuilder(ResponseInterface::class)
  393. ->disableOriginalConstructor()
  394. ->getMock();
  395. $request->expects($this->once())
  396. ->method('getPath')
  397. ->willReturn('/' . $path);
  398. $request->expects($this->once())
  399. ->method('getBodyAsString')
  400. ->willReturn($requestData);
  401. $request->expects($this->once())
  402. ->method('getHeader')
  403. ->with('Content-Type')
  404. ->willReturn('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. ->willReturn($path);
  412. $this->plugin->initialize($this->server);
  413. $this->plugin->httpPost($request, $response);
  414. }
  415. public function testCreateCommentMessageTooLong() {
  416. $this->expectException(\Sabre\DAV\Exception\BadRequest::class);
  417. $this->expectExceptionMessage('Message exceeds allowed character limit of');
  418. $commentData = [
  419. 'actorType' => 'users',
  420. 'verb' => 'comment',
  421. 'message' => str_pad('', IComment::MAX_MESSAGE_LENGTH + 1, 'x'),
  422. ];
  423. $comment = new Comment([
  424. 'objectType' => 'files',
  425. 'objectId' => '42',
  426. 'actorType' => 'users',
  427. 'actorId' => 'alice',
  428. 'verb' => 'comment',
  429. ]);
  430. $comment->setId('23');
  431. $path = 'comments/files/42';
  432. $requestData = json_encode($commentData);
  433. $user = $this->getMockBuilder(IUser::class)
  434. ->disableOriginalConstructor()
  435. ->getMock();
  436. $user->expects($this->once())
  437. ->method('getUID')
  438. ->willReturn('alice');
  439. $node = $this->getMockBuilder(EntityCollection::class)
  440. ->disableOriginalConstructor()
  441. ->getMock();
  442. $node->expects($this->once())
  443. ->method('getName')
  444. ->willReturn('files');
  445. $node->expects($this->once())
  446. ->method('getId')
  447. ->willReturn('42');
  448. $node->expects($this->never())
  449. ->method('setReadMarker');
  450. $this->commentsManager->expects($this->once())
  451. ->method('create')
  452. ->with('users', 'alice', 'files', '42')
  453. ->willReturn($comment);
  454. $this->userSession->expects($this->once())
  455. ->method('getUser')
  456. ->willReturn($user);
  457. // technically, this is a shortcut. Inbetween EntityTypeCollection would
  458. // be returned, but doing it exactly right would not be really
  459. // unit-testing like, as it would require to haul in a lot of other
  460. // things.
  461. $this->tree->expects($this->any())
  462. ->method('getNodeForPath')
  463. ->with('/' . $path)
  464. ->willReturn($node);
  465. $request = $this->getMockBuilder(RequestInterface::class)
  466. ->disableOriginalConstructor()
  467. ->getMock();
  468. $response = $this->getMockBuilder(ResponseInterface::class)
  469. ->disableOriginalConstructor()
  470. ->getMock();
  471. $request->expects($this->once())
  472. ->method('getPath')
  473. ->willReturn('/' . $path);
  474. $request->expects($this->once())
  475. ->method('getBodyAsString')
  476. ->willReturn($requestData);
  477. $request->expects($this->once())
  478. ->method('getHeader')
  479. ->with('Content-Type')
  480. ->willReturn('application/json');
  481. $response->expects($this->never())
  482. ->method('setHeader');
  483. $this->server->expects($this->any())
  484. ->method('getRequestUri')
  485. ->willReturn($path);
  486. $this->plugin->initialize($this->server);
  487. $this->plugin->httpPost($request, $response);
  488. }
  489. public function testOnReportInvalidNode() {
  490. $this->expectException(\Sabre\DAV\Exception\ReportNotSupported::class);
  491. $path = 'totally/unrelated/13';
  492. $this->tree->expects($this->any())
  493. ->method('getNodeForPath')
  494. ->with('/' . $path)
  495. ->willReturn(
  496. $this->getMockBuilder(INode::class)
  497. ->disableOriginalConstructor()
  498. ->getMock()
  499. );
  500. $this->server->expects($this->any())
  501. ->method('getRequestUri')
  502. ->willReturn($path);
  503. $this->plugin->initialize($this->server);
  504. $this->plugin->onReport(CommentsPluginImplementation::REPORT_NAME, [], '/' . $path);
  505. }
  506. public function testOnReportInvalidReportName() {
  507. $this->expectException(\Sabre\DAV\Exception\ReportNotSupported::class);
  508. $path = 'comments/files/42';
  509. $this->tree->expects($this->any())
  510. ->method('getNodeForPath')
  511. ->with('/' . $path)
  512. ->willReturn(
  513. $this->getMockBuilder(INode::class)
  514. ->disableOriginalConstructor()
  515. ->getMock()
  516. );
  517. $this->server->expects($this->any())
  518. ->method('getRequestUri')
  519. ->willReturn($path);
  520. $this->plugin->initialize($this->server);
  521. $this->plugin->onReport('{whoever}whatever', [], '/' . $path);
  522. }
  523. public function testOnReportDateTimeEmpty() {
  524. $path = 'comments/files/42';
  525. $parameters = [
  526. [
  527. 'name' => '{http://owncloud.org/ns}limit',
  528. 'value' => 5,
  529. ],
  530. [
  531. 'name' => '{http://owncloud.org/ns}offset',
  532. 'value' => 10,
  533. ],
  534. [
  535. 'name' => '{http://owncloud.org/ns}datetime',
  536. 'value' => '',
  537. ]
  538. ];
  539. $node = $this->getMockBuilder(EntityCollection::class)
  540. ->disableOriginalConstructor()
  541. ->getMock();
  542. $node->expects($this->once())
  543. ->method('findChildren')
  544. ->with(5, 10, null)
  545. ->willReturn([]);
  546. $response = $this->getMockBuilder(ResponseInterface::class)
  547. ->disableOriginalConstructor()
  548. ->getMock();
  549. $response->expects($this->once())
  550. ->method('setHeader')
  551. ->with('Content-Type', 'application/xml; charset=utf-8');
  552. $response->expects($this->once())
  553. ->method('setStatus')
  554. ->with(207);
  555. $response->expects($this->once())
  556. ->method('setBody');
  557. $this->tree->expects($this->any())
  558. ->method('getNodeForPath')
  559. ->with('/' . $path)
  560. ->willReturn($node);
  561. $this->server->expects($this->any())
  562. ->method('getRequestUri')
  563. ->willReturn($path);
  564. $this->server->httpResponse = $response;
  565. $this->plugin->initialize($this->server);
  566. $this->plugin->onReport(CommentsPluginImplementation::REPORT_NAME, $parameters, '/' . $path);
  567. }
  568. public function testOnReport() {
  569. $path = 'comments/files/42';
  570. $parameters = [
  571. [
  572. 'name' => '{http://owncloud.org/ns}limit',
  573. 'value' => 5,
  574. ],
  575. [
  576. 'name' => '{http://owncloud.org/ns}offset',
  577. 'value' => 10,
  578. ],
  579. [
  580. 'name' => '{http://owncloud.org/ns}datetime',
  581. 'value' => '2016-01-10 18:48:00',
  582. ]
  583. ];
  584. $node = $this->getMockBuilder(EntityCollection::class)
  585. ->disableOriginalConstructor()
  586. ->getMock();
  587. $node->expects($this->once())
  588. ->method('findChildren')
  589. ->with(5, 10, new \DateTime($parameters[2]['value']))
  590. ->willReturn([]);
  591. $response = $this->getMockBuilder(ResponseInterface::class)
  592. ->disableOriginalConstructor()
  593. ->getMock();
  594. $response->expects($this->once())
  595. ->method('setHeader')
  596. ->with('Content-Type', 'application/xml; charset=utf-8');
  597. $response->expects($this->once())
  598. ->method('setStatus')
  599. ->with(207);
  600. $response->expects($this->once())
  601. ->method('setBody');
  602. $this->tree->expects($this->any())
  603. ->method('getNodeForPath')
  604. ->with('/' . $path)
  605. ->willReturn($node);
  606. $this->server->expects($this->any())
  607. ->method('getRequestUri')
  608. ->willReturn($path);
  609. $this->server->httpResponse = $response;
  610. $this->plugin->initialize($this->server);
  611. $this->plugin->onReport(CommentsPluginImplementation::REPORT_NAME, $parameters, '/' . $path);
  612. }
  613. }