unfold cookie tests and fix variable type inconsitency
authorMichael Wallner <mike@php.net>
Thu, 10 Jul 2014 13:56:33 +0000 (15:56 +0200)
committerMichael Wallner <mike@php.net>
Thu, 10 Jul 2014 13:56:33 +0000 (15:56 +0200)
16 files changed:
php_http_cookie.c
php_http_misc.c
php_http_misc.h
phpunit/CookieTest.php [deleted file]
tests/cookie001.phpt [new file with mode: 0644]
tests/cookie002.phpt [new file with mode: 0644]
tests/cookie003.phpt [new file with mode: 0644]
tests/cookie004.phpt [new file with mode: 0644]
tests/cookie005.phpt [new file with mode: 0644]
tests/cookie006.phpt [new file with mode: 0644]
tests/cookie007.phpt [new file with mode: 0644]
tests/cookie008.phpt [new file with mode: 0644]
tests/cookie009.phpt [new file with mode: 0644]
tests/cookie010.phpt [new file with mode: 0644]
tests/cookie011.phpt [new file with mode: 0644]
tests/cookie012.phpt [new file with mode: 0644]

index b565312fe984cc02c41fab7012ad12b091ba79b1..4bd8d80224606f7464a4470250da56d2eb1c07e1 100644 (file)
@@ -526,7 +526,7 @@ static PHP_METHOD(HttpCookie, setCookies)
 
        zend_hash_clean(&obj->list->cookies);
        if (cookies) {
-               array_copy(cookies, &obj->list->cookies);
+               array_copy_strings(cookies, &obj->list->cookies);
        }
 
        RETVAL_ZVAL(getThis(), 1, 0);
@@ -546,7 +546,7 @@ static PHP_METHOD(HttpCookie, addCookies)
 
        PHP_HTTP_COOKIE_OBJECT_INIT(obj);
 
-       array_join(cookies, &obj->list->cookies, 1, ARRAY_JOIN_STRONLY);
+       array_join(cookies, &obj->list->cookies, 1, ARRAY_JOIN_STRONLY|ARRAY_JOIN_STRINGIFY);
 
        RETVAL_ZVAL(getThis(), 1, 0);
 }
@@ -585,7 +585,7 @@ static PHP_METHOD(HttpCookie, setExtras)
 
        zend_hash_clean(&obj->list->extras);
        if (extras) {
-               array_copy(extras, &obj->list->extras);
+               array_copy_strings(extras, &obj->list->extras);
        }
 
        RETVAL_ZVAL(getThis(), 1, 0);
@@ -605,7 +605,7 @@ static PHP_METHOD(HttpCookie, addExtras)
 
        PHP_HTTP_COOKIE_OBJECT_INIT(obj);
 
-       array_join(extras, &obj->list->extras, 1, ARRAY_JOIN_STRONLY);
+       array_join(extras, &obj->list->extras, 1, ARRAY_JOIN_STRONLY|ARRAY_JOIN_STRINGIFY);
 
        RETVAL_ZVAL(getThis(), 1, 0);
 }
index 03b9560483c92198c74de9baec824262c3c05048..79c37893398bc09d860fff560de33083c21c79db 100644 (file)
@@ -166,12 +166,19 @@ unsigned php_http_array_list(HashTable *ht TSRMLS_DC, unsigned argc, ...)
        return argl;
 }
 
