Tagged 0.7.5
[scuttle] / includes / utf8 / tests / cases / utf8_str_ireplace.test.php
1 <?php
2 /**
3 * @version $Id: utf8_str_ireplace.test.php,v 1.3 2007/08/12 01:20:46 harryf Exp $
4 * @package utf8
5 * @subpackage Tests
6 */
7
8 //--------------------------------------------------------------------
9 /**
10 * Includes
11 * @package utf8
12 * @subpackage Tests
13 */
14 require_once(dirname(__FILE__).'/../config.php');
15 require_once UTF8 . '/str_ireplace.php';
16
17 //--------------------------------------------------------------------
18 /**
19 * @package utf8
20 * @subpackage Tests
21 */
22 class test_utf8_str_ireplace extends UnitTestCase {
23
24     function test_utf8_str_ireplace() {
25         $this->UnitTestCase('test_utf8_str_ireplace()');
26     }
27     
28     function testReplace() {
29         $str = 'Iñtërnâtiônàlizætiøn';
30         $replaced = 'Iñtërnâtiônàlisetiøn';
31         $this->assertEqual(utf8_ireplace('lIzÆ','lise',$str),$replaced);
32     }
33     
34     function testReplaceNoMatch() {
35         $str = 'Iñtërnâtiônàlizætiøn';
36         $replaced = 'Iñtërnâtiônàlizætiøn';
37         $this->assertEqual(utf8_ireplace('foo','bar',$str),$replaced);
38     }
39     
40     function testEmptyString() {
41         $str = '';
42         $replaced = '';
43         $this->assertEqual(utf8_ireplace('foo','bar',$str),$replaced);
44     }
45     
46     function testEmptySearch() {
47         $str = 'Iñtërnâtiônàlizætiøn';
48         $replaced = 'Iñtërnâtiônàlizætiøn';
49         $this->assertEqual(utf8_ireplace('','x',$str),$replaced);
50     }
51     
52     function testReplaceCount() {
53         $str = 'Iñtërnâtiônàlizætiøn';
54         $replaced = 'IñtërXâtiôXàlizætiøn';
55         $this->assertEqual(utf8_ireplace('n','X',$str,2),$replaced);
56     }
57     
58     function testReplaceDifferentSearchReplaceLength() {
59         $str = 'Iñtërnâtiônàlizætiøn';
60         $replaced = 'IñtërXXXâtiôXXXàlizætiøXXX';
61         $this->assertEqual(utf8_ireplace('n','XXX',$str),$replaced);
62     }
63     
64     function testReplaceArrayAsciiSearch() {
65         $str = 'Iñtërnâtiônàlizætiøn';
66         $replaced = 'Iñyërxâyiôxàlizæyiøx';
67         $this->assertEqual(
68             utf8_ireplace(
69                 array('n','t'),
70                 array('x','y'),
71                 $str
72                 ),$replaced);
73     }
74     
75     function testReplaceArrayUTF8Search() {
76         $str = 'Iñtërnâtiônàlizætiøn';
77         $replaced = 'I?tërnâti??nàliz????ti???n';
78         $this->assertEqual(
79             utf8_ireplace(
80                 array('Ñ','ô','ø','Æ'),
81                 array('?','??','???','????'),
82                 $str
83                 ),$replaced);
84     }
85     
86     function testReplaceArrayStringReplace() {
87         $str = 'Iñtërnâtiônàlizætiøn';
88         $replaced = 'I?tërnâti?nàliz?ti?n';
89         $this->assertEqual(
90             utf8_ireplace(
91                 array('Ñ','ô','ø','Æ'),
92                 '?',
93                 $str
94                 ),$replaced);
95     }
96     
97     function testReplaceArraySingleArrayReplace() {
98         $str = 'Iñtërnâtiônàlizætiøn';
99         $replaced = 'I?tërnâtinàliztin';
100         $this->assertEqual(
101             utf8_ireplace(
102                 array('Ñ','ô','ø','Æ'),
103                 array('?'),
104                 $str
105                 ),$replaced);
106     }
107     
108     function testReplaceLinefeed() {
109         $str =      "Iñtërnâti\nônàlizætiøn";
110         $replaced = "Iñtërnâti\nônàlisetiøn";
111         $this->assertEqual(utf8_ireplace('lIzÆ','lise',$str),$replaced);
112     }
113     
114     function testReplaceLinefeedSearch() {
115         $str =      "Iñtërnâtiônàli\nzætiøn";
116         $replaced = "Iñtërnâtiônàlisetiøn";
117         $this->assertEqual(utf8_ireplace("lI\nzÆ",'lise',$str),$replaced);
118     }
119     
120 }
121
122 //--------------------------------------------------------------------
123 /**
124 * @package utf8
125 * @subpackage Tests
126 */
127 if (!defined('TEST_RUNNING')) {
128     define('TEST_RUNNING', true);
129     $test = & new test_utf8_str_ireplace();
130     $reporter = & getTestReporter();
131     $test->run($reporter);
132 }

Benjamin Mako Hill || Want to submit a patch?