Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ticket/11492] Fix error on teampage when there are no users. #1336

Merged
merged 7 commits into from Apr 11, 2013
8 changes: 5 additions & 3 deletions phpBB/memberlist.php
Expand Up @@ -146,7 +146,7 @@

$result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));

$user_ary = array();
$user_ary = $user_ids = $group_users = array();
while ($row = $db->sql_fetchrow($result))
{
$row['forums'] = '';
Expand All @@ -157,11 +157,13 @@
}
$db->sql_freeresult($result);

if ($config['teampage_forums'])
$user_ids = array_unique($user_ids);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used later on? !empty($user_ids) has the same result before and after this line.


if (!empty($user_ids) && $config['teampage_forums'])
{
$template->assign_var('S_DISPLAY_MODERATOR_FORUMS', true);
// Get all moderators
$perm_ary = $auth->acl_get_list(array_unique($user_ids), array('m_'), false);
$perm_ary = $auth->acl_get_list($user_ids, array('m_'), false);

foreach ($perm_ary as $forum_id => $forum_ary)
{
Expand Down
35 changes: 35 additions & 0 deletions tests/functional/memberlist_test.php
Expand Up @@ -40,4 +40,39 @@ public function test_viewprofile()
$this->assert_response_success();
$this->assertContains('admin', $crawler->filter('h2')->text());
}

public function test_leaders()
{
$this->login();
$this->create_user('memberlist-test-moderator');

// Admin should be listed, user not
$crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid);
$this->assert_response_success();
$this->assertContains('admin', $crawler->text());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably not good enough.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will always match Logout [ admin ].

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You really should always focus what you are actually testing instead of using the whole page.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are examples in other tests how to do this using $crawler.

$this->assertNotContains('memberlist-test-user', $crawler->text());
$this->assertNotContains('memberlist-test-moderator', $crawler->text());
}

public function test_leaders_remove_users()
{
$this->login();

// Remove admin from admins
$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->text());
}

public function test_leaders_add_users()
{
$this->login();

// 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->text());
}
}
84 changes: 84 additions & 0 deletions tests/test_framework/phpbb_functional_test_case.php
Expand Up @@ -316,6 +316,90 @@ protected function create_user($username)
return user_add($user_row);
}

protected function remove_user_group($group_name, $usernames)
{
global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container, $phpbb_root_path, $phpEx;

$config = new phpbb_config(array());
$config['coppa_enable'] = 0;

$db = $this->get_db();
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$user = $this->getMock('phpbb_user');
$auth = $this->getMock('phpbb_auth');

$phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);
$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');
}

$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_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, $phpbb_root_path, $phpEx;

$config = new phpbb_config(array());
$config['coppa_enable'] = 0;

$db = $this->get_db();
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$user = $this->getMock('phpbb_user');
$auth = $this->getMock('phpbb_auth');

$phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);
$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');
}

$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')
{
$this->add_lang('ucp');
Expand Down