2016-08-01 11:16:30 -04:00
|
|
|
<?php
|
2017-11-06 09:56:42 -05:00
|
|
|
/**
|
2024-05-28 06:34:11 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2017-11-06 09:56:42 -05:00
|
|
|
*/
|
2016-08-01 11:16:30 -04:00
|
|
|
namespace OCA\DAV\Tests\unit\CalDAV\Publishing;
|
|
|
|
|
|
|
|
|
|
use OCA\DAV\CalDAV\Publishing\Xml\Publisher;
|
|
|
|
|
use Sabre\Xml\Writer;
|
2018-01-24 11:23:59 -05:00
|
|
|
use Test\TestCase;
|
2016-08-01 11:16:30 -04:00
|
|
|
|
2018-01-24 11:23:59 -05:00
|
|
|
class PublisherTest extends TestCase {
|
2020-04-10 10:54:27 -04:00
|
|
|
public const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
|
2016-08-01 11:16:30 -04:00
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testSerializePublished(): void {
|
2016-08-01 11:16:30 -04:00
|
|
|
$publish = new Publisher('urltopublish', true);
|
|
|
|
|
|
|
|
|
|
$xml = $this->write([
|
|
|
|
|
'{' . self::NS_CALENDARSERVER . '}publish-url' => $publish,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('urltopublish', $publish->getValue());
|
|
|
|
|
|
|
|
|
|
$this->assertXmlStringEqualsXmlString(
|
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
|
<x1:publish-url xmlns:d="DAV:" xmlns:x1="' . self::NS_CALENDARSERVER . '">
|
|
|
|
|
<d:href>urltopublish</d:href>
|
|
|
|
|
</x1:publish-url>', $xml);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testSerializeNotPublished(): void {
|
2016-08-01 11:16:30 -04:00
|
|
|
$publish = new Publisher('urltopublish', false);
|
|
|
|
|
|
|
|
|
|
$xml = $this->write([
|
|
|
|
|
'{' . self::NS_CALENDARSERVER . '}pre-publish-url' => $publish,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('urltopublish', $publish->getValue());
|
|
|
|
|
|
|
|
|
|
$this->assertXmlStringEqualsXmlString(
|
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
|
<x1:pre-publish-url xmlns:d="DAV:" xmlns:x1="' . self::NS_CALENDARSERVER . '">urltopublish</x1:pre-publish-url>', $xml);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected $elementMap = [];
|
|
|
|
|
protected $namespaceMap = ['DAV:' => 'd'];
|
|
|
|
|
protected $contextUri = '/';
|
|
|
|
|
|
|
|
|
|
private function write($input) {
|
|
|
|
|
$writer = new Writer();
|
|
|
|
|
$writer->contextUri = $this->contextUri;
|
|
|
|
|
$writer->namespaceMap = $this->namespaceMap;
|
|
|
|
|
$writer->openMemory();
|
|
|
|
|
$writer->setIndent(true);
|
|
|
|
|
$writer->write($input);
|
|
|
|
|
return $writer->outputMemory();
|
|
|
|
|
}
|
|
|
|
|
}
|