Add more tests

This commit is contained in:
Dmitrii Metelkin 2019-11-17 00:19:48 +11:00
parent 75f5fa7e15
commit 1f8860f189

View file

@ -1053,4 +1053,35 @@ class auth_plugin_userkey_testcase extends advanced_testcase {
}
}
/**
* Test if a user is logged in and tries to log in again it stays logged in.
*/
public function test_that_already_logged_in_user_stays_logged_in() {
global $DB, $USER, $SESSION;
$this->setUser($this->user);
$this->assertEquals($USER->id, $this->user->id);
$key = new stdClass();
$key->value = 'UserLogin';
$key->script = 'auth/userkey';
$key->userid = $this->user->id;
$key->instance = $this->user->id;
$key->iprestriction = null;
$key->validuntil = time() + 300;
$key->timecreated = time();
$DB->insert_record('user_private_key', $key);
$_POST['key'] = 'UserLogin';
try {
// Using @ is the only way to test this. Thanks moodle!
@$this->auth->user_login_userkey();
} catch (moodle_exception $e) {
$this->assertEquals($this->user->id, $USER->id);
$this->assertSame(sesskey(), $USER->sesskey);
$this->assertObjectHasAttribute('userkey', $SESSION);
}
}
}