mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
Merge PR #1125 branch 'p/ticket/10972' into develop-olympus
* p/ticket/10972: [ticket/10972] Drop user deletion. [ticket/10972] Tweak user addition. [ticket/10972] Add destroy method to mock cache. [ticket/10972] Add mock null cache. [ticket/10972] Backport get_db from develop. [ticket/10972] Added explicit checks for creating duplicate users. [ticket/10972] Moved tests into appropriate places and added comments [ticket/10972] Added methods for creating and deleting basic users
This commit is contained in:
commit
3c542b852a
4 changed files with 138 additions and 3 deletions
|
@ -18,9 +18,19 @@ 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()
|
||||||
|
{
|
||||||
|
$this->create_user('anothertestuser');
|
||||||
|
$this->login('anothertestuser');
|
||||||
|
$crawler = $this->request('GET', 'index.php');
|
||||||
|
$this->assert_response_success();
|
||||||
|
$this->assertContains('anothertestuser', $crawler->filter('.icon-logout')->text());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends test_login
|
* @depends test_login
|
||||||
*/
|
*/
|
||||||
|
@ -31,10 +41,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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,16 @@ class phpbb_mock_cache
|
||||||
$this->data[$var_name] = $var;
|
$this->data[$var_name] = $var;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function destroy($var_name, $table = '')
|
||||||
|
{
|
||||||
|
if ($table)
|
||||||
|
{
|
||||||
|
throw new Exception('Destroying tables is not implemented yet');
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($this->data[$var_name]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain active bots
|
* Obtain active bots
|
||||||
*/
|
*/
|
||||||
|
|
42
tests/mock/null_cache.php
Normal file
42
tests/mock/null_cache.php
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) 2012 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class phpbb_mock_null_cache
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get($var_name)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function put($var_name, $var, $ttl = 0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy($var_name, $table = '')
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function obtain_bots()
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function obtain_word_list()
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_bots($bots)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,7 +16,9 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||||
{
|
{
|
||||||
protected $client;
|
protected $client;
|
||||||
protected $root_url;
|
protected $root_url;
|
||||||
|
|
||||||
protected $cache = null;
|
protected $cache = null;
|
||||||
|
protected $db = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Session ID for current test's session (each test makes its own)
|
* Session ID for current test's session (each test makes its own)
|
||||||
|
@ -65,6 +67,23 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function get_db()
|
||||||
|
{
|
||||||
|
global $phpbb_root_path, $phpEx;
|
||||||
|
// so we don't reopen an open connection
|
||||||
|
if (!($this->db instanceof dbal))
|
||||||
|
{
|
||||||
|
if (!class_exists('dbal_' . self::$config['dbms']))
|
||||||
|
{
|
||||||
|
include($phpbb_root_path . 'includes/db/' . self::$config['dbms'] . ".$phpEx");
|
||||||
|
}
|
||||||
|
$sql_db = 'dbal_' . self::$config['dbms'];
|
||||||
|
$this->db = new $sql_db();
|
||||||
|
$this->db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']);
|
||||||
|
}
|
||||||
|
return $this->db;
|
||||||
|
}
|
||||||
|
|
||||||
protected function get_cache_driver()
|
protected function get_cache_driver()
|
||||||
{
|
{
|
||||||
if (!$this->cache)
|
if (!$this->cache)
|
||||||
|
@ -194,7 +213,57 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||||
$db_conn_mgr->recreate_db();
|
$db_conn_mgr->recreate_db();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function login()
|
/**
|
||||||
|
* Creates a new user with limited permissions
|
||||||
|
*
|
||||||
|
* @param string $username Also doubles up as the user's password
|
||||||
|
* @return int ID of created user
|
||||||
|
*/
|
||||||
|
protected function create_user($username)
|
||||||
|
{
|
||||||
|
// Required by unique_id
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
if (!is_array($config))
|
||||||
|
{
|
||||||
|
$config = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$config['rand_seed'] = '';
|
||||||
|
$config['rand_seed_last_update'] = time() + 600;
|
||||||
|
|
||||||
|
// Required by user_add
|
||||||
|
global $db, $cache;
|
||||||
|
$db = $this->get_db();
|
||||||
|
if (!function_exists('phpbb_mock_null_cache'))
|
||||||
|
{
|
||||||
|
require_once(__DIR__ . '/../mock/null_cache.php');
|
||||||
|
}
|
||||||
|
$cache = new phpbb_mock_null_cache;
|
||||||
|
|
||||||
|
if (!function_exists('utf_clean_string'))
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function login($username = 'admin')
|
||||||
{
|
{
|
||||||
$this->add_lang('ucp');
|
$this->add_lang('ucp');
|
||||||
|
|
||||||
|
@ -202,7 +271,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' => 'admin', 'password' => 'admin'));
|
$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();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue