test serializer

This commit is contained in:
Thomas Citharel 2016-08-01 17:16:30 +02:00 committed by Lukas Reschke
parent 691b3ab448
commit 9af2a9ff4d
No known key found for this signature in database
GPG Key ID: B9F6980CF6E759B1
1 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,56 @@
<?php
namespace OCA\DAV\Tests\unit\CalDAV\Publishing;
use OCA\DAV\CalDAV\Publishing\Xml\Publisher;
use Sabre\Xml\Writer;
class PublisherTest extends \PHPUnit_Framework_TestCase {
const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
public function testSerializePublished() {
$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() {
$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();
}
}