ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
ilSessionTest Class Reference
+ Inheritance diagram for ilSessionTest:
+ Collaboration diagram for ilSessionTest:

Public Member Functions

 testPasswordAssisstanceSession ()
 

Protected Member Functions

 setUp ()
 
 tearDown ()
 
 setGlobalVariable (string $name, $value)
 

Private Attributes

Container $dic_backup = null
 

Detailed Description

Definition at line 24 of file ilSessionTest.php.

Member Function Documentation

◆ setGlobalVariable()

ilSessionTest::setGlobalVariable ( string  $name,
  $value 
)
protected
Parameters
string$name
mixed$value

Definition at line 59 of file ilSessionTest.php.

59 : void
60 {
61 global $DIC;
62
63 $GLOBALS[$name] = $value;
64
65 unset($DIC[$name]);
66 $DIC[$name] = static function (Container $c) use ($name) {
67 return $GLOBALS[$name];
68 };
69 }
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
$c
Definition: deliver.php:25
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54

References $c, $DIC, and $GLOBALS.

Referenced by setUp().

+ Here is the caller graph for this function:

◆ setUp()

ilSessionTest::setUp ( )
protected

Definition at line 28 of file ilSessionTest.php.

28 : void
29 {
30 global $DIC;
31
32 $this->dic_backup = $DIC;
33
34 if (!isset($DIC)) {
35 $DIC = new Container();
36 }
37
38 $this->setGlobalVariable(
39 'ilDB',
40 $this->createMock(ilDBInterface::class)
41 );
42
43 parent::setUp();
44 }
setGlobalVariable(string $name, $value)

References $DIC, and setGlobalVariable().

+ Here is the call graph for this function:

◆ tearDown()

ilSessionTest::tearDown ( )
protected

Definition at line 46 of file ilSessionTest.php.

46 : void
47 {
48 global $DIC;
49
51
52 parent::tearDown();
53 }
Container $dic_backup

References $DIC, and $dic_backup.

◆ testPasswordAssisstanceSession()

ilSessionTest::testPasswordAssisstanceSession ( )

Definition at line 269 of file ilSessionTest.php.

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 {
330 return new ilPDOStatement($sqlite->query($query));
331 });
332 $db->method('manipulate')->willReturnCallback(static function (string $query) use ($sqlite): int {
333 return (int) $sqlite->exec($query);
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
354 return $res;
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...
Interface ilDBStatement.
fetch(int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
$res
Definition: ltiservices.php:69
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.

References Vendor\Package\$e, $res, ilDBStatement\fetch(), ILIAS\Repository\int(), ilDBConstants\T_DATE, ilDBConstants\T_DATETIME, ilDBConstants\T_FLOAT, ilDBConstants\T_INTEGER, ilDBConstants\T_TEXT, and ilDBConstants\T_TIMESTAMP.

+ Here is the call graph for this function:

Field Documentation

◆ $dic_backup

Container ilSessionTest::$dic_backup = null
private

Definition at line 26 of file ilSessionTest.php.

Referenced by tearDown().


The documentation for this class was generated from the following file: