function testHostValidity() { $cookie = new SimpleCookie("name"); $cookie->setHost("this.host.name.here"); $this->assertTrue($cookie->isValidHost("host.name.here")); $this->assertTrue($cookie->isValidHost("that.host.name.here")); $this->assertFalse($cookie->isValidHost("bad.host")); $this->assertFalse($cookie->isValidHost("nearly.name.here")); }
public function testHostValidity() { $cookie = new SimpleCookie('name'); $cookie->setHost('this.host.name.here'); $this->assertTrue($cookie->isValidHost('host.name.here')); $this->assertTrue($cookie->isValidHost('that.host.name.here')); $this->assertFalse($cookie->isValidHost('bad.host')); $this->assertFalse($cookie->isValidHost('nearly.name.here')); }
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; }
/** * 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; } }