1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-02-24 12:03:21 +01:00

[ticket/10972] Tweak user addition.

Always add users, do not keep track of which users have been added.
The tests should know whether users they want exist or not.

Use more unique user names in tests for robustness.

Added some more assertions here and there.

PHPBB3-10972
This commit is contained in:
Oleg Pudeyev 2012-12-06 23:43:22 -05:00
parent 1285bdff00
commit fb5c4440e5
2 changed files with 41 additions and 30 deletions

View File

@ -18,16 +18,18 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
// check for logout link // check for logout link
$crawler = $this->request('GET', 'index.php'); $crawler = $this->request('GET', 'index.php');
$this->assert_response_success();
$this->assertContains($this->lang('LOGOUT_USER', 'admin'), $crawler->filter('.navbar')->text()); $this->assertContains($this->lang('LOGOUT_USER', 'admin'), $crawler->filter('.navbar')->text());
} }
public function test_login_other() public function test_login_other()
{ {
$this->create_user('user'); $this->create_user('anothertestuser');
$this->login('user'); $this->login('anothertestuser');
$crawler = $this->request('GET', 'index.php'); $crawler = $this->request('GET', 'index.php');
$this->assertContains('user', $crawler->filter('.icon-logout')->text()); $this->assert_response_success();
$this->delete_user('user'); $this->assertContains('anothertestuser', $crawler->filter('.icon-logout')->text());
$this->delete_user('anothertestuser');
} }
/** /**
@ -40,10 +42,12 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
// logout // logout
$crawler = $this->request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); $crawler = $this->request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout');
$this->assert_response_success();
$this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text()); $this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text());
// look for a register link, which should be visible only when logged out // look for a register link, which should be visible only when logged out
$crawler = $this->request('GET', 'index.php'); $crawler = $this->request('GET', 'index.php');
$this->assert_response_success();
$this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text()); $this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text());
} }
} }

View File

@ -32,11 +32,6 @@ class phpbb_functional_test_case extends phpbb_test_case
*/ */
protected $lang = array(); protected $lang = array();
/**
* @var array
*/
protected $created_users = array();
static protected $config = array(); static protected $config = array();
static protected $already_installed = false; static protected $already_installed = false;
@ -225,14 +220,10 @@ class phpbb_functional_test_case extends phpbb_test_case
* requires create_user. * requires create_user.
* *
* @param string $username Also doubles up as the user's password * @param string $username Also doubles up as the user's password
* @return int ID of created user
*/ */
protected function create_user($username) protected function create_user($username)
{ {
if (isset($this->created_users[$username]))
{
return;
}
// Required by unique_id // Required by unique_id
global $config; global $config;
@ -244,16 +235,35 @@ class phpbb_functional_test_case extends phpbb_test_case
$config['rand_seed'] = ''; $config['rand_seed'] = '';
$config['rand_seed_last_update'] = time() + 600; $config['rand_seed_last_update'] = time() + 600;
// Required by user_add
global $db, $cache;
$db = $this->get_db(); $db = $this->get_db();
$query = " if (!function_exists('phpbb_mock_null_cache'))
INSERT INTO " . self::$config['table_prefix'] . "users {
(user_type, group_id, username, username_clean, user_regdate, user_password, user_email, user_lang, user_style, user_rank, user_colour, user_posts, user_permissions, user_ip, user_birthday, user_lastpage, user_last_confirm_key, user_post_sortby_type, user_post_sortby_dir, user_topic_sortby_type, user_topic_sortby_dir, user_avatar, user_sig, user_sig_bbcode_uid, user_from, user_icq, user_aim, user_yim, user_msnm, user_jabber, user_website, user_occ, user_interests, user_actkey, user_newpasswd) require_once(__DIR__ . '/../mock/null_cache.php');
VALUES }
(0, 2, 'user', 'user', 0, '" . phpbb_hash($username) . "', 'nobody@example.com', 'en', 1, 0, '', 1, '', '', '', '', '', 't', 'a', 't', 'd', '', '', '', '', '', '', '', '', '', '', '', '', '', '') $cache = new phpbb_mock_null_cache;
";
$db->sql_query($query); if (!function_exists('utf_clean_string'))
$this->created_users[$username] = 1; {
require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php');
}
if (!function_exists('user_add'))
{
require_once(__DIR__ . '/../../phpBB/includes/functions_user.php');
}
$user_row = array(
'username' => $username,
'group_id' => 2,
'user_email' => 'nobody@example.com',
'user_type' => 0,
'user_lang' => 'en',
'user_timezone' => 0,
'user_dateformat' => '',
'user_password' => phpbb_hash($username),
);
return user_add($user_row);
} }
/** /**
@ -263,11 +273,6 @@ class phpbb_functional_test_case extends phpbb_test_case
*/ */
protected function delete_user($username) protected function delete_user($username)
{ {
if (isset($this->created_users[$username]))
{
unset($this->created_users[$username]);
}
$db = $this->get_db(); $db = $this->get_db();
$query = "DELETE FROM " . self::$config['table_prefix'] . "users WHERE username = '" . $db->sql_escape($username) . "'"; $query = "DELETE FROM " . self::$config['table_prefix'] . "users WHERE username = '" . $db->sql_escape($username) . "'";
$db->sql_query($query); $db->sql_query($query);
@ -281,7 +286,9 @@ class phpbb_functional_test_case extends phpbb_test_case
$this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text()); $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text());
$form = $crawler->selectButton($this->lang('LOGIN'))->form(); $form = $crawler->selectButton($this->lang('LOGIN'))->form();
$login = $this->client->submit($form, array('username' => $username, 'password' => $username)); $crawler = $this->client->submit($form, array('username' => $username, 'password' => $username));
$this->assert_response_success();
$this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text());
$cookies = $this->cookieJar->all(); $cookies = $this->cookieJar->all();