[
'{DAV:}displayname' => 'my file',
],
404 => [
'{DAV:}owner' => null,
]
];
$property = new Response('uri', $innerProps);
$this->assertEquals('uri', $property->getHref());
$this->assertEquals($innerProps, $property->getResponseProperties());
}
/**
* @depends testSimple
*/
function testSerialize() {
$innerProps = [
200 => [
'{DAV:}displayname' => 'my file',
],
404 => [
'{DAV:}owner' => null,
]
];
$property = new Response('uri', $innerProps);
$xml = $this->write(['{DAV:}root' => ['{DAV:}response' => $property]]);
$this->assertXmlStringEqualsXmlString(
'
/uri
my file
HTTP/1.1 200 OK
HTTP/1.1 404 Not Found
', $xml);
}
/**
* This one is specifically for testing properties with no namespaces, which is legal xml
*
* @depends testSerialize
*/
function testSerializeEmptyNamespace() {
$innerProps = [
200 => [
'{}propertyname' => 'value',
],
];
$property = new Response('uri', $innerProps);
$xml = $this->write(['{DAV:}root' => ['{DAV:}response' => $property]]);
$this->assertEquals(
'
/uri
value
HTTP/1.1 200 OK
', $xml);
}
/**
* This one is specifically for testing properties with no namespaces, which is legal xml
*
* @depends testSerialize
*/
function testSerializeCustomNamespace() {
$innerProps = [
200 => [
'{http://sabredav.org/NS/example}propertyname' => 'value',
],
];
$property = new Response('uri', $innerProps);
$xml = $this->write(['{DAV:}root' => ['{DAV:}response' => $property]]);
$this->assertXmlStringEqualsXmlString(
'
/uri
value
HTTP/1.1 200 OK
', $xml);
}
/**
* @depends testSerialize
*/
function testSerializeComplexProperty() {
$innerProps = [
200 => [
'{DAV:}link' => new DAV\Xml\Property\Href('http://sabredav.org/', false)
],
];
$property = new Response('uri', $innerProps);
$xml = $this->write(['{DAV:}root' => ['{DAV:}response' => $property]]);
$this->assertXmlStringEqualsXmlString(
'
/uri
http://sabredav.org/
HTTP/1.1 200 OK
', $xml);
}
/**
* @depends testSerialize
* @expectedException \InvalidArgumentException
*/
function testSerializeBreak() {
$innerProps = [
200 => [
'{DAV:}link' => new \STDClass()
],
];
$property = new Response('uri', $innerProps);
$this->write(['{DAV:}root' => ['{DAV:}response' => $property]]);
}
function testDeserializeComplexProperty() {
$xml = '
/uri
hello
HTTP/1.1 200 OK
';
$result = $this->parse($xml, [
'{DAV:}response' => 'Sabre\DAV\Xml\Element\Response',
'{DAV:}foo' => function($reader) {
$reader->next();
return 'world';
},
]);
$this->assertEquals(
new Response('/uri', [
'200' => [
'{DAV:}foo' => 'world',
]
]),
$result['value']
);
}
/**
* In the case of {DAV:}prop, a deserializer should never get called, if
* the property element is empty.
*/
function testDeserializeComplexPropertyEmpty() {
$xml = '
/uri
HTTP/1.1 404 Not Found
';
$result = $this->parse($xml, [
'{DAV:}response' => 'Sabre\DAV\Xml\Element\Response',
'{DAV:}foo' => function($reader) {
throw new \LogicException('This should never happen');
},
]);
$this->assertEquals(
new Response('/uri', [
'404' => [
'{DAV:}foo' => null
]
]),
$result['value']
);
}
}