PublishingTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. *
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Thomas Citharel <nextcloud@tcit.fr>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  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
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\DAV\Tests\unit\CalDAV\Publishing;
  27. use OCA\DAV\CalDAV\Calendar;
  28. use OCA\DAV\CalDAV\Publishing\PublishPlugin;
  29. use OCP\IConfig;
  30. use OCP\IRequest;
  31. use OCP\IURLGenerator;
  32. use Sabre\DAV\Server;
  33. use Sabre\DAV\SimpleCollection;
  34. use Sabre\HTTP\Request;
  35. use Sabre\HTTP\Response;
  36. use Test\TestCase;
  37. class PluginTest extends TestCase {
  38. /** @var PublishPlugin */
  39. private $plugin;
  40. /** @var Server */
  41. private $server;
  42. /** @var Calendar | \PHPUnit_Framework_MockObject_MockObject */
  43. private $book;
  44. /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
  45. private $config;
  46. /** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject */
  47. private $urlGenerator;
  48. protected function setUp(): void {
  49. parent::setUp();
  50. $this->config = $this->getMockBuilder(IConfig::class)->
  51. disableOriginalConstructor()->
  52. getMock();
  53. $this->config->expects($this->any())->method('getSystemValue')
  54. ->with($this->equalTo('secret'))
  55. ->willReturn('mysecret');
  56. $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->
  57. disableOriginalConstructor()->
  58. getMock();
  59. /** @var IRequest $request */
  60. $this->plugin = new PublishPlugin($this->config, $this->urlGenerator);
  61. $root = new SimpleCollection('calendars');
  62. $this->server = new Server($root);
  63. /** @var SimpleCollection $node */
  64. $this->book = $this->getMockBuilder(Calendar::class)->
  65. disableOriginalConstructor()->
  66. getMock();
  67. $this->book->method('getName')->willReturn('cal1');
  68. $root->addChild($this->book);
  69. $this->plugin->initialize($this->server);
  70. }
  71. public function testPublishing() {
  72. $this->book->expects($this->once())->method('setPublishStatus')->with(true);
  73. // setup request
  74. $request = new Request('POST', 'cal1');
  75. $request->addHeader('Content-Type', 'application/xml');
  76. $request->setBody('<o:publish-calendar xmlns:o="http://calendarserver.org/ns/"/>');
  77. $response = new Response();
  78. $this->plugin->httpPost($request, $response);
  79. }
  80. public function testUnPublishing() {
  81. $this->book->expects($this->once())->method('setPublishStatus')->with(false);
  82. // setup request
  83. $request = new Request('POST', 'cal1');
  84. $request->addHeader('Content-Type', 'application/xml');
  85. $request->setBody('<o:unpublish-calendar xmlns:o="http://calendarserver.org/ns/"/>');
  86. $response = new Response();
  87. $this->plugin->httpPost($request, $response);
  88. }
  89. }