diff options
author | Ant Phillips <ant@php.net> | 2008-04-29 08:57:09 +0000 |
---|---|---|
committer | Ant Phillips <ant@php.net> | 2008-04-29 08:57:09 +0000 |
commit | 52af9124b594e8c0e518a4857ff14aa82d240e7e (patch) | |
tree | 67785ccedb0c29b841ca73c24347407b57d39131 | |
parent | 2ecf4bb0a7c66bc882ff82d66d86ac6be5bffdf7 (diff) | |
download | php-git-52af9124b594e8c0e518a4857ff14aa82d240e7e.tar.gz |
More session tests to improve code coverage for untested extension code
-rw-r--r-- | ext/session/tests/session_decode_variation3.phpt | 62 | ||||
-rw-r--r-- | ext/session/tests/session_decode_variation4.phpt | 56 | ||||
-rw-r--r-- | ext/session/tests/session_encode_variation7.phpt | 35 | ||||
-rw-r--r-- | ext/session/tests/session_encode_variation8.phpt | 39 | ||||
-rw-r--r-- | ext/session/tests/session_id_error4.phpt | 33 | ||||
-rw-r--r-- | ext/session/tests/session_id_variation1.phpt | 46 | ||||
-rw-r--r-- | ext/session/tests/session_id_variation2.phpt | 57 | ||||
-rw-r--r-- | ext/session/tests/session_module_name_variation4.phpt | 67 | ||||
-rw-r--r-- | ext/session/tests/session_save_path_variation4.phpt | 59 | ||||
-rw-r--r-- | ext/session/tests/session_save_path_variation5.phpt | 56 | ||||
-rw-r--r-- | ext/session/tests/session_set_save_handler_variation4.phpt | 81 |
11 files changed, 591 insertions, 0 deletions
diff --git a/ext/session/tests/session_decode_variation3.phpt b/ext/session/tests/session_decode_variation3.phpt new file mode 100644 index 0000000000..b7e13cc40c --- /dev/null +++ b/ext/session/tests/session_decode_variation3.phpt @@ -0,0 +1,62 @@ +--TEST-- +Test session_decode() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.serialize_handler=blah +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_decode(void) + * Description : Decodes session data from a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_decode() : variation ***\n"; + +var_dump(session_start()); +var_dump($_SESSION); +$_SESSION["foo"] = 1234567890; +$_SESSION["bar"] = "Blah!"; +$_SESSION["guff"] = 123.456; +var_dump($_SESSION); +$encoded = "A2Zvb2k6MTIzNDU2Nzg5MDs="; +var_dump(session_decode(base64_decode($encoded))); +var_dump($_SESSION); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_decode() : variation *** + +Warning: session_start(): Unknown session.serialize_handler. Failed to decode session object. in %s on line %d +bool(true) +array(0) { +} +array(3) { + ["foo"]=> + int(1234567890) + ["bar"]=> + string(5) "Blah!" + ["guff"]=> + float(123.456) +} + +Warning: session_decode(): Unknown session.serialize_handler. Failed to decode session object. in %s on line %d +bool(true) +array(3) { + ["foo"]=> + int(1234567890) + ["bar"]=> + string(5) "Blah!" + ["guff"]=> + float(123.456) +} +bool(true) +Done + diff --git a/ext/session/tests/session_decode_variation4.phpt b/ext/session/tests/session_decode_variation4.phpt new file mode 100644 index 0000000000..81642754f0 --- /dev/null +++ b/ext/session/tests/session_decode_variation4.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test session_decode() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_decode(void) + * Description : Decodes session data from a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_decode() : variation ***\n"; + +var_dump(session_start()); +var_dump($_SESSION); +$_SESSION["foo"] = 1234567890; +$_SESSION["bar"] = "Blah!"; +$_SESSION["guff"] = 123.456; +var_dump($_SESSION); +$encoded = "A2Zvb2k6MTIzNDU2Nzg5MDs="; +var_dump(session_decode(base64_decode($encoded))); +var_dump($_SESSION); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_decode() : variation *** +bool(true) +array(0) { +} +array(3) { + ["foo"]=> + int(1234567890) + ["bar"]=> + string(5) "Blah!" + ["guff"]=> + float(123.456) +} +bool(true) +array(3) { + ["foo"]=> + int(1234567890) + ["bar"]=> + string(5) "Blah!" + ["guff"]=> + float(123.456) +} +bool(true) +Done + diff --git a/ext/session/tests/session_encode_variation7.phpt b/ext/session/tests/session_encode_variation7.phpt new file mode 100644 index 0000000000..b3de3c68a8 --- /dev/null +++ b/ext/session/tests/session_encode_variation7.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test session_encode() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.serialize_handler=php_binary +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_encode(void) + * Description : Encodes the current session data as a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_encode() : variation ***\n"; + +var_dump(session_start()); +$_SESSION["foo"] = 1234567890; +$encoded = session_encode(); +var_dump(base64_encode($encoded)); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_encode() : variation *** +bool(true) +string(24) "A2Zvb2k6MTIzNDU2Nzg5MDs=" +bool(true) +Done + diff --git a/ext/session/tests/session_encode_variation8.phpt b/ext/session/tests/session_encode_variation8.phpt new file mode 100644 index 0000000000..57c9e17bd4 --- /dev/null +++ b/ext/session/tests/session_encode_variation8.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test session_encode() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.serialize_handler=blah +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_encode(void) + * Description : Encodes the current session data as a string + * Source code : ext/session/session.c + */ + +echo "*** Testing session_encode() : variation ***\n"; + +var_dump(session_start()); +$_SESSION["foo"] = 1234567890; +$encoded = session_encode(); +var_dump(base64_encode($encoded)); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_encode() : variation *** + +Warning: session_start(): Unknown session.serialize_handler. Failed to decode session object. in %s on line %d +bool(true) + +Warning: session_encode(): Unknown session.serialize_handler. Failed to encode session object. in %s on line %d +string(0) "" +bool(true) +Done + diff --git a/ext/session/tests/session_id_error4.phpt b/ext/session/tests/session_id_error4.phpt new file mode 100644 index 0000000000..cc23578aed --- /dev/null +++ b/ext/session/tests/session_id_error4.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test session_id() function : error functionality +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_id([string $id]) + * Description : Get and/or set the current session id + * Source code : ext/session/session.c + */ + +echo "*** Testing session_id() : error functionality ***\n"; + +var_dump(ini_set("session.hash_function", -1)); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_id() : error functionality *** +string(1) "0" +string(0) "" + +Fatal error: session_start(): Invalid session hash function in %s on line %d + diff --git a/ext/session/tests/session_id_variation1.phpt b/ext/session/tests/session_id_variation1.phpt new file mode 100644 index 0000000000..8509f809cc --- /dev/null +++ b/ext/session/tests/session_id_variation1.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test session_id() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_id([string $id]) + * Description : Get and/or set the current session id + * Source code : ext/session/session.c + */ + +echo "*** Testing session_id() : variation ***\n"; + +var_dump(ini_set("session.hash_function", 0)); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_destroy()); + +var_dump(ini_set("session.hash_function", 1)); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_destroy()); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_id() : variation *** +string(1) "0" +string(0) "" +bool(true) +string(32) "%s" +bool(true) +string(1) "0" +string(0) "" +bool(true) +string(40) "%s" +bool(true) +Done + diff --git a/ext/session/tests/session_id_variation2.phpt b/ext/session/tests/session_id_variation2.phpt new file mode 100644 index 0000000000..568896b6ec --- /dev/null +++ b/ext/session/tests/session_id_variation2.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test session_id() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_id([string $id]) + * Description : Get and/or set the current session id + * Source code : ext/session/session.c + */ + +echo "*** Testing session_id() : variation ***\n"; + +$directory = dirname(__FILE__); +$filename = ($directory."/entropy.txt"); +var_dump(ini_set("session.entropy_file", $filename)); +var_dump(file_put_contents($filename, "Hello World!")); +var_dump(ini_set("session.entropy_length", filesize($filename))); + +var_dump(ini_set("session.hash_function", 0)); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_destroy()); + +var_dump(ini_set("session.hash_function", 1)); +var_dump(session_id()); +var_dump(session_start()); +var_dump(session_id()); +var_dump(session_destroy()); +var_dump(unlink($filename)); + +echo "Done"; +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_id() : variation *** +string(0) "" +int(12) +string(1) "0" +string(1) "0" +string(0) "" +bool(true) +string(32) "%s" +bool(true) +string(1) "0" +string(0) "" +bool(true) +string(40) "%s" +bool(true) +bool(true) +Done + diff --git a/ext/session/tests/session_module_name_variation4.phpt b/ext/session/tests/session_module_name_variation4.phpt new file mode 100644 index 0000000000..0748b3db2f --- /dev/null +++ b/ext/session/tests/session_module_name_variation4.phpt @@ -0,0 +1,67 @@ +--TEST-- +Test session_module_name() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.gc_probability=1 +session.gc_divisor=1 +session.gc_maxlifetime=0 +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_module_name([string $module]) + * Description : Get and/or set the current session module + * Source code : ext/session/session.c + */ + +echo "*** Testing session_module_name() : variation ***\n"; + +require_once "save_handler.inc"; +$path = dirname(__FILE__); +session_save_path($path); +session_module_name("files"); + +session_start(); +$_SESSION["Blah"] = "Hello World!"; +$_SESSION["Foo"] = FALSE; +$_SESSION["Guff"] = 1234567890; +var_dump($_SESSION); + +var_dump(session_write_close()); +session_start(); +var_dump($_SESSION); +var_dump(session_destroy()); +session_start(); +var_dump($_SESSION); +var_dump(session_destroy()); + +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_module_name() : variation *** + +array(3) { + ["Blah"]=> + string(12) "Hello World!" + ["Foo"]=> + bool(false) + ["Guff"]=> + int(1234567890) +} +NULL +array(3) { + ["Blah"]=> + string(12) "Hello World!" + ["Foo"]=> + bool(false) + ["Guff"]=> + int(1234567890) +} +bool(true) +array(0) { +} +bool(true) + diff --git a/ext/session/tests/session_save_path_variation4.phpt b/ext/session/tests/session_save_path_variation4.phpt new file mode 100644 index 0000000000..9c0580f64a --- /dev/null +++ b/ext/session/tests/session_save_path_variation4.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test session_save_path() function : variation +--SKIPIF-- +<?php include('skipif.inc'); +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Only for Windows"); +?> +--INI-- +open_basedir=. +session.save_handler=files +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_save_path([string $path]) + * Description : Get and/or set the current session save path + * Source code : ext/session/session.c + */ + +echo "*** Testing session_save_path() : variation ***\n"; +$directory = dirname(__FILE__); +$sessions = ($directory."/sessions"); + +// Delete the existing directory +if (file_exists($sessions) === TRUE) { + @rmdir($sessions); +} + +var_dump(mkdir($sessions)); +var_dump(chdir($sessions)); +ini_set("session.save_path", $directory); +var_dump(session_save_path()); +var_dump(session_start()); +var_dump(session_save_path()); +var_dump(session_destroy()); +var_dump(session_save_path()); +var_dump(rmdir($sessions)); + +echo "Done"; +ob_end_flush(); +?> +--CLEAN-- +$directory = dirname(__FILE__); +$sessions = ($directory."/sessions"); +var_dump(rmdir($sessions)); +--EXPECTF-- +*** Testing session_save_path() : variation *** +bool(true) +bool(true) + +Warning: ini_set(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d +string(0) "" + +Warning: session_start(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d + +Fatal error: session_start(): Failed to initialize storage module: files (path: ) in %s on line %d + diff --git a/ext/session/tests/session_save_path_variation5.phpt b/ext/session/tests/session_save_path_variation5.phpt new file mode 100644 index 0000000000..5d20397b66 --- /dev/null +++ b/ext/session/tests/session_save_path_variation5.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test session_save_path() function : variation +--SKIPIF-- +<?php include('skipif.inc'); +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip Not for Windows"); +?> +--INI-- +open_basedir=. +session.save_handler=files +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : string session_save_path([string $path]) + * Description : Get and/or set the current session save path + * Source code : ext/session/session.c + */ + +echo "*** Testing session_save_path() : variation ***\n"; + +$directory = dirname(__FILE__); +$sessions = ($directory."/sessions"); +var_dump(mkdir($sessions)); +var_dump(chdir($sessions)); +ini_set("session.save_path", $directory); +var_dump(session_save_path()); +var_dump(session_start()); +var_dump(session_save_path()); +var_dump(session_destroy()); +var_dump(session_save_path()); +var_dump(rmdir($sessions)); + +echo "Done"; +ob_end_flush(); +?> +--CLEAN-- +$directory = dirname(__FILE__); +$sessions = ($directory."/sessions"); +var_dump(rmdir($sessions)); +--EXPECTF-- +*** Testing session_save_path() : variation *** +bool(true) +bool(true) + +Warning: ini_set(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d +string(0) "" +bool(true) +string(0) "" +bool(true) +string(0) "" +bool(true) +Done + diff --git a/ext/session/tests/session_set_save_handler_variation4.phpt b/ext/session/tests/session_set_save_handler_variation4.phpt new file mode 100644 index 0000000000..053d453669 --- /dev/null +++ b/ext/session/tests/session_set_save_handler_variation4.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test session_set_save_handler() function : variation +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.gc_probability=1 +session.gc_divisor=1 +session.gc_maxlifetime=0 +--FILE-- +<?php + +ob_start(); + +/* + * Prototype : bool session_set_save_handler(callback $open, callback $close, callback $read, callback $write, callback $destroy, callback $gc) + * Description : Sets user-level session storage functions + * Source code : ext/session/session.c + */ + +echo "*** Testing session_set_save_handler() : variation ***\n"; + +function noisy_gc($maxlifetime) { + echo("GC [".$maxlifetime."]\n"); + gc($maxlifetime); +} + +require_once "save_handler.inc"; +$path = dirname(__FILE__); +session_save_path($path); +session_set_save_handler("open", "close", "read", "write", "destroy", "noisy_gc"); + +session_start(); +$_SESSION["Blah"] = "Hello World!"; +$_SESSION["Foo"] = FALSE; +$_SESSION["Guff"] = 1234567890; +var_dump($_SESSION); +$session_id = session_id(); +var_dump(session_write_close()); + +session_set_save_handler("open", "close", "read", "write", "destroy", "noisy_gc"); +session_id($session_id); +session_start(); +var_dump($_SESSION); +var_dump(session_destroy()); + +ob_end_flush(); +?> +--EXPECTF-- +*** Testing session_set_save_handler() : variation *** + +Open [%s,PHPSESSID] +Read [%s,%s] +GC [0] +array(3) { + ["Blah"]=> + string(12) "Hello World!" + ["Foo"]=> + bool(false) + ["Guff"]=> + int(1234567890) +} +Write [%s,%s,Blah|s:12:"Hello World!";Foo|b:0;Guff|i:1234567890;] +Close [%s,PHPSESSID] +NULL +Open [%s,PHPSESSID] +Read [%s,%s] +GC [0] +array(3) { + ["Blah"]=> + string(12) "Hello World!" + ["Foo"]=> + bool(false) + ["Guff"]=> + int(1234567890) +} +Destroy [%s,%s] + +Warning: unlink(%s): No such file or directory in %s on line %d +Close [%s,PHPSESSID] +bool(true) + |