X-Git-Url: https://projects.mako.cc/source/scuttle/blobdiff_plain/bce919af7b49bbd06223f79b8c37a53a3d263ff0..c7f63c8b9b12efd7b3c10b9f80cda06eaf32068f:/includes/utf8/tests/cases/utf8_str_ireplace.test.php?ds=sidebyside diff --git a/includes/utf8/tests/cases/utf8_str_ireplace.test.php b/includes/utf8/tests/cases/utf8_str_ireplace.test.php new file mode 100644 index 0000000..810c81a --- /dev/null +++ b/includes/utf8/tests/cases/utf8_str_ireplace.test.php @@ -0,0 +1,132 @@ +UnitTestCase('test_utf8_str_ireplace()'); + } + + function testReplace() { + $str = 'Iñtërnâtiônàlizætiøn'; + $replaced = 'Iñtërnâtiônàlisetiøn'; + $this->assertEqual(utf8_ireplace('lIzÆ','lise',$str),$replaced); + } + + function testReplaceNoMatch() { + $str = 'Iñtërnâtiônàlizætiøn'; + $replaced = 'Iñtërnâtiônàlizætiøn'; + $this->assertEqual(utf8_ireplace('foo','bar',$str),$replaced); + } + + function testEmptyString() { + $str = ''; + $replaced = ''; + $this->assertEqual(utf8_ireplace('foo','bar',$str),$replaced); + } + + function testEmptySearch() { + $str = 'Iñtërnâtiônàlizætiøn'; + $replaced = 'Iñtërnâtiônàlizætiøn'; + $this->assertEqual(utf8_ireplace('','x',$str),$replaced); + } + + function testReplaceCount() { + $str = 'Iñtërnâtiônàlizætiøn'; + $replaced = 'IñtërXâtiôXàlizætiøn'; + $this->assertEqual(utf8_ireplace('n','X',$str,2),$replaced); + } + + function testReplaceDifferentSearchReplaceLength() { + $str = 'Iñtërnâtiônàlizætiøn'; + $replaced = 'IñtërXXXâtiôXXXàlizætiøXXX'; + $this->assertEqual(utf8_ireplace('n','XXX',$str),$replaced); + } + + function testReplaceArrayAsciiSearch() { + $str = 'Iñtërnâtiônàlizætiøn'; + $replaced = 'Iñyërxâyiôxàlizæyiøx'; + $this->assertEqual( + utf8_ireplace( + array('n','t'), + array('x','y'), + $str + ),$replaced); + } + + function testReplaceArrayUTF8Search() { + $str = 'Iñtërnâtiônàlizætiøn'; + $replaced = 'I?tërnâti??nàliz????ti???n'; + $this->assertEqual( + utf8_ireplace( + array('Ñ','ô','ø','Æ'), + array('?','??','???','????'), + $str + ),$replaced); + } + + function testReplaceArrayStringReplace() { + $str = 'Iñtërnâtiônàlizætiøn'; + $replaced = 'I?tërnâti?nàliz?ti?n'; + $this->assertEqual( + utf8_ireplace( + array('Ñ','ô','ø','Æ'), + '?', + $str + ),$replaced); + } + + function testReplaceArraySingleArrayReplace() { + $str = 'Iñtërnâtiônàlizætiøn'; + $replaced = 'I?tërnâtinàliztin'; + $this->assertEqual( + utf8_ireplace( + array('Ñ','ô','ø','Æ'), + array('?'), + $str + ),$replaced); + } + + function testReplaceLinefeed() { + $str = "Iñtërnâti\nônàlizætiøn"; + $replaced = "Iñtërnâti\nônàlisetiøn"; + $this->assertEqual(utf8_ireplace('lIzÆ','lise',$str),$replaced); + } + + function testReplaceLinefeedSearch() { + $str = "Iñtërnâtiônàli\nzætiøn"; + $replaced = "Iñtërnâtiônàlisetiøn"; + $this->assertEqual(utf8_ireplace("lI\nzÆ",'lise',$str),$replaced); + } + +} + +//-------------------------------------------------------------------- +/** +* @package utf8 +* @subpackage Tests +*/ +if (!defined('TEST_RUNNING')) { + define('TEST_RUNNING', true); + $test = & new test_utf8_str_ireplace(); + $reporter = & getTestReporter(); + $test->run($reporter); +}