+void php_http_array_copy_strings(void *zpp)
+{
+       zval **zvpp = ((zval **) zpp);
+
+       *zvpp = php_http_zsep(1, IS_STRING, *zvpp);
+}
+
 int php_http_array_apply_append_func(void *pDest TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
 {
        int flags;
        char *key = NULL;
        HashTable *dst;
-       zval **data = NULL, **value = (zval **) pDest;
+       zval **data = NULL, *value = *((zval **) pDest);
 
        dst = va_arg(args, HashTable *);
        flags = va_arg(args, int);
@@ -184,16 +191,21 @@ int php_http_array_apply_append_func(void *pDest TSRMLS_DC, int num_args, va_lis
                        zend_hash_quick_find(dst, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void *) &data);
                }
 
-               Z_ADDREF_P(*value);
+               if (flags & ARRAY_JOIN_STRINGIFY) {
+                       value = php_http_zsep(1, IS_STRING, value);
+               } else {
+                       Z_ADDREF_P(value);
+               }
+
                if (data) {
                        if (Z_TYPE_PP(data) != IS_ARRAY) {
                                convert_to_array(*data);
                        }
-                       add_next_index_zval(*data, *value);
+                       add_next_index_zval(*data, value);
                } else if (key) {
-                       zend_symtable_update(dst, key, hash_key->nKeyLength, value, sizeof(zval *), NULL);
+                       zend_symtable_update(dst, key, hash_key->nKeyLength, &value, sizeof(zval *), NULL);
                } else {
-                       zend_hash_quick_add(dst, hash_key->arKey, hash_key->nKeyLength, hash_key->h, value, sizeof(zval *), NULL);
+                       zend_hash_quick_add(dst, hash_key->arKey, hash_key->nKeyLength, hash_key->h, &value, sizeof(zval *), NULL);
                }
 
                if (key) {
@@ -209,19 +221,24 @@ int php_http_array_apply_merge_func(void *pDest TSRMLS_DC, int num_args, va_list
        int flags;
        char *key = NULL;
        HashTable *dst;
-       zval **value = (zval **) pDest;
+       zval *value = *((zval **) pDest);
 
        dst = va_arg(args, HashTable *);
        flags = va_arg(args, int);
 
        if ((!(flags & ARRAY_JOIN_STRONLY)) || hash_key->nKeyLength) {
-               Z_ADDREF_P(*value);
+               if (flags & ARRAY_JOIN_STRINGIFY) {
+                       value = php_http_zsep(1, IS_STRING, value);
+               } else {
+                       Z_ADDREF_P(value);
+               }
+
                if ((flags & ARRAY_JOIN_PRETTIFY) && hash_key->nKeyLength) {
                        key = php_http_pretty_key(estrndup(hash_key->arKey, hash_key->nKeyLength - 1), hash_key->nKeyLength - 1, 1, 1);
-                       zend_hash_update(dst, key, hash_key->nKeyLength, (void *) value, sizeof(zval *), NULL);
+                       zend_hash_update(dst, key, hash_key->nKeyLength, (void *) &value, sizeof(zval *), NULL);
                        efree(key);
                } else {
-                       zend_hash_quick_update(dst, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void *) value, sizeof(zval *), NULL);
+                       zend_hash_quick_update(dst, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void *) &value, sizeof(zval *), NULL);
                }
        }
 
index fe08d6d1d5efd63b3b54c1adab9362d0d493a431..3759a1aa969f821c7334b92b1b93f6de3214d539 100644 (file)
@@ -291,10 +291,13 @@ static inline void php_http_array_hashkey_stringfree(php_http_array_hashkey_t *k
                        zend_hash_move_forward_ex(hash, &pos))
 
 #define array_copy(src, dst) zend_hash_copy(dst, src, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *))
-#define ARRAY_JOIN_STRONLY 1
-#define ARRAY_JOIN_PRETTIFY 2
+#define array_copy_strings(src, dst) zend_hash_copy(dst, src, php_http_array_copy_strings, NULL, sizeof(zval *))
+#define ARRAY_JOIN_STRONLY   0x01
+#define ARRAY_JOIN_PRETTIFY  0x02
+#define ARRAY_JOIN_STRINGIFY 0x04
 #define array_join(src, dst, append, flags) zend_hash_apply_with_arguments(src TSRMLS_CC, (append)?php_http_array_apply_append_func:php_http_array_apply_merge_func, 2, dst, (int)flags)
 
+void php_http_array_copy_strings(void *zpp);
 int php_http_array_apply_append_func(void *pDest TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key);
 int php_http_array_apply_merge_func(void *pDest TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key);
 
diff --git a/phpunit/CookieTest.php b/phpunit/CookieTest.php
deleted file mode 100644 (file)
index d569c75..0000000
+++ /dev/null
@@ -1,204 +0,0 @@
-<?php
-
-ini_set("date.timezone", "Europe/Vienna");
-
-class CookieTest extends PHPUnit_Framework_TestCase {
-    function testEmpty() {
-        $c = new http\Cookie;
-        $o = clone $c;
-        $a = array(
-            "cookies" => array(),
-            "extras" => array(),
-            "flags" => 0,
-            "expires" => -1,
-            "path" => "",
-            "domain" => "",
-               "max-age" => -1,
-        );
-        $this->assertEquals($a, $c->toArray());
-        $this->assertEquals($a, $o->toArray());
-    }
-
-    function testExpiresAsDate() {
-        $d = new DateTime;
-        $c = new http\Cookie(array("expires" => $d->format(DateTime::RFC1123)));
-        $this->assertEquals($d->format("U"), $c->getExpires());
-    }
-
-    function testNumeric() {
-        $c = new http\Cookie("1=%20; 2=%22; 3=%5D", 0, array(2));
-        $this->assertEquals("1=%20; 3=%5D; 2=%22; ", (string) $c);
-    }
-
-    function testRaw() {
-        $c = new http\Cookie("1=%20; 2=%22; e3=%5D", http\Cookie::PARSE_RAW, array(2));
-        $this->assertEquals("1=%2520; e3=%255D; 2=%2522; ", (string) $c);
-    }
-
-    function testSimple() {
-        $orig = new http\Cookie("key=value");
-        $copy = clone $orig;
-        $same = new http\Cookie($copy);
-        $even = new http\Cookie($same->toArray());
-        foreach (array($orig, $copy) as $c) {
-            $this->assertEquals("value", $c->getCookie("key"));
-            $this->assertEquals(-1, $c->getExpires());
-            $this->assertEquals(-1, $c->getMaxAge());
-            $this->assertEquals(0, $c->getFlags());
-            $this->assertEquals(null, $c->getPath());
-            $this->assertEquals(null, $c->getDomain());
-            $this->assertEquals(array(), $c->getExtras());
-            $this->assertEquals(array("key" => "value"), $c->getCookies());
-            $this->assertEquals("key=value; ", $c->toString());
-            $this->assertEquals(
-                array (
-                    "cookies" => 
-                        array (
-                            "key" => "value",
-                        ),
-                    "extras" => 
-                        array (
-                        ),
-                    "flags" => 0,
-                    "expires" => -1,
-                    "path" => "",
-                    "domain" => "",
-                       "max-age" => -1,
-                ),
-                $c->toArray()
-            );
-        }
-    }
-
-    function testExpires() {
-        $c = new http\Cookie("this=expires; expires=Tue, 24 Jan 2012 10:35:32 +0100");
-        $this->assertEquals("expires", $c->getCookie("this"));
-        $this->assertEquals(1327397732, $c->getExpires());
-        $o = clone $c;
-        $t = time();
-        $o->setExpires();
-        $this->assertEquals(-1, $o->getExpires());
-        $this->assertNotEquals(-1, $c->getExpires());
-        $o->setExpires($t);
-        $this->assertEquals($t, $o->getExpires());
-        $this->assertNotEquals($t, $c->getExpires());
-        $this->assertEquals(
-            sprintf(
-                "this=expires; expires=%s; ", 
-                date_create("@$t")
-                       ->setTimezone(new DateTimezone("UTC"))
-                       ->format("D, d M Y H:i:s \\G\\M\\T")
-            ), 
-            $o->toString()
-        );
-    }
-
-    function testMaxAge() {
-        $c = new http\Cookie("this=max-age; max-age=12345");
-        $this->assertEquals("max-age", $c->getCookie("this"));
-        $this->assertEquals(12345, $c->getMaxAge());
-        $o = clone $c;
-        $t = 54321;
-        $o->setMaxAge();
-        $this->assertEquals(-1, $o->getMaxAge());
-        $this->assertNotEquals(-1, $c->getMaxAge());
-        $o->setMaxAge($t);
-        $this->assertEquals($t, $o->getMaxAge());
-        $this->assertNotEquals($t, $c->getMaxAge());
-        $this->assertEquals(
-               "this=max-age; max-age=$t; ",
-            $o->toString()
-        );
-    }
-
-    function testPath() {
-        $c = new http\Cookie("this=has a path; path=/down; ");
-        $this->assertEquals("has a path", $c->getCookie("this"));
-        $this->assertEquals("this=has%20a%20path; path=/down; ", (string)$c);
-        $this->assertEquals("/down", $c->getPath());
-        $o = clone $c;
-        $p = "/up";
-        $o->setPath();
-        $this->assertEquals(null, $o->getPath());
-        $this->assertNotEquals(null, $c->getPath());
-        $o->setPath($p);
-        $this->assertEquals($p, $o->getPath());
-        $this->assertNotEquals($p, $c->getPath());
-        $this->assertEquals("this=has%20a%20path; path=$p; ", $o->toString());
-    }
-
-    function testDomain() {
-        $c = new http\Cookie("this=has a domain; domain=.example.com; ");
-        $this->assertEquals("has a domain", $c->getCookie("this"));
-        $this->assertEquals("this=has%20a%20domain; domain=.example.com; ", (string)$c);
-        $this->assertEquals(".example.com", $c->getDomain());
-        $o = clone $c;
-        $d = "sub.example.com";
-        $o->setDomain();
-        $this->assertEquals(null, $o->getDomain());
-        $this->assertNotEquals(null, $c->getDomain());
-        $o->setDomain($d);
-        $this->assertEquals($d, $o->getDomain());
-        $this->assertNotEquals($d, $c->getDomain());
-        $this->assertEquals("this=has%20a%20domain; domain=$d; ", $o->toString());
-    }
-
-    function testFlags() {
-        $c = new http\Cookie("icanhas=flags; secure; httpOnly");
-        $this->assertEquals(http\Cookie::SECURE, $c->getFlags() & http\Cookie::SECURE, "secure");
-        $this->assertEquals(http\Cookie::HTTPONLY, $c->getFlags() & http\Cookie::HTTPONLY, "httpOnly");
-        $c->setFlags($c->getFlags() ^ http\Cookie::SECURE);
-        $this->assertEquals(0, $c->getFlags() & http\Cookie::SECURE, "secure");
-        $this->assertEquals(http\Cookie::HTTPONLY, $c->getFlags() & http\Cookie::HTTPONLY, "httpOnly");
-        $c->setFlags($c->getFlags() ^ http\Cookie::HTTPONLY);
-        $this->assertEquals(0, $c->getFlags() & http\Cookie::SECURE, "secure");
-        $this->assertEquals(0, $c->getFlags() & http\Cookie::HTTPONLY, "httpOnly");
-        $this->assertEquals("icanhas=flags; ", $c->toString());
-        $c->setFlags(http\Cookie::SECURE|http\Cookie::HTTPONLY);
-        $this->assertEquals("icanhas=flags; secure; httpOnly; ", $c->toString());
-    }
-
-    function testExtras() {
-        $c = new http\Cookie("c1=v1; e0=1; e2=2; c2=v2", 0, array("e0", "e1", "e2"));
-        $this->assertEquals(array("c1"=>"v1", "c2"=>"v2"), $c->getCookies());
-        $this->assertEquals(array("e0"=>"1", "e2"=>"2"), $c->getExtras());
-        $c->addExtra("e1", 1);
-        $c->setExtra("e0");
-        $c->setExtra("e3", 123);
-        $this->assertEquals(123, $c->getExtra("e3"));
-        $c->setExtra("e3");
-        $this->assertEquals(array("e2"=>"2", "e1"=>1), $c->getExtras());
-        $this->assertEquals("c1=v1; c2=v2; e2=2; e1=1; ", $c->toString());
-        $c->addExtras(array("e3"=>3, "e4"=>4));
-        $this->assertEquals(array("e2"=>"2", "e1"=>1, "e3"=>3, "e4"=>4), $c->getExtras());
-        $this->assertEquals("c1=v1; c2=v2; e2=2; e1=1; e3=3; e4=4; ", $c->toString());
-        $c->setExtras(array("e"=>"x"));
-        $this->assertEquals(array("e"=>"x"), $c->getExtras());
-        $this->assertEquals("c1=v1; c2=v2; e=x; ", $c->toString());
-        $c->setExtras();
-        $this->assertEquals(array(), $c->getExtras());
-        $this->assertEquals("c1=v1; c2=v2; ", $c->toString());
-    }
-
-    function testCookies() {
-        $c = new http\Cookie("e0=1; c1=v1; e2=2; c2=v2", 0, array("c0", "c1", "c2"));
-        $this->assertEquals(array("c1"=>"v1", "c2"=>"v2"), $c->getExtras());
-        $this->assertEquals(array("e0"=>"1", "e2"=>"2"), $c->getCookies());
-        $c->addCookie("e1", 1);
-        $c->setCookie("e0");
-        $c->setCookie("e3", 123);
-        $this->assertEquals(123, $c->getCookie("e3"));
-        $c->setCookie("e3");
-        $this->assertEquals(array("e2"=>"2", "e1"=>1), $c->getCookies());
-        $this->assertEquals("e2=2; e1=1; c1=v1; c2=v2; ", $c->toString());
-        $c->addCookies(array("e3"=>3, "e4"=>4));
-        $this->assertEquals(array("e2"=>"2", "e1"=>1, "e3"=>3, "e4"=>4), $c->getCookies());
-        $this->assertEquals("e2=2; e1=1; e3=3; e4=4; c1=v1; c2=v2; ", $c->toString());
-        $c->setCookies(array("e"=>"x"));
-        $this->assertEquals(array("e"=>"x"), $c->getCookies());
-        $this->assertEquals("e=x; c1=v1; c2=v2; ", $c->toString());
-        $c->setCookies();
-        $this->assertEquals(array(), $c->getCookies());
-        $this->assertEquals("c1=v1; c2=v2; ", $c->toString());
-    }
-}
diff --git a/tests/cookie001.phpt b/tests/cookie001.phpt
new file mode 100644 (file)
index 0000000..3adf8d7
--- /dev/null
@@ -0,0 +1,31 @@
+--TEST--
+cookies empty state
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$c = new http\Cookie;
+$o = clone $c;
+$a = array(
+       "cookies" => array(),
+       "extras" => array(),
+       "flags" => 0,
+       "expires" => -1,
+       "path" => "",
+       "domain" => "",
+       "max-age" => -1,
+);
+var_dump($a == $c->toArray());
+var_dump($a == $o->toArray());
+
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+bool(true)
+DONE
diff --git a/tests/cookie002.phpt b/tests/cookie002.phpt
new file mode 100644 (file)
index 0000000..98c883b
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+cookies expire as date
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--INI--
+date.timezone=UTC
+--FILE--
+<?php
+echo "Test\n";
+
+$d = new DateTime;
+$c = new http\Cookie(array("expires" => $d->format(DateTime::RFC1123)));
+var_dump($d->format("U") == $c->getExpires());
+
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+DONE
diff --git a/tests/cookie003.phpt b/tests/cookie003.phpt
new file mode 100644 (file)
index 0000000..c546f52
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+cookies numeric keys
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$c = new http\Cookie("1=%20; 2=%22; 3=%5D", 0, array(2));
+var_dump("1=%20; 3=%5D; 2=%22; " === (string) $c);
+
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+DONE
diff --git a/tests/cookie004.phpt b/tests/cookie004.phpt
new file mode 100644 (file)
index 0000000..1c4ead4
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+cookies raw
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$c = new http\Cookie("1=%20; 2=%22; e3=%5D", http\Cookie::PARSE_RAW, array(2));
+var_dump("1=%2520; e3=%255D; 2=%2522; " === (string) $c);
+
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+DONE
diff --git a/tests/cookie005.phpt b/tests/cookie005.phpt
new file mode 100644 (file)
index 0000000..f210402
--- /dev/null
@@ -0,0 +1,75 @@
+--TEST--
+cookies simple data
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$orig = new http\Cookie("key=value");
+$copy = clone $orig;
+$same = new http\Cookie($copy);
+$even = new http\Cookie($same->toArray());
+foreach (array($orig, $copy) as $c) {
+       var_dump($c->getCookie("key"));
+       var_dump($c->getExpires());
+       var_dump($c->getMaxAge());
+       var_dump($c->getFlags());
+       var_dump($c->getPath());
+       var_dump($c->getDomain());
+       var_dump($c->getExtras());
+       var_dump($c->getCookies());
+       var_dump($c->toString());
+       var_dump(
+               array (
+                       "cookies" => 
+                               array (
+                                       "key" => "value",
+                               ),
+                       "extras" => 
+                               array (
+                               ),
+                       "flags" => 0,
+                       "expires" => -1,
+                       "path" => "",
+                       "domain" => "",
+                       "max-age" => -1,
+               ) == $c->toArray()
+       );
+}
+
+?>
+DONE
+--EXPECT--
+Test
+string(5) "value"
+int(-1)
+int(-1)
+int(0)
+NULL
+NULL
+array(0) {
+}
+array(1) {
+  ["key"]=>
+  string(5) "value"
+}
+string(11) "key=value; "
+bool(true)
+string(5) "value"
+int(-1)
+int(-1)
+int(0)
+NULL
+NULL
+array(0) {
+}
+array(1) {
+  ["key"]=>
+  string(5) "value"
+}
+string(11) "key=value; "
+bool(true)
+DONE
diff --git a/tests/cookie006.phpt b/tests/cookie006.phpt
new file mode 100644 (file)
index 0000000..d52f982
--- /dev/null
@@ -0,0 +1,47 @@
+--TEST--
+cookies expire
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--INI--
+date.timezone=UTC
+--FILE--
+<?php
+echo "Test\n";
+
+$c = new http\Cookie("this=expires; expires=Tue, 24 Jan 2012 10:35:32 +0100");
+var_dump($c->getCookie("this"));
+var_dump($c->getExpires());
+
+$o = clone $c;
+$t = time();
+
+$o->setExpires();
+var_dump(-1 === $o->getExpires());
+var_dump(-1 != $c->getExpires());
+
+$o->setExpires($t);
+var_dump($t === $o->getExpires());
+var_dump($t != $c->getExpires());
+var_dump(
+       sprintf(
+               "this=expires; expires=%s; ", 
+               date_create("@$t")
+                       ->setTimezone(new DateTimezone("UTC"))
+                       ->format("D, d M Y H:i:s \\G\\M\\T")
+       ) === $o->toString()
+);
+
+?>
+DONE
+--EXPECT--
+Test
+string(7) "expires"
+int(1327397732)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+DONE
diff --git a/tests/cookie007.phpt b/tests/cookie007.phpt
new file mode 100644 (file)
index 0000000..1a7a4c3
--- /dev/null
@@ -0,0 +1,37 @@
+--TEST--
+cookies max-age
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--INI--
+date.timezone=UTC
+--FILE--
+<?php
+echo "Test\n";
+
+$c = new http\Cookie("this=max-age; max-age=12345");
+var_dump($c->getCookie("this"));
+var_dump($c->getMaxAge());
+$o = clone $c;
+$t = 54321;
+$o->setMaxAge();
+var_dump($o->getMaxAge());
+var_dump(-1 != $c->getMaxAge());
+$o->setMaxAge($t);
+var_dump($o->getMaxAge());
+var_dump($t != $c->getMaxAge());
+var_dump($o->toString());
+
+?>
+DONE
+--EXPECT--
+Test
+string(7) "max-age"
+int(12345)
+int(-1)
+bool(true)
+int(54321)
+bool(true)
+string(29) "this=max-age; max-age=54321; "
+DONE
diff --git a/tests/cookie008.phpt b/tests/cookie008.phpt
new file mode 100644 (file)
index 0000000..5ec43dc
--- /dev/null
@@ -0,0 +1,37 @@
+--TEST--
+cookies path
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$c = new http\Cookie("this=has a path; path=/down; ");
+var_dump($c->getCookie("this"));
+var_dump((string)$c);
+var_dump($c->getPath());
+$o = clone $c;
+$p = "/up";
+$o->setPath();
+var_dump($o->getPath());
+var_dump($c->getPath());
+$o->setPath($p);
+var_dump($o->getPath());
+var_dump($c->getPath());
+var_dump($o->toString());
+
+?>
+DONE
+--EXPECT--
+Test
+string(10) "has a path"
+string(33) "this=has%20a%20path; path=/down; "
+string(5) "/down"
+NULL
+string(5) "/down"
+string(3) "/up"
+string(5) "/down"
+string(31) "this=has%20a%20path; path=/up; "
+DONE
diff --git a/tests/cookie009.phpt b/tests/cookie009.phpt
new file mode 100644 (file)
index 0000000..55aac94
--- /dev/null
@@ -0,0 +1,37 @@
+--TEST--
+cookies domain
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$c = new http\Cookie("this=has a domain; domain=.example.com; ");
+var_dump($c->getCookie("this"));
+var_dump((string)$c);
+var_dump($c->getDomain());
+$o = clone $c;
+$d = "sub.example.com";
+$o->setDomain();
+var_dump($o->getDomain());
+var_dump($c->getDomain());
+$o->setDomain($d);
+var_dump($o->getDomain());
+var_dump($c->getDomain());
+var_dump($o->toString());
+
+?>
+DONE
+--EXPECT--
+Test
+string(12) "has a domain"
+string(44) "this=has%20a%20domain; domain=.example.com; "
+string(12) ".example.com"
+NULL
+string(12) ".example.com"
+string(15) "sub.example.com"
+string(12) ".example.com"
+string(47) "this=has%20a%20domain; domain=sub.example.com; "
+DONE
diff --git a/tests/cookie010.phpt b/tests/cookie010.phpt
new file mode 100644 (file)
index 0000000..34d10f2
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+cookies flags
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$c = new http\Cookie("icanhas=flags; secure; httpOnly");
+var_dump(http\Cookie::SECURE === ($c->getFlags() & http\Cookie::SECURE));
+var_dump(http\Cookie::HTTPONLY === ($c->getFlags() & http\Cookie::HTTPONLY));
+$c->setFlags($c->getFlags() ^ http\Cookie::SECURE);
+var_dump(!($c->getFlags() & http\Cookie::SECURE));
+var_dump(http\Cookie::HTTPONLY === ($c->getFlags() & http\Cookie::HTTPONLY));
+$c->setFlags($c->getFlags() ^ http\Cookie::HTTPONLY);
+var_dump(!($c->getFlags() & http\Cookie::SECURE));
+var_dump(!($c->getFlags() & http\Cookie::HTTPONLY));
+var_dump("icanhas=flags; " === $c->toString());
+$c->setFlags(http\Cookie::SECURE|http\Cookie::HTTPONLY);
+var_dump("icanhas=flags; secure; httpOnly; " === $c->toString());
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+DONE
diff --git a/tests/cookie011.phpt b/tests/cookie011.phpt
new file mode 100644 (file)
index 0000000..03700ea
--- /dev/null
@@ -0,0 +1,45 @@
+--TEST--
+cookies extras
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+$c = new http\Cookie("c1=v1; e0=1; e2=2; c2=v2", 0, array("e0", "e1", "e2"));
+var_dump(array("c1"=>"v1", "c2"=>"v2") === $c->getCookies());
+var_dump(array("e0"=>"1", "e2"=>"2") === $c->getExtras());
+$c->addExtra("e1", 1);
+$c->setExtra("e0");
+$c->setExtra("e3", 123);
+var_dump("123" === $c->getExtra("e3"));
+$c->setExtra("e3");
+var_dump(array("e2"=>"2", "e1"=>"1") === $c->getExtras());
+var_dump("c1=v1; c2=v2; e2=2; e1=1; " === $c->toString());
+$c->addExtras(array("e3"=>3, "e4"=>4));
+var_dump(array("e2"=>"2", "e1"=>"1", "e3"=>"3", "e4"=>"4") === $c->getExtras());
+var_dump("c1=v1; c2=v2; e2=2; e1=1; e3=3; e4=4; " === $c->toString());
+$c->setExtras(array("e"=>"x"));
+var_dump(array("e"=>"x") === $c->getExtras());
+var_dump("c1=v1; c2=v2; e=x; " === $c->toString());
+$c->setExtras();
+var_dump(array() === $c->getExtras());
+var_dump("c1=v1; c2=v2; " === $c->toString());
+
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+DONE
diff --git a/tests/cookie012.phpt b/tests/cookie012.phpt
new file mode 100644 (file)
index 0000000..a3898c7
--- /dev/null
@@ -0,0 +1,45 @@
+--TEST--
+cookies cookies
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+$c = new http\Cookie("e0=1; c1=v1; e2=2; c2=v2", 0, array("c0", "c1", "c2"));
+var_dump(array("c1"=>"v1", "c2"=>"v2") === $c->getExtras());
+var_dump(array("e0"=>"1", "e2"=>"2") === $c->getCookies());
+$c->addCookie("e1", 1);
+$c->setCookie("e0");
+$c->setCookie("e3", 123);
+var_dump("123" === $c->getCookie("e3"));
+$c->setCookie("e3");
+var_dump(array("e2"=>"2", "e1"=>"1") === $c->getCookies());
+var_dump("e2=2; e1=1; c1=v1; c2=v2; " === $c->toString());
+$c->addCookies(array("e3"=>3, "e4"=>4));
+var_dump(array("e2"=>"2", "e1"=>"1", "e3"=>"3", "e4"=>"4") === $c->getCookies());
+var_dump("e2=2; e1=1; e3=3; e4=4; c1=v1; c2=v2; " === $c->toString());
+$c->setCookies(array("e"=>"x"));
+var_dump(array("e"=>"x") === $c->getCookies());
+var_dump("e=x; c1=v1; c2=v2; " === $c->toString());
+$c->setCookies();
+var_dump(array() === $c->getCookies());
+var_dump("c1=v1; c2=v2; " === $c->toString());
+
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+DONE