mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 22:28:51 +00:00
[ticket/11492] Add tests for removing/adding users
PHPBB3-11492
This commit is contained in:
parent
60713c8a20
commit
59ad90b25c
2 changed files with 75 additions and 2 deletions
|
@ -44,9 +44,32 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case
|
||||||
public function test_leaders()
|
public function test_leaders()
|
||||||
{
|
{
|
||||||
$this->login();
|
$this->login();
|
||||||
$this->remove_user_group('ADMINISTRATORS', array('admin'));
|
$this->create_user('memberlist-test-user');
|
||||||
|
$this->create_user('memberlist-test-moderator');
|
||||||
|
|
||||||
|
// Admin should be listed, user not
|
||||||
$crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid);
|
$crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid);
|
||||||
$this->assert_response_success();
|
$this->assert_response_success();
|
||||||
|
$this->assertContains('admin', $crawler->filter('tr')->text());
|
||||||
|
$this->assertNotContains('memberlist-test-user', $crawler->filter('tr')->text());
|
||||||
|
$this->assertNotContains('memberlist-test-moderator', $crawler->filter('tr')->text());
|
||||||
|
|
||||||
|
// Remove admin from admins, still a moderator
|
||||||
|
$this->remove_user_group('ADMINISTRATORS', array('admin'));
|
||||||
|
$crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid);
|
||||||
|
$this->assert_response_success();
|
||||||
|
$this->assertContains('admin', $crawler->filter('tr')->text());
|
||||||
|
|
||||||
|
// Remove admin from moderators
|
||||||
|
$this->remove_user_group('GLOBAL_MODERATORS', array('admin'));
|
||||||
|
$crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid);
|
||||||
|
$this->assert_response_success();
|
||||||
|
$this->assertNotContains('admin', $crawler->filter('tr')->text());
|
||||||
|
|
||||||
|
// Add mod to moderators
|
||||||
|
$this->add_user_group('GLOBAL_MODERATORS', array('memberlist-test-moderator'));
|
||||||
|
$crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid);
|
||||||
|
$this->assert_response_success();
|
||||||
|
$this->assertContains('memberlist-test-moderator', $crawler->filter('tr')->text());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -318,13 +318,18 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||||
|
|
||||||
protected function remove_user_group($group_name, $usernames)
|
protected function remove_user_group($group_name, $usernames)
|
||||||
{
|
{
|
||||||
global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_container;
|
global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container;
|
||||||
|
|
||||||
$config = new phpbb_config(array());
|
$config = new phpbb_config(array());
|
||||||
$config['coppa_enable'] = 0;
|
$config['coppa_enable'] = 0;
|
||||||
|
|
||||||
$db = $this->get_db();
|
$db = $this->get_db();
|
||||||
|
|
||||||
|
$phpbb_log = $this->getMock('phpbb_log');
|
||||||
|
$phpbb_log
|
||||||
|
->expects($this->any())
|
||||||
|
->method('add')
|
||||||
|
->will($this->returnValue(true));
|
||||||
$cache = new phpbb_mock_null_cache;
|
$cache = new phpbb_mock_null_cache;
|
||||||
|
|
||||||
$cache_driver = new phpbb_cache_driver_null();
|
$cache_driver = new phpbb_cache_driver_null();
|
||||||
|
@ -356,6 +361,51 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||||
return group_user_del($group_id, false, $usernames, $group_name);
|
return group_user_del($group_id, false, $usernames, $group_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function add_user_group($group_name, $usernames)
|
||||||
|
{
|
||||||
|
global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container;
|
||||||
|
|
||||||
|
$config = new phpbb_config(array());
|
||||||
|
$config['coppa_enable'] = 0;
|
||||||
|
|
||||||
|
$db = $this->get_db();
|
||||||
|
|
||||||
|
$phpbb_log = $this->getMock('phpbb_log');
|
||||||
|
$phpbb_log
|
||||||
|
->expects($this->any())
|
||||||
|
->method('add')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
$cache = new phpbb_mock_null_cache;
|
||||||
|
|
||||||
|
$cache_driver = new phpbb_cache_driver_null();
|
||||||
|
$phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
|
||||||
|
$phpbb_container
|
||||||
|
->expects($this->any())
|
||||||
|
->method('get')
|
||||||
|
->with('cache.driver')
|
||||||
|
->will($this->returnValue($cache_driver));
|
||||||
|
|
||||||
|
if (!function_exists('utf_clean_string'))
|
||||||
|
{
|
||||||
|
require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php');
|
||||||
|
}
|
||||||
|
if (!function_exists('group_user_del'))
|
||||||
|
{
|
||||||
|
require_once(__DIR__ . '/../../phpBB/includes/functions_user.php');
|
||||||
|
}
|
||||||
|
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||||
|
$auth = $this->getMock('Observer', array('acl_clear_prefetch'));
|
||||||
|
|
||||||
|
$sql = 'SELECT group_id
|
||||||
|
FROM ' . GROUPS_TABLE . "
|
||||||
|
WHERE group_name = '" . $db->sql_escape($group_name) . "'";
|
||||||
|
$result = $db->sql_query($sql);
|
||||||
|
$group_id = (int) $db->sql_fetchfield('group_id');
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
|
return group_user_add($group_id, false, $usernames, $group_name);
|
||||||
|
}
|
||||||
|
|
||||||
protected function login($username = 'admin')
|
protected function login($username = 'admin')
|
||||||
{
|
{
|
||||||
$this->add_lang('ucp');
|
$this->add_lang('ucp');
|
||||||
|
|
Loading…
Add table
Reference in a new issue