aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2008-05-04 12:04:08 +0000
committerNils Adermann <naderman@naderman.de>2008-05-04 12:04:08 +0000
commit378838499e0d83de1aa1e3abb7935fd835091f7d (patch)
treec20d05a1074e740d15781e0b15991e4e2f54a348
parent60aad364c8e112f39c9de786c39df7ab0c3b5d53 (diff)
downloadforums-378838499e0d83de1aa1e3abb7935fd835091f7d.tar
forums-378838499e0d83de1aa1e3abb7935fd835091f7d.tar.gz
forums-378838499e0d83de1aa1e3abb7935fd835091f7d.tar.bz2
forums-378838499e0d83de1aa1e3abb7935fd835091f7d.tar.xz
forums-378838499e0d83de1aa1e3abb7935fd835091f7d.zip
Going further with our attempt to make phpBB more stable: Testing with PHPUnit
git-svn-id: file:///svn/phpbb/trunk@8539 89ea8834-ac86-4346-8a33-228a782c2dd0
-rw-r--r--tests/all_tests.php34
-rw-r--r--tests/utf/all_tests.php34
-rw-r--r--tests/utf/utf8_wordwrap_test.php78
3 files changed, 146 insertions, 0 deletions
diff --git a/tests/all_tests.php b/tests/all_tests.php
new file mode 100644
index 0000000000..407a72f4f7
--- /dev/null
+++ b/tests/all_tests.php
@@ -0,0 +1,34 @@
+<?php
+define('IN_PHPBB', true);
+if (!defined('PHPUnit_MAIN_METHOD'))
+{
+ define('PHPUnit_MAIN_METHOD', 'phpbb_all_tests::main');
+}
+
+require_once 'PHPUnit/Framework.php';
+require_once 'PHPUnit/TextUI/TestRunner.php';
+
+require_once 'utf/all_tests.php';
+
+class phpbb_all_tests
+{
+ public static function main()
+ {
+ PHPUnit_TextUI_TestRunner::run(self::suite());
+ }
+
+ public static function suite()
+ {
+ $suite = new PHPUnit_Framework_TestSuite('phpBB');
+
+ $suite->addTest(phpbb_utf_all_tests::suite());
+
+ return $suite;
+ }
+}
+
+if (PHPUnit_MAIN_METHOD == 'phpbb_all_tests::main')
+{
+ phpbb_all_tests::main();
+}
+?> \ No newline at end of file
diff --git a/tests/utf/all_tests.php b/tests/utf/all_tests.php
new file mode 100644
index 0000000000..8d1b1bab3f
--- /dev/null
+++ b/tests/utf/all_tests.php
@@ -0,0 +1,34 @@
+<?php
+define('IN_PHPBB', true);
+if (!defined('PHPUnit_MAIN_METHOD'))
+{
+ define('PHPUnit_MAIN_METHOD', 'phpbb_utf_all_tests::main');
+}
+
+require_once 'PHPUnit/Framework.php';
+require_once 'PHPUnit/TextUI/TestRunner.php';
+
+require_once 'utf/utf8_wordwrap_test.php';
+
+class phpbb_utf_all_tests
+{
+ public static function main()
+ {
+ PHPUnit_TextUI_TestRunner::run(self::suite());
+ }
+
+ public static function suite()
+ {
+ $suite = new PHPUnit_Framework_TestSuite('phpBB Unicode Transformation Format');
+
+ $suite->addTestSuite('phpbb_utf_utf8_wordwrap_test');
+
+ return $suite;
+ }
+}
+
+if (PHPUnit_MAIN_METHOD == 'phpbb_utf_all_tests::main')
+{
+ phpbb_utf_all_tests::main();
+}
+?> \ No newline at end of file
diff --git a/tests/utf/utf8_wordwrap_test.php b/tests/utf/utf8_wordwrap_test.php
new file mode 100644
index 0000000000..5a5417a0b0
--- /dev/null
+++ b/tests/utf/utf8_wordwrap_test.php
@@ -0,0 +1,78 @@
+<?php
+define('IN_PHPBB', true);
+
+require_once 'PHPUnit/Framework.php';
+require_once '../phpBB/includes/utf/utf_tools.php';
+
+class phpbb_utf_utf8_wordwrap_test extends PHPUnit_Framework_TestCase
+{
+ public function test_utf8_wordwrap_ascii()
+ {
+ // if the input is all ascii it should work exactly like php's wordwrap
+
+ $text = 'The quick brown fox jumped over the lazy dog.';
+
+ $php_wordwrap = wordwrap($text, 20);
+ $phpbb_utf8_wordwrap = utf8_wordwrap($text, 20);
+ $this->assertEquals($phpbb_utf8_wordwrap, $php_wordwrap, "Checking ASCII standard behaviour with length 20");
+
+ $php_wordwrap = wordwrap($text, 30, "<br />\n");
+ $phpbb_utf8_wordwrap = utf8_wordwrap($text, 30, "<br />\n");
+ $this->assertEquals($phpbb_utf8_wordwrap, $php_wordwrap, "Checking ASCII special break string with length 30");
+
+ $text = 'A very long woooooooooooord.';
+
+ $php_wordwrap = wordwrap($text, 8, "\n");
+ $phpbb_utf8_wordwrap = utf8_wordwrap($text, 8, "\n");
+ $this->assertEquals($phpbb_utf8_wordwrap, $php_wordwrap, 'Checking ASCII not cutting long words');
+
+ $php_wordwrap = wordwrap($text, 8, "\n", true);
+ $phpbb_utf8_wordwrap = utf8_wordwrap($text, 8, "\n", true);
+ $this->assertEquals($phpbb_utf8_wordwrap, $php_wordwrap, 'Checking ASCII cutting long words');
+ }
+
+ /**
+ * Helper function that generates meaningless greek text
+ */
+ private function turn_into_greek($string)
+ {
+ $greek_chars = array("\xCE\x90", "\xCE\x91", "\xCE\x92", "\xCE\x93", "\xCE\x94", "\xCE\x95", "\xCE\x96", "\xCE\x97", "\xCE\x98", "\xCE\x99");
+
+ $greek = '';
+ for ($i = 0, $n = strlen($string); $i < $n; $i++)
+ {
+ // replace each number with the character from the array
+ if (ctype_digit($string[$i]))
+ {
+ $greek .= $greek_chars[(int) $string[$i]];
+ }
+ else
+ {
+ $greek .= $string[$i];
+ }
+ }
+
+ return $greek;
+ }
+
+ public function test_utf8_wordwrap_utf8()
+ {
+ $text = "0123456 0123 012345 01234";
+ $greek = $this->turn_into_greek($text);
+
+ $expected = $this->turn_into_greek(wordwrap($text, 10));
+ $phpbb_utf8_wordwrap = utf8_wordwrap($greek, 10);
+ $this->assertEquals($phpbb_utf8_wordwrap, $expected, 'Checking UTF-8 standard behaviour with length 10');
+ }
+
+ public function test_utf8_wordwrap_utf8_cut()
+ {
+ $text = "0123456 0123 012345 01234";
+ $greek = $this->turn_into_greek($text);
+
+ $expected = $this->turn_into_greek(wordwrap($text, 5, "\n", true));
+ $phpbb_utf8_wordwrap = utf8_wordwrap($greek, 5, "\n", true);
+ $this->assertEquals($phpbb_utf8_wordwrap, $expected, 'Checking UTF-8 cutting long words');
+ }
+}
+?> \ No newline at end of file