ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AbstractPDOTest.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use Sabre\DAV;
6 use Sabre\HTTP;
7 
9 
11 
12  function setUp() {
13 
14  $this->dropTables(['principals', 'groupmembers']);
15  $this->createSchema('principals');
16 
17  $pdo = $this->getPDO();
18 
19  $pdo->query("INSERT INTO principals (uri,email,displayname) VALUES ('principals/user','user@example.org','User')");
20  $pdo->query("INSERT INTO principals (uri,email,displayname) VALUES ('principals/group','group@example.org','Group')");
21 
22  $pdo->query("INSERT INTO groupmembers (principal_id,member_id) VALUES (5,4)");
23 
24  }
25 
26 
27  function testConstruct() {
28 
29  $pdo = $this->getPDO();
30  $backend = new PDO($pdo);
31  $this->assertTrue($backend instanceof PDO);
32 
33  }
34 
39 
40  $pdo = $this->getPDO();
41  $backend = new PDO($pdo);
42 
43  $expected = [
44  [
45  'uri' => 'principals/admin',
46  '{http://sabredav.org/ns}email-address' => 'admin@example.org',
47  '{DAV:}displayname' => 'Administrator',
48  ],
49  [
50  'uri' => 'principals/user',
51  '{http://sabredav.org/ns}email-address' => 'user@example.org',
52  '{DAV:}displayname' => 'User',
53  ],
54  [
55  'uri' => 'principals/group',
56  '{http://sabredav.org/ns}email-address' => 'group@example.org',
57  '{DAV:}displayname' => 'Group',
58  ],
59  ];
60 
61  $this->assertEquals($expected, $backend->getPrincipalsByPrefix('principals'));
62  $this->assertEquals([], $backend->getPrincipalsByPrefix('foo'));
63 
64  }
65 
70 
71  $pdo = $this->getPDO();
72  $backend = new PDO($pdo);
73 
74  $expected = [
75  'id' => 4,
76  'uri' => 'principals/user',
77  '{http://sabredav.org/ns}email-address' => 'user@example.org',
78  '{DAV:}displayname' => 'User',
79  ];
80 
81  $this->assertEquals($expected, $backend->getPrincipalByPath('principals/user'));
82  $this->assertEquals(null, $backend->getPrincipalByPath('foo'));
83 
84  }
85 
86  function testGetGroupMemberSet() {
87 
88  $pdo = $this->getPDO();
89  $backend = new PDO($pdo);
90  $expected = ['principals/user'];
91 
92  $this->assertEquals($expected, $backend->getGroupMemberSet('principals/group'));
93 
94  }
95 
97 
98  $pdo = $this->getPDO();
99  $backend = new PDO($pdo);
100  $expected = ['principals/group'];
101 
102  $this->assertEquals($expected, $backend->getGroupMembership('principals/user'));
103 
104  }
105 
107 
108  $pdo = $this->getPDO();
109 
110  // Start situation
111  $backend = new PDO($pdo);
112  $this->assertEquals(['principals/user'], $backend->getGroupMemberSet('principals/group'));
113 
114  // Removing all principals
115  $backend->setGroupMemberSet('principals/group', []);
116  $this->assertEquals([], $backend->getGroupMemberSet('principals/group'));
117 
118  // Adding principals again
119  $backend->setGroupMemberSet('principals/group', ['principals/user']);
120  $this->assertEquals(['principals/user'], $backend->getGroupMemberSet('principals/group'));
121 
122 
123  }
124 
125  function testSearchPrincipals() {
126 
127  $pdo = $this->getPDO();
128 
129  $backend = new PDO($pdo);
130 
131  $result = $backend->searchPrincipals('principals', ['{DAV:}blabla' => 'foo']);
132  $this->assertEquals([], $result);
133 
134  $result = $backend->searchPrincipals('principals', ['{DAV:}displayname' => 'ou']);
135  $this->assertEquals(['principals/group'], $result);
136 
137  $result = $backend->searchPrincipals('principals', ['{DAV:}displayname' => 'UsEr', '{http://sabredav.org/ns}email-address' => 'USER@EXAMPLE']);
138  $this->assertEquals(['principals/user'], $result);
139 
140  $result = $backend->searchPrincipals('mom', ['{DAV:}displayname' => 'UsEr', '{http://sabredav.org/ns}email-address' => 'USER@EXAMPLE']);
141  $this->assertEquals([], $result);
142 
143  }
144 
145  function testUpdatePrincipal() {
146 
147  $pdo = $this->getPDO();
148  $backend = new PDO($pdo);
149 
150  $propPatch = new DAV\PropPatch([
151  '{DAV:}displayname' => 'pietje',
152  ]);
153 
154  $backend->updatePrincipal('principals/user', $propPatch);
155  $result = $propPatch->commit();
156 
157  $this->assertTrue($result);
158 
159  $this->assertEquals([
160  'id' => 4,
161  'uri' => 'principals/user',
162  '{DAV:}displayname' => 'pietje',
163  '{http://sabredav.org/ns}email-address' => 'user@example.org',
164  ], $backend->getPrincipalByPath('principals/user'));
165 
166  }
167 
169 
170  $pdo = $this->getPDO();
171  $backend = new PDO($pdo);
172 
173  $propPatch = new DAV\PropPatch([
174  '{DAV:}displayname' => 'pietje',
175  '{DAV:}unknown' => 'foo',
176  ]);
177 
178  $backend->updatePrincipal('principals/user', $propPatch);
179  $result = $propPatch->commit();
180 
181  $this->assertFalse($result);
182 
183  $this->assertEquals([
184  '{DAV:}displayname' => 424,
185  '{DAV:}unknown' => 403
186  ], $propPatch->getResult());
187 
188  $this->assertEquals([
189  'id' => '4',
190  'uri' => 'principals/user',
191  '{DAV:}displayname' => 'User',
192  '{http://sabredav.org/ns}email-address' => 'user@example.org',
193  ], $backend->getPrincipalByPath('principals/user'));
194 
195  }
196 
198 
199  $pdo = $this->getPDO();
200  $backend = new PDO($pdo);
201  $this->assertNull($backend->findByUri('http://foo', 'principals'));
202 
203  }
204 
205 
206  function testFindByUri() {
207 
208  $pdo = $this->getPDO();
209  $backend = new PDO($pdo);
210  $this->assertEquals(
211  'principals/user',
212  $backend->findByUri('mailto:user@example.org', 'principals')
213  );
214 
215  }
216 
217 }
This class represents a set of properties that are going to be updated.
Definition: PropPatch.php:20
$result
getPDO()
Alias for getDb.
dropTables($tableNames)
Drops tables, if they exist.
createSchema($schemaName)
Uses .sql files from the examples directory to initialize the database.
trait DbTestHelperTrait
$pdo
Definition: migrateto20.php:62