251 $sqlite =
new PDO(
'sqlite::memory:');
252 $create_table = <<<SQL
253 create table usr_pwassist
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,
264 $sqlite->query($create_table);
266 $this->markTestIncomplete(
267 'Cannot test the password assistance session storage because of missing sqlite: ' . $e->getMessage()
271 $db = $this->createMock(ilDBInterface::class);
272 $db->method(
'quote')->willReturnCallback(
static function ($value, ?
string $type = null) use ($sqlite):
string {
273 if ($value === null) {
277 $pdo_type = PDO::PARAM_STR;
285 if ($value ===
'NOW()') {
288 $value = (string) $value;
291 return (
string) (
int) $value;
293 $pdo_type = PDO::PARAM_INT;
294 $value = (string) $value;
298 $value = (string) $value;
299 $pdo_type = PDO::PARAM_STR;
303 return $sqlite->quote((
string) $value, $pdo_type);
305 $db->method(
'query')->willReturnCallback(
static function (
string $query) use ($sqlite):
ilDBStatement {
308 $db->method(
'manipulate')->willReturnCallback(
static function (
string $query) use ($sqlite):
int {
309 return (
int) $sqlite->exec($query);
311 $db->method(
'manipulateF')->willReturnCallback(
static function (...$args) use ($db):
int {
315 foreach ($args[1] as $k => $t) {
316 $quoted_values[] = $db->quote($args[2][$k], $t);
318 $query = vsprintf($query, $quoted_values);
320 return $db->manipulate($query);
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();
338 require_once __DIR__ .
'/../../../../cli/inc.pwassist_session_handler.php';
345 if (
$res[
'pwassist_id'] ===
'12345') {
351 if ((
int)
$res[
'user_id'] === $usr_id) {
359 $result .=
'destroy-';
364 $this->assertEquals(
'find-read-destroy-', $result);
setGlobalVariable(string $name, $value)
db_pwassist_session_destroy(string $pwassist_id)
Class ilPDOStatement is a Wrapper Class for PDOStatement.
fetch(int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
db_pwassist_session_read(string $pwassist_id)
db_pwassist_session_write(string $pwassist_id, int $maxlifetime, int $user_id)
db_pwassist_session_find(int $user_id)