Example #1
0
 public function testMatchesPath()
 {
     $cookie = new Cookie();
     $this->assertTrue($cookie->matchesPath('/foo'));
     $cookie->setPath('/foo');
     $this->assertTrue($cookie->matchesPath('/foo'));
     $this->assertTrue($cookie->matchesPath('/foo/bar'));
     $this->assertFalse($cookie->matchesPath('/bar'));
 }
 /**
  * {@inheritdoc}
  */
 protected function changedHeader($action, $header)
 {
     parent::changedHeader($action, $header);
     if ($header === 'host') {
         // If the Host header was changed, be sure to update the internal URL
         $this->setHost((string) $this->getHeader('Host'));
     } elseif ($header === 'cookie') {
         // Be sure to get an cookie updates and update the internal Cookie
         if ($action === 'set') {
             $this->cookie = Cookie::factory($this->getHeader('Cookie'));
         } else {
             if ($this->cookie) {
                 $this->cookie->clear();
             }
         }
     }
 }
 /**
  * @covers Guzzle\Http\QueryString
  * @covers Guzzle\Http\Cookie
  */
 public function testAggregatesMultipleCookieValues()
 {
     $cookie = Cookie::factory('name=a;name=b');
     $this->assertEquals(array('a', 'b'), $cookie->get('name'));
     $this->assertEquals('name=a;name=b', (string) $cookie);
 }
 /**
  * {@inheritdoc}
  */
 public function add(Cookie $cookie)
 {
     if (!$cookie->getValue() || !$cookie->getName() || !$cookie->getDomain()) {
         return false;
     }
     // Resolve conflicts with previously set cookies
     foreach ($this->cookies as $i => $c) {
         // Check the regular comparison fields
         if ($c->getPath() != $cookie->getPath() || $c->getMaxAge() != $cookie->getMaxAge() || $c->getDomain() != $cookie->getDomain() || $c->getHttpOnly() != $cookie->getHttpOnly() || $c->getPorts() != $cookie->getPorts() || $c->getSecure() != $cookie->getSecure() || $c->getName() != $cookie->getName()) {
             continue;
         }
         // The previously set cookie is a discard cookie and this one is not
         // so allow the new cookie to be set
         if (!$cookie->getDiscard() && $c->getDiscard()) {
             unset($this->cookies[$i]);
             continue;
         }
         // If the new cookie's expiration is further into the future, then
         // replace the old cookie
         if ($cookie->getExpires() > $c->getExpires()) {
             unset($this->cookies[$i]);
             continue;
         }
         // If the value has changed, we better change it
         if ($cookie->getValue() !== $c->getValue()) {
             unset($this->cookies[$i]);
             continue;
         }
         // The cookie exists, so no need to continue
         return false;
     }
     $this->cookies[] = $cookie;
     return true;
 }