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

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