ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PrincipalTest.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use Sabre\DAV;
7 use Sabre\HTTP;
9 
11 
12  function testSimple() {
13 
14  $principal = new Principal(Principal::UNAUTHENTICATED);
15  $this->assertEquals(Principal::UNAUTHENTICATED, $principal->getType());
16  $this->assertNull($principal->getHref());
17 
18  $principal = new Principal(Principal::AUTHENTICATED);
19  $this->assertEquals(Principal::AUTHENTICATED, $principal->getType());
20  $this->assertNull($principal->getHref());
21 
22  $principal = new Principal(Principal::HREF, 'admin');
23  $this->assertEquals(Principal::HREF, $principal->getType());
24  $this->assertEquals('admin/', $principal->getHref());
25 
26  }
27 
32  function testNoHref() {
33 
34  $principal = new Principal(Principal::HREF);
35 
36  }
37 
42 
44 
45  $xml = (new DAV\Server())->xml->write('{DAV:}principal', $prin);
46 
47  $this->assertXmlStringEqualsXmlString('
48 <d:principal xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
49 <d:unauthenticated/>
50 </d:principal>', $xml);
51 
52  }
53 
54 
59 
61  $xml = (new DAV\Server())->xml->write('{DAV:}principal', $prin);
62 
63  $this->assertXmlStringEqualsXmlString('
64 <d:principal xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
65 <d:authenticated/>
66 </d:principal>', $xml);
67 
68  }
69 
70 
74  function testSerializeHref() {
75 
76  $prin = new Principal(Principal::HREF, 'principals/admin');
77  $xml = (new DAV\Server())->xml->write('{DAV:}principal', $prin, '/');
78 
79  $this->assertXmlStringEqualsXmlString('
80 <d:principal xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
81 <d:href>/principals/admin/</d:href>
82 </d:principal>', $xml);
83 
84  }
85 
86  function testUnserializeHref() {
87 
88  $xml = '<?xml version="1.0"?>
89 <d:principal xmlns:d="DAV:">' .
90 '<d:href>/principals/admin</d:href>' .
91 '</d:principal>';
92 
93  $principal = $this->parse($xml);
94  $this->assertEquals(Principal::HREF, $principal->getType());
95  $this->assertEquals('/principals/admin/', $principal->getHref());
96 
97  }
98 
100 
101  $xml = '<?xml version="1.0"?>
102 <d:principal xmlns:d="DAV:">' .
103 ' <d:authenticated />' .
104 '</d:principal>';
105 
106  $principal = $this->parse($xml);
107  $this->assertEquals(Principal::AUTHENTICATED, $principal->getType());
108 
109  }
110 
112 
113  $xml = '<?xml version="1.0"?>
114 <d:principal xmlns:d="DAV:">' .
115 ' <d:unauthenticated />' .
116 '</d:principal>';
117 
118  $principal = $this->parse($xml);
119  $this->assertEquals(Principal::UNAUTHENTICATED, $principal->getType());
120 
121  }
122 
127 
128  $xml = '<?xml version="1.0"?>
129 <d:principal xmlns:d="DAV:">' .
130 ' <d:foo />' .
131 '</d:principal>';
132 
133  $this->parse($xml);
134 
135  }
136 
137  function parse($xml) {
138 
139  $reader = new Reader();
140  $reader->elementMap['{DAV:}principal'] = 'Sabre\\DAVACL\\Xml\\Property\\Principal';
141  $reader->xml($xml);
142  $result = $reader->parse();
143  return $result['value'];
144 
145  }
146 
151  function testToHtml($principal, $output) {
152 
153  $html = $principal->toHtml(new HtmlOutputHelper('/', []));
154 
155  $this->assertXmlStringEqualsXmlString(
156  $output,
157  $html
158  );
159 
160  }
161 
167  function htmlProvider() {
168 
169  return [
170  [
172  '<em>unauthenticated</em>',
173  ],
174  [
176  '<em>authenticated</em>',
177  ],
178  [
180  '<em>all</em>',
181  ],
182  [
183  new Principal(Principal::HREF, 'principals/admin'),
184  '<a href="/principals/admin/">/principals/admin/</a>',
185  ],
186 
187  ];
188 
189  }
190 
191 }
$result
htmlProvider()
Provides data for the html tests.
testSerializeHref()
testSerializeUnAuthenticated
const ALL
Everybody, basically.
Definition: Principal.php:41
const UNAUTHENTICATED
To specify a not-logged-in user, use the UNAUTHENTICATED principal.
Definition: Principal.php:26
The Reader class expands upon PHP&#39;s built-in XMLReader.
Definition: Reader.php:20
const AUTHENTICATED
To specify any principal that is logged in, use AUTHENTICATED.
Definition: Principal.php:31
Main DAV server class.
Definition: Server.php:23
testSerializeAuthenticated()
testSerializeUnAuthenticated
const HREF
Specific principals can be specified with the HREF.
Definition: Principal.php:36
$html
Definition: example_001.php:87
testToHtml($principal, $output)
testSimple htmlProvider
This class provides a few utility functions for easily generating HTML for the browser plugin...