]> granicus.if.org Git - php/commitdiff
These tests were backported from the PHP 6.0 branch, which in turn were ported from...
authorAnt Phillips <ant@php.net>
Tue, 22 Apr 2008 15:58:34 +0000 (15:58 +0000)
committerAnt Phillips <ant@php.net>
Tue, 22 Apr 2008 15:58:34 +0000 (15:58 +0000)
ext/session/tests/022.phpt [new file with mode: 0644]
ext/session/tests/023.phpt [new file with mode: 0644]
ext/session/tests/024.phpt [new file with mode: 0644]
ext/session/tests/025.phpt [new file with mode: 0644]
ext/session/tests/026.phpt [new file with mode: 0644]
ext/session/tests/027.phpt [new file with mode: 0644]
ext/session/tests/028.phpt [new file with mode: 0644]
ext/session/tests/029.phpt [new file with mode: 0644]
ext/session/tests/030.phpt [new file with mode: 0644]

diff --git a/ext/session/tests/022.phpt b/ext/session/tests/022.phpt
new file mode 100644 (file)
index 0000000..5923bbe
--- /dev/null
@@ -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 (file)
index 0000000..42b1e5b
--- /dev/null
@@ -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 (file)
index 0000000..2ad2606
--- /dev/null
@@ -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 (file)
index 0000000..4fd095f
--- /dev/null
@@ -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 (file)
index 0000000..06c135d
--- /dev/null
@@ -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 (file)
index 0000000..600a992
--- /dev/null
@@ -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 (file)
index 0000000..79638d2
--- /dev/null
@@ -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 (file)
index 0000000..ff1adba
--- /dev/null
@@ -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 (file)
index 0000000..8d0f284
--- /dev/null
@@ -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