fix segfault when initializing a request message with a body
[m6w6/ext-http] / phpunit / CookieTest.php
index a1a75db576a9b6c58ac39269f7c9f36c8b7d5c89..d569c75f88c02cc464824ce774d1644a7acc8104 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+ini_set("date.timezone", "Europe/Vienna");
+
 class CookieTest extends PHPUnit_Framework_TestCase {
     function testEmpty() {
         $c = new http\Cookie;
@@ -10,7 +12,8 @@ class CookieTest extends PHPUnit_Framework_TestCase {
             "flags" => 0,
             "expires" => -1,
             "path" => "",
-            "domain" => ""
+            "domain" => "",
+               "max-age" => -1,
         );
         $this->assertEquals($a, $c->toArray());
         $this->assertEquals($a, $o->toArray());
@@ -40,6 +43,7 @@ class CookieTest extends PHPUnit_Framework_TestCase {
         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());
@@ -59,6 +63,7 @@ class CookieTest extends PHPUnit_Framework_TestCase {
                     "expires" => -1,
                     "path" => "",
                     "domain" => "",
+                       "max-age" => -1,
                 ),
                 $c->toArray()
             );
@@ -80,12 +85,32 @@ class CookieTest extends PHPUnit_Framework_TestCase {
         $this->assertEquals(
             sprintf(
                 "this=expires; expires=%s; ", 
-                date_create("@$t")->format("D, d M Y H:i:s \\G\\M\\T")
+                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"));