ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Mock.php
Go to the documentation of this file.
1<?php
2
4
5class Mock extends AbstractBackend {
6
7 public $groupMembers = [];
8 public $principals;
9
10 function __construct(array $principals = null) {
11
12 $this->principals = $principals;
13
14 if (is_null($principals)) {
15
16 $this->principals = [
17 [
18 'uri' => 'principals/user1',
19 '{DAV:}displayname' => 'User 1',
20 '{http://sabredav.org/ns}email-address' => 'user1.sabredav@sabredav.org',
21 '{http://sabredav.org/ns}vcard-url' => 'addressbooks/user1/book1/vcard1.vcf',
22 ],
23 [
24 'uri' => 'principals/admin',
25 '{DAV:}displayname' => 'Admin',
26 ],
27 [
28 'uri' => 'principals/user2',
29 '{DAV:}displayname' => 'User 2',
30 '{http://sabredav.org/ns}email-address' => 'user2.sabredav@sabredav.org',
31 ],
32 ];
33
34 }
35
36 }
37
38 function getPrincipalsByPrefix($prefix) {
39
40 $prefix = trim($prefix, '/');
41 if ($prefix) $prefix .= '/';
42 $return = [];
43
44 foreach ($this->principals as $principal) {
45
46 if ($prefix && strpos($principal['uri'], $prefix) !== 0) continue;
47
48 $return[] = $principal;
49
50 }
51
52 return $return;
53
54 }
55
56 function addPrincipal(array $principal) {
57
58 $this->principals[] = $principal;
59
60 }
61
63
64 foreach ($this->getPrincipalsByPrefix('principals') as $principal) {
65 if ($principal['uri'] === $path) return $principal;
66 }
67
68 }
69
70 function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') {
71
72 $matches = [];
73 foreach ($this->getPrincipalsByPrefix($prefixPath) as $principal) {
74
75 foreach ($searchProperties as $key => $value) {
76
77 if (!isset($principal[$key])) {
78 continue 2;
79 }
80 if (mb_stripos($principal[$key], $value, 0, 'UTF-8') === false) {
81 continue 2;
82 }
83
84 // We have a match for this searchProperty!
85 if ($test === 'allof') {
86 continue;
87 } else {
88 break;
89 }
90
91 }
92 $matches[] = $principal['uri'];
93
94 }
95 return $matches;
96
97 }
98
100
101 return isset($this->groupMembers[$path]) ? $this->groupMembers[$path] : [];
102
103 }
104
106
107 $membership = [];
108 foreach ($this->groupMembers as $group => $members) {
109 if (in_array($path, $members)) $membership[] = $group;
110 }
111 return $membership;
112
113 }
114
115 function setGroupMemberSet($path, array $members) {
116
117 $this->groupMembers[$path] = $members;
118
119 }
120
136 function updatePrincipal($path, \Sabre\DAV\PropPatch $propPatch) {
137
138 $value = null;
139 foreach ($this->principals as $principalIndex => $value) {
140 if ($value['uri'] === $path) {
141 $principal = $value;
142 break;
143 }
144 }
145 if (!$principal) return;
146
147 $propPatch->handleRemaining(function($mutations) use ($principal, $principalIndex) {
148
149 foreach ($mutations as $prop => $value) {
150
151 if (is_null($value) && isset($principal[$prop])) {
152 unset($principal[$prop]);
153 } else {
154 $principal[$prop] = $value;
155 }
156
157 }
158
159 $this->principals[$principalIndex] = $principal;
160
161 return true;
162
163 });
164
165 }
166
167
168}
$test
Definition: Utf8Test.php:84
$path
Definition: aliased.php:25
An exception for terminatinating execution or to throw for unit testing.
getGroupMembership($path)
Returns the list of groups a principal is a member of.
Definition: Mock.php:105
searchPrincipals($prefixPath, array $searchProperties, $test='allof')
This method is used to search for principals matching a set of properties.
Definition: Mock.php:70
addPrincipal(array $principal)
Definition: Mock.php:56
getPrincipalsByPrefix($prefix)
Returns a list of principals based on a prefix.
Definition: Mock.php:38
setGroupMemberSet($path, array $members)
Updates the list of group members for a group principal.
Definition: Mock.php:115
getGroupMemberSet($path)
Returns the list of members for a group-principal.
Definition: Mock.php:99
getPrincipalByPath($path)
Returns a specific principal, specified by it's path.
Definition: Mock.php:62
updatePrincipal($path, \Sabre\DAV\PropPatch $propPatch)
Updates one ore more webdav properties on a principal.
Definition: Mock.php:136
__construct(array $principals=null)
Definition: Mock.php:10
This class represents a set of properties that are going to be updated.
Definition: PropPatch.php:20
$key
Definition: croninfo.php:18