mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[feature/auth-refactor] Fix auth tests to use mock objects correctly
PHPBB3-9734
This commit is contained in:
parent
5444e5b683
commit
5f3ed197e7
1 changed files with 123 additions and 25 deletions
|
@ -40,7 +40,15 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case
|
||||||
public function test_init()
|
public function test_init()
|
||||||
{
|
{
|
||||||
$this->user->data['username'] = 'foobar';
|
$this->user->data['username'] = 'foobar';
|
||||||
$this->request->overwrite('PHP_AUTH_USER', 'foobar', phpbb_request_interface::SERVER);
|
$this->request->expects($this->once())
|
||||||
|
->method('is_set')
|
||||||
|
->with('PHP_AUTH_USER',
|
||||||
|
phpbb_request_interface::SERVER)
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
$this->request->expects($this->once())
|
||||||
|
->method('server')
|
||||||
|
->with('PHP_AUTH_USER')
|
||||||
|
->will($this->returnValue('foobar'));
|
||||||
|
|
||||||
$this->assertFalse($this->provider->init());
|
$this->assertFalse($this->provider->init());
|
||||||
}
|
}
|
||||||
|
@ -50,8 +58,19 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case
|
||||||
$username = 'foobar';
|
$username = 'foobar';
|
||||||
$password = 'example';
|
$password = 'example';
|
||||||
|
|
||||||
$this->request->overwrite('PHP_AUTH_USER', $username, phpbb_request_interface::SERVER);
|
$this->request->expects($this->once())
|
||||||
$this->request->overwrite('PHP_AUTH_PW', $password, phpbb_request_interface::SERVER);
|
->method('is_set')
|
||||||
|
->with('PHP_AUTH_USER',
|
||||||
|
phpbb_request_interface::SERVER)
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
$this->request->expects($this->at(1))
|
||||||
|
->method('server')
|
||||||
|
->with('PHP_AUTH_USER')
|
||||||
|
->will($this->returnValue('foobar'));
|
||||||
|
$this->request->expects($this->at(2))
|
||||||
|
->method('server')
|
||||||
|
->with('PHP_AUTH_PW')
|
||||||
|
->will($this->returnValue('example'));
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'status' => LOGIN_SUCCESS,
|
'status' => LOGIN_SUCCESS,
|
||||||
|
@ -71,27 +90,96 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case
|
||||||
|
|
||||||
public function test_autologin()
|
public function test_autologin()
|
||||||
{
|
{
|
||||||
$this->request->overwrite('PHP_AUTH_USER', 'foobar', phpbb_request_interface::SERVER);
|
$this->request->expects($this->once())
|
||||||
$this->request->overwrite('PHP_AUTH_PW', 'example', phpbb_request_interface::SERVER);
|
->method('is_set')
|
||||||
|
->with('PHP_AUTH_USER',
|
||||||
|
phpbb_request_interface::SERVER)
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
$this->request->expects($this->at(1))
|
||||||
|
->method('server')
|
||||||
|
->with('PHP_AUTH_USER')
|
||||||
|
->will($this->returnValue('foobar'));
|
||||||
|
$this->request->expects($this->at(2))
|
||||||
|
->method('server')
|
||||||
|
->with('PHP_AUTH_PW')
|
||||||
|
->will($this->returnValue('example'));
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'status' => LOGIN_SUCCESS,
|
'user_id' => '1',
|
||||||
'error_msg' => false,
|
'user_type' => '0',
|
||||||
'user_row' => array(
|
'group_id' => '3',
|
||||||
'user_id' => '1',
|
'user_permissions' => '',
|
||||||
'username' => 'foobar',
|
'user_perm_from' => '0',
|
||||||
'username_clean' => 'foobar',
|
'user_ip' => '',
|
||||||
'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/',
|
'user_regdate' => '0',
|
||||||
'user_passchg' => '0',
|
'username' => 'foobar',
|
||||||
'user_pass_convert' => '0',
|
'username_clean' => 'foobar',
|
||||||
'user_email' => 'example@example.com',
|
'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/',
|
||||||
'user_type' => '0',
|
'user_passchg' => '0',
|
||||||
'user_login_attempts' => '0',
|
'user_pass_convert' => '0',
|
||||||
'user_permission' => '',
|
'user_email' => 'example@example.com',
|
||||||
'user_sig' => '',
|
'user_email_hash' => '0',
|
||||||
'user_occ' => '',
|
'user_birthday' => '',
|
||||||
'user_interests' => '',
|
'user_lastvisit' => '0',
|
||||||
),
|
'user_lastmark' => '0',
|
||||||
|
'user_lastpost_time' => '0',
|
||||||
|
'user_lastpage' => '',
|
||||||
|
'user_last_confirm_key' => '',
|
||||||
|
'user_last_search' => '0',
|
||||||
|
'user_warnings' => '0',
|
||||||
|
'user_last_warning' => '0',
|
||||||
|
'user_login_attempts' => '0',
|
||||||
|
'user_inactive_reason' => '0',
|
||||||
|
'user_inactive_time' => '0',
|
||||||
|
'user_posts' => '0',
|
||||||
|
'user_lang' => '',
|
||||||
|
'user_timezone' => 'UTC',
|
||||||
|
'user_dateformat' => 'd M Y H:i',
|
||||||
|
'user_style' => '0',
|
||||||
|
'user_rank' => '0',
|
||||||
|
'user_colour' => '',
|
||||||
|
'user_new_privmsg' => '0',
|
||||||
|
'user_unread_privmsg' => '0',
|
||||||
|
'user_last_privmsg' => '0',
|
||||||
|
'user_message_rules' => '0',
|
||||||
|
'user_full_folder' => '-3',
|
||||||
|
'user_emailtime' => '0',
|
||||||
|
'user_topic_show_days' => '0',
|
||||||
|
'user_topic_sortby_type' => 't',
|
||||||
|
'user_topic_sortby_dir' => 'd',
|
||||||
|
'user_post_show_days' => '0',
|
||||||
|
'user_post_sortby_type' => 't',
|
||||||
|
'user_post_sortby_dir' => 'a',
|
||||||
|
'user_notify' => '0',
|
||||||
|
'user_notify_pm' => '1',
|
||||||
|
'user_notify_type' => '0',
|
||||||
|
'user_allow_pm' => '1',
|
||||||
|
'user_allow_viewonline' => '1',
|
||||||
|
'user_allow_viewemail' => '1',
|
||||||
|
'user_allow_massemail' => '1',
|
||||||
|
'user_options' => '230271',
|
||||||
|
'user_avatar' => '',
|
||||||
|
'user_avatar_type' => '',
|
||||||
|
'user_avatar_width' => '0',
|
||||||
|
'user_avatar_height' => '0',
|
||||||
|
'user_sig' => '',
|
||||||
|
'user_sig_bbcode_uid' => '',
|
||||||
|
'user_sig_bbcode_bitfield' => '',
|
||||||
|
'user_from' => '',
|
||||||
|
'user_icq' => '',
|
||||||
|
'user_aim' => '',
|
||||||
|
'user_yim' => '',
|
||||||
|
'user_msnm' => '',
|
||||||
|
'user_jabber' => '',
|
||||||
|
'user_website' => '',
|
||||||
|
'user_occ' => '',
|
||||||
|
'user_interests' => '',
|
||||||
|
'user_actkey' => '',
|
||||||
|
'user_newpasswd' => '',
|
||||||
|
'user_form_salt' => '',
|
||||||
|
'user_new' => '1',
|
||||||
|
'user_reminded' => '0',
|
||||||
|
'user_reminded_time' => '0',
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals($expected, $this->provider->autologin());
|
$this->assertEquals($expected, $this->provider->autologin());
|
||||||
|
@ -99,9 +187,19 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case
|
||||||
|
|
||||||
public function test_validate_session()
|
public function test_validate_session()
|
||||||
{
|
{
|
||||||
$user = $this->getMock('phpbb_user');
|
$user = array(
|
||||||
$user->data['username'] = 'foobar';
|
'username' => 'foobar',
|
||||||
$this->request->overwrite('PHP_AUTH_USER', 'foobar', phpbb_request_interface::SERVER);
|
'user_type'
|
||||||
|
);
|
||||||
|
$this->request->expects($this->once())
|
||||||
|
->method('is_set')
|
||||||
|
->with('PHP_AUTH_USER',
|
||||||
|
phpbb_request_interface::SERVER)
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
$this->request->expects($this->once())
|
||||||
|
->method('server')
|
||||||
|
->with('PHP_AUTH_USER')
|
||||||
|
->will($this->returnValue('foobar'));
|
||||||
|
|
||||||
$this->assertTrue($this->provider->validate_session($user));
|
$this->assertTrue($this->provider->validate_session($user));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue