diff options
author | Callum Macrae <callum@lynxphp.com> | 2011-08-22 15:35:47 +0100 |
---|---|---|
committer | Callum Macrae <callum@lynxphp.com> | 2011-08-22 19:02:27 +0100 |
commit | fa5c7f6440282891dba1142920157971b90b5ad1 (patch) | |
tree | 4c5c6ae65dc58deceb718847df9c1ce7b03cc74f | |
parent | 540ca1a8d88279b120b142c244c96c9fae9a867b (diff) | |
download | forums-fa5c7f6440282891dba1142920157971b90b5ad1.tar forums-fa5c7f6440282891dba1142920157971b90b5ad1.tar.gz forums-fa5c7f6440282891dba1142920157971b90b5ad1.tar.bz2 forums-fa5c7f6440282891dba1142920157971b90b5ad1.tar.xz forums-fa5c7f6440282891dba1142920157971b90b5ad1.zip |
[ticket/10240] Added censor_text tests.
PHPBB-10240
-rw-r--r-- | tests/mock/cache.php | 22 | ||||
-rw-r--r-- | tests/mock_user.php | 12 | ||||
-rw-r--r-- | tests/text_processing/censor_text_test.php | 73 |
3 files changed, 107 insertions, 0 deletions
diff --git a/tests/mock/cache.php b/tests/mock/cache.php index 11e525ff79..020574b0bb 100644 --- a/tests/mock/cache.php +++ b/tests/mock/cache.php @@ -41,6 +41,28 @@ class phpbb_mock_cache { return $this->data['_bots']; } + + /** + * Obtain list of word censors. We don't need to parse them here, + * that is tested elsewhere. + */ + public function obtain_word_list() + { + return array( + 'match' => array( + '#(?<![\\p{Nd}\\p{L}_-])([\\p{Nd}\\p{L}_-]*?badword1[\\p{Nd}\\p{L}_-]*?)(?![\\p{Nd}\\p{L}_-])#iu', + '#(?<![\\p{Nd}\\p{L}_-])([\\p{Nd}\\p{L}_-]*?badword2)(?![\\p{Nd}\\p{L}_-])#iu', + '#(?<![\\p{Nd}\\p{L}_-])(badword3[\\p{Nd}\\p{L}_-]*?)(?![\\p{Nd}\\p{L}_-])#iu', + '#(?<![\\p{Nd}\\p{L}_-])(badword4)(?![\\p{Nd}\\p{L}_-])#iu', + ), + 'replace' => array( + 'replacement1', + 'replacement2', + 'replacement3', + 'replacement4', + ), + ); + } public function set_bots($bots) { diff --git a/tests/mock_user.php b/tests/mock_user.php index 74d31c4c4a..a6ff5f6628 100644 --- a/tests/mock_user.php +++ b/tests/mock_user.php @@ -17,4 +17,16 @@ class phpbb_mock_user { public $host = "testhost"; public $page = array('root_script_path' => '/'); + + public function optionget($item) + { + switch ($item) + { + case 'viewcensors': + return false; + + default: + trigger_error('Option not found, add it to the mock user object.'); + } + } } diff --git a/tests/text_processing/censor_text_test.php b/tests/text_processing/censor_text_test.php new file mode 100644 index 0000000000..3820a1135f --- /dev/null +++ b/tests/text_processing/censor_text_test.php @@ -0,0 +1,73 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2008 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; +require_once dirname(__FILE__) . '/../mock_user.php'; +require_once dirname(__FILE__) . '/../mock/cache.php'; + +class phpbb_text_processing_censor_text_test extends phpbb_test_case +{ + public function censor_text_data() + { + global $cache, $user; + $cache = new phpbb_mock_cache; + $user = new phpbb_mock_user; + + return array( + array('', ''), + + array('badword1', 'replacement1'), + array(' badword1', ' replacement1'), + array('badword1 ', 'replacement1 '), + array(' badword1 ', ' replacement1 '), + array('abadword1', 'replacement1'), + array('badword1w', 'replacement1'), + array('abadword1w', 'replacement1'), + array('anotherbadword1test', 'replacement1'), + array('this badword1', 'this replacement1'), + array('this badword1 word', 'this replacement1 word'), + + array('badword2', 'replacement2'), + array('bbadword2', 'replacement2'), + array('bbbadword2', 'replacement2'), + array('badword2d', 'badword2d'), + array('bbadword2d', 'bbadword2d'), + array('test badword2', 'test replacement2'), + array('test badword2 word', 'test replacement2 word'), + + array('badword3', 'replacement3'), + array('bbadword3', 'bbadword3'), + array('badword3d', 'replacement3'), + array('badword3ddd', 'replacement3'), + array('bbadword3d', 'bbadword3d'), + array(' badword3 ', ' replacement3 '), + array(' badword3', ' replacement3'), + + array('badword4', 'replacement4'), + array('this badword4 word', 'this replacement4 word'), + array('abadword4', 'abadword4'), + array('badword4d', 'badword4d'), + array('abadword4d', 'abadword4d'), + + array('badword1 badword2 badword3 badword4', 'replacement1 replacement2 replacement3 replacement4'), + array('badword1 badword2 badword3 badword4d', 'replacement1 replacement2 replacement3 badword4d'), + array('abadword1 badword2 badword3 badword4', 'replacement1 replacement2 replacement3 replacement4'), + ); + } + + /** + * @dataProvider censor_text_data + */ + public function test_censor_text($input, $expected) + { + $label = 'Testing word censor: ' . $input; + $this->assertEquals(censor_text($input), $expected, $label); + } +} |