summaryrefslogtreecommitdiff
path: root/ext/standard/tests/array
diff options
context:
space:
mode:
authorJosie Messa <jmessa@php.net>2008-02-19 10:53:10 +0000
committerJosie Messa <jmessa@php.net>2008-02-19 10:53:10 +0000
commit23e18f966bd2b7e710e76ea5e4fb588ec35cb168 (patch)
treec6ad9c3ff373c7d9a36203e35e2203868be7bf8a /ext/standard/tests/array
parent1b03ecf1c70aad2cadbd41b184fa10f005f5b0c9 (diff)
downloadphp-git-23e18f966bd2b7e710e76ea5e4fb588ec35cb168.tar.gz
- New tests for natcasesort() function
Diffstat (limited to 'ext/standard/tests/array')
-rw-r--r--ext/standard/tests/array/natcasesort_basic.phpt57
-rw-r--r--ext/standard/tests/array/natcasesort_error.phpt40
-rw-r--r--ext/standard/tests/array/natcasesort_object1.phpt99
-rw-r--r--ext/standard/tests/array/natcasesort_object2.phpt99
-rw-r--r--ext/standard/tests/array/natcasesort_variation1.phpt220
-rw-r--r--ext/standard/tests/array/natcasesort_variation10.phpt52
-rw-r--r--ext/standard/tests/array/natcasesort_variation11.phpt232
-rw-r--r--ext/standard/tests/array/natcasesort_variation2.phpt227
-rw-r--r--ext/standard/tests/array/natcasesort_variation3.phpt131
-rw-r--r--ext/standard/tests/array/natcasesort_variation4.phpt86
-rw-r--r--ext/standard/tests/array/natcasesort_variation5.phpt49
-rw-r--r--ext/standard/tests/array/natcasesort_variation6.phpt56
-rw-r--r--ext/standard/tests/array/natcasesort_variation7.phpt96
-rw-r--r--ext/standard/tests/array/natcasesort_variation8.phpt46
-rw-r--r--ext/standard/tests/array/natcasesort_variation9.phpt110
15 files changed, 1600 insertions, 0 deletions
diff --git a/ext/standard/tests/array/natcasesort_basic.phpt b/ext/standard/tests/array/natcasesort_basic.phpt
new file mode 100644
index 0000000000..cf6cc57288
--- /dev/null
+++ b/ext/standard/tests/array/natcasesort_basic.phpt
@@ -0,0 +1,57 @@
+--TEST--
+Test natcasesort() function : basic functionality
+--FILE--
+<?php
+/* Prototype : bool natcasesort(array &$array_arg)
+ * Description: Sort an array using case-insensitive natural sort
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test basic functionality of natcasesort()
+ */
+
+echo "*** Testing natcasesort() : basic functionality ***\n";
+
+$array = array ('A01', 'a1', 'b10', 'a01', 'b01');
+echo "\n-- Before sorting: --\n";
+var_dump($array);
+
+echo "\n-- After Sorting: --\n";
+var_dump(natcasesort($array));
+var_dump($array);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing natcasesort() : basic functionality ***
+
+-- Before sorting: --
+array(5) {
+ [0]=>
+ string(3) "A01"
+ [1]=>
+ string(2) "a1"
+ [2]=>
+ string(3) "b10"
+ [3]=>
+ string(3) "a01"
+ [4]=>
+ string(3) "b01"
+}
+
+-- After Sorting: --
+bool(true)
+array(5) {
+ [3]=>
+ string(3) "a01"
+ [0]=>
+ string(3) "A01"
+ [1]=>
+ string(2) "a1"
+ [4]=>
+ string(3) "b01"
+ [2]=>
+ string(3) "b10"
+}
+Done \ No newline at end of file
diff --git a/ext/standard/tests/array/natcasesort_error.phpt b/ext/standard/tests/array/natcasesort_error.phpt
new file mode 100644
index 0000000000..9ae8691e1e
--- /dev/null
+++ b/ext/standard/tests/array/natcasesort_error.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Test natcasesort() function : error conditions - Pass incorrect number of args
+--FILE--
+<?php
+/* Prototype : bool natcasesort(array &$array_arg)
+ * Description: Sort an array using case-insensitive natural sort
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass incorrect number of arguments to natcasesort() to test behaviour
+ */
+
+echo "*** Testing natcasesort() : error conditions ***\n";
+
+// Zero arguments
+echo "\n-- Testing natcasesort() function with Zero arguments --\n";
+var_dump( natcasesort() );
+
+// Test natcasesort with one more than the expected number of arguments
+echo "\n-- Testing natcasesort() function with more than expected no. of arguments --\n";
+$array_arg = array(1, 2);
+$extra_arg = 10;
+var_dump( natcasesort($array_arg, $extra_arg) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing natcasesort() : error conditions ***
+
+-- Testing natcasesort() function with Zero arguments --
+
+Warning: natcasesort() expects exactly 1 parameter, 0 given in %s on line %d
+NULL
+
+-- Testing natcasesort() function with more than expected no. of arguments --
+
+Warning: natcasesort() expects exactly 1 parameter, 2 given in %s on line %d
+NULL
+Done \ No newline at end of file
diff --git a/ext/standard/tests/array/natcasesort_object1.phpt b/ext/standard/tests/array/natcasesort_object1.phpt
new file mode 100644
index 0000000000..aab98a45d8
--- /dev/null
+++ b/ext/standard/tests/array/natcasesort_object1.phpt
@@ -0,0 +1,99 @@
+--TEST--
+Test natcasesort() function : object functionality - array of objects
+--FILE--
+<?php
+/* Prototype : bool natcasesort(array &$array_arg)
+ * Description: Sort an array using case-insensitive natural sort
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass natcasesort() an array of objects to test how it re-orders them
+ */
+
+echo "*** Testing natcasesort() : object functionality ***\n";
+
+// class declaration for string objects
+class for_string_natcasesort
+{
+ public $class_value;
+ // initializing object member value
+ function __construct($value){
+ $this->class_value = $value;
+ }
+
+ // return string value
+ function __tostring() {
+ return (string)$this->class_value;
+ }
+
+}
+
+
+
+// array of string objects
+$unsorted_str_obj = array (
+ new for_string_natcasesort("axx"), new for_string_natcasesort("t"),
+ new for_string_natcasesort("w"), new for_string_natcasesort("py"),
+ new for_string_natcasesort("apple"), new for_string_natcasesort("Orange"),
+ new for_string_natcasesort("Lemon"), new for_string_natcasesort("aPPle")
+);
+
+
+echo "\n-- Testing natcasesort() by supplying various object arrays --\n";
+
+// testing natcasesort() function by supplying string object array
+var_dump(natcasesort($unsorted_str_obj) );
+var_dump($unsorted_str_obj);
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing natcasesort() : object functionality ***
+
+-- Testing natcasesort() by supplying various object arrays --
+bool(true)
+array(8) {
+ [4]=>
+ object(for_string_natcasesort)#%d (1) {
+ ["class_value"]=>
+ string(5) "apple"
+ }
+ [7]=>
+ object(for_string_natcasesort)#%d (1) {
+ ["class_value"]=>
+ string(5) "aPPle"
+ }
+ [0]=>
+ object(for_string_natcasesort)#%d (1) {
+ ["class_value"]=>
+ string(3) "axx"
+ }
+ [6]=>
+ object(for_string_natcasesort)#%d (1) {
+ ["class_value"]=>
+ string(5) "Lemon"
+ }
+ [5]=>
+ object(for_string_natcasesort)#%d (1) {
+ ["class_value"]=>
+ string(6) "Orange"
+ }
+ [3]=>
+ object(for_string_natcasesort)#%d (1) {
+ ["class_value"]=>
+ string(2) "py"
+ }
+ [1]=>
+ object(for_string_natcasesort)#%d (1) {
+ ["class_value"]=>
+ string(1) "t"
+ }
+ [2]=>
+ object(for_string_natcasesort)#%d (1) {
+ ["class_value"]=>
+ string(1) "w"
+ }
+}
+Done \ No newline at end of file
diff --git a/ext/standard/tests/array/natcasesort_object2.phpt b/ext/standard/tests/array/natcasesort_object2.phpt
new file mode 100644
index 0000000000..38efefc4a3
--- /dev/null
+++ b/ext/standard/tests/array/natcasesort_object2.phpt
@@ -0,0 +1,99 @@
+--TEST--
+Test natcasesort() function : object functionality - mixed visibility within objects
+--FILE--
+<?php
+/* Prototype : bool natcasesort(array &$array_arg)
+ * Description: Sort an array using case-insensitive natural sort
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass natcasesort() an array of objects which have properties of different
+ * visibilities to test how it re-orders the array.
+ */
+
+echo "*** Testing natcasesort() : object functionality ***\n";
+
+// class declaration for string objects
+class for_string_natcasesort
+{
+ public $public_class_value;
+ private $private_class_value;
+ protected $protected_class_value;
+ // initializing object member value
+ function __construct($value1, $value2,$value3){
+ $this->public_class_value = $value1;
+ $this->private_class_value = $value2;
+ $this->protected_class_value = $value3;
+ }
+
+ // return string value
+ function __tostring() {
+ return (string)$this->public_class_value;
+ }
+
+}
+
+// array of string objects
+$unsorted_str_obj = array (
+new for_string_natcasesort("axx","AXX","ass"),
+new for_string_natcasesort("t","eee","abb"),
+new for_string_natcasesort("w","W", "c"),
+new for_string_natcasesort("py","PY", "pt"),
+);
+
+
+echo "\n-- Testing natcasesort() by supplying object arrays --\n";
+
+// testing natcasesort() function by supplying string object array
+$temp_array = $unsorted_str_obj;
+var_dump(natcasesort($temp_array) );
+var_dump($temp_array);
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing natcasesort() : object functionality ***
+
+-- Testing natcasesort() by supplying object arrays --
+bool(true)
+array(4) {
+ [0]=>
+ object(for_string_natcasesort)#%d (3) {
+ ["public_class_value"]=>
+ string(3) "axx"
+ ["private_class_value":"for_string_natcasesort":private]=>
+ string(3) "AXX"
+ ["protected_class_value":protected]=>
+ string(3) "ass"
+ }
+ [3]=>
+ object(for_string_natcasesort)#%d (3) {
+ ["public_class_value"]=>
+ string(2) "py"
+ ["private_class_value":"for_string_natcasesort":private]=>
+ string(2) "PY"
+ ["protected_class_value":protected]=>
+ string(2) "pt"
+ }
+ [1]=>
+ object(for_string_natcasesort)#%d (3) {
+ ["public_class_value"]=>
+ string(1) "t"
+ ["private_class_value":"for_string_natcasesort":private]=>
+ string(3) "eee"
+ ["protected_class_value":protected]=>
+ string(3) "abb"
+ }
+ [2]=>
+ object(for_string_natcasesort)#%d (3) {
+ ["public_class_value"]=>
+ string(1) "w"
+ ["private_class_value":"for_string_natcasesort":private]=>
+ string(1) "W"
+ ["protected_class_value":protected]=>
+ string(1) "c"
+ }
+}
+Done \ No newline at end of file
diff --git a/ext/standard/tests/array/natcasesort_variation1.phpt b/ext/standard/tests/array/natcasesort_variation1.phpt
new file mode 100644
index 0000000000..f6019508c7
--- /dev/null
+++ b/ext/standard/tests/array/natcasesort_variation1.phpt
@@ -0,0 +1,220 @@
+--TEST--
+Test natcasesort() function : usage variations - Pass different data types as $array_arg arg
+--FILE--
+<?php
+/* Prototype : bool natcasesort(array &$array_arg)
+ * Description: Sort an array using case-insensitive natural sort
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass different data types as $array_arg argument to natcasesort() to test behaviour
+ */
+
+echo "*** Testing natcasesort() : usage variation ***\n";
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// get a resource variable
+$fp = fopen(__FILE__, "r");
+
+// unexpected values to be passed to $array_arg argument
+$inputs = array(
+
+ // int data
+/*1*/ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+/*5*/ 10.5,
+ -10.5,
+ 12.3456789000e10,
+ 12.3456789000E-10,
+ .5,
+
+ // null data
+/*10*/ NULL,
+ null,
+
+ // boolean data
+/*12*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+/*16*/ "",
+ '',
+ array(),
+
+ // string data
+/*19*/ "string",
+ 'string',
+ $heredoc,
+
+ // object data
+/*22*/ new classA(),
+
+ // undefined data
+/*23*/ @$undefined_var,
+
+ // unset data
+/*24*/ @$unset_var,
+
+ // resource variable
+/*25*/ $fp
+);
+
+// loop through each element of $inputs to check the behavior of natcasesort()
+$iterator = 1;
+foreach($inputs as $input) {
+ echo "\n-- Iteration $iterator --\n";
+ var_dump( natcasesort($input) );
+ $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing natcasesort() : usage variation ***
+
+-- Iteration 1 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 2 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 3 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 4 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 5 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 6 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 7 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 8 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 9 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 10 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 11 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 12 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 13 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 14 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 15 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 16 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 17 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 18 --
+bool(true)
+
+-- Iteration 19 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 20 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 21 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 22 --
+bool(true)
+
+-- Iteration 23 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 24 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+
+-- Iteration 25 --
+
+Warning: natcasesort(): The argument should be an array in %s on line %d
+NULL
+Done \ No newline at end of file
diff --git a/ext/standard/tests/array/natcasesort_variation10.phpt b/ext/standard/tests/array/natcasesort_variation10.phpt
new file mode 100644
index 0000000000..cffa007b74
--- /dev/null
+++ b/ext/standard/tests/array/natcasesort_variation10.phpt
@@ -0,0 +1,52 @@
+--TEST--
+Test natcasesort() function : usage variations - position of internal array pointer
+--FILE--
+<?php
+/* Prototype : bool natcasesort(array &$array_arg)
+ * Description: Sort an array using case-insensitive natural sort
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Check position of internal array pointer after calling natcasesort()
+ */
+
+echo "*** Testing natcasesort() : usage variations ***\n";
+
+$array_arg = array ('img13', 'img20', 'img2', 'img1');
+
+echo "\n-- Initial Position of Internal Pointer: --\n";
+echo key($array_arg) . " => " . current ($array_arg) . "\n";
+
+echo "\n-- Call natcasesort() --\n";
+var_dump(natcasesort($array_arg));
+var_dump($array_arg);
+
+echo "\n-- Position of Internal Pointer in Passed Array: --\n";
+echo key($array_arg) . " => " . current ($array_arg) . "\n";
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing natcasesort() : usage variations ***
+
+-- Initial Position of Internal Pointer: --
+0 => img13
+
+-- Call natcasesort() --
+bool(true)
+array(4) {
+ [3]=>
+ string(4) "img1"
+ [2]=>
+ string(4) "img2"
+ [0]=>
+ string(5) "img13"
+ [1]=>
+ string(5) "img20"
+}
+
+-- Position of Internal Pointer in Passed Array: --
+3 => img1
+Done
diff --git a/ext/standard/tests/array/natcasesort_variation11.phpt b/ext/standard/tests/array/natcasesort_variation11.phpt
new file mode 100644
index 0000000000..98158f15d0
--- /dev/null
+++ b/ext/standard/tests/array/natcasesort_variation11.phpt
@@ -0,0 +1,232 @@
+--TEST--
+Test natcasesort() function : usage variations - Different array keys
+--FILE--
+<?php
+/* Prototype : bool natcasesort(array &$array_arg)
+ * Description: Sort an array using case-insensitive natural sort
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass arrays where the keys are different data types to test behaviour of natcasesort()
+ */
+
+echo "*** Testing natcasesort() : usage variations ***\n";
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// arrays with keys as different data types to be passed as $array_arg
+$inputs = array(
+
+ // int data
+/*1*/ 'int' => array(
+ 0 => 'zero',
+ 1 => 'one',
+ 12345 => 'positive',
+ -2345 => 'negative',
+ ),
+
+ // float data
+/*2*/ 'float' => array(
+ 10.5 => 'positive',
+ -10.5 => 'negative',
+ .5 => 'half',
+ ),
+
+/*3*/ 'extreme floats' => array(
+ 12.3456789000e6 => 'large',
+ 12.3456789000E-10 => 'small',
+ ),
+
+ // null data
+/*4*/ 'null uppercase' => array(
+ NULL => 'null 1',
+ ),
+
+/*5*/ 'null lowercase' => array(
+ null => 'null 2',
+ ),
+
+ // boolean data
+/*6*/ 'bool lowercase' => array(
+ true => 'lowert',
+ false => 'lowerf',
+ ),
+
+/*7*/ 'bool uppercase' => array(
+ TRUE => 'uppert',
+ FALSE => 'upperf',
+ ),
+
+ // empty data
+/*8*/ 'empty double quotes' => array(
+ "" => 'emptyd',
+ ),
+
+/*9*/ 'empty single quotes' => array(
+ '' => 'emptys',
+ ),
+
+ // string data
+/*10*/ 'string' => array(
+ "stringd" => 'stringd',
+ 'strings' => 'strings',
+ $heredoc => 'stringh',
+ ),
+
+ // undefined data
+/*11*/ 'undefined' => array(
+ @$undefined_var => 'undefined',
+ ),
+
+ // unset data
+/*12*/ 'unset' => array(
+ @$unset_var => 'unset',
+ ),
+
+ // duplicate values
+/*13*/ 'duplicate' => array(
+ 'foo' => 'bar',
+ 'baz' => 'bar',
+ 'hello' => 'world'
+ ),
+
+);
+
+// loop through each element of $inputs to check the behavior of natcasesort()
+$iterator = 1;
+foreach($inputs as $input) {
+ echo "\n-- Iteration $iterator --\n";
+ var_dump( natcasesort($input) );
+ var_dump($input);
+ $iterator++;
+};
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing natcasesort() : usage variations ***
+
+-- Iteration 1 --
+bool(true)
+array(4) {
+ [-2345]=>
+ string(8) "negative"
+ [1]=>
+ string(3) "one"
+ [12345]=>
+ string(8) "positive"
+ [0]=>
+ string(4) "zero"
+}
+
+-- Iteration 2 --
+bool(true)
+array(3) {
+ [0]=>
+ string(4) "half"
+ [-10]=>
+ string(8) "negative"
+ [10]=>
+ string(8) "positive"
+}
+
+-- Iteration 3 --
+bool(true)
+array(2) {
+ [12345678]=>
+ string(5) "large"
+ [0]=>
+ string(5) "small"
+}
+
+-- Iteration 4 --
+bool(true)
+array(1) {
+ [""]=>
+ string(6) "null 1"
+}
+
+-- Iteration 5 --
+bool(true)
+array(1) {
+ [""]=>
+ string(6) "null 2"
+}
+
+-- Iteration 6 --
+bool(true)
+array(2) {
+ [0]=>
+ string(6) "lowerf"
+ [1]=>
+ string(6) "lowert"
+}
+
+-- Iteration 7 --
+bool(true)
+array(2) {
+ [0]=>
+ string(6) "upperf"
+ [1]=>
+ string(6) "uppert"
+}
+
+-- Iteration 8 --
+bool(true)
+array(1) {
+ [""]=>
+ string(6) "emptyd"
+}
+
+-- Iteration 9 --
+bool(true)
+array(1) {
+ [""]=>
+ string(6) "emptys"
+}
+
+-- Iteration 10 --
+bool(true)
+array(3) {
+ ["stringd"]=>
+ string(7) "stringd"
+ ["hello world"]=>
+ string(7) "stringh"
+ ["strings"]=>
+ string(7) "strings"
+}
+
+-- Iteration 11 --
+bool(true)
+array(1) {
+ [""]=>
+ string(9) "undefined"
+}
+
+-- Iteration 12 --
+bool(true)
+array(1) {
+ [""]=>
+ string(5) "unset"
+}
+
+-- Iteration 13 --
+bool(true)
+array(3) {
+ ["foo"]=>
+ string(3) "bar"
+ ["baz"]=>
+ string(3) "bar"
+ ["hello"]=>
+ string(5) "world"
+}
+Done \ No newline at end of file
diff --git a/ext/standard/tests/array/natcasesort_variation2.phpt b/ext/standard/tests/array/natcasesort_variation2.phpt
new file mode 100644
index 0000000000..00edf94346
--- /dev/null
+++ b/ext/standard/tests/array/natcasesort_variation2.phpt
@@ -0,0 +1,227 @@
+--TEST--
+Test natcasesort() function : usage variations - Pass arrays of different data types
+--FILE--
+<?php
+
+/* Prototype : bool natcasesort(array &$array_arg)
+ * Description: Sort an array using case-insensitive natural sort
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass arrays of different data types to natcasesort() to test how they are sorted
+ */
+
+echo "*** Testing natcasesort() : usage variation ***\n";
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// get a resource variable
+$fp = fopen(__FILE__, "r");
+
+// arrays of different data types to be passed to $array_arg argument
+$inputs = array(
+
+ // int data
+/*1*/ 'int' => array(
+ 0,
+ 1,
+ 12345,
+ -2345,
+ ),
+
+ // float data
+/*2*/ 'float' => array(
+ 10.5,
+ -10.5,
+ 12.3456789000e10,
+ 12.3456789000E-10,
+ .5,
+ ),
+
+ // null data
+/*3*/ 'null' => array(
+ NULL,
+ null,
+ ),
+
+ // boolean data
+/*4*/ 'bool' => array(
+ true,
+ false,
+ TRUE,
+ FALSE,
+ ),
+
+ // empty data
+/*5*/ 'empty string' => array(
+ "",
+ '',
+ ),
+
+/*6*/ 'empty array' => array(
+ ),
+
+ // string data
+/*7*/ 'string' => array(
+ "string",
+ 'string',
+ $heredoc,
+ ),
+
+ // object data
+/*8*/ 'object' => array(
+ new classA(),
+ ),
+
+ // undefined data
+/*9*/ 'undefined' => array(
+ @$undefined_var,
+ ),
+
+ // unset data
+/*10*/ 'unset' => array(
+ @$unset_var,
+ ),
+
+ // resource variable
+/*11*/ 'resource' => array(
+ $fp
+ ),
+);
+// loop through each element of $inputs to check the behavior of natcasesort()
+$iterator = 1;
+foreach($inputs as $input) {
+ echo "\n-- Iteration $iterator --\n";
+ var_dump( natcasesort($input) );
+ var_dump($input);
+ $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing natcasesort() : usage variation ***
+
+-- Iteration 1 --
+bool(true)
+array(4) {
+ [3]=>
+ int(-2345)
+ [0]=>
+ int(0)
+ [1]=>
+ int(1)
+ [2]=>
+ int(12345)
+}
+
+-- Iteration 2 --
+bool(true)
+array(5) {
+ [1]=>
+ float(-10.5)
+ [4]=>
+ float(0.5)
+ [3]=>
+ float(1.23456789E-9)
+ [0]=>
+ float(10.5)
+ [2]=>
+ float(123456789000)
+}
+
+-- Iteration 3 --
+bool(true)
+array(2) {
+ [1]=>
+ NULL
+ [0]=>
+ NULL
+}
+
+-- Iteration 4 --
+bool(true)
+array(4) {
+ [3]=>
+ bool(false)
+ [1]=>
+ bool(false)
+ [0]=>
+ bool(true)
+ [2]=>
+ bool(true)
+}
+
+-- Iteration 5 --
+bool(true)
+array(2) {
+ [1]=>
+ string(0) ""
+ [0]=>
+ string(0) ""
+}
+
+-- Iteration 6 --
+bool(true)
+array(0) {
+}
+
+-- Iteration 7 --
+bool(true)
+array(3) {
+ [2]=>
+ string(11) "hello world"
+ [1]=>
+ string(6) "string"
+ [0]=>
+ string(6) "string"
+}
+
+-- Iteration 8 --
+bool(true)
+array(1) {
+ [0]=>
+ object(classA)#%d (0) {
+ }
+}
+
+-- Iteration 9 --
+bool(true)
+array(1) {
+ [0]=>
+ NULL
+}
+
+-- Iteration 10 --
+bool(true)
+array(1) {
+ [0]=>
+ NULL
+}
+
+-- Iteration 11 --
+bool(true)
+array(1) {
+ [0]=>
+ resource(%d) of type (stream)
+}
+Done \ No newline at end of file
diff --git a/ext/standard/tests/array/natcasesort_variation3.phpt b/ext/standard/tests/array/natcasesort_variation3.phpt
new file mode 100644
index 0000000000..49781710b6
--- /dev/null
+++ b/ext/standard/tests/array/natcasesort_variation3.phpt
@@ -0,0 +1,131 @@
+--TEST--
+Test natcasesort() function : usage variations - different numeric types
+--FILE--
+<?php
+/* Prototype : bool natcasesort(array &$array_arg)
+ * Description: Sort an array using case-insensitive natural sort
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass arrays of numeric data to test how natcasesort re-orders the array
+ */
+
+echo "*** Testing natcasesort() : usage variation ***\n";
+
+$inputs = array (
+
+ // negative/positive integers array
+ array(11, -11, 21, -21, 31, -31, 0, 41, -41),
+
+ // float value array
+ array(10.5, -10.5, 10.5e2, 10.6E-2, .5, .01, -.1),
+
+ // mixed value array
+ array(.0001, .0021, -.01, -1, 0, .09, 2, -.9, 10.6E-2, -10.6E-2, 33),
+
+ // array values contains minimum and maximum ranges
+ array(2147483647, 2147483648, -2147483647, -2147483648, -0, 0, -2147483649)
+);
+
+$iterator = 1;
+foreach ($inputs as $array_arg) {
+ echo "\n-- Iteration $iterator --\n";
+ var_dump(natcasesort($array_arg));
+ var_dump($array_arg);
+}
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing natcasesort() : usage variation ***
+
+-- Iteration 1 --
+bool(true)
+array(9) {
+ [1]=>
+ int(-11)
+ [3]=>
+ int(-21)
+ [5]=>
+ int(-31)
+ [8]=>
+ int(-41)
+ [6]=>
+ int(0)
+ [0]=>
+ int(11)
+ [2]=>
+ int(21)
+ [4]=>
+ int(31)
+ [7]=>
+ int(41)
+}
+
+-- Iteration 1 --
+bool(true)
+array(7) {
+ [6]=>
+ float(-0.1)
+ [1]=>
+ float(-10.5)
+ [5]=>
+ float(0.01)
+ [4]=>
+ float(0.5)
+ [3]=>
+ float(0.106)
+ [0]=>
+ float(10.5)
+ [2]=>
+ float(1050)
+}
+
+-- Iteration 1 --
+bool(true)
+array(11) {
+ [2]=>
+ float(-0.01)
+ [7]=>
+ float(-0.9)
+ [9]=>
+ float(-0.106)
+ [3]=>
+ int(-1)
+ [4]=>
+ int(0)
+ [0]=>
+ float(0.0001)
+ [1]=>
+ float(0.0021)
+ [5]=>
+ float(0.09)
+ [8]=>
+ float(0.106)
+ [6]=>
+ int(2)
+ [10]=>
+ int(33)
+}
+
+-- Iteration 1 --
+bool(true)
+array(7) {
+ [2]=>
+ int(-2147483647)
+ [3]=>
+ float(-2147483648)
+ [6]=>
+ float(-2147483649)
+ [5]=>
+ int(0)
+ [4]=>
+ int(0)
+ [0]=>
+ int(2147483647)
+ [1]=>
+ float(2147483648)
+}
+Done \ No newline at end of file
diff --git a/ext/standard/tests/array/natcasesort_variation4.phpt b/ext/standard/tests/array/natcasesort_variation4.phpt
new file mode 100644
index 0000000000..81276ef1cd
--- /dev/null
+++ b/ext/standard/tests/array/natcasesort_variation4.phpt
@@ -0,0 +1,86 @@
+--TEST--
+Test natcasesort() function : usage variations - different string types
+--FILE--
+<?php
+/* Prototype : bool natcasesort(array &$array_arg)
+ * Description: Sort an array using case-insensitive natural sort
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass arrays of string data to see how natcasesort() re-orders the array
+ */
+
+echo "*** Testing natcasesort() : usage variation ***\n";
+
+$inputs = array (
+ // group of escape sequences
+ array(null, NULL, "\a", "\cx", "\e", "\f", "\n", "\t", "\xhh", "\ddd", "\v"),
+
+ // array contains combination of capital/small letters
+ array("lemoN", "Orange", "banana", "apple", "Test", "TTTT", "ttt", "ww", "x", "X", "oraNGe", "BANANA")
+);
+
+foreach ($inputs as $array_arg) {
+ var_dump( natcasesort($array_arg) );
+ var_dump($array_arg);
+}
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing natcasesort() : usage variation ***
+bool(true)
+array(11) {
+ [0]=>
+ NULL
+ [1]=>
+ NULL
+ [6]=>
+ string(1) "
+"
+ [10]=>
+ string(1) " "
+ [7]=>
+ string(1) " "
+ [5]=>
+ string(1) " "
+ [2]=>
+ string(2) "\a"
+ [3]=>
+ string(3) "\cx"
+ [9]=>
+ string(4) "\ddd"
+ [4]=>
+ string(2) "\e"
+ [8]=>
+ string(4) "\xhh"
+}
+bool(true)
+array(12) {
+ [3]=>
+ string(5) "apple"
+ [11]=>
+ string(6) "BANANA"
+ [2]=>
+ string(6) "banana"
+ [0]=>
+ string(5) "lemoN"
+ [10]=>
+ string(6) "oraNGe"
+ [1]=>
+ string(6) "Orange"
+ [4]=>
+ string(4) "Test"
+ [6]=>
+ string(3) "ttt"
+ [5]=>
+ string(4) "TTTT"
+ [7]=>
+ string(2) "ww"
+ [8]=>
+ string(1) "x"
+ [9]=>
+ string(1) "X"
+}
+Done \ No newline at end of file
diff --git a/ext/standard/tests/array/natcasesort_variation5.phpt b/ext/standard/tests/array/natcasesort_variation5.phpt
new file mode 100644
index 0000000000..867d0b89e4
--- /dev/null
+++ b/ext/standard/tests/array/natcasesort_variation5.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Test natcasesort() function : usage variations - different hex values
+--FILE--
+<?php
+/* Prototype : bool natcasesort(array &$array_arg)
+ * Description: Sort an array using case-insensitive natural sort
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass an array of different hex values to test how natcasesort() re-orders it
+ */
+
+echo "*** Testing natcasesort() : usage variation ***\n";
+
+$unsorted_hex_array = array(0x1AB, 0xFFF, 0xF, 0xFF, 0x2AA, 0xBB, 0x1ab, 0xff, -0xFF, 0, -0x2aa);
+var_dump( natcasesort($unsorted_hex_array) );
+var_dump($unsorted_hex_array);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing natcasesort() : usage variation ***
+bool(true)
+array(11) {
+ [8]=>
+ int(-255)
+ [10]=>
+ int(-682)
+ [9]=>
+ int(0)
+ [2]=>
+ int(15)
+ [5]=>
+ int(187)
+ [3]=>
+ int(255)
+ [7]=>
+ int(255)
+ [0]=>
+ int(427)
+ [6]=>
+ int(427)
+ [4]=>
+ int(682)
+ [1]=>
+ int(4095)
+}
+Done \ No newline at end of file
diff --git a/ext/standard/tests/array/natcasesort_variation6.phpt b/ext/standard/tests/array/natcasesort_variation6.phpt
new file mode 100644
index 0000000000..1d151d80d3
--- /dev/null
+++ b/ext/standard/tests/array/natcasesort_variation6.phpt
@@ -0,0 +1,56 @@
+--TEST--
+Test natcasesort() function : usage variations - referenced variables
+--FILE--
+<?php
+/* Prototype : bool natcasesort(array &$array_arg)
+ * Description: Sort an array using case-insensitive natural sort
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass an array of referenced varaibles to test how natcasesort() re-orders it
+ */
+
+echo "*** Testing natcasesort() : usage variation ***\n";
+
+$value1 = 100;
+$value2 = 33;
+$value3 = 555;
+
+echo "\n-- Initial test --\n";
+$array = array( &$value1 , &$value2, &$value3);
+var_dump( natcasesort($array) );
+var_dump($array);
+
+echo "\n-- Change \$value1 --\n";
+$value1 = -29;
+var_dump( natcasesort($array) );
+var_dump($array);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing natcasesort() : usage variation ***
+
+-- Initial test --
+bool(true)
+array(3) {
+ [1]=>
+ &int(33)
+ [0]=>
+ &int(100)
+ [2]=>
+ &int(555)
+}
+
+-- Change $value1 --
+bool(true)
+array(3) {
+ [0]=>
+ &int(-29)
+ [1]=>
+ &int(33)
+ [2]=>
+ &int(555)
+}
+Done \ No newline at end of file
diff --git a/ext/standard/tests/array/natcasesort_variation7.phpt b/ext/standard/tests/array/natcasesort_variation7.phpt
new file mode 100644
index 0000000000..c038f7d1c5
--- /dev/null
+++ b/ext/standard/tests/array/natcasesort_variation7.phpt
@@ -0,0 +1,96 @@
+--TEST--
+Test natcasesort() function : usage variations - recursive arrays
+--FILE--
+<?php
+/* Prototype : bool natcasesort(array &$array_arg)
+ * Description: Sort an array using case-insensitive natural sort
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass natcasesort() an infinitely recursive array to test how it is re-ordered
+ */
+
+echo "*** Testing natcasesort() : usage variations ***\n";
+
+$array = array (1, 3.00, 'zero', '2');
+$array[] = &$array;
+var_dump($array);
+
+var_dump(@natcasesort($array));
+var_dump($array);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing natcasesort() : usage variations ***
+array(5) {
+ [0]=>
+ int(1)
+ [1]=>
+ float(3)
+ [2]=>
+ string(4) "zero"
+ [3]=>
+ string(1) "2"
+ [4]=>
+ &array(5) {
+ [0]=>
+ int(1)
+ [1]=>
+ float(3)
+ [2]=>
+ string(4) "zero"
+ [3]=>
+ string(1) "2"
+ [4]=>
+ &array(5) {
+ [0]=>
+ int(1)
+ [1]=>
+ float(3)
+ [2]=>
+ string(4) "zero"
+ [3]=>
+ string(1) "2"
+ [4]=>
+ *RECURSION*
+ }
+ }
+}
+bool(true)
+array(5) {
+ [0]=>
+ int(1)
+ [3]=>
+ string(1) "2"
+ [1]=>
+ float(3)
+ [4]=>
+ &array(5) {
+ [0]=>
+ int(1)
+ [3]=>
+ string(1) "2"
+ [1]=>
+ float(3)
+ [4]=>
+ &array(5) {
+ [0]=>
+ int(1)
+ [3]=>
+ string(1) "2"
+ [1]=>
+ float(3)
+ [4]=>
+ *RECURSION*
+ [2]=>
+ string(4) "zero"
+ }
+ [2]=>
+ string(4) "zero"
+ }
+ [2]=>
+ string(4) "zero"
+}
+Done \ No newline at end of file
diff --git a/ext/standard/tests/array/natcasesort_variation8.phpt b/ext/standard/tests/array/natcasesort_variation8.phpt
new file mode 100644
index 0000000000..fbced4a229
--- /dev/null
+++ b/ext/standard/tests/array/natcasesort_variation8.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Test natcasesort() function : usage variations - octal values
+--FILE--
+<?php
+/* Prototype : bool natcasesort(array &$array_arg)
+ * Description: Sort an array using case-insensitive natural sort
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass an array of octal values to test how natcasesort() re-orders it
+ */
+
+echo "*** Testing natcasesort() : usage variation ***\n";
+
+$unsorted_oct_array = array(01235, 0321, 0345, 066, 0772, 077, -066, -0345, 0);
+
+var_dump( natcasesort($unsorted_oct_array) );
+var_dump($unsorted_oct_array);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing natcasesort() : usage variation ***
+bool(true)
+array(9) {
+ [6]=>
+ int(-54)
+ [7]=>
+ int(-229)
+ [8]=>
+ int(0)
+ [3]=>
+ int(54)
+ [5]=>
+ int(63)
+ [1]=>
+ int(209)
+ [2]=>
+ int(229)
+ [4]=>
+ int(506)
+ [0]=>
+ int(669)
+}
+Done \ No newline at end of file
diff --git a/ext/standard/tests/array/natcasesort_variation9.phpt b/ext/standard/tests/array/natcasesort_variation9.phpt
new file mode 100644
index 0000000000..98eec05a05
--- /dev/null
+++ b/ext/standard/tests/array/natcasesort_variation9.phpt
@@ -0,0 +1,110 @@
+--TEST--
+Test natcasesort() function : usage variations - mixed array
+--FILE--
+<?php
+/* Prototype : bool natcasesort(array &$array_arg)
+ * Description: Sort an array using case-insensitive natural sort
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass an array containing sub-arrays, ints, floats, strings, boolean, null
+ * and escape characters to test how natcasesort() re-orders it
+ */
+
+echo "*** Testing natcasesort() : usage variation ***\n";
+
+$mixed_values = array (
+ array(),
+ array( array(33, -5, 6),
+ array(11),
+ array(22, -55),
+ array()
+ ),
+ -4, "4", 4.00, "b", "5", -2, -2.0, -2.98989, "-.9", "True", "",
+ NULL, "ab", "abcd", 0.0, -0, "abcd\x00abcd\x00abcd", '', true, false
+);
+// suppress errors as is generating a lot of "array to string" notices
+var_dump( @natcasesort($mixed_values) );
+
+var_dump($mixed_values);
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing natcasesort() : usage variation ***
+bool(true)
+array(22) {
+ [13]=>
+ NULL
+ [19]=>
+ string(0) ""
+ [21]=>
+ bool(false)
+ [12]=>
+ string(0) ""
+ [10]=>
+ string(3) "-.9"
+ [7]=>
+ int(-2)
+ [8]=>
+ float(-2)
+ [9]=>
+ float(-2.98989)
+ [2]=>
+ int(-4)
+ [16]=>
+ float(0)
+ [17]=>
+ int(0)
+ [20]=>
+ bool(true)
+ [3]=>
+ string(1) "4"
+ [4]=>
+ float(4)
+ [6]=>
+ string(1) "5"
+ [14]=>
+ string(2) "ab"
+ [15]=>
+ string(4) "abcd"
+ [18]=>
+ string(14) "%s"
+ [0]=>
+ array(0) {
+ }
+ [1]=>
+ array(4) {
+ [0]=>
+ array(3) {
+ [0]=>
+ int(33)
+ [1]=>
+ int(-5)
+ [2]=>
+ int(6)
+ }
+ [1]=>
+ array(1) {
+ [0]=>
+ int(11)
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ int(22)
+ [1]=>
+ int(-55)
+ }
+ [3]=>
+ array(0) {
+ }
+ }
+ [5]=>
+ string(1) "b"
+ [11]=>
+ string(4) "True"
+}
+Done \ No newline at end of file