ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 245 of file ilSessionTest.php.

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 {
306 return new ilPDOStatement($sqlite->query($query));
307 });
308 $db->method('manipulate')->willReturnCallback(static function (string $query) use ($sqlite): int {
309 return (int) $sqlite->exec($query);
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
330 return $res;
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...
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: