function testAging() { $cookie = new SimpleCookie("name", "value", "/path", 200); $cookie->agePrematurely(199); $this->assertFalse($cookie->isExpired(0)); $cookie->agePrematurely(2); $this->assertTrue($cookie->isExpired(0)); }
function testHostFilter() { $jar = new CookieJar(); $cookie = new SimpleCookie("a", "A"); $cookie->setHost("my-host.com"); $jar->setCookie($cookie); $cookie = new SimpleCookie("b", "B"); $cookie->setHost("another-host.com"); $jar->setCookie($cookie); $cookie = new SimpleCookie("c", "C"); $jar->setCookie($cookie); $cookies = $jar->getValidCookies("my-host.com"); $this->assertEqual(count($cookies), 2); $this->assertEqual($cookies[0]->getValue(), "A"); $this->assertEqual($cookies[1]->getValue(), "C"); $this->assertEqual(count($jar->getValidCookies("another-host.com")), 2); $this->assertEqual(count($jar->getValidCookies("www.another-host.com")), 2); $this->assertEqual(count($jar->getValidCookies("new-host.org")), 1); $this->assertEqual(count($jar->getValidCookies()), 3); }
function testHostFilter() { $jar = new SimpleCookieJar(); $cookie = new SimpleCookie('a', 'A'); $cookie->setHost('my-host.com'); $jar->setCookie($cookie); $cookie = new SimpleCookie('b', 'B'); $cookie->setHost('another-host.com'); $jar->setCookie($cookie); $cookie = new SimpleCookie('c', 'C'); $jar->setCookie($cookie); $cookies = $jar->getValidCookies('my-host.com'); $this->assertEqual(count($cookies), 2); $this->assertEqual($cookies[0]->getValue(), 'A'); $this->assertEqual($cookies[1]->getValue(), 'C'); $this->assertEqual(count($jar->getValidCookies('another-host.com')), 2); $this->assertEqual(count($jar->getValidCookies('www.another-host.com')), 2); $this->assertEqual(count($jar->getValidCookies('new-host.org')), 1); $this->assertEqual(count($jar->getValidCookies()), 3); }
/** * Sets an additional cookie. If a cookie has * the same name and path it is replaced. * @param string $name Cookie key. * @param string $value Value of cookie. * @param string $host Host upon which the cookie is valid. * @param string $path Cookie path if not host wide. * @param string $expiry Expiry date. * @access public */ function setCookie($name, $value, $host = false, $path = '/', $expiry = false) { $cookie = new SimpleCookie($name, $value, $path, $expiry); if ($host) { $cookie->setHost($host); } $this->_cookie_jar->setCookie($cookie); }
/** * Sets an additional cookie. If a cookie has * the same name and path it is replaced. * @param string $name Cookie key. * @param string $value Value of cookie. * @param string $host Host upon which the cookie is valid. * @param string $path Cookie path if not host wide. * @param string $expiry Expiry date. * @access public */ function setCookie($name, $value, $host = false, $path = '/', $expiry = false) { $cookie = new SimpleCookie($name, $value, $path, $expiry); if ($host) { $cookie->setHost($host); } $this->cookies[$this->findFirstMatch($cookie)] = $cookie; }
public function testAging() { $cookie = new SimpleCookie('name', 'value', '/path', 200); $cookie->agePrematurely(199); $this->assertFalse($cookie->isExpired(0)); $cookie->agePrematurely(2); $this->assertTrue($cookie->isExpired(0)); }
/** * Sets an additional cookie. If a cookie has * the same name and path it is replaced. * @param string $name Cookie key. * @param string $value Value of cookie. * @param string $host Host upon which the cookie is valid. * @param string $path Cookie path if not host wide. * @param string $expiry Expiry date. * @access public */ function setCookie($name, $value, $host = false, $path = '/', $expiry = false) { $cookie = new SimpleCookie($name, $value, $path, $expiry); if ($host) { $cookie->setHost($host); } $this->cookies[$this->findFirstMatch($cookie)] = $cookie; if ($cookie->isExpired(time())) { unset($this->cookies[$this->findFirstMatch($cookie)]); // Rebuild cookies array without the one we just removed. $new = array(); foreach ($this->cookies as $c) { $new[] = $c; } $this->cookies = $new; } }
function testDateExpiry() { $cookie = new SimpleCookie("name", "value", "/path", "Mon, 18 Nov 2002 15:50:29 GMT"); $this->assertTrue($cookie->isExpired("Mon, 18 Nov 2002 15:50:30 GMT")); $this->assertFalse($cookie->isExpired("Mon, 18 Nov 2002 15:50:28 GMT")); }