add max-age to http\Cookie
[m6w6/ext-http] / phpunit / CookieTest.php
index a1a75db576a9b6c58ac39269f7c9f36c8b7d5c89..affe798dbb647c7bf130a02ffb472635e4ff065e 100644 (file)
@@ -10,7 +10,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 +41,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 +61,7 @@ class CookieTest extends PHPUnit_Framework_TestCase {
                     "expires" => -1,
                     "path" => "",
                     "domain" => "",
+                       "max-age" => -1,
                 ),
                 $c->toArray()
             );
@@ -86,6 +89,24 @@ class CookieTest extends PHPUnit_Framework_TestCase {
         );
     }
 
+    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"));