PublishingTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\DAV\Tests\unit\CalDAV\Publishing;
  7. use OCA\DAV\CalDAV\Calendar;
  8. use OCA\DAV\CalDAV\Publishing\PublishPlugin;
  9. use OCP\IConfig;
  10. use OCP\IRequest;
  11. use OCP\IURLGenerator;
  12. use Sabre\DAV\Server;
  13. use Sabre\DAV\SimpleCollection;
  14. use Sabre\HTTP\Request;
  15. use Sabre\HTTP\Response;
  16. use Test\TestCase;
  17. class PublishingTest extends TestCase {
  18. /** @var PublishPlugin */
  19. private $plugin;
  20. /** @var Server */
  21. private $server;
  22. /** @var Calendar | \PHPUnit\Framework\MockObject\MockObject */
  23. private $book;
  24. /** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */
  25. private $config;
  26. /** @var IURLGenerator | \PHPUnit\Framework\MockObject\MockObject */
  27. private $urlGenerator;
  28. protected function setUp(): void {
  29. parent::setUp();
  30. $this->config = $this->getMockBuilder(IConfig::class)->
  31. disableOriginalConstructor()->
  32. getMock();
  33. $this->config->expects($this->any())->method('getSystemValue')
  34. ->with($this->equalTo('secret'))
  35. ->willReturn('mysecret');
  36. $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->
  37. disableOriginalConstructor()->
  38. getMock();
  39. /** @var IRequest $request */
  40. $this->plugin = new PublishPlugin($this->config, $this->urlGenerator);
  41. $root = new SimpleCollection('calendars');
  42. $this->server = new Server($root);
  43. /** @var SimpleCollection $node */
  44. $this->book = $this->getMockBuilder(Calendar::class)->
  45. disableOriginalConstructor()->
  46. getMock();
  47. $this->book->method('getName')->willReturn('cal1');
  48. $root->addChild($this->book);
  49. $this->plugin->initialize($this->server);
  50. }
  51. public function testPublishing(): void {
  52. $this->book->expects($this->once())->method('setPublishStatus')->with(true);
  53. // setup request
  54. $request = new Request('POST', 'cal1');
  55. $request->addHeader('Content-Type', 'application/xml');
  56. $request->setBody('<o:publish-calendar xmlns:o="http://calendarserver.org/ns/"/>');
  57. $response = new Response();
  58. $this->plugin->httpPost($request, $response);
  59. }
  60. public function testUnPublishing(): void {
  61. $this->book->expects($this->once())->method('setPublishStatus')->with(false);
  62. // setup request
  63. $request = new Request('POST', 'cal1');
  64. $request->addHeader('Content-Type', 'application/xml');
  65. $request->setBody('<o:unpublish-calendar xmlns:o="http://calendarserver.org/ns/"/>');
  66. $response = new Response();
  67. $this->plugin->httpPost($request, $response);
  68. }
  69. }