diff options
author | Robin Fernandes <robinf@php.net> | 2008-12-18 15:20:46 +0000 |
---|---|---|
committer | Robin Fernandes <robinf@php.net> | 2008-12-18 15:20:46 +0000 |
commit | dae1582b66443d087a10f4fe1c7f6caa07f12f1b (patch) | |
tree | 428637dfe6ef9c322f7949a71e2a27e08766acfc | |
parent | e3388ff043b417e8478e0b71f281a16d709d5e59 (diff) | |
download | php-git-dae1582b66443d087a10f4fe1c7f6caa07f12f1b.tar.gz |
Additional output buffering tests.
39 files changed, 1486 insertions, 0 deletions
diff --git a/tests/output/flush_basic_001.phpt b/tests/output/flush_basic_001.phpt new file mode 100644 index 0000000000..d9bb639794 --- /dev/null +++ b/tests/output/flush_basic_001.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test basic functionality of flush() +--FILE-- +<?php +/* + * proto void flush(void) + * Function is implemented in ext/standard/basic_functions.c. + */ + +// Verify return type +var_dump(flush()); + +// Ensure user buffers are not flushed by flush() +ob_start(); +echo "Inside a user buffer\n"; +flush(); +ob_end_clean(); + +echo "Outside of any user buffers\n"; +var_dump(flush()); + +?> +--EXPECT-- +NULL +Outside of any user buffers +NULL
\ No newline at end of file diff --git a/tests/output/flush_error_001.phpt b/tests/output/flush_error_001.phpt new file mode 100644 index 0000000000..720c0d503b --- /dev/null +++ b/tests/output/flush_error_001.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test wrong number of arguments for flush() (no impact) +--FILE-- +<?php +/* + * proto void flush(void) + * Function is implemented in ext/standard/basic_functions.c. + */ + +$extra_arg = 1; +echo "\nToo many arguments\n"; +var_dump(flush($extra_arg)); +?> +--EXPECTF-- +Too many arguments +NULL
\ No newline at end of file diff --git a/tests/output/ob_clean_basic_001.phpt b/tests/output/ob_clean_basic_001.phpt new file mode 100644 index 0000000000..c93bea3588 --- /dev/null +++ b/tests/output/ob_clean_basic_001.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test ob_clean() function : basic functionality +--FILE-- +<?php +/* Prototype : proto bool ob_clean(void) + * Description: Clean (delete) the current output buffer + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_clean() : basic functionality ***\n"; + +// Zero arguments +echo "\n-- Testing ob_clean() function with Zero arguments --\n"; +var_dump( ob_clean() ); + +ob_start(); +echo "You should never see this."; +var_dump(ob_clean()); + +echo "Ensure the buffer is still active after the clean."; +$out = ob_get_clean(); +var_dump($out); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_clean() : basic functionality *** + +-- Testing ob_clean() function with Zero arguments -- + +Notice: ob_clean(): failed to delete buffer. No buffer to delete. in %s on line 12 +bool(false) +string(61) "bool(true) +Ensure the buffer is still active after the clean." +Done
\ No newline at end of file diff --git a/tests/output/ob_clean_error_001.phpt b/tests/output/ob_clean_error_001.phpt new file mode 100644 index 0000000000..7b74ff8f1a --- /dev/null +++ b/tests/output/ob_clean_error_001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test ob_clean() function : error conditions +--FILE-- +<?php +/* Prototype : proto bool ob_clean(void) + * Description: Clean (delete) the current output buffer + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_clean() : error conditions ***\n"; + +// One argument +echo "\n-- Testing ob_clean() function with one argument --\n"; +$extra_arg = 10;; +var_dump( ob_clean($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_clean() : error conditions *** + +-- Testing ob_clean() function with one argument -- + +Warning: Wrong parameter count for ob_clean() in %s on line 13 +NULL +Done
\ No newline at end of file diff --git a/tests/output/ob_end_clean_basic_001.phpt b/tests/output/ob_end_clean_basic_001.phpt new file mode 100644 index 0000000000..0b694e36ca --- /dev/null +++ b/tests/output/ob_end_clean_basic_001.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test return type and value, as well as basic behaviour, for ob_end_clean() +--FILE-- +<?php +/* + * proto bool ob_end_clean(void) + * Function is implemented in main/output.c +*/ + +var_dump(ob_end_clean()); + +ob_start(); +var_dump(ob_end_clean()); + +ob_start(); +echo "Hello"; +var_dump(ob_end_clean()); + +var_dump(ob_end_clean()); + +?> +--EXPECTF-- + +Notice: ob_end_clean(): failed to delete buffer. No buffer to delete. in %s on line 7 +bool(false) +bool(true) +bool(true) + +Notice: ob_end_clean(): failed to delete buffer. No buffer to delete. in %s on line 16 +bool(false) + diff --git a/tests/output/ob_end_clean_error_001.phpt b/tests/output/ob_end_clean_error_001.phpt new file mode 100644 index 0000000000..f7b549e724 --- /dev/null +++ b/tests/output/ob_end_clean_error_001.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test wrong number of arguments for ob_end_clean() +--FILE-- +<?php +/* + * proto bool ob_end_clean(void) + * Function is implemented in main/output.c +*/ + +$extra_arg = 1; + +echo "\nToo many arguments\n"; +var_dump(ob_end_clean($extra_arg)); + + +?> +--EXPECTF-- + +Too many arguments + +Warning: Wrong parameter count for ob_end_clean() in %s on line 10 +NULL diff --git a/tests/output/ob_end_flush_basic_001.phpt b/tests/output/ob_end_flush_basic_001.phpt new file mode 100644 index 0000000000..7515face06 --- /dev/null +++ b/tests/output/ob_end_flush_basic_001.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test ob_end_flush() function : basic functionality +--FILE-- +<?php +/* Prototype : proto bool ob_end_flush(void) + * Description: Flush (send) the output buffer, and delete current output buffer + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_end_flush() : basic functionality ***\n"; + +// Zero arguments +echo "\n-- Testing ob_end_flush() function with Zero arguments --\n"; +var_dump(ob_end_flush()); + +ob_start(); +var_dump(ob_end_flush()); + +ob_start(); +echo "Hello\n"; +var_dump(ob_end_flush()); + +var_dump(ob_end_flush()); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_end_flush() : basic functionality *** + +-- Testing ob_end_flush() function with Zero arguments -- + +Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush. in %s on line 12 +bool(false) +bool(true) +Hello +bool(true) + +Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush. in %s on line 21 +bool(false) +Done
\ No newline at end of file diff --git a/tests/output/ob_end_flush_error_001.phpt b/tests/output/ob_end_flush_error_001.phpt new file mode 100644 index 0000000000..f9e118a102 --- /dev/null +++ b/tests/output/ob_end_flush_error_001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test ob_end_flush() function : error conditions +--FILE-- +<?php +/* Prototype : proto bool ob_end_flush(void) + * Description: Flush (send) the output buffer, and delete current output buffer + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_end_flush() : error conditions ***\n"; + +// One argument +echo "\n-- Testing ob_end_flush() function with one argument --\n"; +$extra_arg = 10;; +var_dump( ob_end_flush($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_end_flush() : error conditions *** + +-- Testing ob_end_flush() function with one argument -- + +Warning: Wrong parameter count for ob_end_flush() in %s on line 13 +NULL +Done diff --git a/tests/output/ob_flush_basic_001.phpt b/tests/output/ob_flush_basic_001.phpt new file mode 100644 index 0000000000..91fb695266 --- /dev/null +++ b/tests/output/ob_flush_basic_001.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test ob_flush() function : basic functionality +--FILE-- +<?php +/* Prototype : proto bool ob_flush(void) + * Description: Flush (send) contents of the output buffer. The last buffer content is sent to next buffer + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_flush() : basic functionality ***\n"; + +// Zero arguments +echo "\n-- Testing ob_flush() function with Zero arguments --\n"; +var_dump(ob_flush()); + +ob_start(); +echo "This should get flushed.\n"; +var_dump(ob_flush()); + +echo "Ensure the buffer is still active after the flush.\n"; +$out = ob_flush(); +var_dump($out); + +echo "Done"; + +?> +--EXPECTF-- +*** Testing ob_flush() : basic functionality *** + +-- Testing ob_flush() function with Zero arguments -- + +Notice: ob_flush(): failed to flush buffer. No buffer to flush. in %s on line 12 +bool(false) +This should get flushed. +bool(true) +Ensure the buffer is still active after the flush. +bool(true) +Done
\ No newline at end of file diff --git a/tests/output/ob_flush_error_001.phpt b/tests/output/ob_flush_error_001.phpt new file mode 100644 index 0000000000..44f51785e8 --- /dev/null +++ b/tests/output/ob_flush_error_001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test ob_flush() function : error conditions +--FILE-- +<?php +/* Prototype : proto bool ob_flush(void) + * Description: Flush (send) contents of the output buffer. The last buffer content is sent to next buffer + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_flush() : error conditions ***\n"; + +// One argument +echo "\n-- Testing ob_flush() function with one argument --\n"; +$extra_arg = 10;; +var_dump( ob_flush($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_flush() : error conditions *** + +-- Testing ob_flush() function with one argument -- + +Warning: Wrong parameter count for ob_flush() in %s on line 13 +NULL +Done diff --git a/tests/output/ob_get_clean_basic_001.phpt b/tests/output/ob_get_clean_basic_001.phpt new file mode 100644 index 0000000000..07673dfac4 --- /dev/null +++ b/tests/output/ob_get_clean_basic_001.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test return type and value, as well as basic behaviour, of ob_get_clean() +--FILE-- +<?php +/* + * proto bool ob_get_clean(void) + * Function is implemented in main/output.c +*/ + +var_dump(ob_get_clean()); + +ob_start(); +echo "Hello World"; +var_dump(ob_get_clean()); +?> +--EXPECTF-- +bool(false) +string(11) "Hello World"
\ No newline at end of file diff --git a/tests/output/ob_get_clean_basic_002.phpt b/tests/output/ob_get_clean_basic_002.phpt new file mode 100644 index 0000000000..a5992734c6 --- /dev/null +++ b/tests/output/ob_get_clean_basic_002.phpt @@ -0,0 +1,20 @@ +--TEST-- +Test basic behaviour of ob_get_clean() +--FILE-- +<?php +/* + * proto bool ob_get_clean(void) + * Function is implemented in main/output.c +*/ + +ob_start(); + +echo "Hello World"; + +$out = ob_get_clean(); +$out = strtolower($out); + +var_dump($out); +?> +--EXPECT-- +string(11) "hello world"
\ No newline at end of file diff --git a/tests/output/ob_get_clean_error_001.phpt b/tests/output/ob_get_clean_error_001.phpt new file mode 100644 index 0000000000..25c775700a --- /dev/null +++ b/tests/output/ob_get_clean_error_001.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test wrong number of arguments for ob_get_clean() +--FILE-- +<?php +/* + * proto bool ob_get_clean(void) + * Function is implemented in main/output.c +*/ + +$extra_arg = 1; + +echo "\nToo many arguments\n"; +var_dump(ob_get_clean($extra_arg)); + + +?> +--EXPECTF-- + +Too many arguments + +Warning: Wrong parameter count for ob_get_clean() in %s on line 10 +NULL
\ No newline at end of file diff --git a/tests/output/ob_get_contents_basic_001.phpt b/tests/output/ob_get_contents_basic_001.phpt new file mode 100644 index 0000000000..a99024506d --- /dev/null +++ b/tests/output/ob_get_contents_basic_001.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test ob_get_contents() function : basic functionality +--CREDITS-- +Iain Lewis <ilewis@php.net> +--FILE-- +<?php +/* Prototype : proto string ob_get_contents(void) + * Description: Return the contents of the output buffer + * Source code: main/output.c + * Alias to functions: + */ + + +echo "*** Testing ob_get_contents() : basic functionality ***\n"; + +// Zero arguments +echo "\n-- Testing ob_get_contents() function with Zero arguments --\n"; +/* Buffering not started yet, should return false */ +var_dump( ob_get_contents() ); + +ob_start(); +echo "Hello World\n"; +$hello = ob_get_contents(); +var_dump($hello); +ob_end_flush(); + + +echo "\ncheck that we dont have a reference\n"; +ob_start(); +echo "Hello World\n"; +$hello2 = ob_get_contents(); +$hello2 = "bob"; +var_dump(ob_get_contents()); +ob_end_flush(); + +echo "\ncheck that contents disappear after a flush\n"; +ob_start(); +echo "Hello World\n"; +ob_flush(); +var_dump(ob_get_contents()); +ob_end_flush(); + +echo "\ncheck that no contents found after an end\n"; +ob_start(); +echo "Hello World\n"; +ob_end_flush(); +var_dump(ob_get_contents()); + + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ob_get_contents() : basic functionality *** + +-- Testing ob_get_contents() function with Zero arguments -- +bool(false) +Hello World +string(12) "Hello World +" + +check that we dont have a reference +Hello World +string(12) "Hello World +" + +check that contents disappear after a flush +Hello World +string(0) "" + +check that no contents found after an end +Hello World +bool(false) +Done
\ No newline at end of file diff --git a/tests/output/ob_get_contents_error_001.phpt b/tests/output/ob_get_contents_error_001.phpt new file mode 100644 index 0000000000..10253c37a7 --- /dev/null +++ b/tests/output/ob_get_contents_error_001.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test ob_get_contents() function : error cases +--CREDITS-- +Iain Lewis <ilewis@php.net> +--FILE-- +<?php +/* Prototype : proto string ob_get_contents(void) + * Description: Return the contents of the output buffer + * Source code: main/output.c + * Alias to functions: + */ + + +echo "*** Testing ob_get_contents() : error cases ***\n"; + +var_dump(ob_get_contents("bob")); + +ob_start(); + +var_dump(ob_get_contents("bob2",345)); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ob_get_contents() : error cases *** + +Warning: Wrong parameter count for ob_get_contents() in %s on line 11 +NULL + +Warning: Wrong parameter count for ob_get_contents() in %s on line 15 +NULL +Done diff --git a/tests/output/ob_get_length_basic_001.phpt b/tests/output/ob_get_length_basic_001.phpt new file mode 100644 index 0000000000..98469c2583 --- /dev/null +++ b/tests/output/ob_get_length_basic_001.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test return type and value, as well as basic behaviour, of ob_get_length() +--FILE-- +<?php +/* + * proto int ob_get_length(void) + * Function is implemented in main/output.c +*/ + +echo "No output buffers\n"; +var_dump(ob_get_length()); + +ob_start(); +var_dump(ob_get_length()); +echo "hello\n"; +var_dump(ob_get_length()); +ob_flush(); +$value = ob_get_length(); +echo "hello\n"; +ob_clean(); +var_dump(ob_get_length()); +var_dump($value); +ob_end_flush(); + +echo "No output buffers\n"; +var_dump(ob_get_length()); +?> +--EXPECTF-- +No output buffers +bool(false) +int(0) +hello +int(13) +int(0) +int(0) +No output buffers +bool(false)
\ No newline at end of file diff --git a/tests/output/ob_get_length_error_001.phpt b/tests/output/ob_get_length_error_001.phpt new file mode 100644 index 0000000000..8b461a2c1a --- /dev/null +++ b/tests/output/ob_get_length_error_001.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test wrong number of arguments for ob_get_length() +--FILE-- +<?php +/* + * proto int ob_get_length(void) + * Function is implemented in main/output.c +*/ + +$extra_arg = 1; + +echo "\nToo many arguments\n"; +var_dump(ob_get_length($extra_arg)); + + +?> +--EXPECTF-- + +Too many arguments + +Warning: Wrong parameter count for ob_get_length() in %s on line 10 +NULL
\ No newline at end of file diff --git a/tests/output/ob_get_level_basic_001.phpt b/tests/output/ob_get_level_basic_001.phpt new file mode 100644 index 0000000000..78217e4a45 --- /dev/null +++ b/tests/output/ob_get_level_basic_001.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test ob_get_level() function : basic functionality +--FILE-- +<?php +/* Prototype : proto int ob_get_level(void) + * Description: Return the nesting level of the output buffer + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_get_level() : basic functionality ***\n"; + +// Zero arguments +echo "\n-- Testing ob_get_level() function with Zero arguments --\n"; +var_dump(ob_get_level()); + +ob_start(); +var_dump(ob_get_level()); + +ob_start(); +var_dump(ob_get_level()); + +ob_end_flush(); +var_dump(ob_get_level()); + +ob_end_flush(); +var_dump(ob_get_level()); + +ob_end_flush(); +var_dump(ob_get_level()); + + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_get_level() : basic functionality *** + +-- Testing ob_get_level() function with Zero arguments -- +int(0) +int(1) +int(2) +int(1) +int(0) + +Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush. in %s on line 26 +int(0) +Done
\ No newline at end of file diff --git a/tests/output/ob_get_level_error_001.phpt b/tests/output/ob_get_level_error_001.phpt new file mode 100644 index 0000000000..5f3e4e7ed5 --- /dev/null +++ b/tests/output/ob_get_level_error_001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test ob_get_level() function : error conditions +--FILE-- +<?php +/* Prototype : proto int ob_get_level(void) + * Description: Return the nesting level of the output buffer + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_get_level() : error conditions ***\n"; + +// One argument +echo "\n-- Testing ob_get_level() function with one argument --\n"; +$extra_arg = 10;; +var_dump( ob_get_level($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_get_level() : error conditions *** + +-- Testing ob_get_level() function with one argument -- + +Warning: Wrong parameter count for ob_get_level() in %s on line 13 +NULL +Done
\ No newline at end of file diff --git a/tests/output/ob_implicit_flush_basic_001.phpt b/tests/output/ob_implicit_flush_basic_001.phpt new file mode 100644 index 0000000000..ab6f6a7a6e --- /dev/null +++ b/tests/output/ob_implicit_flush_basic_001.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test ob_implicit_flush() function : check return value (always null). +--FILE-- +<?php +/* Prototype : proto void ob_implicit_flush([int flag]) + * Description: Turn implicit flush on/off and is equivalent to calling flush() after every output call + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_implicit_flush() : check return value ***\n"; + +var_dump(ob_implicit_flush()); +var_dump(ob_implicit_flush(true)); +var_dump(ob_implicit_flush(false)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_implicit_flush() : check return value *** +NULL +NULL +NULL +Done diff --git a/tests/output/ob_implicit_flush_basic_002.phpt b/tests/output/ob_implicit_flush_basic_002.phpt new file mode 100644 index 0000000000..6b378a7f18 --- /dev/null +++ b/tests/output/ob_implicit_flush_basic_002.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test ob_implicit_flush() function : ensure implicit flushing does not apply to user buffers. +--FILE-- +<?php +/* Prototype : proto void ob_implicit_flush([int flag]) + * Description: Turn implicit flush on/off and is equivalent to calling flush() after every output call + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_implicit_flush() : ensure implicit flushing does not apply to user buffers. ***\n"; + +// Start a user buffer +ob_start(); +// Switch on implicit flushing. +ob_implicit_flush(1); + +echo "This is being written to a user buffer.\n"; +echo "Note that even though implicit flushing is on, you should never see this,\n"; +echo "because implicit flushing affects only the top level buffer, not user buffers.\n"; + +// Wipe the user buffer. Nothing should have been flushed. +ob_end_clean(); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_implicit_flush() : ensure implicit flushing does not apply to user buffers. *** +Done
\ No newline at end of file diff --git a/tests/output/ob_implicit_flush_error_001.phpt b/tests/output/ob_implicit_flush_error_001.phpt new file mode 100644 index 0000000000..d4d14c6fb7 --- /dev/null +++ b/tests/output/ob_implicit_flush_error_001.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test ob_implicit_flush() function : wrong number of arguments +--FILE-- +<?php +/* Prototype : proto void ob_implicit_flush([int flag]) + * Description: Turn implicit flush on/off and is equivalent to calling flush() after every output call + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_implicit_flush() : error conditions ***\n"; + + +//Test ob_implicit_flush with one more than the expected number of arguments +echo "\n-- Testing ob_implicit_flush() function with more than expected no. of arguments --\n"; +$flag = 10; +$extra_arg = 10; +var_dump( ob_implicit_flush($flag, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_implicit_flush() : error conditions *** + +-- Testing ob_implicit_flush() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for ob_implicit_flush() in %s on line 15 +NULL +Done
\ No newline at end of file diff --git a/tests/output/ob_implicit_flush_variation_001.phpt b/tests/output/ob_implicit_flush_variation_001.phpt new file mode 100644 index 0000000000..e10bd493e4 --- /dev/null +++ b/tests/output/ob_implicit_flush_variation_001.phpt @@ -0,0 +1,182 @@ +--TEST-- +Test ob_implicit_flush() function : usage variation +--FILE-- +<?php +/* Prototype : void ob_implicit_flush([int flag]) + * Description: Turn implicit flush on/off and is equivalent to calling flush() after every output call + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_implicit_flush() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for flag + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( ob_implicit_flush($value) ); +}; + +?> +--EXPECTF-- +*** Testing ob_implicit_flush() : usage variation *** + +--float 10.5-- +NULL + +--float -10.5-- +NULL + +--float 12.3456789000e10-- +NULL + +--float -12.3456789000e10-- +NULL + +--float .5-- +NULL + +--empty array-- +NULL + +--int indexed array-- +NULL + +--associative array-- +NULL + +--nested arrays-- +NULL + +--uppercase NULL-- +NULL + +--lowercase null-- +NULL + +--lowercase true-- +NULL + +--lowercase false-- +NULL + +--uppercase TRUE-- +NULL + +--uppercase FALSE-- +NULL + +--empty string DQ-- +NULL + +--empty string SQ-- +NULL + +--string DQ-- +NULL + +--string SQ-- +NULL + +--mixed case string-- +NULL + +--heredoc-- +NULL + +--instance of classWithToString-- +Error: 8 - Object of class classWithToString could not be converted to int, %s(97) +NULL + +--instance of classWithoutToString-- +Error: 8 - Object of class classWithoutToString could not be converted to int, %s(97) +NULL + +--undefined var-- +NULL + +--unset var-- +NULL
\ No newline at end of file diff --git a/tests/output/ob_start_basic_001.phpt b/tests/output/ob_start_basic_001.phpt new file mode 100644 index 0000000000..d93a7313b8 --- /dev/null +++ b/tests/output/ob_start_basic_001.phpt @@ -0,0 +1,14 @@ +--TEST-- +Test return type and value for ob_start() +--FILE-- +<?php +/* + * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) + * Function is implemented in main/output.c +*/ + +var_dump(ob_start()); + +?> +--EXPECT-- +bool(true)
\ No newline at end of file diff --git a/tests/output/ob_start_basic_002.phpt b/tests/output/ob_start_basic_002.phpt new file mode 100644 index 0000000000..92d9069f32 --- /dev/null +++ b/tests/output/ob_start_basic_002.phpt @@ -0,0 +1,55 @@ +--TEST-- +ob_start(): Check behaviour with various callback return values. +--FILE-- +<?php +function return_empty_string($string) { + return ""; +} + +function return_false($string) { + return false; +} + +function return_null($string) { + return null; +} + +function return_string($string) { + return "I stole your output."; +} + +function return_zero($string) { + return 0; +} + +// Use each of the above functions as an output buffering callback: +$functions = get_defined_functions(); +$callbacks = $functions['user']; +sort($callbacks); +foreach ($callbacks as $callback) { + echo "--> Use callback '$callback':\n"; + ob_start($callback); + echo 'My output.'; + ob_end_flush(); + echo "\n\n"; +} + +?> +==DONE== +--EXPECTF-- +--> Use callback 'return_empty_string': + + +--> Use callback 'return_false': +My output. + +--> Use callback 'return_null': + + +--> Use callback 'return_string': +I stole your output. + +--> Use callback 'return_zero': +0 + +==DONE==
\ No newline at end of file diff --git a/tests/output/ob_start_basic_003.phpt b/tests/output/ob_start_basic_003.phpt new file mode 100644 index 0000000000..ebd883af73 --- /dev/null +++ b/tests/output/ob_start_basic_003.phpt @@ -0,0 +1,18 @@ +--TEST-- +ob_start(): ensure even fatal error test is affected by output buffering. +--FILE-- +<?php + +function f() { + return "I have stolen your output"; +} + +ob_start('f'); +cause_fatal_error(); // call undefined function +ob_end_flush(); + +echo "done (you shouldn't see this)"; + +?> +--EXPECTF-- +I have stolen your output
\ No newline at end of file diff --git a/tests/output/ob_start_basic_004.phpt b/tests/output/ob_start_basic_004.phpt new file mode 100644 index 0000000000..39d3aadc49 --- /dev/null +++ b/tests/output/ob_start_basic_004.phpt @@ -0,0 +1,122 @@ +--TEST-- +ob_start() chunk_size: confirm buffer is flushed after any output call that causes its length to equal or exceed chunk_size. +--FILE-- +<?php +/* + * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) + * Function is implemented in main/output.c +*/ + +function callback($string) { + global $callback_invocations; + $callback_invocations++; + $len = strlen($string); + return "f[call:$callback_invocations; len:$len]$string\n"; +} + +for ($cs=-1; $cs<10; $cs++) { + echo "\n----( chunk_size: $cs, output append size: 1 )----\n"; + $callback_invocations=0; + ob_start('callback', $cs); + echo '1'; echo '2'; echo '3'; echo '4'; echo '5'; echo '6'; echo '7'; echo '8'; + ob_end_flush(); +} + +for ($cs=-1; $cs<10; $cs++) { + echo "\n----( chunk_size: $cs, output append size: 4 )----\n"; + $callback_invocations=0; + ob_start('callback', $cs); + echo '1234'; echo '5678'; + ob_end_flush(); +} + +?> +--EXPECTF-- + +----( chunk_size: -1, output append size: 1 )---- +f[call:1; len:8]12345678 + +----( chunk_size: 0, output append size: 1 )---- +f[call:1; len:8]12345678 + +----( chunk_size: 1, output append size: 1 )---- +f[call:1; len:8]12345678 + +----( chunk_size: 2, output append size: 1 )---- +f[call:1; len:2]12 +f[call:2; len:2]34 +f[call:3; len:2]56 +f[call:4; len:2]78 +f[call:5; len:0] + +----( chunk_size: 3, output append size: 1 )---- +f[call:1; len:3]123 +f[call:2; len:3]456 +f[call:3; len:2]78 + +----( chunk_size: 4, output append size: 1 )---- +f[call:1; len:4]1234 +f[call:2; len:4]5678 +f[call:3; len:0] + +----( chunk_size: 5, output append size: 1 )---- +f[call:1; len:5]12345 +f[call:2; len:3]678 + +----( chunk_size: 6, output append size: 1 )---- +f[call:1; len:6]123456 +f[call:2; len:2]78 + +----( chunk_size: 7, output append size: 1 )---- +f[call:1; len:7]1234567 +f[call:2; len:1]8 + +----( chunk_size: 8, output append size: 1 )---- +f[call:1; len:8]12345678 +f[call:2; len:0] + +----( chunk_size: 9, output append size: 1 )---- +f[call:1; len:8]12345678 + +----( chunk_size: -1, output append size: 4 )---- +f[call:1; len:8]12345678 + +----( chunk_size: 0, output append size: 4 )---- +f[call:1; len:8]12345678 + +----( chunk_size: 1, output append size: 4 )---- +f[call:1; len:8]12345678 + +----( chunk_size: 2, output append size: 4 )---- +f[call:1; len:4]1234 +f[call:2; len:4]5678 +f[call:3; len:0] + +----( chunk_size: 3, output append size: 4 )---- +f[call:1; len:4]1234 +f[call:2; len:4]5678 +f[call:3; len:0] + +----( chunk_size: 4, output append size: 4 )---- +f[call:1; len:4]1234 +f[call:2; len:4]5678 +f[call:3; len:0] + +----( chunk_size: 5, output append size: 4 )---- +f[call:1; len:8]12345678 +f[call:2; len:0] + +----( chunk_size: 6, output append size: 4 )---- +f[call:1; len:8]12345678 +f[call:2; len:0] + +----( chunk_size: 7, output append size: 4 )---- +f[call:1; len:8]12345678 +f[call:2; len:0] + +----( chunk_size: 8, output append size: 4 )---- +f[call:1; len:8]12345678 +f[call:2; len:0] + +----( chunk_size: 9, output append size: 4 )---- +f[call:1; len:8]12345678
\ No newline at end of file diff --git a/tests/output/ob_start_basic_005.phpt b/tests/output/ob_start_basic_005.phpt new file mode 100644 index 0000000000..e449503083 --- /dev/null +++ b/tests/output/ob_start_basic_005.phpt @@ -0,0 +1,31 @@ +--TEST-- +ob_start(): don't allow non-static functions as static callbacks. +--FILE-- +<?php +/* + * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) + * Function is implemented in main/output.c +*/ + +Class C { + function h($string) { + return $string; + } +} + +function checkAndClean() { + print_r(ob_list_handlers()); + while (ob_get_level()>0) { + ob_end_flush(); + } +} + +var_dump(ob_start('C::h')); +checkAndClean(); + +?> +--EXPECT-- +bool(false) +Array +( +)
\ No newline at end of file diff --git a/tests/output/ob_start_basic_006.phpt b/tests/output/ob_start_basic_006.phpt new file mode 100644 index 0000000000..e24ebd61c3 --- /dev/null +++ b/tests/output/ob_start_basic_006.phpt @@ -0,0 +1,134 @@ +--TEST-- +ob_start(): multiple buffer initialization with a single call, using arrays. +--FILE-- +<?php +/* + * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) + * Function is implemented in main/output.c +*/ + +function f($string) { + static $i=0; + $i++; + $len = strlen($string); + return "f[call:$i; len:$len] - $string\n"; +} + +Class C { + public $id = 'none'; + + function __construct($id) { + $this->id = $id; + } + + static function g($string) { + static $i=0; + $i++; + $len = strlen($string); + return "C::g[call:$i; len:$len] - $string\n"; + } + + function h($string) { + static $i=0; + $i++; + $len = strlen($string); + return "C::h[call:$i; len:$len; id:$this->id] - $string\n"; + } +} + +function checkAndClean() { + print_r(ob_list_handlers()); + while (ob_get_level()>0) { + ob_end_flush(); + } +} + +echo "\n ---> Test arrays: \n"; +var_dump(ob_start(array("f"))); +checkAndClean(); + +var_dump(ob_start(array("f", "f"))); +checkAndClean(); + +var_dump(ob_start(array("f", "C::g", "f", "C::g"))); +checkAndClean(); + +var_dump(ob_start(array("f", "non_existent", "f"))); +checkAndClean(); + +var_dump(ob_start(array("f", "non_existent", "f", "f"))); +checkAndClean(); + +$c = new c('originalID'); +var_dump(ob_start(array($c, "h"))); +checkAndClean(); + +var_dump(ob_start(array($c, "h"))); +$c->id = 'changedID'; +checkAndClean(); + +$c->id = 'changedIDagain'; +var_dump(ob_start(array('f', 'C::g', array(array($c, "g"), array($c, "h"))))); +checkAndClean(); +?> +--EXPECTF-- + + ---> Test arrays: +f[call:1; len:34] - bool(true) +Array +( + [0] => f +) + +f[call:3; len:68] - f[call:2; len:47] - bool(true) +Array +( + [0] => f + [1] => f +) + + +f[call:5; len:150] - C::g[call:2; len:125] - f[call:4; len:103] - C::g[call:1; len:79] - bool(true) +Array +( + [0] => f + [1] => C::g + [2] => f + [3] => C::g +) + + + + +f[call:6; len:35] - bool(false) +Array +( + [0] => f +) + +f[call:7; len:35] - bool(false) +Array +( + [0] => f +) + +C::h[call:1; len:37; id:originalID] - bool(true) +Array +( + [0] => C::h +) + +C::h[call:2; len:37; id:changedID] - bool(true) +Array +( + [0] => C::h +) + +f[call:8; len:175] - C::g[call:4; len:150] - C::g[call:3; len:125] - C::h[call:3; len:82; id:changedIDagain] - bool(true) +Array +( + [0] => f + [1] => C::g + [2] => C::g + [3] => C::h +)
\ No newline at end of file diff --git a/tests/output/ob_start_basic_unerasable_001.phpt b/tests/output/ob_start_basic_unerasable_001.phpt new file mode 100644 index 0000000000..8e7280edda --- /dev/null +++ b/tests/output/ob_start_basic_unerasable_001.phpt @@ -0,0 +1,22 @@ +--TEST-- +ob_start(): Ensure content of unerasable buffer can be accessed by ob_get_contents(). +--FILE-- +<?php +function callback($string) { + static $callback_invocations; + $callback_invocations++; + return "[callback:$callback_invocations]$string\n"; +} + +ob_start('callback', 0, false); + +echo "This call will obtain the content:\n"; +$str = ob_get_contents(); +var_dump($str); +?> +==DONE== +--EXPECTF-- +[callback:1]This call will obtain the content: +string(35) "This call will obtain the content: +" +==DONE==
\ No newline at end of file diff --git a/tests/output/ob_start_basic_unerasable_002.phpt b/tests/output/ob_start_basic_unerasable_002.phpt new file mode 100644 index 0000000000..2ffcbb9dc1 --- /dev/null +++ b/tests/output/ob_start_basic_unerasable_002.phpt @@ -0,0 +1,33 @@ +--TEST-- +ob_start(): Ensure unerasable buffer cannot be erased by ob_clean(), ob_end_clean() or ob_end_flush(). +--FILE-- +<?php +function callback($string) { + static $callback_invocations; + $callback_invocations++; + return "[callback:$callback_invocations]$string\n"; +} + +ob_start('callback', 0, false); + +echo "All of the following calls will fail to clean/remove the topmost buffer:\n"; +var_dump(ob_clean()); +var_dump(ob_end_clean()); +var_dump(ob_end_flush()); + +echo "The OB nesting will still be 1 level deep:\n"; +var_dump(ob_get_level()); +?> +--EXPECTF-- +[callback:1]All of the following calls will fail to clean/remove the topmost buffer: + +Notice: ob_clean(): failed to delete buffer callback. in %s on line 11 +bool(false) + +Notice: ob_end_clean(): failed to delete buffer callback. in %s on line 12 +bool(false) + +Notice: ob_end_flush(): failed to delete buffer callback. in %s on line 13 +bool(false) +The OB nesting will still be 1 level deep: +int(1)
\ No newline at end of file diff --git a/tests/output/ob_start_basic_unerasable_003.phpt b/tests/output/ob_start_basic_unerasable_003.phpt new file mode 100644 index 0000000000..d201414533 --- /dev/null +++ b/tests/output/ob_start_basic_unerasable_003.phpt @@ -0,0 +1,21 @@ +--TEST-- +ob_start(): Ensure unerasable buffer cannot be accessed or erased by ob_get_clean(). +--FILE-- +<?php +function callback($string) { + static $callback_invocations; + $callback_invocations++; + return "[callback:$callback_invocations]$string\n"; +} + +ob_start('callback', 0, false); + +echo "This call will fail to obtain the content, since it is also requesting a clean:\n"; +$str = ob_get_clean(); +var_dump($str); +?> +--EXPECTF-- +[callback:1]This call will fail to obtain the content, since it is also requesting a clean: + +Notice: ob_get_clean(): failed to delete buffer callback. in %s on line 11 +bool(false)
\ No newline at end of file diff --git a/tests/output/ob_start_basic_unerasable_004.phpt b/tests/output/ob_start_basic_unerasable_004.phpt new file mode 100644 index 0000000000..88fdda5b3f --- /dev/null +++ b/tests/output/ob_start_basic_unerasable_004.phpt @@ -0,0 +1,21 @@ +--TEST-- +ob_start(): Ensure unerasable buffer cannot be accessed or flushed by ob_get_flush(). +--FILE-- +<?php +function callback($string) { + static $callback_invocations; + $callback_invocations++; + return "[callback:$callback_invocations]$string\n"; +} + +ob_start('callback', 0, false); + +echo "This call will fail to flush and fail to obtain the content:\n"; +$str = ob_get_flush(); +var_dump($str); +?> +--EXPECTF-- +[callback:1]This call will fail to flush and fail to obtain the content: + +Notice: ob_get_flush(): failed to delete buffer callback. in %s on line 11 +bool(false)
\ No newline at end of file diff --git a/tests/output/ob_start_basic_unerasable_005.phpt b/tests/output/ob_start_basic_unerasable_005.phpt new file mode 100644 index 0000000000..48d611c9c0 --- /dev/null +++ b/tests/output/ob_start_basic_unerasable_005.phpt @@ -0,0 +1,27 @@ +--TEST-- +ob_start(): Ensure unerasable buffer cannot be flushed by ob_flush(). +--XFAIL-- +On PHP5, ob_flush() DOES clear the buffer. See bug: 46897 +--FILE-- +<?php +function callback($string) { + static $callback_invocations; + $callback_invocations++; + return "[callback:$callback_invocations]$string\n"; +} + +ob_start('callback', 0, false); + +echo "Attempt to flush unerasable buffer - should fail... "; +var_dump(ob_flush()); +// Check content of buffer after flush - if flush failed it should still contain the string above. +var_dump(ob_get_contents()); +?> +--EXPECTF-- +[callback:1]Attempt to flush unerasable buffer - should fail... +Notice: ob_flush(): failed to flush buffer callback in %s on line 11 +bool(false) +string(%d) "Attempt to flush unerasable buffer - should fail... +Notice: ob_flush(): failed to flush buffer callback in %s on line 11 +bool(false) +"
\ No newline at end of file diff --git a/tests/output/ob_start_error_001.phpt b/tests/output/ob_start_error_001.phpt new file mode 100644 index 0000000000..b1a52e3213 --- /dev/null +++ b/tests/output/ob_start_error_001.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test wrong number of arguments and wrong arg types for ob_start() +--FILE-- +<?php +/* + * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) + * Function is implemented in main/output.c +*/ + +function justPrint($str) { + return $str; +} + +$arg_1 = "justPrint"; +$arg_2 = 0; +$arg_3 = false; +$extra_arg = 1; + +echo "\n- Too many arguments\n"; +var_dump(ob_start($arg_1, $arg_2, $arg_3, $extra_arg)); + +echo "\n- Arg 1 wrong type\n"; +var_dump(ob_start(1.5)); + +echo "\n- Arg 2 wrong type\n"; +var_dump(ob_start("justPrint", "this should be an int")); + +echo "\n- Arg 3 wrong type\n"; +var_dump(ob_start("justPrint", 0, "this should be a bool")); + +?> +--EXPECTF-- + +- Too many arguments + +Warning: ob_start() expects at most 3 parameters, 4 given in %s on line 17 +bool(false) + +- Arg 1 wrong type +bool(true) + +- Arg 2 wrong type + +Warning: ob_start() expects parameter 2 to be long, string given in %s on line 23 +bool(false) + +- Arg 3 wrong type +bool(true)
\ No newline at end of file diff --git a/tests/output/ob_start_error_002.phpt b/tests/output/ob_start_error_002.phpt new file mode 100644 index 0000000000..aca2ad9d2c --- /dev/null +++ b/tests/output/ob_start_error_002.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test wrong number of arguments and wrong arg types for ob_start() +--FILE-- +<?php +/* + * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) + * Function is implemented in main/output.c +*/ + +Class C { + static function f($str) { + return $str; + } +} + +var_dump(ob_start(array("nonExistent","f"))); +var_dump(ob_start(array("C","nonExistent"))); +var_dump(ob_start("C::no")); +var_dump(ob_start("no")); +echo "done" +?> +--EXPECTF-- +bool(false) +bool(false) +bool(false) +bool(false) +done
\ No newline at end of file diff --git a/tests/output/ob_start_error_003.phpt b/tests/output/ob_start_error_003.phpt new file mode 100644 index 0000000000..d26e38b9da --- /dev/null +++ b/tests/output/ob_start_error_003.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test ob_start() with object supplied but no method. +--FILE-- +<?php +/* + * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) + * Function is implemented in main/output.c +*/ + +Class C { +} + +$c = new C; +var_dump(ob_start(array($c))); +echo "done" +?> +--EXPECTF-- +Fatal error: ob_start(): No method name given: use ob_start(array($object,'method')) to specify instance $object and the name of a method of class C to use as output handler in %s on line 11
\ No newline at end of file diff --git a/tests/output/ob_start_error_004.phpt b/tests/output/ob_start_error_004.phpt new file mode 100644 index 0000000000..2742476023 --- /dev/null +++ b/tests/output/ob_start_error_004.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test ob_start() with non existent callback method. +--FILE-- +<?php +/* + * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) + * Function is implemented in main/output.c +*/ + +Class C { +} + +$c = new C; +var_dump(ob_start(array($c, 'f'))); +echo "done" +?> +--EXPECTF-- +Fatal error: ob_start(): No method name given: use ob_start(array($object,'method')) to specify instance $object and the name of a method of class C to use as output handler in %s on line 11
\ No newline at end of file diff --git a/tests/output/ob_start_error_005.phpt b/tests/output/ob_start_error_005.phpt new file mode 100644 index 0000000000..3e503c6354 --- /dev/null +++ b/tests/output/ob_start_error_005.phpt @@ -0,0 +1,23 @@ +--TEST-- +ob_start(): ensure buffers can't be added from within callback. +--FILE-- +<?php + +/* + * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) + * Function is implemented in main/output.c +*/ + +function f($str) { + ob_start(); + echo "hello"; + ob_end_flush(); + return $str; +} + + +var_dump(ob_start('f')); +echo "done"; +?> +--EXPECTF-- +Fatal error: ob_start(): Cannot use output buffering in output buffering display handlers in %s on line 9
\ No newline at end of file |