245 : void
246 {
247 $actual = '';
248 $usr_id = 4711;
249
250 try {
251 $sqlite = new PDO('sqlite::memory:');
252 $create_table = <<<SQL
253create table usr_pwassist
254(
255 pwassist_id char(180) default '' not null primary key,
256 expires int default 0 not null,
257 ctime int default 0 not null,
258 user_id int default 0 not null,
259 constraint c1_idx
260 unique (user_id)
261);
262SQL;
263
264 $sqlite->query($create_table);
265 }
catch (Exception
$e) {
266 $this->markTestIncomplete(
267 'Cannot test the password assistance session storage because of missing sqlite: ' .
$e->getMessage()
268 );
269 }
270
271 $db = $this->createMock(ilDBInterface::class);
272 $db->method('quote')->willReturnCallback(static function ($value, ?string $type = null) use ($sqlite): string {
273 if ($value === null) {
274 return 'NULL';
275 }
276
277 $pdo_type = PDO::PARAM_STR;
278 switch ($type) {
282 if ($value === '') {
283 return 'NULL';
284 }
285 if ($value === 'NOW()') {
286 return $value;
287 }
288 $value = (string) $value;
289 break;
291 return (
string) (
int) $value;
293 $pdo_type = PDO::PARAM_INT;
294 $value = (string) $value;
295 break;
297 default:
298 $value = (string) $value;
299 $pdo_type = PDO::PARAM_STR;
300 break;
301 }
302
303 return $sqlite->quote((string) $value, $pdo_type);
304 });
305 $db->method(
'query')->willReturnCallback(
static function (
string $query) use ($sqlite):
ilDBStatement {
307 });
308 $db->method(
'manipulate')->willReturnCallback(
static function (
string $query) use ($sqlite):
int {
310 });
311 $db->method(
'manipulateF')->willReturnCallback(
static function (...$args) use ($db):
int {
312 $query = $args[0];
313
314 $quoted_values = [];
315 foreach ($args[1] as $k => $t) {
316 $quoted_values[] = $db->quote($args[2][$k], $t);
317 }
318 $query = vsprintf($query, $quoted_values);
319
320 return $db->manipulate($query);
321 });
322 $db->method(
'fetchAssoc')->willReturnCallback(
static function (
ilDBStatement $statement): ?array {
323 $res = $statement->
fetch(PDO::FETCH_ASSOC);
324 if (
$res ===
null ||
$res ===
false) {
325 $statement->closeCursor();
326
327 return null;
328 }
329
331 });
332
333 $pwa_repository = new \ILIAS\Init\PasswordAssitance\Repository\PasswordAssistanceDbRepository(
334 $db,
335 (
new \
ILIAS\Data\Factory())->clock()->system()
336 );
337
338 $hash = new \ILIAS\Init\PasswordAssitance\ValueObject\PasswordAssistanceHash(
339 'ae869e66007cc9812f1752f7a3a59f07d3e28bed8361827d0a05563e5c2f4b11'
340 );
341 $session = $pwa_repository->createSession(
342 $hash,
343 (
new \
ILIAS\Data\Factory())->objId($usr_id)
344 );
345
346 $result = $pwa_repository->getSessionByUsrId($session->usrId());
347 if ($result->value()->hash()->value() === $session->hash()->value()) {
348 $actual .= 'find-';
349 }
350
351 $result = $pwa_repository->getSessionByHash($session->hash());
352 if ($result->value()->usrId()->toInt() === $usr_id) {
353 $actual .= 'read-';
354 }
355
356 $pwa_repository->deleteSession($session);
357 $result = $pwa_repository->getSessionByHash($session->hash());
358 if ($result->isError()) {
359 $actual .= 'destroy-';
360 }
361
362 $this->assertEquals('find-read-destroy-', $actual);
363
364 $sqlite = null;
365 }
Class ilPDOStatement is a Wrapper Class for PDOStatement.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
fetch(int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.