Fix existing tests for core key manager class after changing the interface
This commit is contained in:
parent
cbfbb5cb8a
commit
b93919bf5f
1 changed files with 26 additions and 37 deletions
|
@ -58,18 +58,7 @@ class core_userkey_manager_testcase extends advanced_testcase {
|
||||||
* Test that core_userkey_manager implements userkey_manager_interface interface.
|
* Test that core_userkey_manager implements userkey_manager_interface interface.
|
||||||
*/
|
*/
|
||||||
public function test_implements_userkey_manager_interface() {
|
public function test_implements_userkey_manager_interface() {
|
||||||
$manager = new core_userkey_manager($this->user->id, $this->config);
|
$manager = new core_userkey_manager($this->config);
|
||||||
|
|
||||||
$expected = 'auth_userkey\userkey_manager_interface';
|
|
||||||
$this->assertInstanceOf($expected, $manager);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that we can use user ID of not existing user.
|
|
||||||
*/
|
|
||||||
public function test_that_manager_does_not_care_if_user_is_not_exists() {
|
|
||||||
$brokenuserid = 500;
|
|
||||||
$manager = new core_userkey_manager($brokenuserid, $this->config);
|
|
||||||
|
|
||||||
$expected = 'auth_userkey\userkey_manager_interface';
|
$expected = 'auth_userkey\userkey_manager_interface';
|
||||||
$this->assertInstanceOf($expected, $manager);
|
$this->assertInstanceOf($expected, $manager);
|
||||||
|
@ -82,8 +71,8 @@ class core_userkey_manager_testcase extends advanced_testcase {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$_SERVER['HTTP_CLIENT_IP'] = '192.168.1.1';
|
$_SERVER['HTTP_CLIENT_IP'] = '192.168.1.1';
|
||||||
$manager = new core_userkey_manager($this->user->id, $this->config);
|
$manager = new core_userkey_manager($this->config);
|
||||||
$value = $manager->create_key();
|
$value = $manager->create_key($this->user->id);
|
||||||
|
|
||||||
$actualkey = $DB->get_record('user_private_key', array('userid' => $this->user->id));
|
$actualkey = $DB->get_record('user_private_key', array('userid' => $this->user->id));
|
||||||
|
|
||||||
|
@ -103,8 +92,8 @@ class core_userkey_manager_testcase extends advanced_testcase {
|
||||||
|
|
||||||
$this->config->iprestriction = true;
|
$this->config->iprestriction = true;
|
||||||
$_SERVER['HTTP_CLIENT_IP'] = '192.168.1.1';
|
$_SERVER['HTTP_CLIENT_IP'] = '192.168.1.1';
|
||||||
$manager = new core_userkey_manager($this->user->id, $this->config);
|
$manager = new core_userkey_manager($this->config);
|
||||||
$value = $manager->create_key();
|
$value = $manager->create_key($this->user->id);
|
||||||
|
|
||||||
$actualkey = $DB->get_record('user_private_key', array('userid' => $this->user->id));
|
$actualkey = $DB->get_record('user_private_key', array('userid' => $this->user->id));
|
||||||
|
|
||||||
|
@ -123,8 +112,8 @@ class core_userkey_manager_testcase extends advanced_testcase {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$this->config->iprestriction = true;
|
$this->config->iprestriction = true;
|
||||||
$manager = new core_userkey_manager($this->user->id, $this->config, '192.168.1.3');
|
$manager = new core_userkey_manager($this->config);
|
||||||
$value = $manager->create_key();
|
$value = $manager->create_key($this->user->id, '192.168.1.3');
|
||||||
|
|
||||||
$actualkey = $DB->get_record('user_private_key', array('userid' => $this->user->id));
|
$actualkey = $DB->get_record('user_private_key', array('userid' => $this->user->id));
|
||||||
|
|
||||||
|
@ -144,8 +133,8 @@ class core_userkey_manager_testcase extends advanced_testcase {
|
||||||
|
|
||||||
$this->config->iprestriction = false;
|
$this->config->iprestriction = false;
|
||||||
$_SERVER['HTTP_CLIENT_IP'] = '192.168.1.1';
|
$_SERVER['HTTP_CLIENT_IP'] = '192.168.1.1';
|
||||||
$manager = new core_userkey_manager($this->user->id, $this->config);
|
$manager = new core_userkey_manager($this->config);
|
||||||
$value = $manager->create_key();
|
$value = $manager->create_key($this->user->id);
|
||||||
|
|
||||||
$actualkey = $DB->get_record('user_private_key', array('userid' => $this->user->id));
|
$actualkey = $DB->get_record('user_private_key', array('userid' => $this->user->id));
|
||||||
|
|
||||||
|
@ -165,8 +154,8 @@ class core_userkey_manager_testcase extends advanced_testcase {
|
||||||
|
|
||||||
$this->config->iprestriction = false;
|
$this->config->iprestriction = false;
|
||||||
$_SERVER['HTTP_CLIENT_IP'] = '192.168.1.1';
|
$_SERVER['HTTP_CLIENT_IP'] = '192.168.1.1';
|
||||||
$manager = new core_userkey_manager($this->user->id, $this->config, '192.168.1.1');
|
$manager = new core_userkey_manager($this->config);
|
||||||
$value = $manager->create_key();
|
$value = $manager->create_key($this->user->id, '192.168.1.1');
|
||||||
|
|
||||||
$actualkey = $DB->get_record('user_private_key', array('userid' => $this->user->id));
|
$actualkey = $DB->get_record('user_private_key', array('userid' => $this->user->id));
|
||||||
|
|
||||||
|
@ -186,8 +175,8 @@ class core_userkey_manager_testcase extends advanced_testcase {
|
||||||
|
|
||||||
$this->config->iprestriction = 'string';
|
$this->config->iprestriction = 'string';
|
||||||
$_SERVER['HTTP_CLIENT_IP'] = '192.168.1.1';
|
$_SERVER['HTTP_CLIENT_IP'] = '192.168.1.1';
|
||||||
$manager = new core_userkey_manager($this->user->id, $this->config);
|
$manager = new core_userkey_manager($this->config);
|
||||||
$value = $manager->create_key();
|
$value = $manager->create_key($this->user->id);
|
||||||
|
|
||||||
$actualkey = $DB->get_record('user_private_key', array('userid' => $this->user->id));
|
$actualkey = $DB->get_record('user_private_key', array('userid' => $this->user->id));
|
||||||
|
|
||||||
|
@ -205,8 +194,8 @@ class core_userkey_manager_testcase extends advanced_testcase {
|
||||||
public function test_create_correct_key_if_keylifetime_is_not_set() {
|
public function test_create_correct_key_if_keylifetime_is_not_set() {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$manager = new core_userkey_manager($this->user->id, $this->config);
|
$manager = new core_userkey_manager($this->config);
|
||||||
$value = $manager->create_key();
|
$value = $manager->create_key($this->user->id);
|
||||||
|
|
||||||
$actualkey = $DB->get_record('user_private_key', array('userid' => $this->user->id));
|
$actualkey = $DB->get_record('user_private_key', array('userid' => $this->user->id));
|
||||||
|
|
||||||
|
@ -226,8 +215,8 @@ class core_userkey_manager_testcase extends advanced_testcase {
|
||||||
|
|
||||||
$this->config->keylifetime = 3000;
|
$this->config->keylifetime = 3000;
|
||||||
|
|
||||||
$manager = new core_userkey_manager($this->user->id, $this->config);
|
$manager = new core_userkey_manager($this->config);
|
||||||
$value = $manager->create_key();
|
$value = $manager->create_key($this->user->id);
|
||||||
|
|
||||||
$actualkey = $DB->get_record('user_private_key', array('userid' => $this->user->id));
|
$actualkey = $DB->get_record('user_private_key', array('userid' => $this->user->id));
|
||||||
|
|
||||||
|
@ -248,8 +237,8 @@ class core_userkey_manager_testcase extends advanced_testcase {
|
||||||
|
|
||||||
$this->config->keylifetime = '3000';
|
$this->config->keylifetime = '3000';
|
||||||
|
|
||||||
$manager = new core_userkey_manager($this->user->id, $this->config);
|
$manager = new core_userkey_manager($this->config);
|
||||||
$value = $manager->create_key();
|
$value = $manager->create_key($this->user->id);
|
||||||
|
|
||||||
$actualkey = $DB->get_record('user_private_key', array('userid' => $this->user->id));
|
$actualkey = $DB->get_record('user_private_key', array('userid' => $this->user->id));
|
||||||
|
|
||||||
|
@ -268,13 +257,13 @@ class core_userkey_manager_testcase extends advanced_testcase {
|
||||||
public function test_can_delete_created_key() {
|
public function test_can_delete_created_key() {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$manager = new core_userkey_manager($this->user->id, $this->config);
|
$manager = new core_userkey_manager($this->config);
|
||||||
$manager->create_key();
|
$value = $manager->create_key($this->user->id);
|
||||||
|
|
||||||
$keys = $DB->get_records('user_private_key', array('userid' => $this->user->id));
|
$keys = $DB->get_records('user_private_key', array('userid' => $this->user->id));
|
||||||
$this->assertEquals(1, count($keys));
|
$this->assertEquals(1, count($keys));
|
||||||
|
|
||||||
$manager->delete_key();
|
$manager->delete_keys($this->user->id);
|
||||||
|
|
||||||
$keys = $DB->get_records('user_private_key', array('userid' => $this->user->id));
|
$keys = $DB->get_records('user_private_key', array('userid' => $this->user->id));
|
||||||
$this->assertEquals(0, count($keys));
|
$this->assertEquals(0, count($keys));
|
||||||
|
@ -286,7 +275,7 @@ class core_userkey_manager_testcase extends advanced_testcase {
|
||||||
public function test_can_delete_all_existing_keys() {
|
public function test_can_delete_all_existing_keys() {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$manager = new core_userkey_manager($this->user->id, $this->config);
|
$manager = new core_userkey_manager($this->config);
|
||||||
|
|
||||||
create_user_key('auth/userkey', $this->user->id);
|
create_user_key('auth/userkey', $this->user->id);
|
||||||
create_user_key('auth/userkey', $this->user->id);
|
create_user_key('auth/userkey', $this->user->id);
|
||||||
|
@ -295,7 +284,7 @@ class core_userkey_manager_testcase extends advanced_testcase {
|
||||||
$keys = $DB->get_records('user_private_key', array('userid' => $this->user->id));
|
$keys = $DB->get_records('user_private_key', array('userid' => $this->user->id));
|
||||||
$this->assertEquals(3, count($keys));
|
$this->assertEquals(3, count($keys));
|
||||||
|
|
||||||
$manager->delete_key();
|
$manager->delete_keys($this->user->id);
|
||||||
|
|
||||||
$keys = $DB->get_records('user_private_key', array('userid' => $this->user->id));
|
$keys = $DB->get_records('user_private_key', array('userid' => $this->user->id));
|
||||||
$this->assertEquals(0, count($keys));
|
$this->assertEquals(0, count($keys));
|
||||||
|
@ -307,7 +296,7 @@ class core_userkey_manager_testcase extends advanced_testcase {
|
||||||
public function test_create_only_one_key() {
|
public function test_create_only_one_key() {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$manager = new core_userkey_manager($this->user->id, $this->config);
|
$manager = new core_userkey_manager($this->config);
|
||||||
|
|
||||||
create_user_key('auth/userkey', $this->user->id);
|
create_user_key('auth/userkey', $this->user->id);
|
||||||
create_user_key('auth/userkey', $this->user->id);
|
create_user_key('auth/userkey', $this->user->id);
|
||||||
|
@ -316,7 +305,7 @@ class core_userkey_manager_testcase extends advanced_testcase {
|
||||||
$keys = $DB->get_records('user_private_key', array('userid' => $this->user->id));
|
$keys = $DB->get_records('user_private_key', array('userid' => $this->user->id));
|
||||||
$this->assertEquals(3, count($keys));
|
$this->assertEquals(3, count($keys));
|
||||||
|
|
||||||
$manager->create_key();
|
$manager->create_key($this->user->id);
|
||||||
$keys = $DB->get_records('user_private_key', array('userid' => $this->user->id));
|
$keys = $DB->get_records('user_private_key', array('userid' => $this->user->id));
|
||||||
$this->assertEquals(1, count($keys));
|
$this->assertEquals(1, count($keys));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue