1<?php
2
3namespace Sabre\DAVACL\Xml\Property;
4
5use Sabre\DAV;
6use Sabre\HTTP;
7use Sabre\DAV\Browser\HtmlOutputHelper;
8
9class SupportedPrivilegeSetTest extends \PHPUnit_Framework_TestCase {
10
11    function testSimple() {
12
13        $prop = new SupportedPrivilegeSet([
14            'privilege' => '{DAV:}all',
15        ]);
16        $this->assertInstanceOf('Sabre\DAVACL\Xml\Property\SupportedPrivilegeSet', $prop);
17
18    }
19
20
21    /**
22     * @depends testSimple
23     */
24    function testSerializeSimple() {
25
26        $prop = new SupportedPrivilegeSet([
27            'privilege' => '{DAV:}all',
28        ]);
29
30        $xml = (new DAV\Server())->xml->write('{DAV:}supported-privilege-set', $prop);
31
32        $this->assertXmlStringEqualsXmlString('
33<d:supported-privilege-set xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
34  <d:supported-privilege>
35    <d:privilege>
36      <d:all/>
37    </d:privilege>
38  </d:supported-privilege>
39</d:supported-privilege-set>', $xml);
40
41    }
42
43    /**
44     * @depends testSimple
45     */
46    function testSerializeAggregate() {
47
48        $prop = new SupportedPrivilegeSet([
49            'privilege'  => '{DAV:}all',
50            'abstract'   => true,
51            'aggregates' => [
52                [
53                    'privilege' => '{DAV:}read',
54                ],
55                [
56                    'privilege'   => '{DAV:}write',
57                    'description' => 'booh',
58                ],
59            ],
60        ]);
61
62        $xml = (new DAV\Server())->xml->write('{DAV:}supported-privilege-set', $prop);
63
64        $this->assertXmlStringEqualsXmlString('
65<d:supported-privilege-set xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
66 <d:supported-privilege>
67  <d:privilege>
68   <d:all/>
69  </d:privilege>
70  <d:abstract/>
71  <d:supported-privilege>
72   <d:privilege>
73    <d:read/>
74   </d:privilege>
75  </d:supported-privilege>
76  <d:supported-privilege>
77   <d:privilege>
78    <d:write/>
79   </d:privilege>
80  <d:description>booh</d:description>
81  </d:supported-privilege>
82 </d:supported-privilege>
83</d:supported-privilege-set>', $xml);
84
85    }
86
87    function testToHtml() {
88
89        $prop = new SupportedPrivilegeSet([
90            'privilege'  => '{DAV:}all',
91            'abstract'   => true,
92            'aggregates' => [
93                [
94                    'privilege' => '{DAV:}read',
95                ],
96                [
97                    'privilege'   => '{DAV:}write',
98                    'description' => 'booh',
99                ],
100            ],
101        ]);
102        $html = new HtmlOutputHelper(
103            '/base/',
104            ['DAV:' => 'd']
105        );
106
107        $expected = <<<HTML
108<ul class="tree"><li><span title="{DAV:}all">d:all</span> <i>(abstract)</i>
109<ul>
110<li><span title="{DAV:}read">d:read</span></li>
111<li><span title="{DAV:}write">d:write</span> booh</li>
112</ul></li>
113</ul>
114
115HTML;
116
117        $this->assertEquals($expected, $prop->toHtml($html));
118
119    }
120}
121