nextcloud/apps/dav/tests/unit/CalDAV/Publishing/PublisherTest.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.6 KiB
PHP
Raw Normal View History

2016-08-01 11:16:30 -04:00
<?php
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
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;
use Test\TestCase;
2016-08-01 11:16:30 -04:00
class PublisherTest extends TestCase {
public const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
2016-08-01 11:16:30 -04: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);
}
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();
}
}