diff options
author | Raghubansh Kumar <kraghuba@php.net> | 2007-10-08 15:21:36 +0000 |
---|---|---|
committer | Raghubansh Kumar <kraghuba@php.net> | 2007-10-08 15:21:36 +0000 |
commit | 7ccc5eef20c2bfbcc42c47c979941bf3df1cb38b (patch) | |
tree | bc3d70d6199eb105e98eadf663696db878c63256 /ext/standard | |
parent | f8eacb31c0ad2a5a4eb6610689c74a3b79ba6001 (diff) | |
download | php-git-7ccc5eef20c2bfbcc42c47c979941bf3df1cb38b.tar.gz |
New testcases for strtr() function
Diffstat (limited to 'ext/standard')
-rw-r--r-- | ext/standard/tests/strings/strtr_basic.phpt | 54 | ||||
-rw-r--r-- | ext/standard/tests/strings/strtr_error.phpt | 41 | ||||
-rw-r--r-- | ext/standard/tests/strings/strtr_variation1.phpt | 86 | ||||
-rw-r--r-- | ext/standard/tests/strings/strtr_variation2.phpt | 90 | ||||
-rw-r--r-- | ext/standard/tests/strings/strtr_variation3.phpt | 104 | ||||
-rw-r--r-- | ext/standard/tests/strings/strtr_variation4.phpt | 79 | ||||
-rw-r--r-- | ext/standard/tests/strings/strtr_variation5.phpt | 137 | ||||
-rw-r--r-- | ext/standard/tests/strings/strtr_variation6.phpt | 137 | ||||
-rw-r--r-- | ext/standard/tests/strings/strtr_variation7.phpt | 156 | ||||
-rw-r--r-- | ext/standard/tests/strings/strtr_variation8.phpt | 179 | ||||
-rw-r--r-- | ext/standard/tests/strings/strtr_variation9.phpt | 243 |
11 files changed, 1306 insertions, 0 deletions
diff --git a/ext/standard/tests/strings/strtr_basic.phpt b/ext/standard/tests/strings/strtr_basic.phpt new file mode 100644 index 0000000000..2892ab0082 --- /dev/null +++ b/ext/standard/tests/strings/strtr_basic.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test strtr() function : basic functionality +--FILE-- +<?php +/* Prototype : string strtr(string $str, string $from[, string $to]); + * Description: Translates characters in str using given translation pairs + * Source code: ext/standard/string.c +*/ + +echo "*** Testing strtr() : basic functionality ***\n"; +//definitions of required input variables +$trans1_arr = array("t" => "T", "e" => "E", "st" => "ST"); +$trans2_arr = array('t' => 'T', 'e' => 'E', 'st' => 'ST'); +$heredoc_str = <<<EOD +test strtr +EOD; + +//translating single char +var_dump( strtr("test strtr", "t", "T") ); +var_dump( strtr('test strtr', 't', 'T') ); +var_dump( strtr($heredoc_str, "t", "T") ); + +//translating set of chars +//$from and $to are of same length +var_dump( strtr("test strtr", "test", "TEST") ); +var_dump( strtr('test strtr', 'test', 'TEST') ); +var_dump( strtr($heredoc_str, "test", "TEST") ); + +//$from and $to are of different lengths, extra chars in the longer one are ignored +var_dump( strtr("test strtr", "test", "TESTz") ); +var_dump( strtr('test strtr', 'testz', 'TEST') ); +var_dump( strtr($heredoc_str, "test", "TESTz") ); + +//by using replace_pairs array +var_dump( strtr("test strtr", $trans1_arr) ); +var_dump( strtr('test strtr', $trans2_arr) ); +var_dump( strtr($heredoc_str, $trans1_arr) ); +echo "*** Done ***"; +?> +--EXPECTF-- +*** Testing strtr() : basic functionality *** +string(10) "TesT sTrTr" +string(10) "TesT sTrTr" +string(10) "TesT sTrTr" +string(10) "TEST STrTr" +string(10) "TEST STrTr" +string(10) "TEST STrTr" +string(10) "TEST STrTr" +string(10) "TEST STrTr" +string(10) "TEST STrTr" +string(10) "TEST STrTr" +string(10) "TEST STrTr" +string(10) "TEST STrTr" +*** Done *** diff --git a/ext/standard/tests/strings/strtr_error.phpt b/ext/standard/tests/strings/strtr_error.phpt new file mode 100644 index 0000000000..8466a92011 --- /dev/null +++ b/ext/standard/tests/strings/strtr_error.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test strtr() function : error conditions +--FILE-- +<?php +/* Prototype : string strtr(string str, string from[, string to]) + * Description: Translates characters in str using given translation tables + * Source code: ext/standard/string.c +*/ + +echo "*** Testing strtr() : error conditions ***\n"; +$str = "string"; +$from = "string"; +$to = "STRING"; +$extra_arg = "extra_argument"; + +echo "\n-- Testing strtr() function with Zero arguments --"; +var_dump( strtr() ); + +echo "\n-- Testing strtr() function with less than expected no. of arguments --"; +var_dump( strtr($str) ); + +echo "\n-- Testing strtr() function with more than expected no. of arguments --"; +var_dump( strtr($str, $from, $to, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing strtr() : error conditions *** + +-- Testing strtr() function with Zero arguments -- +Warning: Wrong parameter count for strtr() in %s on line %d +NULL + +-- Testing strtr() function with less than expected no. of arguments -- +Warning: Wrong parameter count for strtr() in %s on line %d +NULL + +-- Testing strtr() function with more than expected no. of arguments -- +Warning: Wrong parameter count for strtr() in %s on line %d +NULL +Done diff --git a/ext/standard/tests/strings/strtr_variation1.phpt b/ext/standard/tests/strings/strtr_variation1.phpt new file mode 100644 index 0000000000..640194fd48 --- /dev/null +++ b/ext/standard/tests/strings/strtr_variation1.phpt @@ -0,0 +1,86 @@ +--TEST-- +Test strtr() function : usage variations - regular & numeric strings for 'str' argument +--FILE-- +<?php +/* Prototype : string strtr(string $str, string $from[, string $to]); + string strtr(string $str, array $replace_pairs); + * Description: Translates characters in str using given translation tables + * Source code: ext/standard/string.c +*/ + +/* Testing strtr() function by passing the + * combination of numeric & regular strings for 'str' argument and + * corresponding translation pair of chars for 'from', 'to' & 'replace_pairs' arguments +*/ + +echo "*** Testing strtr() : numeric & regular double quoted strings ***\n"; +/* definitions of required input variables */ +$count = 1; +$heredoc_str = <<<EOD +123 +abc +1a2b3c +EOD; +//array of string inputs for $str +$str_arr = array( + //double quoted strings + "123", + "abc", + "1a2b3c", + + //single quoted strings + '123', + 'abc', + '1a2b3c', + + //heredoc string + $heredoc_str +); +$from = "123abc"; +$to = "abc123"; +$replace_pairs = array("1" => "a", "a" => 1, "2b3c" => "b2c3", "b2c3" => "3c2b"); + +/* loop through to test strtr() with each element of $str_arr */ +for($index = 0; $index < count($str_arr); $index++) { + echo "-- Iteration $count --\n"; + + $str = $str_arr[$index]; //getting the $str_arr element in $str variable + + //strtr() call in three args syntax form + var_dump( strtr($str, $from, $to) ); + + //strtr() call in two args syntax form + var_dump( strtr($str, $replace_pairs) ); + + $count++; +} +echo "*** Done ***"; +?> +--EXPECTF-- +*** Testing strtr() : numeric & regular double quoted strings *** +-- Iteration 1 -- +string(3) "abc" +string(3) "a23" +-- Iteration 2 -- +string(3) "123" +string(3) "1bc" +-- Iteration 3 -- +string(6) "a1b2c3" +string(6) "a1b2c3" +-- Iteration 4 -- +string(3) "abc" +string(3) "a23" +-- Iteration 5 -- +string(3) "123" +string(3) "1bc" +-- Iteration 6 -- +string(6) "a1b2c3" +string(6) "a1b2c3" +-- Iteration 7 -- +string(14) "abc +123 +a1b2c3" +string(14) "a23 +1bc +a1b2c3" +*** Done *** diff --git a/ext/standard/tests/strings/strtr_variation2.phpt b/ext/standard/tests/strings/strtr_variation2.phpt new file mode 100644 index 0000000000..5772f01fc4 --- /dev/null +++ b/ext/standard/tests/strings/strtr_variation2.phpt @@ -0,0 +1,90 @@ +--TEST-- +Test strtr() function : usage variations - string containing special chars for 'str' argument +--FILE-- +<?php +/* Prototype : string strtr(string $str, string $from[, string $to]); + string strtr(string $str, array $replace_pairs); + * Description: Translates characters in str using given translation tables + * Source code: ext/standard/string.c +*/ + +/* Testing strtr() function by passing the + * string containing various special characters for 'str' argument and + * corresponding translation pair of chars for 'from', 'to' & 'replace_pairs' arguments +*/ + +echo "*** Testing strtr() : string containing special chars for 'str' arg ***\n"; + +/* definitions of required input variables */ +$count = 1; + +$heredoc_str = <<<EOD +% +#$*& +text & @() +EOD; + +//array of string inputs for $str +$str_arr = array( + //double quoted strings + "%", + "#$*", + "text & @()", + + //single quoted strings + '%', + '#$*', + 'text & @()', + + //heredoc string + $heredoc_str +); + +$from = "%#$*&@()"; +$to = "specials"; +$replace_pairs = array("$" => "%", "%" => "$", "#*&@()" => "()@&*#"); + +/* loop through to test strtr() with each element of $str_arr */ +for($index = 0; $index < count($str_arr); $index++) { + echo "-- Iteration $count --\n"; + + $str = $str_arr[$index]; //getting the array element in 'str' variable + + //strtr() call in three args syntax form + var_dump( strtr($str, $from, $to) ); + + //strtr() call in two args syntax form + var_dump( strtr($str, $replace_pairs) ); + + $count++; +} +echo "*** Done ***"; +?> +--EXPECTF-- +*** Testing strtr() : string containing special chars for 'str' arg *** +-- Iteration 1 -- +string(1) "s" +string(1) "$" +-- Iteration 2 -- +string(3) "pec" +string(3) "#%*" +-- Iteration 3 -- +string(10) "text i als" +string(10) "text & @()" +-- Iteration 4 -- +string(1) "s" +string(1) "$" +-- Iteration 5 -- +string(3) "pec" +string(3) "#%*" +-- Iteration 6 -- +string(10) "text i als" +string(10) "text & @()" +-- Iteration 7 -- +string(17) "s +peci +text i als" +string(17) "$ +#%*& +text & @()" +*** Done *** diff --git a/ext/standard/tests/strings/strtr_variation3.phpt b/ext/standard/tests/strings/strtr_variation3.phpt new file mode 100644 index 0000000000..d52f8507b3 --- /dev/null +++ b/ext/standard/tests/strings/strtr_variation3.phpt @@ -0,0 +1,104 @@ +--TEST-- +Test strtr() function : usage variations - string containing escape sequences for 'str' argument +--FILE-- +<?php +/* Prototype : string strtr(string $str, string $from[, string $to]); + string strtr(string $str, array $replace_pairs); + * Description: Translates characters in str using given translation tables + * Source code: ext/standard/string.c +*/ + +/* Testing strtr() function by passing the + * string containing various escape sequences for 'str' argument and + * corresponding translation pair of chars for 'from', 'to' & 'replace_pairs' arguments +*/ + +echo "*** Testing strtr() : string containing escape sequences for 'str' arg ***\n"; +/* definitions of required input variables */ +$count = 1; + +$heredoc_str = <<<EOD +\tes\t\\stt\r +\\test\\\strtr +\ntest\r\nstrtr +\$variable +\"quotes +EOD; + +//array of string inputs for $str +$str_arr = array( + //double quoted strings + "\tes\t\\stt\r", + "\\test\\\strtr", + "\ntest\r\nstrtr", + "\$variable", + "\"quotes", + + //single quoted strings + '\tes\t\\stt\r', + '\\test\\\strtr', + '\ntest\r\nstrtr', + '\$variable', + '\"quotes', + + //heredoc string + $heredoc_str +); + +$from = "\n\r\t\\"; +$to = "TEST"; +$replace_pairs = array("\n" => "t", "\r\n" => "T", "\n\r\t\\" => "TEST"); + +/* loop through to test strtr() with each element of $str_arr */ +for($index = 0; $index < count($str_arr); $index++) { + echo "-- Iteration $count --\n"; + + $str = $str_arr[$index]; //getting the array element in 'str' variable + + //strtr() call in three args syntax form + var_dump( strtr($str, $from, $to) ); + + //strtr() call in two args syntax form + var_dump( strtr($str, $replace_pairs) ); + + $count++; +} +echo "*** Done ***"; +?> +--EXPECTF-- +*** Testing strtr() : string containing escape sequences for 'str' arg *** +-- Iteration 1 -- +string(9) "SesSTsttE" +string(9) " es \stt +" +-- Iteration 2 -- +string(12) "TtestTTstrtr" +string(12) "\test\\strtr" +-- Iteration 3 -- +string(12) "TtestETstrtr" +string(11) "ttestTstrtr" +-- Iteration 4 -- +string(9) "$variable" +string(9) "$variable" +-- Iteration 5 -- +string(7) ""quotes" +string(7) ""quotes" +-- Iteration 6 -- +string(12) "TtesTtTsttTr" +string(12) "\tes\t\stt\r" +-- Iteration 7 -- +string(12) "TtestTTstrtr" +string(12) "\test\\strtr" +-- Iteration 8 -- +string(15) "TntestTrTnstrtr" +string(15) "\ntest\r\nstrtr" +-- Iteration 9 -- +string(10) "T$variable" +string(10) "\$variable" +-- Iteration 10 -- +string(8) "T"quotes" +string(8) "\"quotes" +-- Iteration 11 -- +string(54) "SesSTsttETTtestTTstrtrTTtestETstrtrT$variableTT"quotes" +string(52) " es \sttT\test\\strtrtttestTstrtrt$variablet\"quotes" +*** Done ***
\ No newline at end of file diff --git a/ext/standard/tests/strings/strtr_variation4.phpt b/ext/standard/tests/strings/strtr_variation4.phpt new file mode 100644 index 0000000000..faec849830 --- /dev/null +++ b/ext/standard/tests/strings/strtr_variation4.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test strtr() function : usage variations - empty string & null for 'str' argument +--FILE-- +<?php +/* Prototype : string strtr(string $str, string $from[, string $to]); + string strtr(string $str, array $replace_pairs); + * Description: Translates characters in str using given translation tables + * Source code: ext/standard/string.c +*/ + +/* Testing strtr() function by passing the + * empty string & null for 'str' argument and + * corresponding translation pair of chars for 'from', 'to' & 'replace_pairs' arguments +*/ + +echo "*** Testing strtr() : empty string & null for 'str' arg ***\n"; +/* definitions of required input variables */ +$count = 1; + +$heredoc_str = <<<EOD + +EOD; + +//array of string inputs for $str +$str_arr = array( + "", + '', + NULL, + null, + FALSE, + false, + $heredoc_str +); + +$from = ""; +$to = "TEST"; +$replace_pairs = array("" => "t", '' => "TEST"); + + +/* loop through to test strtr() with each element of $str_arr */ +for($index = 0; $index < count($str_arr); $index++) { + echo "-- Iteration $count --\n"; + + $str = $str_arr[$index]; //getting the array element in 'str' variable + + //strtr() call in three args syntax form + var_dump( strtr($str, $from, $to) ); + + //strtr() call in two args syntax form + var_dump( strtr($str, $replace_pairs) ); + + $count++; +} +echo "*** Done ***"; +?> +--EXPECTF-- +*** Testing strtr() : empty string & null for 'str' arg *** +-- Iteration 1 -- +string(0) "" +string(0) "" +-- Iteration 2 -- +string(0) "" +string(0) "" +-- Iteration 3 -- +string(0) "" +string(0) "" +-- Iteration 4 -- +string(0) "" +string(0) "" +-- Iteration 5 -- +string(0) "" +string(0) "" +-- Iteration 6 -- +string(0) "" +string(0) "" +-- Iteration 7 -- +string(0) "" +string(0) "" +*** Done *** diff --git a/ext/standard/tests/strings/strtr_variation5.phpt b/ext/standard/tests/strings/strtr_variation5.phpt new file mode 100644 index 0000000000..b8cf518594 --- /dev/null +++ b/ext/standard/tests/strings/strtr_variation5.phpt @@ -0,0 +1,137 @@ +--TEST-- +Test strtr() function : usage variations - unexpected inputs for 'str' argument +--FILE-- +<?php +/* Prototype : string strtr(string $str, string $from[, string $to]); + string strtr(string $str, array $replace_pairs); + * Description: Translates characters in str using given translation tables + * Source code: ext/standard/string.c +*/ + +/* Test strtr() function: with unexpected inputs for 'str' + * and expected type for 'from' & 'to' arguments +*/ + +echo "*** Testing strtr() function: with unexpected inputs for 'str' ***\n"; + +//get an unset variable +$unset_var = 'string_val'; +unset($unset_var); + +//defining a class +class sample { + public function __toString() { + return "sample object"; + } +} + +//getting the resource +$file_handle = fopen(__FILE__, "r"); + +// array with different values +$strings = array ( + + // integer values + 0, + 1, + -2, + + // float values + 10.5, + -20.5, + 10.5e10, + + // array values + array(), + array(0), + array(1, 2), + + // boolean values + true, + false, + TRUE, + FALSE, + + // null vlaues + NULL, + null, + + // objects + new sample(), + + // resource + $file_handle, + + // undefined variable + @$undefined_var, + + // unset variable + @$unset_var +); + +//defining 'from' argument +$from = "012atm"; + +//defining 'to' argument +$to = "atm012"; + +// loop through with each element of the $strings array to test strtr() function +$count = 1; +for($index = 0; $index < count($strings); $index++) { + echo "-- Iteration $count --\n"; + $str = $strings[$index]; + var_dump( strtr($str, $from, $to) ); + $count ++; +} + +fclose($file_handle); //closing the file handle + +echo "*** Done ***"; +?> +--EXPECTF-- +*** Testing strtr() function: with unexpected inputs for 'str' *** +-- Iteration 1 -- +string(1) "a" +-- Iteration 2 -- +string(1) "t" +-- Iteration 3 -- +string(2) "-m" +-- Iteration 4 -- +string(4) "ta.5" +-- Iteration 5 -- +string(5) "-ma.5" +-- Iteration 6 -- +string(12) "ta5aaaaaaaaa" +-- Iteration 7 -- + +Notice: Array to string conversion in %s on line %d +string(5) "Arr0y" +-- Iteration 8 -- + +Notice: Array to string conversion in %s on line %d +string(5) "Arr0y" +-- Iteration 9 -- + +Notice: Array to string conversion in %s on line %d +string(5) "Arr0y" +-- Iteration 10 -- +string(1) "t" +-- Iteration 11 -- +string(0) "" +-- Iteration 12 -- +string(1) "t" +-- Iteration 13 -- +string(0) "" +-- Iteration 14 -- +string(0) "" +-- Iteration 15 -- +string(0) "" +-- Iteration 16 -- +string(13) "s02ple objec1" +-- Iteration 17 -- +string(14) "Resource id #5" +-- Iteration 18 -- +string(0) "" +-- Iteration 19 -- +string(0) "" +*** Done *** diff --git a/ext/standard/tests/strings/strtr_variation6.phpt b/ext/standard/tests/strings/strtr_variation6.phpt new file mode 100644 index 0000000000..2d8ab71831 --- /dev/null +++ b/ext/standard/tests/strings/strtr_variation6.phpt @@ -0,0 +1,137 @@ +--TEST-- +Test strtr() function : usage variations - unexpected inputs for 'from' argument +--FILE-- +<?php +/* Prototype : string strtr(string $str, string $from[, string $to]); + string strtr(string $str, array $replace_pairs); + * Description: Translates characters in str using given translation tables + * Source code: ext/standard/string.c +*/ + +/* Test strtr() function: with unexpected inputs for 'from' + * and expected type for 'str' & 'to' arguments +*/ + +echo "*** Testing strtr() function: with unexpected inputs for 'from' ***\n"; + +//get an unset variable +$unset_var = 'string_val'; +unset($unset_var); + +//defining a class +class sample { + public function __toString() { + return "sample object"; + } +} + +//getting the resource +$file_handle = fopen(__FILE__, "r"); + +//defining 'str' argument +$str = "012atm"; + +// array of values for 'from' +$from_arr = array ( + + // integer values + 0, + 1, + -2, + + // float values + 10.5, + -20.5, + 10.5e10, + + // array values + array(), + array(0), + array(1, 2), + + // boolean values + true, + false, + TRUE, + FALSE, + + // null vlaues + NULL, + null, + + // objects + new sample(), + + // resource + $file_handle, + + // undefined variable + @$undefined_var, + + // unset variable + @$unset_var +); + +//defining 'to' argument +$to = "atm012"; + +// loop through with each element of the $from array to test strtr() function +$count = 1; +for($index = 0; $index < count($from_arr); $index++) { + echo "-- Iteration $count --\n"; + $from = $from_arr[$index]; + var_dump( strtr($str, $from, $to) ); + $count ++; +} + +fclose($file_handle); //closing the file handle + +echo "*** Done ***"; +?> +--EXPECTF-- +*** Testing strtr() function: with unexpected inputs for 'from' *** +-- Iteration 1 -- +string(6) "a12atm" +-- Iteration 2 -- +string(6) "0a2atm" +-- Iteration 3 -- +string(6) "01tatm" +-- Iteration 4 -- +string(6) "ta2atm" +-- Iteration 5 -- +string(6) "m1tatm" +-- Iteration 6 -- +string(6) "2a2atm" +-- Iteration 7 -- + +Notice: Array to string conversion in %s on line %d +string(6) "0120tm" +-- Iteration 8 -- + +Notice: Array to string conversion in %s on line %d +string(6) "0120tm" +-- Iteration 9 -- + +Notice: Array to string conversion in %s on line %d +string(6) "0120tm" +-- Iteration 10 -- +string(6) "0a2atm" +-- Iteration 11 -- +string(6) "012atm" +-- Iteration 12 -- +string(6) "0a2atm" +-- Iteration 13 -- +string(6) "012atm" +-- Iteration 14 -- +string(6) "012atm" +-- Iteration 15 -- +string(6) "012atm" +-- Iteration 16 -- +string(6) "012ttm" +-- Iteration 17 -- +string(6) "012atm" +-- Iteration 18 -- +string(6) "012atm" +-- Iteration 19 -- +string(6) "012atm" +*** Done *** diff --git a/ext/standard/tests/strings/strtr_variation7.phpt b/ext/standard/tests/strings/strtr_variation7.phpt new file mode 100644 index 0000000000..04b742f312 --- /dev/null +++ b/ext/standard/tests/strings/strtr_variation7.phpt @@ -0,0 +1,156 @@ +--TEST-- +Test strtr() function : usage variations - unexpected inputs for 'to' argument +--FILE-- +<?php +/* Prototype : string strtr(string $str, string $from[, string $to]); + string strtr(string $str, array $replace_pairs); + * Description: Translates characters in str using given translation tables + * Source code: ext/standard/string.c +*/ + +/* Test strtr() function: with unexpected inputs for 'to' + * and expected types for 'str' & 'from' arguments +*/ + +echo "*** Testing strtr() function: with unexpected inputs for 'to' ***\n"; + +//get an unset variable +$unset_var = 'string_val'; +unset($unset_var); + +//defining a class +class sample { + public function __toString() { + return "sample object"; + } +} + +//getting the resource +$file_handle = fopen(__FILE__, "r"); + +//defining 'str' argument +$str = "012atm"; + +//defining 'from' argument +$from = "atm012"; + +// array of values for 'to' argument +$to_arr = array ( + + // integer values + 0, + 1, + -2, + + // float values + 10.5, + -20.5, + 10.5e10, + + // array values + array(), + array(0), + array(1, 2), + + // boolean values + true, + false, + TRUE, + FALSE, + + // null vlaues + NULL, + null, + + // objects + new sample(), + + // resource + $file_handle, + + // undefined variable + @$undefined_var, + + // unset variable + @$unset_var +); + +// loop through with each element of the $to array to test strtr() function +$count = 1; +for($index = 0; $index < count($to_arr); $index++) { + echo "\n-- Iteration $count --\n"; + $to = $to_arr[$index]; + var_dump( strtr($str, $from, $to) ); + $count ++; +} + +fclose($file_handle); //closing the file handle + +echo "*** Done ***"; +?> +--EXPECTF-- +*** Testing strtr() function: with unexpected inputs for 'to' *** + +-- Iteration 1 -- +string(6) "0120tm" + +-- Iteration 2 -- +string(6) "0121tm" + +-- Iteration 3 -- +string(6) "012-2m" + +-- Iteration 4 -- +string(6) "51210." + +-- Iteration 5 -- +string(6) ".52-20" + +-- Iteration 6 -- +string(6) "000105" + +-- Iteration 7 -- + +Notice: Array to string conversion in %s on line %d +string(6) "ay2Arr" + +-- Iteration 8 -- + +Notice: Array to string conversion in %s on line %d +string(6) "ay2Arr" + +-- Iteration 9 -- + +Notice: Array to string conversion in %s on line %d +string(6) "ay2Arr" + +-- Iteration 10 -- +string(6) "0121tm" + +-- Iteration 11 -- +string(6) "012atm" + +-- Iteration 12 -- +string(6) "0121tm" + +-- Iteration 13 -- +string(6) "012atm" + +-- Iteration 14 -- +string(6) "012atm" + +-- Iteration 15 -- +string(6) "012atm" + +-- Iteration 16 -- +string(6) "plesam" + +-- Iteration 17 -- +string(6) "ourRes" + +-- Iteration 18 -- +string(6) "012atm" + +-- Iteration 19 -- +string(6) "012atm" +*** Done *** diff --git a/ext/standard/tests/strings/strtr_variation8.phpt b/ext/standard/tests/strings/strtr_variation8.phpt new file mode 100644 index 0000000000..4d2b42b02b --- /dev/null +++ b/ext/standard/tests/strings/strtr_variation8.phpt @@ -0,0 +1,179 @@ +--TEST-- +Test strtr() function : usage variations - unexpected inputs for 'replace_pairs' argument +--FILE-- +<?php +/* Prototype : string strtr(string $str, string $from[, string $to]); + string strtr(string $str, array $replace_pairs); + * Description: Translates characters in str using given translation tables + * Source code: ext/standard/string.c +*/ + +/* Test strtr() function: with unexpected inputs for 'replace_pairs' + * and expected type for 'str' arguments +*/ + +echo "*** Testing strtr() function: with unexpected inputs for 'replace_pairs' ***\n"; + +//get an unset variable +$unset_var = 'string_val'; +unset($unset_var); + +//defining a class +class sample { + public function __toString() { + return "sample object"; + } +} + +//getting the resource +$file_handle = fopen(__FILE__, "r"); + +//defining 'str' argument +$str = "012atm"; + +// array of inputs for 'replace_pairs' argument +$replace_pairs_arr = array ( + + // integer values + 0, + 1, + -2, + + // float values + 10.5, + -20.5, + 10.5e10, + + // array values + array(), + array(0), + array(1, 2), + + // boolean values + true, + false, + TRUE, + FALSE, + + // null vlaues + NULL, + null, + + // objects + new sample(), + + // resource + $file_handle, + + // undefined variable + @$undefined_var, + + // unset variable + @$unset_var +); + +// loop through with each element of the $replace_pairs array to test strtr() function +$count = 1; +for($index = 0; $index < count($replace_pairs_arr); $index++) { + echo "\n-- Iteration $count --\n"; + $replace_pairs = $replace_pairs_arr[$index]; + var_dump( strtr($str, $replace_pairs) ); + $count ++; +} + +fclose($file_handle); //closing the file handle + +echo "*** Done ***"; +?> +--EXPECTF-- +*** Testing strtr() function: with unexpected inputs for 'replace_pairs' *** + +-- Iteration 1 -- + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 7 -- +string(6) "012atm" + +-- Iteration 8 -- +string(6) "012atm" + +-- Iteration 9 -- +string(6) "122atm" + +-- Iteration 10 -- + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 18 -- + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 19 -- + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) +*** Done *** diff --git a/ext/standard/tests/strings/strtr_variation9.phpt b/ext/standard/tests/strings/strtr_variation9.phpt new file mode 100644 index 0000000000..810ece1df9 --- /dev/null +++ b/ext/standard/tests/strings/strtr_variation9.phpt @@ -0,0 +1,243 @@ +--TEST-- +Test strtr() function : usage variations - unexpected inputs for all arguments +--FILE-- +<?php +/* Prototype : string strtr(string $str, string $from[, string $to]); + string strtr(string $str, array $replace_pairs); + * Description: Translates characters in str using given translation tables + * Source code: ext/standard/string.c +*/ + +/* Test strtr() function: with unexpected inputs for 'str', 'from', 'to' & 'replace_pairs' arguments */ + +echo "*** Testing strtr() function: with unexpected inputs for all arguments ***\n"; + +//get an unset variable +$unset_var = 'string_val'; +unset($unset_var); + +//defining a class +class sample { + public function __toString() { + return "sample object"; + } +} + +//getting the resource +$file_handle = fopen(__FILE__, "r"); + +// array with different values +$values = array ( + + // integer values + 0, + 1, + -2, + + // float values + 10.5, + -20.5, + 10.5e10, + + // array values + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // boolean values + true, + false, + TRUE, + FALSE, + + // null vlaues + NULL, + null, + + // objects + new sample(), + + // resource + $file_handle, + + // undefined variable + @$undefined_var, + + // unset variable + @$unset_var +); + +// loop through with each element of the $values array to test strtr() function +$count = 1; +for($index = 0; $index < count($values); $index++) { + echo "\n-- Iteration $count --\n"; + var_dump( strtr($values[$index], $values[$index], $values[$index]) ); //fn call with three args + var_dump( strtr($values[$index], $values[$index]) ); //fn call with two args + $count ++; +} + +fclose($file_handle); //closing the file handle + +echo "*** Done ***"; +?> +--EXPECTF-- +*** Testing strtr() function: with unexpected inputs for all arguments *** + +-- Iteration 1 -- +string(1) "0" + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 2 -- +string(1) "1" + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 3 -- +string(2) "-2" + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 4 -- +string(4) "10.5" + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 5 -- +string(5) "-20.5" + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 6 -- +string(12) "105000000000" + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 7 -- + +Notice: Array to string conversion in %s on line %d + +Notice: Array to string conversion in %s on line %d + +Notice: Array to string conversion in %s on line %d +string(5) "Array" + +Notice: Array to string conversion in %s on line %d +string(5) "Array" + +-- Iteration 8 -- + +Notice: Array to string conversion in %s on line %d + +Notice: Array to string conversion in %s on line %d + +Notice: Array to string conversion in %s on line %d +string(5) "Array" + +Notice: Array to string conversion in %s on line %d +string(5) "Array" + +-- Iteration 9 -- + +Notice: Array to string conversion in %s on line %d + +Notice: Array to string conversion in %s on line %d + +Notice: Array to string conversion in %s on line %d +string(5) "Array" + +Notice: Array to string conversion in %s on line %d +string(5) "Array" + +-- Iteration 10 -- + +Notice: Array to string conversion in %s on line %d + +Notice: Array to string conversion in %s on line %d + +Notice: Array to string conversion in %s on line %d +string(5) "Array" + +Notice: Array to string conversion in %s on line %d +string(5) "Array" + +-- Iteration 11 -- + +Notice: Array to string conversion in %s on line %d + +Notice: Array to string conversion in %s on line %d + +Notice: Array to string conversion in %s on line %d +string(5) "Array" + +Notice: Array to string conversion in %s on line %d +string(5) "Array" + +-- Iteration 12 -- +string(1) "1" + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 13 -- +string(0) "" + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 14 -- +string(1) "1" + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 15 -- +string(0) "" + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 16 -- +string(0) "" + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 17 -- +string(0) "" + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 18 -- +string(13) "sample object" + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 19 -- +string(14) "Resource id #5" + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 20 -- +string(0) "" + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) + +-- Iteration 21 -- +string(0) "" + +Warning: strtr(): The second argument is not an array in %s on line %d +bool(false) +*** Done *** |