mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-09 10:16:36 +02:00
Merge remote-tracking branch 'p/ticket/10758' into develop
* p/ticket/10758: [ticket/10758] Add return to the other compat function. [ticket/10758] Add periods. [ticket/10758] Yes, only one empty line. [ticket/10758] Add deprecated tags. [ticket/10758] Add compat functions. [ticket/10758] Admin is not working yet. [ticket/10758] Test moderator and admin permissions. [ticket/10758] Check that acl was changed in the test. [ticket/10758] Extract obtain_user_data for the benefit of tests. [ticket/10758] Functional test for changing a user's permission. [ticket/10758] Spelling fix. [ticket/10758] Add a test for acp login. [ticket/10758] Dependency inject parameters into update_foes. [ticket/10758] Dependency inject parameters into cache_moderators.
This commit is contained in:
128
tests/functional/acp_permissions_test.php
Normal file
128
tests/functional/acp_permissions_test.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @group functional
|
||||
*/
|
||||
class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->login();
|
||||
$this->admin_login();
|
||||
$this->add_lang('acp/permissions');
|
||||
}
|
||||
|
||||
public function test_permissions_tab()
|
||||
{
|
||||
// Permissions tab
|
||||
// XXX hardcoded id
|
||||
$crawler = $this->request('GET', 'adm/index.php?i=16&sid=' . $this->sid);
|
||||
$this->assert_response_success();
|
||||
// these language strings are html
|
||||
$this->assertContains($this->lang('ACP_PERMISSIONS_EXPLAIN'), $this->client->getResponse()->getContent());
|
||||
}
|
||||
|
||||
public function test_select_user()
|
||||
{
|
||||
// User permissions
|
||||
$crawler = $this->request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid);
|
||||
$this->assert_response_success();
|
||||
$this->assertContains($this->lang('ACP_USERS_PERMISSIONS_EXPLAIN'), $this->client->getResponse()->getContent());
|
||||
|
||||
// Select admin
|
||||
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
|
||||
$data = array('username[0]' => 'admin');
|
||||
$form->setValues($data);
|
||||
$crawler = $this->client->submit($form);
|
||||
$this->assert_response_success();
|
||||
$this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text());
|
||||
}
|
||||
|
||||
public function permissions_data()
|
||||
{
|
||||
return array(
|
||||
// description
|
||||
// permission type
|
||||
// permission name
|
||||
// mode
|
||||
// object name
|
||||
// object id
|
||||
array(
|
||||
'user permission',
|
||||
'u_',
|
||||
'u_hideonline',
|
||||
'setting_user_global',
|
||||
'user_id',
|
||||
2,
|
||||
),
|
||||
array(
|
||||
'moderator permission',
|
||||
'm_',
|
||||
'm_ban',
|
||||
'setting_mod_global',
|
||||
'group_id',
|
||||
4,
|
||||
),
|
||||
/* Admin does not work yet, probably because founder can do everything
|
||||
array(
|
||||
'admin permission',
|
||||
'a_',
|
||||
'a_forum',
|
||||
'setting_admin_global',
|
||||
'group_id',
|
||||
5,
|
||||
),
|
||||
*/
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider permissions_data
|
||||
*/
|
||||
public function test_change_permission($description, $permission_type, $permission, $mode, $object_name, $object_id)
|
||||
{
|
||||
// Get the form
|
||||
$crawler = $this->request('GET', "adm/index.php?i=acp_permissions&icat=16&mode=$mode&${object_name}[0]=$object_id&type=$permission_type&sid=" . $this->sid);
|
||||
$this->assert_response_success();
|
||||
$this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text());
|
||||
|
||||
// XXX globals for phpbb_auth, refactor it later
|
||||
global $db, $cache;
|
||||
$db = $this->get_db();
|
||||
$cache = new phpbb_mock_null_cache;
|
||||
|
||||
$auth = new phpbb_auth;
|
||||
// XXX hardcoded id
|
||||
$user_data = $auth->obtain_user_data(2);
|
||||
$auth->acl($user_data);
|
||||
$this->assertEquals(1, $auth->acl_get($permission));
|
||||
|
||||
// Set u_hideonline to never
|
||||
$form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form();
|
||||
// initially it should be a yes
|
||||
$values = $form->getValues();
|
||||
$this->assertEquals(1, $values["setting[$object_id][0][$permission]"]);
|
||||
// set to never
|
||||
$data = array("setting[$object_id][0][$permission]" => '0');
|
||||
$form->setValues($data);
|
||||
$crawler = $this->client->submit($form);
|
||||
$this->assert_response_success();
|
||||
$this->assertContains($this->lang('AUTH_UPDATED'), $crawler->text());
|
||||
|
||||
// check acl again
|
||||
$auth = new phpbb_auth;
|
||||
// XXX hardcoded id
|
||||
$user_data = $auth->obtain_user_data(2);
|
||||
$auth->acl($user_data);
|
||||
$this->assertEquals(0, $auth->acl_get($permission));
|
||||
}
|
||||
}
|
@@ -49,4 +49,15 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
|
||||
$this->assert_response_success();
|
||||
$this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text());
|
||||
}
|
||||
|
||||
public function test_acp_login()
|
||||
{
|
||||
$this->login();
|
||||
$this->admin_login();
|
||||
|
||||
// check that we are logged in
|
||||
$crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid);
|
||||
$this->assert_response_success();
|
||||
$this->assertContains($this->lang('ADMIN_PANEL'), $crawler->filter('h1')->text());
|
||||
}
|
||||
}
|
||||
|
@@ -323,7 +323,7 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
* Login to the ACP
|
||||
* You must run login() before calling this.
|
||||
*/
|
||||
protected function admin_login()
|
||||
protected function admin_login($username = 'admin')
|
||||
{
|
||||
$this->add_lang('acp/common');
|
||||
|
||||
@@ -343,7 +343,9 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
{
|
||||
if (strpos($field, 'password_') === 0)
|
||||
{
|
||||
$login = $this->client->submit($form, array('username' => 'admin', $field => 'admin'));
|
||||
$crawler = $this->client->submit($form, array('username' => $username, $field => $username));
|
||||
$this->assert_response_success();
|
||||
$this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text());
|
||||
|
||||
$cookies = $this->cookieJar->all();
|
||||
|
||||
|
Reference in New Issue
Block a user