PublisherTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. *
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Thomas Citharel <nextcloud@tcit.fr>
  10. *
  11. * @license GNU AGPL version 3 or any later version
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as
  15. * published by the Free Software Foundation, either version 3 of the
  16. * License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *
  26. */
  27. namespace OCA\DAV\Tests\unit\CalDAV\Publishing;
  28. use OCA\DAV\CalDAV\Publishing\Xml\Publisher;
  29. use Sabre\Xml\Writer;
  30. use Test\TestCase;
  31. class PublisherTest extends TestCase {
  32. public const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
  33. public function testSerializePublished() {
  34. $publish = new Publisher('urltopublish', true);
  35. $xml = $this->write([
  36. '{' . self::NS_CALENDARSERVER . '}publish-url' => $publish,
  37. ]);
  38. $this->assertEquals('urltopublish', $publish->getValue());
  39. $this->assertXmlStringEqualsXmlString(
  40. '<?xml version="1.0"?>
  41. <x1:publish-url xmlns:d="DAV:" xmlns:x1="' . self::NS_CALENDARSERVER . '">
  42. <d:href>urltopublish</d:href>
  43. </x1:publish-url>', $xml);
  44. }
  45. public function testSerializeNotPublished() {
  46. $publish = new Publisher('urltopublish', false);
  47. $xml = $this->write([
  48. '{' . self::NS_CALENDARSERVER . '}pre-publish-url' => $publish,
  49. ]);
  50. $this->assertEquals('urltopublish', $publish->getValue());
  51. $this->assertXmlStringEqualsXmlString(
  52. '<?xml version="1.0"?>
  53. <x1:pre-publish-url xmlns:d="DAV:" xmlns:x1="' . self::NS_CALENDARSERVER . '">urltopublish</x1:pre-publish-url>', $xml);
  54. }
  55. protected $elementMap = [];
  56. protected $namespaceMap = ['DAV:' => 'd'];
  57. protected $contextUri = '/';
  58. private function write($input) {
  59. $writer = new Writer();
  60. $writer->contextUri = $this->contextUri;
  61. $writer->namespaceMap = $this->namespaceMap;
  62. $writer->openMemory();
  63. $writer->setIndent(true);
  64. $writer->write($input);
  65. return $writer->outputMemory();
  66. }
  67. }