Skip to content

Commit dae1582

Browse files
author
Robin Fernandes
committed
Additional output buffering tests.
1 parent e3388ff commit dae1582

39 files changed

+1486
-0
lines changed

tests/output/flush_basic_001.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Test basic functionality of flush()
3+
--FILE--
4+
<?php
5+
/*
6+
* proto void flush(void)
7+
* Function is implemented in ext/standard/basic_functions.c.
8+
*/
9+
10+
// Verify return type
11+
var_dump(flush());
12+
13+
// Ensure user buffers are not flushed by flush()
14+
ob_start();
15+
echo "Inside a user buffer\n";
16+
flush();
17+
ob_end_clean();
18+
19+
echo "Outside of any user buffers\n";
20+
var_dump(flush());
21+
22+
?>
23+
--EXPECT--
24+
NULL
25+
Outside of any user buffers
26+
NULL

tests/output/flush_error_001.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Test wrong number of arguments for flush() (no impact)
3+
--FILE--
4+
<?php
5+
/*
6+
* proto void flush(void)
7+
* Function is implemented in ext/standard/basic_functions.c.
8+
*/
9+
10+
$extra_arg = 1;
11+
echo "\nToo many arguments\n";
12+
var_dump(flush($extra_arg));
13+
?>
14+
--EXPECTF--
15+
Too many arguments
16+
NULL

tests/output/ob_clean_basic_001.phpt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
Test ob_clean() function : basic functionality
3+
--FILE--
4+
<?php
5+
/* Prototype : proto bool ob_clean(void)
6+
* Description: Clean (delete) the current output buffer
7+
* Source code: main/output.c
8+
* Alias to functions:
9+
*/
10+
11+
echo "*** Testing ob_clean() : basic functionality ***\n";
12+
13+
// Zero arguments
14+
echo "\n-- Testing ob_clean() function with Zero arguments --\n";
15+
var_dump( ob_clean() );
16+
17+
ob_start();
18+
echo "You should never see this.";
19+
var_dump(ob_clean());
20+
21+
echo "Ensure the buffer is still active after the clean.";
22+
$out = ob_get_clean();
23+
var_dump($out);
24+
25+
echo "Done";
26+
?>
27+
--EXPECTF--
28+
*** Testing ob_clean() : basic functionality ***
29+
30+
-- Testing ob_clean() function with Zero arguments --
31+
32+
Notice: ob_clean(): failed to delete buffer. No buffer to delete. in %s on line 12
33+
bool(false)
34+
string(61) "bool(true)
35+
Ensure the buffer is still active after the clean."
36+
Done

tests/output/ob_clean_error_001.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Test ob_clean() function : error conditions
3+
--FILE--
4+
<?php
5+
/* Prototype : proto bool ob_clean(void)
6+
* Description: Clean (delete) the current output buffer
7+
* Source code: main/output.c
8+
* Alias to functions:
9+
*/
10+
11+
echo "*** Testing ob_clean() : error conditions ***\n";
12+
13+
// One argument
14+
echo "\n-- Testing ob_clean() function with one argument --\n";
15+
$extra_arg = 10;;
16+
var_dump( ob_clean($extra_arg) );
17+
18+
echo "Done";
19+
?>
20+
--EXPECTF--
21+
*** Testing ob_clean() : error conditions ***
22+
23+
-- Testing ob_clean() function with one argument --
24+
25+
Warning: Wrong parameter count for ob_clean() in %s on line 13
26+
NULL
27+
Done
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Test return type and value, as well as basic behaviour, for ob_end_clean()
3+
--FILE--
4+
<?php
5+
/*
6+
* proto bool ob_end_clean(void)
7+
* Function is implemented in main/output.c
8+
*/
9+
10+
var_dump(ob_end_clean());
11+
12+
ob_start();
13+
var_dump(ob_end_clean());
14+
15+
ob_start();
16+
echo "Hello";
17+
var_dump(ob_end_clean());
18+
19+
var_dump(ob_end_clean());
20+
21+
?>
22+
--EXPECTF--
23+
24+
Notice: ob_end_clean(): failed to delete buffer. No buffer to delete. in %s on line 7
25+
bool(false)
26+
bool(true)
27+
bool(true)
28+
29+
Notice: ob_end_clean(): failed to delete buffer. No buffer to delete. in %s on line 16
30+
bool(false)
31+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Test wrong number of arguments for ob_end_clean()
3+
--FILE--
4+
<?php
5+
/*
6+
* proto bool ob_end_clean(void)
7+
* Function is implemented in main/output.c
8+
*/
9+
10+
$extra_arg = 1;
11+
12+
echo "\nToo many arguments\n";
13+
var_dump(ob_end_clean($extra_arg));
14+
15+
16+
?>
17+
--EXPECTF--
18+
19+
Too many arguments
20+
21+
Warning: Wrong parameter count for ob_end_clean() in %s on line 10
22+
NULL
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
Test ob_end_flush() function : basic functionality
3+
--FILE--
4+
<?php
5+
/* Prototype : proto bool ob_end_flush(void)
6+
* Description: Flush (send) the output buffer, and delete current output buffer
7+
* Source code: main/output.c
8+
* Alias to functions:
9+
*/
10+
11+
echo "*** Testing ob_end_flush() : basic functionality ***\n";
12+
13+
// Zero arguments
14+
echo "\n-- Testing ob_end_flush() function with Zero arguments --\n";
15+
var_dump(ob_end_flush());
16+
17+
ob_start();
18+
var_dump(ob_end_flush());
19+
20+
ob_start();
21+
echo "Hello\n";
22+
var_dump(ob_end_flush());
23+
24+
var_dump(ob_end_flush());
25+
26+
echo "Done";
27+
?>
28+
--EXPECTF--
29+
*** Testing ob_end_flush() : basic functionality ***
30+
31+
-- Testing ob_end_flush() function with Zero arguments --
32+
33+
Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush. in %s on line 12
34+
bool(false)
35+
bool(true)
36+
Hello
37+
bool(true)
38+
39+
Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush. in %s on line 21
40+
bool(false)
41+
Done
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Test ob_end_flush() function : error conditions
3+
--FILE--
4+
<?php
5+
/* Prototype : proto bool ob_end_flush(void)
6+
* Description: Flush (send) the output buffer, and delete current output buffer
7+
* Source code: main/output.c
8+
* Alias to functions:
9+
*/
10+
11+
echo "*** Testing ob_end_flush() : error conditions ***\n";
12+
13+
// One argument
14+
echo "\n-- Testing ob_end_flush() function with one argument --\n";
15+
$extra_arg = 10;;
16+
var_dump( ob_end_flush($extra_arg) );
17+
18+
echo "Done";
19+
?>
20+
--EXPECTF--
21+
*** Testing ob_end_flush() : error conditions ***
22+
23+
-- Testing ob_end_flush() function with one argument --
24+
25+
Warning: Wrong parameter count for ob_end_flush() in %s on line 13
26+
NULL
27+
Done

