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/15318] Make user option to disable word censoring effective again #4900

Merged
merged 3 commits into from Sep 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions phpBB/includes/functions_content.php
Expand Up @@ -557,6 +557,7 @@ function strip_bbcode(&$text, $uid = '')
function generate_text_for_display($text, $uid, $bitfield, $flags, $censor_text = true)
{
static $bbcode;
global $auth, $config, $user;
global $phpbb_dispatcher, $phpbb_container;

if ($text === '')
Expand Down Expand Up @@ -584,6 +585,13 @@ function generate_text_for_display($text, $uid, $bitfield, $flags, $censor_text

// Temporarily switch off viewcensors if applicable
$old_censor = $renderer->get_viewcensors();

// Check here if the user is having viewing censors disabled (and also allowed to do so).
if (!$user->optionget('viewcensors') && $config['allow_nocensors'] && $auth->acl_get('u_chgcensors'))
{
$censor_text = false;
}

if ($old_censor !== $censor_text)
{
$renderer->set_viewcensors($censor_text);
Expand Down
17 changes: 13 additions & 4 deletions tests/text_processing/generate_text_for_display_test.php
Expand Up @@ -29,7 +29,7 @@ public function setUp()
*/
public function test_legacy($original, $expected, $uid = '', $bitfield = '', $flags = 0, $censor_text = true)
{
global $cache, $user;
global $auth, $cache, $config, $user;

global $phpbb_root_path, $phpEx;

Expand Down Expand Up @@ -63,7 +63,7 @@ public function get_legacy_tests()

public function test_censor_is_restored()
{
global $phpbb_container;
global $auth, $user, $config, $phpbb_container;

$phpbb_container = new phpbb_mock_container_builder;

Expand All @@ -72,7 +72,8 @@ public function test_censor_is_restored()
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
$lang = new \phpbb\language\language($lang_loader);
$user = new \phpbb\user($lang, '\phpbb\datetime');
$user->optionset('viewcensors', false);
// Do not ignore word censoring by user (switch censoring on in UCP)
$user->optionset('viewcensors', true);

$config = new \phpbb\config\config(array('allow_nocensors' => true));

Expand Down Expand Up @@ -102,14 +103,22 @@ public function test_censor_is_restored()
$this->assertSame('apple', $renderer->render($original));
$this->assertSame('banana', generate_text_for_display($original, '', '', 0, true));
$this->assertSame('apple', $renderer->render($original), 'The original setting was not restored');

// Test user option switch to ignore censoring
$renderer->set_viewcensors(true);
// 1st: censoring is still on in UCP
$this->assertSame('banana', generate_text_for_display($original, '', '', 0, true));
// 2nd: switch censoring off in UCP
$user->optionset('viewcensors', false);
$this->assertSame('apple', generate_text_for_display($original, '', '', 0, true));
}

/**
* @dataProvider get_text_formatter_tests
*/
public function test_text_formatter($original, $expected, $censor_text = true, $setup = null)
{
global $phpbb_container;
global $auth, $user, $config, $phpbb_container;

$phpbb_container = new phpbb_mock_container_builder;

Expand Down