269 : void
270 {
271 $actual = '';
272 $usr_id = 4711;
273
274 try {
275 $sqlite = new PDO('sqlite::memory:');
276 $create_table = <<<SQL
277create table usr_pwassist
278(
279 pwassist_id char(180) default '' not null primary key,
280 expires int default 0 not null,
281 ctime int default 0 not null,
282 user_id int default 0 not null,
283 constraint c1_idx
284 unique (user_id)
285);
286SQL;
287
288 $sqlite->query($create_table);
289 }
catch (Exception
$e) {
290 $this->markTestIncomplete(
291 'Cannot test the password assistance session storage because of missing sqlite: ' .
$e->getMessage()
292 );
293 }
294
295 $db = $this->createMock(ilDBInterface::class);
296 $db->method('quote')->willReturnCallback(static function ($value, ?string $type = null) use ($sqlite): string {
297 if ($value === null) {
298 return 'NULL';
299 }
300
301 $pdo_type = PDO::PARAM_STR;
302 switch ($type) {
306 if ($value === '') {
307 return 'NULL';
308 }
309 if ($value === 'NOW()') {
310 return $value;
311 }
312 $value = (string) $value;
313 break;
315 return (
string) (
int) $value;
317 $pdo_type = PDO::PARAM_INT;
318 $value = (string) $value;
319 break;
321 default:
322 $value = (string) $value;
323 $pdo_type = PDO::PARAM_STR;
324 break;
325 }
326
327 return $sqlite->quote((string) $value, $pdo_type);
328 });
329 $db->method(
'query')->willReturnCallback(
static function (
string $query) use ($sqlite):
ilDBStatement {
331 });
332 $db->method(
'manipulate')->willReturnCallback(
static function (
string $query) use ($sqlite):
int {
334 });
335 $db->method(
'manipulateF')->willReturnCallback(
static function (...$args) use ($db):
int {
336 $query = $args[0];
337
338 $quoted_values = [];
339 foreach ($args[1] as $k => $t) {
340 $quoted_values[] = $db->quote($args[2][$k], $t);
341 }
342 $query = vsprintf($query, $quoted_values);
343
344 return $db->manipulate($query);
345 });
346 $db->method(
'fetchAssoc')->willReturnCallback(
static function (
ilDBStatement $statement): ?array {
347 $res = $statement->
fetch(PDO::FETCH_ASSOC);
348 if (
$res ===
null ||
$res ===
false) {
349 $statement->closeCursor();
350
351 return null;
352 }
353
355 });
356
357 $pwa_repository = new \ILIAS\Init\PasswordAssitance\Repository\PasswordAssistanceDbRepository(
358 $db,
359 (
new \
ILIAS\Data\Factory())->clock()->system()
360 );
361
362 $hash = new \ILIAS\Init\PasswordAssitance\ValueObject\PasswordAssistanceHash(
363 'ae869e66007cc9812f1752f7a3a59f07d3e28bed8361827d0a05563e5c2f4b11'
364 );
365 $session = $pwa_repository->createSession(
366 $hash,
367 (
new \
ILIAS\Data\Factory())->objId($usr_id)
368 );
369
370 $result = $pwa_repository->getSessionByUsrId($session->usrId());
371 if ($result->value()->hash()->value() === $session->hash()->value()) {
372 $actual .= 'find-';
373 }
374
375 $result = $pwa_repository->getSessionByHash($session->hash());
376 if ($result->value()->usrId()->toInt() === $usr_id) {
377 $actual .= 'read-';
378 }
379
380 $pwa_repository->deleteSession($session);
381 $result = $pwa_repository->getSessionByHash($session->hash());
382 if ($result->isError()) {
383 $actual .= 'destroy-';
384 }
385
386 $this->assertEquals('find-read-destroy-', $actual);
387
388 $sqlite = null;
389 }
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.