[ticket/14315] Add functional tests for permission roles and fix non-js

Without JS the settings were not applied due to duplicate input names.

PHPBB3-14315
This commit is contained in:
Marc Alexander 2016-02-17 12:56:19 +01:00
parent d429fd03bf
commit 620a862266
4 changed files with 97 additions and 4 deletions

View file

@ -42,7 +42,7 @@
{% if p_mask.f_mask.role_options %}
<dd style="margin-{S_CONTENT_FLOW_BEGIN}{L_COLON} 20%">
<div class="dropdown-container dropdown-button-control roles-options" data-alt-text="{LA_ROLE_DESCRIPTION}">
<select id="role{p_mask.S_ROW_COUNT}{p_mask.f_mask.S_ROW_COUNT}" name="role[{p_mask.f_mask.UG_ID}][{p_mask.f_mask.FORUM_ID}]" onchange="set_role_settings(this.options[selectedIndex].value, 'advanced{p_mask.S_ROW_COUNT}{p_mask.f_mask.S_ROW_COUNT}'); init_colours('{p_mask.S_ROW_COUNT}{p_mask.f_mask.S_ROW_COUNT}')">{p_mask.f_mask.S_ROLE_OPTIONS}</select>
<select id="role{p_mask.S_ROW_COUNT}{p_mask.f_mask.S_ROW_COUNT}" name="role[{p_mask.f_mask.UG_ID}][{p_mask.f_mask.FORUM_ID}]">{p_mask.f_mask.S_ROLE_OPTIONS}</select>
<span title="Roles" class="button icon-button tools-icon dropdown-trigger dropdown-select">{L_NO_ROLE_ASSIGNED}</span>
<div class="dropdown hidden">
<ul class="dropdown-contents" id="role{p_mask.S_ROW_COUNT}{p_mask.f_mask.S_ROW_COUNT}" >
@ -51,7 +51,7 @@
{% endfor %}
</ul>
</div>
<input type="hidden" name="role[{p_mask.f_mask.UG_ID}][{p_mask.f_mask.FORUM_ID}]"{% if p_mask.f_mask.S_ROLE_ID %}value="{{ p_mask.f_mask.S_ROLE_ID }}"{% endif %} />
<input type="hidden" data-name="role[{p_mask.f_mask.UG_ID}][{p_mask.f_mask.FORUM_ID}]"{% if p_mask.f_mask.S_ROLE_ID %}value="{{ p_mask.f_mask.S_ROLE_ID }}"{% endif %} />
</div>
</dd>
{% else %}

View file

@ -145,6 +145,13 @@ phpbb.prepareRolesDropdown = function () {
// Display span and hide select
$('.roles-options > span').css('display', 'block');
$('.roles-options > select').hide();
$('.roles-options > input[type=hidden]').each(function () {
var $this = $(this);
if ($this.attr('data-name') && !$this.attr('name')) {
$this.attr('name', $this.attr('data-name'));
}
});
// Prepare highlighting of select options and settings update
$options.each(function () {

View file

@ -0,0 +1,86 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
require_once __DIR__ . '/../../phpBB/includes/functions.php';
/**
* @group functional
*/
class functional_permission_roles_test extends phpbb_functional_test_case
{
public function data_permission_roles()
{
return array(
array(
array(0, 14),
array(17, 17),
array(
'role[5][1]' => 14,
)
),
array(
array(14, 14),
array(17, 17),
array(
'role[5][1]' => 0,
)
),
array(
array(0, 14),
array(17, 17)
),
);
}
/**
* @dataProvider data_permission_roles
*/
public function test_permission_roles($admin_roles, $guest_roles, $set_values = array())
{
$this->login();
$this->admin_login();
$this->add_lang('acp/permissions');
$crawler = self::request('GET', 'adm/index.php?i=acp_permissions&mode=setting_forum_local&sid=' . $this->sid);
// Select forums
$form = $crawler->filter('form[id=select_victim]')->form();
$form['forum_id']->setValue(array(1,2));
$crawler = self::$client->submit($form);
// Select administrators and guests
$groups_form = $crawler->filter('form[id=groups]')->form();
$groups_form['group_id']->setValue(array(1,5));
$crawler = self::submit($groups_form);
$form = $crawler->filter('form')->form();
$values = $form->getValues();
// Check default settings
$this->assertEquals($admin_roles[0], $values['role[5][1]']);
$this->assertEquals($admin_roles[1], $values['role[5][2]']);
$this->assertEquals($guest_roles[0], $values['role[1][1]']);
$this->assertEquals($guest_roles[1], $values['role[1][2]']);
// Set admin to full access on category
foreach ($set_values as $key => $value)
{
$form[$key]->setValue($value);
}
$form_values = $form->getValues();
$form_values['action[apply_all_permissions]'] = true;
$crawler = self::request('POST', 'adm/index.php?i=acp_permissions&mode=setting_forum_local&sid=' . $this->sid, $form_values);
$this->assertContainsLang('AUTH_UPDATED', $crawler->text());
$this->logout();
}
}

View file

@ -14,10 +14,10 @@
/**
* @group ui
*/
class permission_roles_test extends phpbb_ui_test_case
class ui_permission_roles_test extends phpbb_ui_test_case
{
public function test_quick_links()
public function test_permission_roles()
{
$this->login();
$this->admin_login();