From fa5c7f6440282891dba1142920157971b90b5ad1 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Mon, 22 Aug 2011 15:35:47 +0100 Subject: [ticket/10240] Added censor_text tests. PHPBB-10240 --- tests/mock/cache.php | 22 +++++++++ tests/mock_user.php | 12 +++++ tests/text_processing/censor_text_test.php | 73 ++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 tests/text_processing/censor_text_test.php 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( + '#(? 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 @@ +assertEquals(censor_text($input), $expected, $label); + } +} -- cgit v1.2.1 From e7ab7f5f7a3e72c94df6e16360a1594c96618caa Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Tue, 23 Aug 2011 10:56:36 +0100 Subject: [ticket/10240] Added censor_text tests for special characters. PHPBB3-10240 --- tests/text_processing/censor_text_test.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/text_processing/censor_text_test.php b/tests/text_processing/censor_text_test.php index 3820a1135f..ac620597b9 100644 --- a/tests/text_processing/censor_text_test.php +++ b/tests/text_processing/censor_text_test.php @@ -59,6 +59,16 @@ class phpbb_text_processing_censor_text_test extends phpbb_test_case 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'), + + array("new\nline\ntest", "new\nline\ntest"), + array("tab\ttest\t", "tab\ttest\t"), + array('öäü', 'öäü'), + array('badw' . chr(1) . 'ord1', 'badw' . chr(1) . 'ord1'), + array('badw' . chr(2) . 'ord1', 'badw' . chr(2) . 'ord1'), + array('badw' . chr(3) . 'ord1', 'badw' . chr(3) . 'ord1'), + array('badw' . chr(4) . 'ord1', 'badw' . chr(4) . 'ord1'), + array('badw' . chr(5) . 'ord1', 'badw' . chr(5) . 'ord1'), + array('badw' . chr(6) . 'ord1', 'badw' . chr(6) . 'ord1'), ); } -- cgit v1.2.1 From 0d104b00c887db311576ab390ed2c79d2fb8ec99 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Tue, 23 Aug 2011 11:32:35 +0100 Subject: [ticket/10240] Fixed censor_text test assetEquals param order. Before, expected and input were the wrong way round. PHPBB3-10240 --- tests/text_processing/censor_text_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/text_processing/censor_text_test.php b/tests/text_processing/censor_text_test.php index ac620597b9..1d4b3fa943 100644 --- a/tests/text_processing/censor_text_test.php +++ b/tests/text_processing/censor_text_test.php @@ -78,6 +78,6 @@ class phpbb_text_processing_censor_text_test extends phpbb_test_case public function test_censor_text($input, $expected) { $label = 'Testing word censor: ' . $input; - $this->assertEquals(censor_text($input), $expected, $label); + $this->assertEquals($expected, censor_text($input), $label); } } -- cgit v1.2.1 From d4f1b92479aeaab313d18c172e5e2fede7035281 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Tue, 23 Aug 2011 11:38:59 +0100 Subject: [ticket/10240] Fixed copyright year in censor_text_test.php. PHPBB3-10240 --- tests/text_processing/censor_text_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/text_processing/censor_text_test.php b/tests/text_processing/censor_text_test.php index 1d4b3fa943..6138d92e65 100644 --- a/tests/text_processing/censor_text_test.php +++ b/tests/text_processing/censor_text_test.php @@ -2,7 +2,7 @@ /** * * @package testing -* @copyright (c) 2008 phpBB Group +* @copyright (c) 2011 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ -- cgit v1.2.1 From 03da3c7c4c2d3957b738485935386723c536671b Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Tue, 23 Aug 2011 12:21:20 +0100 Subject: [ticket/10240] Added optionset to mock_user in the tests. Also made optionset use the value set by optionset. We're not checking whether the option is set or not, because we would just throw an error if it wasn't set, and it throws an error anyway. PHPBB3-10240 --- tests/mock_user.php | 16 ++++++++++------ tests/text_processing/censor_text_test.php | 2 ++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/mock_user.php b/tests/mock_user.php index a6ff5f6628..5b89ea3e19 100644 --- a/tests/mock_user.php +++ b/tests/mock_user.php @@ -18,15 +18,19 @@ class phpbb_mock_user public $host = "testhost"; public $page = array('root_script_path' => '/'); + private $options = array(); public function optionget($item) { - switch ($item) + if (!isset($this->options[$item])) { - case 'viewcensors': - return false; - - default: - trigger_error('Option not found, add it to the mock user object.'); + throw new Exception(sprintf("You didn't set the option '%s' on the mock user using optionset.", $item)); } + + return $this->options[$item]; + } + + public function optionset($item, $value) + { + $this->options[$item] = $value; } } diff --git a/tests/text_processing/censor_text_test.php b/tests/text_processing/censor_text_test.php index 6138d92e65..2843f0b20b 100644 --- a/tests/text_processing/censor_text_test.php +++ b/tests/text_processing/censor_text_test.php @@ -19,6 +19,8 @@ class phpbb_text_processing_censor_text_test extends phpbb_test_case global $cache, $user; $cache = new phpbb_mock_cache; $user = new phpbb_mock_user; + + $user->optionset('viewcensors', false); return array( array('', ''), -- cgit v1.2.1