diff options
author | Ant Phillips <ant@php.net> | 2008-04-22 16:04:31 +0000 |
---|---|---|
committer | Ant Phillips <ant@php.net> | 2008-04-22 16:04:31 +0000 |
commit | 57e0d2acec72065b33082d2aefccd96bbe365d47 (patch) | |
tree | 02de55727ee693477f762cc8911ce163ec3e6f6b | |
parent | 79b73d12183936f19ea88008e81adaa9e97b807e (diff) | |
download | php-git-57e0d2acec72065b33082d2aefccd96bbe365d47.tar.gz |
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.
-rw-r--r-- | ext/session/tests/022.phpt | 32 | ||||
-rw-r--r-- | ext/session/tests/023.phpt | 46 | ||||
-rw-r--r-- | ext/session/tests/024.phpt | 114 | ||||
-rw-r--r-- | ext/session/tests/025.phpt | 159 | ||||
-rw-r--r-- | ext/session/tests/026.phpt | 71 | ||||
-rw-r--r-- | ext/session/tests/027.phpt | 55 | ||||
-rw-r--r-- | ext/session/tests/028.phpt | 16 | ||||
-rw-r--r-- | ext/session/tests/029.phpt | 17 | ||||
-rw-r--r-- | ext/session/tests/030.phpt | 24 |
9 files changed, 534 insertions, 0 deletions
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-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- +<?php +error_reporting(E_ALL); + +class foo { + public $bar = "ok"; + + function method() { $this->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-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- +<?php +error_reporting(E_ALL); + +class foo { + public $bar = "ok"; + function method() { $this->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-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.name=PHPSESSID +session.serialize_handler=php +--FILE-- +<?php +error_reporting(E_ALL); + +class handler { + public $data = '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;}}'; + + function open($save_path, $session_name) + { + print "OPEN: $session_name\n"; + return true; + } + function close() + { + return true; + } + function read($key) + { + print "READ: $key\n"; + return $GLOBALS["hnd"]->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-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.name=PHPSESSID +session.serialize_handler=php +--FILE-- +<?php + +error_reporting(E_ALL); + +class handler { + public $data = '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;}}'; + + function open($save_path, $session_name) + { + print "OPEN: $session_name\n"; + return true; + } + function close() + { + print "CLOSE\n"; + return true; + } + function read($key) + { + print "READ: $key\n"; + return $GLOBALS["hnd"]->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-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- +<?php +error_reporting(E_ALL); + +session_id("abtest"); +session_start(); + +class a { + public $test = "hallo"; +} + +class b { + public $a; + function b(&$a) { + $this->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-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- +<?php +error_reporting(E_ALL); + +session_id("abtest"); + +### Phase 1 cleanup +session_start(); +session_destroy(); + +### Phase 2 $_SESSION["c"] does not contain any value +session_id("abtest"); +session_start(); +var_dump($_SESSION); +$_SESSION["name"] = "foo"; +var_dump($_SESSION); +session_write_close(); + +### Phase 3 $_SESSION["c"] is set +session_start(); +var_dump($_SESSION); +unset($_SESSION["name"]); +var_dump($_SESSION); +session_write_close(); + +### Phase 4 final + +session_start(); +var_dump($_SESSION); +session_destroy(); +?> +--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-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +--FILE-- +<?php +error_reporting(E_ALL); + +$session_array = explode(";", @session_encode()); +print "I live\n"; +?> +--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-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +--FILE-- +<?php +error_reporting(E_ALL); + +@session_decode("garbage data and no session started"); +@session_decode("userid|s:5:\"mazen\";chatRoom|s:1:\"1\";"); +print "I live\n"; +?> +--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-- +<?php include('skipif.inc'); ?> +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.serialize_handler=php +session.save_handler=files +--FILE-- +<?php +error_reporting(E_ALL); + +session_id("abtest"); +session_start(); +session_destroy(); +session_id("abtest2"); +session_start(); +session_destroy(); + +print "I live\n"; +?> +--EXPECT-- +I live |