File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / session / tests / session_decode_basic.phpt
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 23:48:01 2012 UTC (12 years, 4 months ago) by misho
Branches: php, MAIN
CVS tags: v5_4_3elwix, v5_4_29p0, v5_4_29, v5_4_20p0, v5_4_20, v5_4_17p0, v5_4_17, v5_3_10, HEAD
php

    1: --TEST--
    2: Test session_decode() function : basic functionality
    3: --SKIPIF--
    4: <?php include('skipif.inc'); ?>
    5: --FILE--
    6: <?php
    7: 
    8: ob_start();
    9: 
   10: /* 
   11:  * Prototype : string session_decode(void)
   12:  * Description : Decodes session data from a string
   13:  * Source code : ext/session/session.c 
   14:  */
   15: 
   16: echo "*** Testing session_decode() : basic functionality ***\n";
   17: 
   18: // Get an unset variable
   19: $unset_var = 10;
   20: unset($unset_var);
   21: 
   22: class classA
   23: {
   24:     public function __toString() {
   25:         return "Hello World!";
   26:     }
   27: }
   28: 
   29: $heredoc = <<<EOT
   30: Hello World!
   31: EOT;
   32: 
   33: $fp = fopen(__FILE__, "r");
   34: 
   35: // Unexpected values to be passed as arguments
   36: $inputs = array(
   37: 
   38:        // Integer data
   39: /*1*/  0,
   40:        1,
   41:        12345,
   42:        -2345,
   43: 
   44:        // Float data
   45: /*5*/  10.5,
   46:        -10.5,
   47:        12.3456789000e10,
   48:        12.3456789000E-10,
   49:        .5,
   50: 
   51:        // Null data
   52: /*10*/ NULL,
   53:        null,
   54: 
   55:        // Boolean data
   56: /*12*/ true,
   57:        false,
   58:        TRUE,
   59:        FALSE,
   60:        
   61:        // Empty strings
   62: /*16*/ "",
   63:        '',
   64: 
   65:        // Invalid string data
   66: /*18*/ "Nothing",
   67:        'Nothing',
   68:        $heredoc,
   69:        
   70:        // Object data
   71: /*21*/ new classA(),
   72: 
   73:        // Undefined data
   74: /*22*/ @$undefined_var,
   75: 
   76:        // Unset data
   77: /*23*/ @$unset_var,
   78: 
   79:        // Resource variable
   80: /*24*/ $fp
   81: );
   82: 
   83: var_dump(session_start());
   84: $iterator = 1;
   85: foreach($inputs as $input) {
   86:     echo "\n-- Iteration $iterator --\n";
   87:     $_SESSION["data"] = $input;
   88:     $encoded = session_encode();
   89:     var_dump(session_decode($encoded));
   90:     var_dump($_SESSION);
   91:     $iterator++;
   92: };
   93: 
   94: var_dump(session_destroy());
   95: fclose($fp);
   96: echo "Done";
   97: ob_end_flush();
   98: ?>
   99: --EXPECTF--
  100: *** Testing session_decode() : basic functionality ***
  101: bool(true)
  102: 
  103: -- Iteration 1 --
  104: bool(true)
  105: array(1) {
  106:   ["data"]=>
  107:   int(0)
  108: }
  109: 
  110: -- Iteration 2 --
  111: bool(true)
  112: array(1) {
  113:   ["data"]=>
  114:   int(1)
  115: }
  116: 
  117: -- Iteration 3 --
  118: bool(true)
  119: array(1) {
  120:   ["data"]=>
  121:   int(12345)
  122: }
  123: 
  124: -- Iteration 4 --
  125: bool(true)
  126: array(1) {
  127:   ["data"]=>
  128:   int(-2345)
  129: }
  130: 
  131: -- Iteration 5 --
  132: bool(true)
  133: array(1) {
  134:   ["data"]=>
  135:   float(10.5)
  136: }
  137: 
  138: -- Iteration 6 --
  139: bool(true)
  140: array(1) {
  141:   ["data"]=>
  142:   float(-10.5)
  143: }
  144: 
  145: -- Iteration 7 --
  146: bool(true)
  147: array(1) {
  148:   ["data"]=>
  149:   float(123456789000)
  150: }
  151: 
  152: -- Iteration 8 --
  153: bool(true)
  154: array(1) {
  155:   ["data"]=>
  156:   float(1.23456789E-9)
  157: }
  158: 
  159: -- Iteration 9 --
  160: bool(true)
  161: array(1) {
  162:   ["data"]=>
  163:   float(0.5)
  164: }
  165: 
  166: -- Iteration 10 --
  167: bool(true)
  168: array(1) {
  169:   ["data"]=>
  170:   NULL
  171: }
  172: 
  173: -- Iteration 11 --
  174: bool(true)
  175: array(1) {
  176:   ["data"]=>
  177:   NULL
  178: }
  179: 
  180: -- Iteration 12 --
  181: bool(true)
  182: array(1) {
  183:   ["data"]=>
  184:   bool(true)
  185: }
  186: 
  187: -- Iteration 13 --
  188: bool(true)
  189: array(1) {
  190:   ["data"]=>
  191:   bool(false)
  192: }
  193: 
  194: -- Iteration 14 --
  195: bool(true)
  196: array(1) {
  197:   ["data"]=>
  198:   bool(true)
  199: }
  200: 
  201: -- Iteration 15 --
  202: bool(true)
  203: array(1) {
  204:   ["data"]=>
  205:   bool(false)
  206: }
  207: 
  208: -- Iteration 16 --
  209: bool(true)
  210: array(1) {
  211:   ["data"]=>
  212:   string(0) ""
  213: }
  214: 
  215: -- Iteration 17 --
  216: bool(true)
  217: array(1) {
  218:   ["data"]=>
  219:   string(0) ""
  220: }
  221: 
  222: -- Iteration 18 --
  223: bool(true)
  224: array(1) {
  225:   ["data"]=>
  226:   string(7) "Nothing"
  227: }
  228: 
  229: -- Iteration 19 --
  230: bool(true)
  231: array(1) {
  232:   ["data"]=>
  233:   string(7) "Nothing"
  234: }
  235: 
  236: -- Iteration 20 --
  237: bool(true)
  238: array(1) {
  239:   ["data"]=>
  240:   string(12) "Hello World!"
  241: }
  242: 
  243: -- Iteration 21 --
  244: bool(true)
  245: array(1) {
  246:   ["data"]=>
  247:   object(classA)#2 (0) {
  248:   }
  249: }
  250: 
  251: -- Iteration 22 --
  252: bool(true)
  253: array(1) {
  254:   ["data"]=>
  255:   NULL
  256: }
  257: 
  258: -- Iteration 23 --
  259: bool(true)
  260: array(1) {
  261:   ["data"]=>
  262:   NULL
  263: }
  264: 
  265: -- Iteration 24 --
  266: bool(true)
  267: array(1) {
  268:   ["data"]=>
  269:   int(0)
  270: }
  271: bool(true)
  272: Done
  273: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>