aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Wiedler <igor@wiedler.ch>2011-09-05 09:14:06 +0200
committerIgor Wiedler <igor@wiedler.ch>2011-09-05 09:14:06 +0200
commit3048fcf4b811d471b26acdc790bdac18b8e9500e (patch)
tree3ae214da08be5f76b5ac827fa15a1b569a57bb34
parent6f9df6199cee4a845a1cc654ebb92cfc67328ec7 (diff)
parent85bdc65df1ffa31a395623941e363d397f6688ac (diff)
downloadforums-3048fcf4b811d471b26acdc790bdac18b8e9500e.tar
forums-3048fcf4b811d471b26acdc790bdac18b8e9500e.tar.gz
forums-3048fcf4b811d471b26acdc790bdac18b8e9500e.tar.bz2
forums-3048fcf4b811d471b26acdc790bdac18b8e9500e.tar.xz
forums-3048fcf4b811d471b26acdc790bdac18b8e9500e.zip
Merge branch 'develop-olympus' into develop
* develop-olympus: [ticket/10240] Added optionset to mock_user in the tests. [ticket/10240] Fixed copyright year in censor_text_test.php. [ticket/10240] Fixed censor_text test assetEquals param order. [ticket/10240] Added censor_text tests for special characters. [ticket/10240] Added censor_text tests. Conflicts: tests/mock/cache.php
-rw-r--r--tests/mock/cache.php22
-rw-r--r--tests/mock_user.php16
-rw-r--r--tests/text_processing/censor_text_test.php85
3 files changed, 123 insertions, 0 deletions
diff --git a/tests/mock/cache.php b/tests/mock/cache.php
index d3f9b8ad5a..989180c256 100644
--- a/tests/mock/cache.php
+++ b/tests/mock/cache.php
@@ -31,6 +31,28 @@ class phpbb_mock_cache implements phpbb_cache_driver_interface
$this->data[$var_name] = $var;
}
+ /**
+ * 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 checkVar(PHPUnit_Framework_Assert $test, $var_name, $data)
{
$test->assertTrue(isset($this->data[$var_name]));
diff --git a/tests/mock_user.php b/tests/mock_user.php
index 74d31c4c4a..5b89ea3e19 100644
--- a/tests/mock_user.php
+++ b/tests/mock_user.php
@@ -17,4 +17,20 @@ class phpbb_mock_user
{
public $host = "testhost";
public $page = array('root_script_path' => '/');
+
+ private $options = array();
+ public function optionget($item)
+ {
+ if (!isset($this->options[$item]))
+ {
+ 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
new file mode 100644
index 0000000000..2843f0b20b
--- /dev/null
+++ b/tests/text_processing/censor_text_test.php
@@ -0,0 +1,85 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 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;
+
+ $user->optionset('viewcensors', false);
+
+ 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'),
+
+ 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'),
+ );
+ }
+
+ /**
+ * @dataProvider censor_text_data
+ */
+ public function test_censor_text($input, $expected)
+ {
+ $label = 'Testing word censor: ' . $input;
+ $this->assertEquals($expected, censor_text($input), $label);
+ }
+}