ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
CurrentUserPrivilegeSetTest.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use Sabre\DAV;
7 use Sabre\HTTP;
9 
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>
30 XML;
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 }
$result
The Reader class expands upon PHP&#39;s built-in XMLReader.
Definition: Reader.php:20
Main DAV server class.
Definition: Server.php:23
$source
Definition: linkback.php:22
$html
Definition: example_001.php:87
This class provides a few utility functions for easily generating HTML for the browser plugin...