ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PrincipalTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\DAVACL;
4 
5 use Sabre\DAV;
6 use Sabre\HTTP;
7 
9 
10  function testConstruct() {
11 
12  $principalBackend = new PrincipalBackend\Mock();
13  $principal = new Principal($principalBackend, ['uri' => 'principals/admin']);
14  $this->assertTrue($principal instanceof Principal);
15 
16  }
17 
21  function testConstructNoUri() {
22 
23  $principalBackend = new PrincipalBackend\Mock();
24  $principal = new Principal($principalBackend, []);
25 
26  }
27 
28  function testGetName() {
29 
30  $principalBackend = new PrincipalBackend\Mock();
31  $principal = new Principal($principalBackend, ['uri' => 'principals/admin']);
32  $this->assertEquals('admin', $principal->getName());
33 
34  }
35 
36  function testGetDisplayName() {
37 
38  $principalBackend = new PrincipalBackend\Mock();
39  $principal = new Principal($principalBackend, ['uri' => 'principals/admin']);
40  $this->assertEquals('admin', $principal->getDisplayname());
41 
42  $principal = new Principal($principalBackend, [
43  'uri' => 'principals/admin',
44  '{DAV:}displayname' => 'Mr. Admin'
45  ]);
46  $this->assertEquals('Mr. Admin', $principal->getDisplayname());
47 
48  }
49 
50  function testGetProperties() {
51 
52  $principalBackend = new PrincipalBackend\Mock();
53  $principal = new Principal($principalBackend, [
54  'uri' => 'principals/admin',
55  '{DAV:}displayname' => 'Mr. Admin',
56  '{http://www.example.org/custom}custom' => 'Custom',
57  '{http://sabredav.org/ns}email-address' => 'admin@example.org',
58  ]);
59 
60  $keys = [
61  '{DAV:}displayname',
62  '{http://www.example.org/custom}custom',
63  '{http://sabredav.org/ns}email-address',
64  ];
65  $props = $principal->getProperties($keys);
66 
67  foreach ($keys as $key) $this->assertArrayHasKey($key, $props);
68 
69  $this->assertEquals('Mr. Admin', $props['{DAV:}displayname']);
70 
71  $this->assertEquals('admin@example.org', $props['{http://sabredav.org/ns}email-address']);
72  }
73 
74  function testUpdateProperties() {
75 
76  $principalBackend = new PrincipalBackend\Mock();
77  $principal = new Principal($principalBackend, ['uri' => 'principals/admin']);
78 
79  $propPatch = new DAV\PropPatch(['{DAV:}yourmom' => 'test']);
80 
81  $result = $principal->propPatch($propPatch);
82  $result = $propPatch->commit();
83  $this->assertTrue($result);
84 
85  }
86 
87  function testGetPrincipalUrl() {
88 
89  $principalBackend = new PrincipalBackend\Mock();
90  $principal = new Principal($principalBackend, ['uri' => 'principals/admin']);
91  $this->assertEquals('principals/admin', $principal->getPrincipalUrl());
92 
93  }
94 
96 
97  $principalBackend = new PrincipalBackend\Mock();
98  $principal = new Principal($principalBackend, [
99  'uri' => 'principals/admin',
100  '{DAV:}displayname' => 'Mr. Admin',
101  '{http://www.example.org/custom}custom' => 'Custom',
102  '{http://sabredav.org/ns}email-address' => 'admin@example.org',
103  '{DAV:}alternate-URI-set' => [
104  'mailto:admin+1@example.org',
105  'mailto:admin+2@example.org',
106  'mailto:admin@example.org',
107  ],
108  ]);
109 
110  $expected = [
111  'mailto:admin+1@example.org',
112  'mailto:admin+2@example.org',
113  'mailto:admin@example.org',
114  ];
115 
116  $this->assertEquals($expected, $principal->getAlternateUriSet());
117 
118  }
120 
121  $principalBackend = new PrincipalBackend\Mock();
122  $principal = new Principal($principalBackend, [
123  'uri' => 'principals/admin',
124  ]);
125 
126  $expected = [];
127 
128  $this->assertEquals($expected, $principal->getAlternateUriSet());
129 
130  }
131 
133 
134  $principalBackend = new PrincipalBackend\Mock();
135  $principal = new Principal($principalBackend, ['uri' => 'principals/admin']);
136  $this->assertEquals([], $principal->getGroupMemberSet());
137 
138  }
140 
141  $principalBackend = new PrincipalBackend\Mock();
142  $principal = new Principal($principalBackend, ['uri' => 'principals/admin']);
143  $this->assertEquals([], $principal->getGroupMembership());
144 
145  }
146 
148 
149  $principalBackend = new PrincipalBackend\Mock();
150  $principal = new Principal($principalBackend, ['uri' => 'principals/admin']);
151  $principal->setGroupMemberSet(['principals/foo']);
152 
153  $this->assertEquals([
154  'principals/admin' => ['principals/foo'],
155  ], $principalBackend->groupMembers);
156 
157  }
158 
159  function testGetOwner() {
160 
161  $principalBackend = new PrincipalBackend\Mock();
162  $principal = new Principal($principalBackend, ['uri' => 'principals/admin']);
163  $this->assertEquals('principals/admin', $principal->getOwner());
164 
165  }
166 
167  function testGetGroup() {
168 
169  $principalBackend = new PrincipalBackend\Mock();
170  $principal = new Principal($principalBackend, ['uri' => 'principals/admin']);
171  $this->assertNull($principal->getGroup());
172 
173  }
174 
175  function testGetACl() {
176 
177  $principalBackend = new PrincipalBackend\Mock();
178  $principal = new Principal($principalBackend, ['uri' => 'principals/admin']);
179  $this->assertEquals([
180  [
181  'privilege' => '{DAV:}all',
182  'principal' => '{DAV:}owner',
183  'protected' => true,
184  ]
185  ], $principal->getACL());
186 
187  }
188 
192  function testSetACl() {
193 
194  $principalBackend = new PrincipalBackend\Mock();
195  $principal = new Principal($principalBackend, ['uri' => 'principals/admin']);
196  $principal->setACL([]);
197 
198  }
199 
201 
202  $principalBackend = new PrincipalBackend\Mock();
203  $principal = new Principal($principalBackend, ['uri' => 'principals/admin']);
204  $this->assertNull($principal->getSupportedPrivilegeSet());
205 
206  }
207 
208 }
This class represents a set of properties that are going to be updated.
Definition: PropPatch.php:20
$result
Principal class.
Definition: Principal.php:23
$keys
$key
Definition: croninfo.php:18
$principalBackend