PublisherTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\Publishing\Xml\Publisher;
  8. use Sabre\Xml\Writer;
  9. use Test\TestCase;
  10. class PublisherTest extends TestCase {
  11. public const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
  12. public function testSerializePublished(): void {
  13. $publish = new Publisher('urltopublish', true);
  14. $xml = $this->write([
  15. '{' . self::NS_CALENDARSERVER . '}publish-url' => $publish,
  16. ]);
  17. $this->assertEquals('urltopublish', $publish->getValue());
  18. $this->assertXmlStringEqualsXmlString(
  19. '<?xml version="1.0"?>
  20. <x1:publish-url xmlns:d="DAV:" xmlns:x1="' . self::NS_CALENDARSERVER . '">
  21. <d:href>urltopublish</d:href>
  22. </x1:publish-url>', $xml);
  23. }
  24. public function testSerializeNotPublished(): void {
  25. $publish = new Publisher('urltopublish', false);
  26. $xml = $this->write([
  27. '{' . self::NS_CALENDARSERVER . '}pre-publish-url' => $publish,
  28. ]);
  29. $this->assertEquals('urltopublish', $publish->getValue());
  30. $this->assertXmlStringEqualsXmlString(
  31. '<?xml version="1.0"?>
  32. <x1:pre-publish-url xmlns:d="DAV:" xmlns:x1="' . self::NS_CALENDARSERVER . '">urltopublish</x1:pre-publish-url>', $xml);
  33. }
  34. protected $elementMap = [];
  35. protected $namespaceMap = ['DAV:' => 'd'];
  36. protected $contextUri = '/';
  37. private function write($input) {
  38. $writer = new Writer();
  39. $writer->contextUri = $this->contextUri;
  40. $writer->namespaceMap = $this->namespaceMap;
  41. $writer->openMemory();
  42. $writer->setIndent(true);
  43. $writer->write($input);
  44. return $writer->outputMemory();
  45. }
  46. }