diff options
Diffstat (limited to 'ext/standard/tests')
19 files changed, 884 insertions, 10 deletions
diff --git a/ext/standard/tests/class_object/get_class_variation_001.phpt b/ext/standard/tests/class_object/get_class_variation_001.phpt index d39da3a991..3987968e90 100644 --- a/ext/standard/tests/class_object/get_class_variation_001.phpt +++ b/ext/standard/tests/class_object/get_class_variation_001.phpt @@ -152,12 +152,12 @@ bool(false) Arg value: (type: NULL) -Warning: get_class() called without object from outside a class in %sget_class_variation_001.php on line %d +Warning: get_class() expects parameter 1 to be object, null given in %s on line %d bool(false) Arg value: (type: NULL) -Warning: get_class() called without object from outside a class in %sget_class_variation_001.php on line %d +Warning: get_class() expects parameter 1 to be object, null given in %s on line %d bool(false) Arg value: 1 (type: boolean) @@ -202,11 +202,11 @@ bool(false) Arg value: (type: NULL) -Warning: get_class() called without object from outside a class in %sget_class_variation_001.php on line %d +Warning: get_class() expects parameter 1 to be object, null given in %s on line %d bool(false) Arg value: (type: NULL) -Warning: get_class() called without object from outside a class in %sget_class_variation_001.php on line %d +Warning: get_class() expects parameter 1 to be object, null given in %s on line %d bool(false) Done diff --git a/ext/standard/tests/general_functions/proc_nice_basic-win.phpt b/ext/standard/tests/general_functions/proc_nice_basic-win.phpt new file mode 100644 index 0000000000..232389fd90 --- /dev/null +++ b/ext/standard/tests/general_functions/proc_nice_basic-win.phpt @@ -0,0 +1,96 @@ +--TEST-- +proc_nice() basic behaviour +--SKIPIF-- +<?php +/* No function_exists() check, proc_nice() is always available on Windows */ + +if (!defined('PHP_WINDOWS_VERSION_MAJOR')) { + die('skip: Only for Windows'); +} + +if (PHP_SAPI != 'cli') { + die('skip: Only for CLI'); +} + +if (getenv('SKIP_SLOW_TESTS')) { + doe('skip: Slow test'); +} +?> +--FILE-- +<?php +function get_priority_from_wmic() { + static $bin, $pid; + + if (!$bin) { + $t = explode('\\', PHP_BINARY); + + $bin = end($t); + $pid = getmypid(); + } + + $t = ''; + $p = popen('wmic process where name="' . $bin . '"', 'r'); + + if (!$p) { + return false; + } + + while(!feof($p)) { + $t .= fread($p, 1024); + } + + pclose($p); + + $t = explode(PHP_EOL, $t); + + $f = false; + $m = [ + strpos($t[0], ' ProcessId' ), + strpos($t[0], ' Priority ') + ]; + + foreach ($t as $n => $l) { + if (!$n || empty($l)) { + continue; + } + + $d = []; + + foreach ($m as $c) { + $d[] = (int) substr($l, $c + 1, strpos($l, ' ', $c + 2) - ($c + 1)); + } + + if ($d[0] === $pid) { + return $d[1]; + } + } + + return false; +} + +$p = [ + /* '<verbose name>' => ['<wmic value>', '<proc_nice value>'] */ + + 'Idle' => [4, 10], + 'Below normal' => [6, 5], + 'Normal' => [8, 0], + 'Above normal' => [10, -5], + 'High priority' => [13, -10], + 'Real time' => [24, -16] + ]; + +foreach ($p as $test => $data) { + printf('Testing \'%s\' (%d): ', $test, $data[1]); + + proc_nice($data[1]); + + print (($wp = get_priority_from_wmic()) === $data[0] ? 'Passed' : 'Failed (' . $wp . ')') . PHP_EOL; +} +?> +--EXPECTF-- +Testing 'Idle' (10): Passed +Testing 'Below normal' (5): Passed +Testing 'Normal' (0): Passed +Testing 'Above normal' (-5): Passed +Testing 'High priority' (-10): Passed +Testing 'Real time' (-16): Passed diff --git a/ext/standard/tests/general_functions/proc_nice_basic.phpt b/ext/standard/tests/general_functions/proc_nice_basic.phpt index 83b5165679..12469bf4eb 100644 --- a/ext/standard/tests/general_functions/proc_nice_basic.phpt +++ b/ext/standard/tests/general_functions/proc_nice_basic.phpt @@ -8,6 +8,7 @@ Simone Gentili (sensorario@gmail.com) --SKIPIF-- <?php if(!function_exists('proc_nice')) die("skip. proc_nice not available "); +if(substr(strtoupper(PHP_OS), 0, 3) == 'WIN') die('skip. not for Windows'); ?> --FILE-- <?php diff --git a/ext/standard/tests/general_functions/type.phpt b/ext/standard/tests/general_functions/type.phpt index eb6f0672fe..df2dbaf461 100644 --- a/ext/standard/tests/general_functions/type.phpt +++ b/ext/standard/tests/general_functions/type.phpt @@ -63,7 +63,7 @@ string(6) "double" string(4) "NULL" string(7) "boolean" string(6) "string" -string(12) "unknown type" +string(17) "resource (closed)" string(8) "resource" string(6) "object" bool(true) diff --git a/ext/standard/tests/mail/mail_basic7.phpt b/ext/standard/tests/mail/mail_basic7.phpt new file mode 100644 index 0000000000..3b389d2c4e --- /dev/null +++ b/ext/standard/tests/mail/mail_basic7.phpt @@ -0,0 +1,218 @@ +--TEST-- +Test mail() function : array extra header basic functionality +--INI-- +sendmail_path=tee mailBasic.out >/dev/null +mail.add_x_header = Off +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip Won't run on Windows"); +?> +--FILE-- +<?php +/* Prototype : int mail(string to, string subject, string message [, mixed additional_headers [, string additional_parameters]]) + * Description: Send an email message + * Source code: ext/standard/mail.c + * Alias to functions: + */ + +error_reporting(-1); + +echo "*** Testing mail() : basic functionality ***\n"; + +echo "\n\n************* TEST ******************\n"; +// Should pass +// Initialise all required variables +$to = 'user@example.com'; +$subject = 'Test Subject'; +$message = 'A Message'; +$additional_headers = array( + 'KHeaders' => 'aaaa', + 'bcc'=>'foo@bar', + 'foo'=> + array( + "bar\r\n hoge", + "bar\r\n\t fuga", + ), +); +$outFile = "mailBasic.out"; +@unlink($outFile); + +echo "-- All Mail Content Parameters --\n"; +// Calling mail() with all additional headers +var_dump( mail($to, $subject, $message, $additional_headers) ); +echo file_get_contents($outFile); +unlink($outFile); + + +echo "\n\n************* TEST ******************\n"; +// Should fail all +// Initialise all required variables +$to = 'user@example.com'; +$subject = 'Test Subject'; +$message = 'A Message'; +// Headers should not have array values +$additional_headers = array( + 'orig-date' => array('foo1'), + 'from' => array('foo2'), + 'sender' => array('foo3'), + 'reply-to' => array('foo4'), + 'to' => array('foo5'), + 'bcc' => array('foo6'), + 'message-id' => array('foo7'), + 'in-reply-to'=> array('foo8'), +); +$outFile = "mailBasic.out"; +@unlink($outFile); + +echo "-- All Mail Content Parameters --\n"; +// Calling mail() with all additional headers +var_dump( mail($to, $subject, $message, $additional_headers) ); +echo file_get_contents($outFile); +unlink($outFile); + + +echo "\n\n************* TEST ******************\n"; +// Should fail all +// Initialise all required variables +$to = 'user@example.com'; +$subject = 'Test Subject'; +$message = 'A Message'; +$additional_headers = array( + 'foo1' => array('foo1'=>'bar1'), + 'foo2' => array('foo2', array('foo3')), + 'foo3' => array(123), + 'foo4' => array(123.456), + 'foo5' => array(FALSE), + 'foo6' => array(NULL), + 'foo7' => array(new StdClass), +); +$outFile = "mailBasic.out"; +@unlink($outFile); + +echo "-- All Mail Content Parameters --\n"; +// Calling mail() with all additional headers +var_dump( mail($to, $subject, $message, $additional_headers) ); +echo file_get_contents($outFile); +unlink($outFile); + + +echo "\n\n************* TEST ******************\n"; +// Should fail most +// Initialise all required variables +$to = 'user@example.com'; +$subject = 'Test Subject'; +$message = 'A Message'; +$additional_headers = array( + '*:foo1' => array('bar1'), + 'foo2:::' => array('bar1'), + 'foo3()' => array('bar1'), + 'foo4@' => array('bar1'), + 'foo5|' => array('bar1'), + "\0foo6" => array('bar1'), + "foo7\0" => array('bar1'), + "foo8" => array(), + "foo9" => '%&$#!', + "foo10" => "abc\0\tdef", +); +$outFile = "mailBasic.out"; +@unlink($outFile); + +echo "-- All Mail Content Parameters --\n"; +// Calling mail() with all additional headers +var_dump( mail($to, $subject, $message, $additional_headers) ); +echo file_get_contents($outFile); +unlink($outFile); + +?> +===DONE=== +--EXPECTF-- +*** Testing mail() : basic functionality *** + + +************* TEST ****************** +-- All Mail Content Parameters -- +bool(true) +To: user@example.com +Subject: Test Subject +KHeaders: aaaa +bcc: foo@bar +foo: bar + hoge +foo: bar + fuga + +A Message + + +************* TEST ****************** +-- All Mail Content Parameters -- + +Warning: mail(): 'orig-date' header must be at most one header. Array is passed for 'orig-date' in %s on line 59 + +Warning: mail(): 'from' header must be at most one header. Array is passed for 'from' in %s on line 59 + +Warning: mail(): 'sender' header must be at most one header. Array is passed for 'sender' in %s on line 59 + +Warning: mail(): 'reply-to' header must be at most one header. Array is passed for 'reply-to' in %s on line 59 + +Warning: mail(): Extra header cannot contain 'To' header in %s on line 59 + +Warning: mail(): 'bcc' header must be at most one header. Array is passed for 'bcc' in %s on line 59 + +Warning: mail(): 'message-id' header must be at most one header. Array is passed for 'message-id' in %s on line 59 + +Warning: mail(): 'in-reply-to' header must be at most one header. Array is passed for 'in-reply-to' in %s on line 59 +bool(true) +To: user@example.com +Subject: Test Subject + +A Message + + +************* TEST ****************** +-- All Mail Content Parameters -- + +Warning: mail(): Multiple header key must be numeric index (foo1) in %s on line 84 + +Warning: mail(): Multiple header values must be string (foo2) in %s on line 84 + +Warning: mail(): Multiple header values must be string (foo3) in %s on line 84 + +Warning: mail(): Multiple header values must be string (foo4) in %s on line 84 + +Warning: mail(): Multiple header values must be string (foo5) in %s on line 84 + +Warning: mail(): Multiple header values must be string (foo6) in %s on line 84 + +Warning: mail(): Multiple header values must be string (foo7) in %s on line 84 +bool(true) +To: user@example.com +Subject: Test Subject +foo2: foo2 + +A Message + + +************* TEST ****************** +-- All Mail Content Parameters -- + +Warning: mail(): Header field name (*:foo1) contains invalid chars in %s on line 112 + +Warning: mail(): Header field name (foo2:::) contains invalid chars in %s on line 112 + +Warning: mail(): Header field name () contains invalid chars in %s on line 112 + +Warning: mail(): Header field name (foo7) contains invalid chars in %s on line 112 + +Warning: mail(): Header field value (foo10 => abc) contains invalid chars or format in %s on line 112 +bool(true) +To: user@example.com +Subject: Test Subject +foo3(): bar1 +foo4@: bar1 +foo5|: bar1 +foo9: %&$#! + +A Message +===DONE=== diff --git a/ext/standard/tests/network/dns_get_mx.phpt b/ext/standard/tests/network/dns_get_mx.phpt index c5bf361b12..f6bb7ec05e 100644 --- a/ext/standard/tests/network/dns_get_mx.phpt +++ b/ext/standard/tests/network/dns_get_mx.phpt @@ -14,7 +14,7 @@ if (substr(PHP_OS, 0, 3) == 'WIN') { ?> --FILE-- <?php -$domains = array('yahoo.co.jp', 'yahoo.com', 'es.yahoo.com', 'fr.yahoo.com', 'it.yahoo.com'); +$domains = array('php.net', 'doc.php.net', 'wiki.php.net'); foreach ($domains as $domain) { if (getmxrr($domain, $hosts, $weights)) { echo "Hosts: " . count($hosts) . ", weights: " . count($weights) . "\n"; @@ -25,5 +25,3 @@ foreach ($domains as $domain) { Hosts: %i, weights: %i Hosts: %i, weights: %i Hosts: %i, weights: %i -Hosts: %i, weights: %i -Hosts: %i, weights: %i diff --git a/ext/standard/tests/password/password_get_info_argon2.phpt b/ext/standard/tests/password/password_get_info_argon2.phpt new file mode 100644 index 0000000000..80c6f93416 --- /dev/null +++ b/ext/standard/tests/password/password_get_info_argon2.phpt @@ -0,0 +1,29 @@ +--TEST--
+Test normal operation of password_get_info() with Argon2
+--SKIPIF--
+<?php
+if (!defined('PASSWORD_ARGON2I')) die('skip password_get_info not built with Argon2');
+?>
+--FILE--
+<?php
+
+var_dump(password_get_info('$argon2i$v=19$m=65536,t=3,p=1$SWhIcG5MT21Pc01PbWdVZw$WagZELICsz7jlqOR2YzoEVTWb2oOX1tYdnhZYXxptbU'));
+echo "OK!";
+?>
+--EXPECT--
+array(3) {
+ ["algo"]=>
+ int(2)
+ ["algoName"]=>
+ string(7) "argon2i"
+ ["options"]=>
+ array(3) {
+ ["memory_cost"]=>
+ int(65536)
+ ["time_cost"]=>
+ int(3)
+ ["threads"]=>
+ int(1)
+ }
+}
+OK!
\ No newline at end of file diff --git a/ext/standard/tests/password/password_hash_argon2.phpt b/ext/standard/tests/password/password_hash_argon2.phpt new file mode 100644 index 0000000000..7bd8cd700c --- /dev/null +++ b/ext/standard/tests/password/password_hash_argon2.phpt @@ -0,0 +1,18 @@ +--TEST--
+Test normal operation of password_hash() with argon2
+--SKIPIF--
+<?php
+if (!defined('PASSWORD_ARGON2I')) die('skip password_hash not built with Argon2');
+--FILE--
+<?php
+
+$password = "the password for testing 12345!";
+
+$hash = password_hash($password, PASSWORD_ARGON2I);
+var_dump(password_verify($password, $hash));
+
+echo "OK!";
+?>
+--EXPECT--
+bool(true)
+OK!
\ No newline at end of file diff --git a/ext/standard/tests/password/password_hash_error_argon2.phpt b/ext/standard/tests/password/password_hash_error_argon2.phpt new file mode 100644 index 0000000000..7e8722ec6f --- /dev/null +++ b/ext/standard/tests/password/password_hash_error_argon2.phpt @@ -0,0 +1,21 @@ +--TEST--
+Test error operation of password_hash() with argon2
+--SKIPIF--
+<?php
+if (!defined('PASSWORD_ARGON2I')) die('skip password_hash not built with Argon2');
+?>
+--FILE--
+<?php
+var_dump(password_hash('test', PASSWORD_ARGON2I, ['memory_cost' => 0]));
+var_dump(password_hash('test', PASSWORD_ARGON2I, ['time_cost' => 0]));
+var_dump(password_hash('test', PASSWORD_ARGON2I, ['threads' => 0]));
+?>
+--EXPECTF--
+Warning: password_hash(): Memory cost is outside of allowed memory range in %s on line %d
+NULL
+
+Warning: password_hash(): Time cost is outside of allowed time range in %s on line %d
+NULL
+
+Warning: password_hash(): Invalid number of threads in %s on line %d
+NULL
\ No newline at end of file diff --git a/ext/standard/tests/password/password_needs_rehash_argon2.phpt b/ext/standard/tests/password/password_needs_rehash_argon2.phpt new file mode 100644 index 0000000000..61fc0a5cae --- /dev/null +++ b/ext/standard/tests/password/password_needs_rehash_argon2.phpt @@ -0,0 +1,22 @@ +--TEST--
+Test normal operation of password_needs_rehash() with argon2
+--SKIPIF--
+<?php
+if (!defined('PASSWORD_ARGON2I')) die('skip password_needs_rehash not built with Argon2');
+?>
+--FILE--
+<?php
+
+$hash = password_hash('test', PASSWORD_ARGON2I);
+var_dump(password_needs_rehash($hash, PASSWORD_ARGON2I));
+var_dump(password_needs_rehash($hash, PASSWORD_ARGON2I, ['memory_cost' => 1<<17]));
+var_dump(password_needs_rehash($hash, PASSWORD_ARGON2I, ['time_cost' => 4]));
+var_dump(password_needs_rehash($hash, PASSWORD_ARGON2I, ['threads' => 4]));
+echo "OK!";
+?>
+--EXPECT--
+bool(false)
+bool(true)
+bool(true)
+bool(true)
+OK!
diff --git a/ext/standard/tests/password/password_verify_argon2.phpt b/ext/standard/tests/password/password_verify_argon2.phpt new file mode 100644 index 0000000000..e3a35942f5 --- /dev/null +++ b/ext/standard/tests/password/password_verify_argon2.phpt @@ -0,0 +1,18 @@ +--TEST--
+Test normal operation of password_verify() with argon2
+--SKIPIF--
+<?php
+if (!defined('PASSWORD_ARGON2I')) die('skip password_verify not built with Argon2');
+?>
+--FILE--
+<?php
+
+var_dump(password_verify('test', '$argon2i$v=19$m=65536,t=3,p=1$OEVjWWs2Z3YvWlNZQ0ZmNw$JKin7ahjmh8JYvMyFcXri0Ss/Uvd3uYpD7MG6C/5Cy0'));
+
+var_dump(password_verify('argon2', '$argon2i$v=19$m=65536,t=3,p=1$OEVjWWs2Z3YvWlNZQ0ZmNw$JKin7ahjmh8JYvMyFcXri0Ss/Uvd3uYpD7MG6C/5Cy0'));
+echo "OK!";
+?>
+--EXPECT--
+bool(true)
+bool(false)
+OK!
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_005.phpt b/ext/standard/tests/serialize/serialization_objects_005.phpt index 35b1593879..9800168ca2 100644 --- a/ext/standard/tests/serialize/serialization_objects_005.phpt +++ b/ext/standard/tests/serialize/serialization_objects_005.phpt @@ -88,7 +88,7 @@ object(__PHP_Incomplete_Class)#%d (2) { ["p"]=> int(1) } -bool(false) +bool(true) Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 43 NULL @@ -117,4 +117,4 @@ Notice: main(): The script tried to execute a method or access a property of an Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 57 NULL -Fatal error: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 59
\ No newline at end of file +Fatal error: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 59 diff --git a/ext/standard/tests/strings/bug43957.phpt b/ext/standard/tests/strings/bug43957.phpt new file mode 100644 index 0000000000..0380787b73 --- /dev/null +++ b/ext/standard/tests/strings/bug43957.phpt @@ -0,0 +1,8 @@ +--TEST-- +Bug #43957 (utf8_decode() bogus conversion on multibyte indicator near end of string) +--FILE-- +<?php + echo utf8_decode('abc'.chr(0xe0)); +?> +--EXPECTF-- +abc? diff --git a/ext/standard/tests/strings/bug49687.phpt b/ext/standard/tests/strings/bug49687.phpt new file mode 100644 index 0000000000..99e8dc3ec6 --- /dev/null +++ b/ext/standard/tests/strings/bug49687.phpt @@ -0,0 +1,19 @@ +--TEST--
+Bug #49687 Several utf8_decode deficiencies and vulnerabilities
+--FILE--
+<?php
+
+$tests = array(
+ "\x41\xC2\x3E\x42",
+ "\xE3\x80\x22",
+ "\x41\x98\xBA\x42\xE2\x98\x43\xE2\x98\xBA\xE2\x98",
+);
+foreach ($tests as $t) {
+ echo bin2hex(utf8_decode($t)), "\n";
+}
+echo "Done.\n";
+--EXPECT--
+413f3e42
+3f22
+413f3f423f433f3f
+Done.
diff --git a/ext/standard/tests/strings/utf8.phpt b/ext/standard/tests/strings/utf8.phpt new file mode 100644 index 0000000000..aea04fdecd --- /dev/null +++ b/ext/standard/tests/strings/utf8.phpt @@ -0,0 +1,10 @@ +--TEST-- +UTF-8<->ISO Latin 1 encoding/decoding test +--FILE-- +<?php +printf("%s -> %s\n", urlencode("æ"), urlencode(utf8_encode("æ"))); +printf("%s <- %s\n", urlencode(utf8_decode(urldecode("%C3%A6"))), "%C3%A6"); +?> +--EXPECT-- +%E6 -> %C3%A6 +%E6 <- %C3%A6 diff --git a/ext/standard/tests/strings/utf8_decode_error.phpt b/ext/standard/tests/strings/utf8_decode_error.phpt new file mode 100644 index 0000000000..911cc15cfc --- /dev/null +++ b/ext/standard/tests/strings/utf8_decode_error.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test utf8_decode() function : error conditions +--FILE-- +<?php +/* Prototype : proto string utf8_decode(string data) + * Description: Converts a UTF-8 encoded string to ISO-8859-1 + * Source code: ext/standard/string.c + * Alias to functions: + */ + +echo "*** Testing utf8_decode() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing utf8_decode() function with Zero arguments --\n"; +var_dump( utf8_decode() ); + +//Test utf8_decode with one more than the expected number of arguments +echo "\n-- Testing utf8_decode() function with more than expected no. of arguments --\n"; +$data = 'string_val'; +$extra_arg = 10; +var_dump( utf8_decode($data, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing utf8_decode() : error conditions *** + +-- Testing utf8_decode() function with Zero arguments -- + +Warning: utf8_decode() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing utf8_decode() function with more than expected no. of arguments -- + +Warning: utf8_decode() expects exactly 1 parameter, 2 given in %s on line %d +NULL +Done + diff --git a/ext/standard/tests/strings/utf8_decode_variation1.phpt b/ext/standard/tests/strings/utf8_decode_variation1.phpt new file mode 100644 index 0000000000..f564b87da0 --- /dev/null +++ b/ext/standard/tests/strings/utf8_decode_variation1.phpt @@ -0,0 +1,170 @@ +--TEST-- +Test utf8_decode() function : usage variations - different types for data +--FILE-- +<?php +/* Prototype : proto string utf8_decode(string data) + * Description: Converts a UTF-8 encoded string to ISO-8859-1 + * Source code: ext/standard/string.c + * Alias to functions: + */ + +echo "*** Testing utf8_decode() : usage variations ***\n"; +error_reporting(E_ALL & ~E_NOTICE); + +class aClass { + function __toString() { + return "Some Ascii Data"; + } +} + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new aClass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for data + +foreach($values as $value) { + echo @"\nArg value $value \n"; + var_dump( utf8_decode($value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing utf8_decode() : usage variations *** + +Arg value 0 +string(1) "0" + +Arg value 1 +string(1) "1" + +Arg value 12345 +string(5) "12345" + +Arg value -2345 +string(5) "-2345" + +Arg value 10.5 +string(4) "10.5" + +Arg value -10.5 +string(5) "-10.5" + +Arg value 101234567000 +string(12) "101234567000" + +Arg value 1.07654321E-9 +string(13) "1.07654321E-9" + +Arg value 0.5 +string(3) "0.5" + +Arg value Array + +Warning: utf8_decode() expects parameter 1 to be string, array given in %s on line %d +NULL + +Arg value Array + +Warning: utf8_decode() expects parameter 1 to be string, array given in %s on line %d +NULL + +Arg value Array + +Warning: utf8_decode() expects parameter 1 to be string, array given in %s on line %d +NULL + +Arg value Array + +Warning: utf8_decode() expects parameter 1 to be string, array given in %s on line %d +NULL + +Arg value Array + +Warning: utf8_decode() expects parameter 1 to be string, array given in %s on line %d +NULL + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value 1 +string(1) "1" + +Arg value +string(0) "" + +Arg value 1 +string(1) "1" + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value Some Ascii Data +string(15) "Some Ascii Data" + +Arg value +string(0) "" + +Arg value +string(0) "" +Done + diff --git a/ext/standard/tests/strings/utf8_encode_error.phpt b/ext/standard/tests/strings/utf8_encode_error.phpt new file mode 100644 index 0000000000..e12f0978b6 --- /dev/null +++ b/ext/standard/tests/strings/utf8_encode_error.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test utf8_encode() function : error conditions +--FILE-- +<?php +/* Prototype : proto string utf8_encode(string data) + * Description: Encodes an ISO-8859-1 string to UTF-8 + * Source code: ext/standard/string.c + * Alias to functions: + */ + +echo "*** Testing utf8_encode() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing utf8_encode() function with Zero arguments --\n"; +var_dump( utf8_encode() ); + +//Test utf8_encode with one more than the expected number of arguments +echo "\n-- Testing utf8_encode() function with more than expected no. of arguments --\n"; +$data = 'string_val'; +$extra_arg = 10; +var_dump( utf8_encode($data, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing utf8_encode() : error conditions *** + +-- Testing utf8_encode() function with Zero arguments -- + +Warning: utf8_encode() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing utf8_encode() function with more than expected no. of arguments -- + +Warning: utf8_encode() expects exactly 1 parameter, 2 given in %s on line %d +NULL +Done + diff --git a/ext/standard/tests/strings/utf8_encode_variation1.phpt b/ext/standard/tests/strings/utf8_encode_variation1.phpt new file mode 100644 index 0000000000..fa4b79976e --- /dev/null +++ b/ext/standard/tests/strings/utf8_encode_variation1.phpt @@ -0,0 +1,170 @@ +--TEST-- +Test utf8_encode() function : usage variations - <type here specifics of this variation> +--FILE-- +<?php +/* Prototype : proto string utf8_encode(string data) + * Description: Encodes an ISO-8859-1 string to UTF-8 + * Source code: ext/standard/string.c + * Alias to functions: + */ + +echo "*** Testing utf8_encode() : usage variations ***\n"; +error_reporting(E_ALL & ~E_NOTICE); + +class aClass { + function __toString() { + return "Some Ascii Data"; + } +} + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new aClass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for data + +foreach($values as $value) { + echo @"\nArg value $value \n"; + var_dump( utf8_encode($value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing utf8_encode() : usage variations *** + +Arg value 0 +string(1) "0" + +Arg value 1 +string(1) "1" + +Arg value 12345 +string(5) "12345" + +Arg value -2345 +string(5) "-2345" + +Arg value 10.5 +string(4) "10.5" + +Arg value -10.5 +string(5) "-10.5" + +Arg value 101234567000 +string(12) "101234567000" + +Arg value 1.07654321E-9 +string(13) "1.07654321E-9" + +Arg value 0.5 +string(3) "0.5" + +Arg value Array + +Warning: utf8_encode() expects parameter 1 to be string, array given in %s on line %d +NULL + +Arg value Array + +Warning: utf8_encode() expects parameter 1 to be string, array given in %s on line %d +NULL + +Arg value Array + +Warning: utf8_encode() expects parameter 1 to be string, array given in %s on line %d +NULL + +Arg value Array + +Warning: utf8_encode() expects parameter 1 to be string, array given in %s on line %d +NULL + +Arg value Array + +Warning: utf8_encode() expects parameter 1 to be string, array given in %s on line %d +NULL + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value 1 +string(1) "1" + +Arg value +string(0) "" + +Arg value 1 +string(1) "1" + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value Some Ascii Data +string(15) "Some Ascii Data" + +Arg value +string(0) "" + +Arg value +string(0) "" +Done + |