tests/output/ob_flush_basic_001.phpt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
Test ob_flush() function : basic functionality
3+
--FILE--
4+
<?php
5+
/* Prototype : proto bool ob_flush(void)
6+
* Description: Flush (send) contents of the output buffer. The last buffer content is sent to next buffer
7+
* Source code: main/output.c
8+
* Alias to functions:
9+
*/
10+
11+
echo "*** Testing ob_flush() : basic functionality ***\n";
12+
13+
// Zero arguments
14+
echo "\n-- Testing ob_flush() function with Zero arguments --\n";
15+
var_dump(ob_flush());
16+
17+
ob_start();
18+
echo "This should get flushed.\n";
19+
var_dump(ob_flush());
20+
21+
echo "Ensure the buffer is still active after the flush.\n";
22+
$out = ob_flush();
23+
var_dump($out);
24+
25+
echo "Done";
26+
27+
?>
28+
--EXPECTF--
29+
*** Testing ob_flush() : basic functionality ***
30+
31+
-- Testing ob_flush() function with Zero arguments --
32+
33+
Notice: ob_flush(): failed to flush buffer. No buffer to flush. in %s on line 12
34+
bool(false)
35+
This should get flushed.
36+
bool(true)
37+
Ensure the buffer is still active after the flush.
38+
bool(true)
39+
Done

tests/output/ob_flush_error_001.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Test ob_flush() function : error conditions
3+
--FILE--
4+
<?php
5+
/* Prototype : proto bool ob_flush(void)
6+
* Description: Flush (send) contents of the output buffer. The last buffer content is sent to next buffer
7+
* Source code: main/output.c
8+
* Alias to functions:
9+
*/
10+
11+
echo "*** Testing ob_flush() : error conditions ***\n";
12+
13+
// One argument
14+
echo "\n-- Testing ob_flush() function with one argument --\n";
15+
$extra_arg = 10;;
16+
var_dump( ob_flush($extra_arg) );
17+
18+
echo "Done";
19+
?>
20+
--EXPECTF--
21+
*** Testing ob_flush() : error conditions ***
22+
23+
-- Testing ob_flush() function with one argument --
24+
25+
Warning: Wrong parameter count for ob_flush() in %s on line 13
26+
NULL
27+
Done
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Test return type and value, as well as basic behaviour, of ob_get_clean()
3+
--FILE--
4+
<?php
5+
/*
6+
* proto bool ob_get_clean(void)
7+
* Function is implemented in main/output.c
8+
*/
9+
10+
var_dump(ob_get_clean());
11+
12+
ob_start();
13+
echo "Hello World";
14+
var_dump(ob_get_clean());
15+
?>
16+
--EXPECTF--
17+
bool(false)
18+
string(11) "Hello World"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Test basic behaviour of ob_get_clean()
3+
--FILE--
4+
<?php
5+
/*
6+
* proto bool ob_get_clean(void)
7+
* Function is implemented in main/output.c
8+
*/
9+
10+
ob_start();
11+
12+
echo "Hello World";
13+
14+
$out = ob_get_clean();
15+
$out = strtolower($out);
16+
17+
var_dump($out);
18+
?>
19+
--EXPECT--
20+
string(11) "hello world"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Test wrong number of arguments for ob_get_clean()
3+
--FILE--
4+
<?php
5+
/*
6+
* proto bool ob_get_clean(void)
7+
* Function is implemented in main/output.c
8+
*/
9+
10+
$extra_arg = 1;
11+
12+
echo "\nToo many arguments\n";
13+
var_dump(ob_get_clean($extra_arg));
14+
15+
16+
?>
17+
--EXPECTF--
18+
19+
Too many arguments
20+
21+
Warning: Wrong parameter count for ob_get_clean() in %s on line 10
22+
NULL

0 commit comments

Comments
 (0)