aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/DAV/Property/HrefListTest.php
blob: fe2bc81f94a7879bdf4829c08b8d6d15d8cc9107 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php

namespace Sabre\DAV\Property;
use Sabre\DAV;

class HrefListTest extends \PHPUnit_Framework_TestCase {

    function testConstruct() {

        $href = new HrefList(array('foo','bar'));
        $this->assertEquals(array('foo','bar'),$href->getHrefs());

    }

    function testSerialize() {

        $href = new HrefList(array('foo','bar'));
        $this->assertEquals(array('foo','bar'),$href->getHrefs());

        $doc = new \DOMDocument();
        $root = $doc->createElement('d:anything');
        $root->setAttribute('xmlns:d','DAV:');

        $doc->appendChild($root);
        $server = new DAV\Server();
        $server->setBaseUri('/bla/');

        $href->serialize($server, $root);

        $xml = $doc->saveXML();

        $this->assertEquals(
'<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:href>/bla/foo</d:href><d:href>/bla/bar</d:href></d:anything>
', $xml);

    }

    function testSerializeNoPrefix() {

        $href = new HrefList(array('foo','bar'), false);
        $this->assertEquals(array('foo','bar'),$href->getHrefs());

        $doc = new \DOMDocument();
        $root = $doc->createElement('d:anything');
        $root->setAttribute('xmlns:d','DAV:');

        $doc->appendChild($root);
        $server = new DAV\Server();
        $server->setBaseUri('/bla/');

        $href->serialize($server, $root);

        $xml = $doc->saveXML();

        $this->assertEquals(
'<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:href>foo</d:href><d:href>bar</d:href></d:anything>
', $xml);

    }

    function testUnserialize() {

        $xml = '<?xml version="1.0"?>
<d:anything xmlns:d="urn:DAV"><d:href>/bla/foo</d:href><d:href>/bla/bar</d:href></d:anything>
';

        $dom = new \DOMDocument();
        $dom->loadXML($xml);

        $href = HrefList::unserialize($dom->firstChild);
        $this->assertEquals(array('/bla/foo','/bla/bar'),$href->getHrefs());

    }

    function testUnserializeIncompatible() {

        $xml = '<?xml version="1.0"?>
<d:anything xmlns:d="urn:DAV"><d:href2>/bla/foo</d:href2></d:anything>
';

        $dom = new \DOMDocument();
        $dom->loadXML($xml);

        $href = HrefList::unserialize($dom->firstChild);
        $this->assertEquals(array(), $href->getHrefs());

    }

}