]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/DAV/Property/HrefTest.php
Merge branch 'master' of git://github.com/friendica/friendica-addons
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / DAV / Property / HrefTest.php
1 <?php
2
3 class Sabre_DAV_Property_HrefTest extends PHPUnit_Framework_TestCase {
4
5     function testConstruct() {
6
7         $href = new Sabre_DAV_Property_Href('path');
8         $this->assertEquals('path',$href->getHref());
9
10     }
11
12     function testSerialize() {
13
14         $href = new Sabre_DAV_Property_Href('path');
15         $this->assertEquals('path',$href->getHref());
16
17         $doc = new DOMDocument();
18         $root = $doc->createElement('d:anything');
19         $root->setAttribute('xmlns:d','DAV:');
20
21         $doc->appendChild($root);
22         $server = new Sabre_DAV_Server();
23         $server->setBaseUri('/bla/');
24
25         $href->serialize($server, $root);
26
27         $xml = $doc->saveXML();
28
29         $this->assertEquals(
30 '<?xml version="1.0"?>
31 <d:anything xmlns:d="DAV:"><d:href>/bla/path</d:href></d:anything>
32 ', $xml);
33
34     }
35
36     function testSerializeNoPrefix() {
37
38         $href = new Sabre_DAV_Property_Href('path',false);
39         $this->assertEquals('path',$href->getHref());
40
41         $doc = new DOMDocument();
42         $root = $doc->createElement('d:anything');
43         $root->setAttribute('xmlns:d','DAV:');
44
45         $doc->appendChild($root);
46         $server = new Sabre_DAV_Server();
47         $server->setBaseUri('/bla/');
48
49         $href->serialize($server, $root);
50
51         $xml = $doc->saveXML();
52
53         $this->assertEquals(
54 '<?xml version="1.0"?>
55 <d:anything xmlns:d="DAV:"><d:href>path</d:href></d:anything>
56 ', $xml);
57
58     }
59
60     function testUnserialize() {
61
62         $xml = '<?xml version="1.0"?>
63 <d:anything xmlns:d="urn:DAV"><d:href>/bla/path</d:href></d:anything>
64 ';
65
66         $dom = new DOMDocument();
67         $dom->loadXML($xml);
68
69         $href = Sabre_DAV_Property_Href::unserialize($dom->firstChild);
70         $this->assertEquals('/bla/path',$href->getHref());
71
72     }
73
74     function testUnserializeIncompatible() {
75
76         $xml = '<?xml version="1.0"?>
77 <d:anything xmlns:d="urn:DAV"><d:href2>/bla/path</d:href2></d:anything>
78 ';
79
80         $dom = new DOMDocument();
81         $dom->loadXML($xml);
82
83         $href = Sabre_DAV_Property_Href::unserialize($dom->firstChild);
84         $this->assertNull($href);
85
86     }
87
88 }