1<?php
2
3namespace Sabre\DAVACL\Xml\Property;
4
5use Sabre\DAV;
6use Sabre\DAV\Browser\HtmlOutputHelper;
7use Sabre\HTTP;
8use Sabre\Xml\Reader;
9
10class CurrentUserPrivilegeSetTest extends \PHPUnit_Framework_TestCase {
11
12    function testSerialize() {
13
14        $privileges = [
15            '{DAV:}read',
16            '{DAV:}write',
17        ];
18        $prop = new CurrentUserPrivilegeSet($privileges);
19        $xml = (new DAV\Server())->xml->write('{DAV:}root', $prop);
20
21        $expected = <<<XML
22<d:root xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
23    <d:privilege>
24        <d:read />
25    </d:privilege>
26    <d:privilege>
27        <d:write />
28    </d:privilege>
29</d:root>
30XML;
31
32
33        $this->assertXmlStringEqualsXmlString($expected, $xml);
34
35    }
36
37    function testUnserialize() {
38
39        $source = '<?xml version="1.0"?>
40<d:root xmlns:d="DAV:">
41    <d:privilege>
42        <d:write-properties />
43    </d:privilege>
44    <d:ignoreme />
45    <d:privilege>
46        <d:read />
47    </d:privilege>
48</d:root>
49';
50
51        $result = $this->parse($source);
52        $this->assertTrue($result->has('{DAV:}read'));
53        $this->assertTrue($result->has('{DAV:}write-properties'));
54        $this->assertFalse($result->has('{DAV:}bind'));
55
56    }
57
58    function parse($xml) {
59
60        $reader = new Reader();
61        $reader->elementMap['{DAV:}root'] = 'Sabre\\DAVACL\\Xml\\Property\\CurrentUserPrivilegeSet';
62        $reader->xml($xml);
63        $result = $reader->parse();
64        return $result['value'];
65
66    }
67
68    function testToHtml() {
69
70        $privileges = ['{DAV:}read', '{DAV:}write'];
71
72        $prop = new CurrentUserPrivilegeSet($privileges);
73        $html = new HtmlOutputHelper(
74            '/base/',
75            ['DAV:' => 'd']
76        );
77
78        $expected =
79            '<span title="{DAV:}read">d:read</span>, ' .
80            '<span title="{DAV:}write">d:write</span>';
81
82        $this->assertEquals($expected, $prop->toHtml($html));
83
84    }
85
86}
87