]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/DAV/Property/ResourceTypeTest.php
Merge branch 'master' of git://github.com/friendica/friendica-addons
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / DAV / Property / ResourceTypeTest.php
1 <?php
2
3 class Sabre_DAV_Property_ResourceTypeTest extends PHPUnit_Framework_TestCase {
4
5     function testConstruct() {
6
7         $resourceType = new Sabre_DAV_Property_ResourceType(array('{DAV:}collection'));
8         $this->assertEquals(array('{DAV:}collection'),$resourceType->getValue());
9
10         $resourceType = new Sabre_DAV_Property_ResourceType(Sabre_DAV_Server::NODE_FILE);
11         $this->assertEquals(array(),$resourceType->getValue());
12
13         $resourceType = new Sabre_DAV_Property_ResourceType(Sabre_DAV_Server::NODE_DIRECTORY);
14         $this->assertEquals(array('{DAV:}collection'),$resourceType->getValue());
15
16         $resourceType = new Sabre_DAV_Property_ResourceType('{DAV:}principal');
17         $this->assertEquals(array('{DAV:}principal'),$resourceType->getValue());
18
19     }
20
21     /**
22      * @depends testConstruct
23      */
24     function testSerialize() {
25
26         $resourceType = new Sabre_DAV_Property_ResourceType(array('{DAV:}collection','{DAV:}principal'));
27
28         $doc = new DOMDocument();
29         $root = $doc->createElement('d:anything');
30         $root->setAttribute('xmlns:d','DAV:');
31
32         $doc->appendChild($root);
33         $server = new Sabre_DAV_Server();
34         $resourceType->serialize($server, $root);
35
36         $xml = $doc->saveXML();
37
38         $this->assertEquals(
39 '<?xml version="1.0"?>
40 <d:anything xmlns:d="DAV:"><d:collection/><d:principal/></d:anything>
41 ', $xml);
42
43     }
44
45     /**
46      * @depends testSerialize
47      */
48     function testSerializeCustomNS() {
49
50         $resourceType = new Sabre_DAV_Property_ResourceType(array('{http://example.org/NS}article'));
51
52         $doc = new DOMDocument();
53         $root = $doc->createElement('d:anything');
54         $root->setAttribute('xmlns:d','DAV:');
55
56         $doc->appendChild($root);
57         $server = new Sabre_DAV_Server();
58         $resourceType->serialize($server, $root);
59
60         $xml = $doc->saveXML();
61
62         $this->assertEquals(
63 '<?xml version="1.0"?>
64 <d:anything xmlns:d="DAV:"><custom:article xmlns:custom="http://example.org/NS"/></d:anything>
65 ', $xml);
66
67     }
68
69     /**
70      * @depends testConstruct
71      */
72     function testIs() {
73
74         $resourceType = new Sabre_DAV_Property_ResourceType(array('{DAV:}collection','{DAV:}principal'));
75         $this->assertTrue($resourceType->is('{DAV:}collection'));
76         $this->assertFalse($resourceType->is('{DAV:}blabla'));
77
78     }
79
80     /**
81      * @depends testConstruct
82      */
83     function testAdd() {
84
85         $resourceType = new Sabre_DAV_Property_ResourceType(array('{DAV:}collection','{DAV:}principal'));
86         $resourceType->add('{DAV:}foo');
87         $this->assertEquals(array('{DAV:}collection','{DAV:}principal','{DAV:}foo'), $resourceType->getValue());
88
89     }
90
91     /**
92      * @depends testConstruct
93      */
94     function testUnserialize() {
95
96         $xml ='<?xml version="1.0"?>
97 <d:anything xmlns:d="DAV:"><d:collection/><d:principal/></d:anything>
98 ';
99
100         $dom = Sabre_DAV_XMLUtil::loadDOMDocument($xml);
101
102         $resourceType = Sabre_DAV_Property_ResourceType::unserialize($dom->firstChild);
103         $this->assertEquals(array('{DAV:}collection','{DAV:}principal'),$resourceType->getValue());
104
105     }
106
107 }