3 class Sabre_DAV_XMLUtilTest extends PHPUnit_Framework_TestCase {
5 function testToClarkNotation() {
7 $dom = new DOMDocument();
8 $dom->loadXML('<?xml version="1.0"?><test1 xmlns="http://www.example.org/">Testdoc</test1>');
11 '{http://www.example.org/}test1',
12 Sabre_DAV_XMLUtil::toClarkNotation($dom->firstChild)
17 function testToClarkNotation2() {
19 $dom = new DOMDocument();
20 $dom->loadXML('<?xml version="1.0"?><s:test1 xmlns:s="http://www.example.org/">Testdoc</s:test1>');
23 '{http://www.example.org/}test1',
24 Sabre_DAV_XMLUtil::toClarkNotation($dom->firstChild)
29 function testToClarkNotationDAVNamespace() {
31 $dom = new DOMDocument();
32 $dom->loadXML('<?xml version="1.0"?><s:test1 xmlns:s="urn:DAV">Testdoc</s:test1>');
36 Sabre_DAV_XMLUtil::toClarkNotation($dom->firstChild)
41 function testToClarkNotationNoElem() {
43 $dom = new DOMDocument();
44 $dom->loadXML('<?xml version="1.0"?><s:test1 xmlns:s="urn:DAV">Testdoc</s:test1>');
47 Sabre_DAV_XMLUtil::toClarkNotation($dom->firstChild->firstChild)
52 function testConvertDAVNamespace() {
54 $xml='<?xml version="1.0"?><document xmlns="DAV:">blablabla</document>';
56 '<?xml version="1.0"?><document xmlns="urn:DAV">blablabla</document>',
57 Sabre_DAV_XMLUtil::convertDAVNamespace($xml)
62 function testConvertDAVNamespace2() {
64 $xml='<?xml version="1.0"?><s:document xmlns:s="DAV:">blablabla</s:document>';
66 '<?xml version="1.0"?><s:document xmlns:s="urn:DAV">blablabla</s:document>',
67 Sabre_DAV_XMLUtil::convertDAVNamespace($xml)
72 function testConvertDAVNamespace3() {
74 $xml='<?xml version="1.0"?><s:document xmlns="http://bla" xmlns:s="DAV:" xmlns:z="http://othernamespace">blablabla</s:document>';
76 '<?xml version="1.0"?><s:document xmlns="http://bla" xmlns:s="urn:DAV" xmlns:z="http://othernamespace">blablabla</s:document>',
77 Sabre_DAV_XMLUtil::convertDAVNamespace($xml)
82 function testConvertDAVNamespace4() {
84 $xml='<?xml version="1.0"?><document xmlns=\'DAV:\'>blablabla</document>';
86 '<?xml version="1.0"?><document xmlns=\'urn:DAV\'>blablabla</document>',
87 Sabre_DAV_XMLUtil::convertDAVNamespace($xml)
92 function testConvertDAVNamespaceMixedQuotes() {
94 $xml='<?xml version="1.0"?><document xmlns=\'DAV:" xmlns="Another attribute\'>blablabla</document>';
97 Sabre_DAV_XMLUtil::convertDAVNamespace($xml)
103 * @depends testConvertDAVNamespace
105 function testLoadDOMDocument() {
107 $xml='<?xml version="1.0"?><document></document>';
108 $dom = Sabre_DAV_XMLUtil::loadDOMDocument($xml);
109 $this->assertTrue($dom instanceof DOMDocument);
114 * @depends testLoadDOMDocument
115 * @expectedException Sabre_DAV_Exception_BadRequest
117 function testLoadDOMDocumentEmpty() {
119 Sabre_DAV_XMLUtil::loadDOMDocument('');
124 * @depends testConvertDAVNamespace
125 * @expectedException Sabre_DAV_Exception_BadRequest
127 function testLoadDOMDocumentInvalid() {
129 $xml='<?xml version="1.0"?><document></docu';
130 $dom = Sabre_DAV_XMLUtil::loadDOMDocument($xml);
135 * @depends testLoadDOMDocument
137 function testLoadDOMDocumentUTF16() {
139 $xml='<?xml version="1.0" encoding="UTF-16"?><root xmlns="DAV:">blabla</root>';
140 $xml = iconv('UTF-8','UTF-16LE',$xml);
141 $dom = Sabre_DAV_XMLUtil::loadDOMDocument($xml);
142 $this->assertEquals('blabla',$dom->firstChild->nodeValue);
147 function testParseProperties() {
149 $xml='<?xml version="1.0"?>
152 <displayname>Calendars</displayname>
156 $dom = Sabre_DAV_XMLUtil::loadDOMDocument($xml);
157 $properties = Sabre_DAV_XMLUtil::parseProperties($dom->firstChild);
159 $this->assertEquals(array(
160 '{DAV:}displayname' => 'Calendars',
168 * @depends testParseProperties
170 function testParsePropertiesEmpty() {
172 $xml='<?xml version="1.0"?>
173 <root xmlns="DAV:" xmlns:s="http://www.rooftopsolutions.nl/example">
175 <displayname>Calendars</displayname>
182 $dom = Sabre_DAV_XMLUtil::loadDOMDocument($xml);
183 $properties = Sabre_DAV_XMLUtil::parseProperties($dom->firstChild);
185 $this->assertEquals(array(
186 '{DAV:}displayname' => 'Calendars',
187 '{http://www.rooftopsolutions.nl/example}example' => null
194 * @depends testParseProperties
196 function testParsePropertiesComplex() {
198 $xml='<?xml version="1.0"?>
201 <displayname>Calendars</displayname>
204 <someprop>Complex value <b>right here</b></someprop>
208 $dom = Sabre_DAV_XMLUtil::loadDOMDocument($xml);
209 $properties = Sabre_DAV_XMLUtil::parseProperties($dom->firstChild);
211 $this->assertEquals(array(
212 '{DAV:}displayname' => 'Calendars',
213 '{DAV:}someprop' => 'Complex value right here',
220 * @depends testParseProperties
222 function testParsePropertiesNoProperties() {
224 $xml='<?xml version="1.0"?>
230 $dom = Sabre_DAV_XMLUtil::loadDOMDocument($xml);
231 $properties = Sabre_DAV_XMLUtil::parseProperties($dom->firstChild);
233 $this->assertEquals(array(), $properties);
237 function testParsePropertiesMapHref() {
239 $xml='<?xml version="1.0"?>
242 <displayname>Calendars</displayname>
245 <someprop><href>http://sabredav.org/</href></someprop>
249 $dom = Sabre_DAV_XMLUtil::loadDOMDocument($xml);
250 $properties = Sabre_DAV_XMLUtil::parseProperties($dom->firstChild,array('{DAV:}someprop'=>'Sabre_DAV_Property_Href'));
252 $this->assertEquals(array(
253 '{DAV:}displayname' => 'Calendars',
254 '{DAV:}someprop' => new Sabre_DAV_Property_Href('http://sabredav.org/',false),
259 function testParseClarkNotation() {
261 $this->assertEquals(array(
264 ), Sabre_DAV_XMLUtil::parseClarkNotation('{DAV:}foo'));
266 $this->assertEquals(array(
267 'http://example.org/ns/bla',
269 ), Sabre_DAV_XMLUtil::parseClarkNotation('{http://example.org/ns/bla}bar-soap'));
273 * @expectedException InvalidArgumentException
275 function testParseClarkNotationFail() {
277 Sabre_DAV_XMLUtil::parseClarkNotation('}foo');