From: Ant Phillips Date: Tue, 22 Apr 2008 15:58:34 +0000 (+0000) Subject: These tests were backported from the PHP 6.0 branch, which in turn were ported from... X-Git-Tag: php-5.2.6~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1f4fa0ba1f5eb04dc52773a131e65cae579a4e49;p=php These tests were backported from the PHP 6.0 branch, which in turn were ported from this branch and then updated to remove any dependencies on register_globals. With register_globals removed they are useful tests to run against the 5.X branches. --- diff --git a/ext/session/tests/022.phpt b/ext/session/tests/022.phpt new file mode 100644 index 0000000000..5923bbe0bf --- /dev/null +++ b/ext/session/tests/022.phpt @@ -0,0 +1,32 @@ +--TEST-- +session object serialization +--SKIPIF-- + +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- +yes = "done"; } +} + +$baz = new foo; +$baz->method(); + +$arr[3] = new foo; +$arr[3]->method(); +session_start(); +$_SESSION["baz"] = $baz; +$_SESSION["arr"] = $arr; +var_dump(session_encode()); +session_destroy(); +?> +--EXPECT-- +string(126) "baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";s:4:"done";}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";s:4:"done";}}" diff --git a/ext/session/tests/023.phpt b/ext/session/tests/023.phpt new file mode 100644 index 0000000000..42b1e5b1be --- /dev/null +++ b/ext/session/tests/023.phpt @@ -0,0 +1,46 @@ +--TEST-- +session object deserialization +--SKIPIF-- + +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- +yes++; } +} + +session_id("abtest"); +session_start(); +session_decode('baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}}'); +$baz = $_SESSION['baz']; +$arr = $_SESSION['arr']; + +$baz->method(); +$arr[3]->method(); + +var_dump($baz); +var_dump($arr); +session_destroy(); +--EXPECT-- +object(foo)#1 (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) +} +array(1) { + [3]=> + object(foo)#2 (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) + } +} diff --git a/ext/session/tests/024.phpt b/ext/session/tests/024.phpt new file mode 100644 index 0000000000..2ad26067a5 --- /dev/null +++ b/ext/session/tests/024.phpt @@ -0,0 +1,114 @@ +--TEST-- +session_set_save_handler test +--SKIPIF-- + +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.name=PHPSESSID +session.serialize_handler=php +--FILE-- +data; + } + + function write($key, $val) + { + print "WRITE: $key, $val\n"; + $GLOBALS["hnd"]->data = $val; + return true; + } + + function destroy($key) + { + print "DESTROY: $key\n"; + return true; + } + + function gc() { return true; } +} + +$hnd = new handler; + +class foo { + public $bar = "ok"; + function method() { $this->yes++; } +} + +session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc")); + +session_id("abtest"); +session_start(); + +$baz = $_SESSION['baz']; +$arr = $_SESSION['arr']; +$baz->method(); +$arr[3]->method(); + +var_dump($baz); +var_dump($arr); + +session_write_close(); + +session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc")); +session_start(); + +var_dump($baz); +var_dump($arr); + +session_destroy(); +?> +--EXPECTF-- +OPEN: PHPSESSID +READ: abtest +object(foo)#%d (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) +} +array(1) { + [3]=> + object(foo)#%d (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) + } +} +WRITE: abtest, baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:2;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:2;}} +OPEN: PHPSESSID +READ: abtest +object(foo)#%d (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) +} +array(1) { + [3]=> + object(foo)#%d (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) + } +} +DESTROY: abtest diff --git a/ext/session/tests/025.phpt b/ext/session/tests/025.phpt new file mode 100644 index 0000000000..4fd095f817 --- /dev/null +++ b/ext/session/tests/025.phpt @@ -0,0 +1,159 @@ +--TEST-- +custom save handler, multiple session_start()s, complex data structure test. +--SKIPIF-- + +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.name=PHPSESSID +session.serialize_handler=php +--FILE-- +data; + } + + function write($key, $val) + { + print "WRITE: $key, $val\n"; + $GLOBALS["hnd"]->data = $val; + return true; + } + + function destroy($key) + { + print "DESTROY: $key\n"; + return true; + } + + function gc() { return true; } + + function __construct() + { + if (ini_get("unicode.semantics")) { + $this->data = str_replace('s:', 'U:', $this->data); + } + } +} + +$hnd = new handler; + +class foo { + public $bar = "ok"; + function method() { $this->yes++; } +} + +session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc")); + +session_id("abtest"); +session_start(); +$baz = $_SESSION['baz']; +$arr = $_SESSION['arr']; +$baz->method(); +$arr[3]->method(); + +var_dump($baz); +var_dump($arr); + +session_write_close(); + +session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc")); +session_start(); +$baz = $_SESSION['baz']; +$arr = $_SESSION['arr']; + + +$baz->method(); +$arr[3]->method(); + + +$c = 123; +$_SESSION['c'] = $c; +var_dump($baz); var_dump($arr); var_dump($c); + +session_write_close(); + +session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc")); +session_start(); +var_dump($baz); var_dump($arr); var_dump($c); + +session_destroy(); +?> +--EXPECTF-- +OPEN: PHPSESSID +READ: abtest +object(foo)#%d (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) +} +array(1) { + [3]=> + object(foo)#%d (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(2) + } +} +WRITE: abtest, baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:2;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:2;}} +CLOSE +OPEN: PHPSESSID +READ: abtest +object(foo)#%d (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(3) +} +array(1) { + [3]=> + object(foo)#%d (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(3) + } +} +int(123) +WRITE: abtest, baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:3;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:3;}}c|i:123; +CLOSE +OPEN: PHPSESSID +READ: abtest +object(foo)#%d (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(3) +} +array(1) { + [3]=> + object(foo)#%d (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + int(3) + } +} +int(123) +DESTROY: abtest +CLOSE diff --git a/ext/session/tests/026.phpt b/ext/session/tests/026.phpt new file mode 100644 index 0000000000..06c135d046 --- /dev/null +++ b/ext/session/tests/026.phpt @@ -0,0 +1,71 @@ +--TEST-- +correct instantiation of references between variables in sessions +--SKIPIF-- + +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- +a = &$a; + } +} + +$a = new a(); +$b = new b($a); + +echo "original values:\n"; +var_dump($a,$b); + +$_SESSION['a'] = $a; +$_SESSION['b'] = $b; + +session_write_close(); +unset($_SESSION['a']); +unset($_SESSION['b']); + +session_start(); +$a = $_SESSION['a']; +$b = $_SESSION['b']; +echo "values after session:\n"; +var_dump($a,$b); +?> +--EXPECTF-- +original values: +object(a)#%d (1) { + ["test"]=> + string(5) "hallo" +} +object(b)#%d (1) { + ["a"]=> + &object(a)#%d (1) { + ["test"]=> + string(5) "hallo" + } +} +values after session: +object(a)#%d (1) { + ["test"]=> + string(5) "hallo" +} +object(b)#%d (1) { + ["a"]=> + &object(a)#%d (1) { + ["test"]=> + string(5) "hallo" + } +} diff --git a/ext/session/tests/027.phpt b/ext/session/tests/027.phpt new file mode 100644 index 0000000000..600a992f7f --- /dev/null +++ b/ext/session/tests/027.phpt @@ -0,0 +1,55 @@ +--TEST-- +unset($_SESSION["name"]); should work +--SKIPIF-- + +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- + +--EXPECT-- +array(0) { +} +array(1) { + ["name"]=> + string(3) "foo" +} +array(1) { + ["name"]=> + string(3) "foo" +} +array(0) { +} +array(0) { +} diff --git a/ext/session/tests/028.phpt b/ext/session/tests/028.phpt new file mode 100644 index 0000000000..79638d283d --- /dev/null +++ b/ext/session/tests/028.phpt @@ -0,0 +1,16 @@ +--TEST-- +$session_array = explode(";", session_encode()); should not segfault +--SKIPIF-- + +--INI-- +session.use_cookies=0 +session.cache_limiter= +--FILE-- + +--EXPECT-- +I live diff --git a/ext/session/tests/029.phpt b/ext/session/tests/029.phpt new file mode 100644 index 0000000000..ff1adbaec8 --- /dev/null +++ b/ext/session/tests/029.phpt @@ -0,0 +1,17 @@ +--TEST-- +session_decode(); should not segfault +--SKIPIF-- + +--INI-- +session.use_cookies=0 +session.cache_limiter= +--FILE-- + +--EXPECT-- +I live diff --git a/ext/session/tests/030.phpt b/ext/session/tests/030.phpt new file mode 100644 index 0000000000..8d0f284b17 --- /dev/null +++ b/ext/session/tests/030.phpt @@ -0,0 +1,24 @@ +--TEST-- +redefining SID should not cause warnings +--SKIPIF-- + +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- + +--EXPECT-- +I live