public function testUpdateFromResponse()
 {
     $response = new Response('', 200, array('Set-Cookie' => 'foo=foo'));
     $cookieJar = new CookieJar();
     $cookieJar->set(new Cookie('bar', 'bar'));
     $cookieJar->updateFromResponse($response);
     $this->assertEquals('foo', $cookieJar->get('foo')->getValue(), '->updateFromResponse() updates cookies from a Response objects');
     $this->assertEquals('bar', $cookieJar->get('bar')->getValue(), '->updateFromResponse() keeps existing cookies');
 }
Example #2
0
 public function testUpdateFromSetCookieWithMultipleCookies()
 {
     $timestamp = time() + 3600;
     $date = gmdate('D, d M Y H:i:s \\G\\M\\T', $timestamp);
     $setCookies = array(sprintf('foo=foo; expires=%s; domain=.symfony.com; path=/, bar=bar; domain=.blog.symfony.com, PHPSESSID=id; expires=%s', $date, $date));
     $cookieJar = new CookieJar();
     $cookieJar->updateFromSetCookie($setCookies);
     $fooCookie = $cookieJar->get('foo', '/', '.symfony.com');
     $barCookie = $cookieJar->get('bar', '/', '.blog.symfony.com');
     $phpCookie = $cookieJar->get('PHPSESSID');
     $this->assertInstanceOf('Symfony\\Component\\BrowserKit\\Cookie', $fooCookie);
     $this->assertInstanceOf('Symfony\\Component\\BrowserKit\\Cookie', $barCookie);
     $this->assertInstanceOf('Symfony\\Component\\BrowserKit\\Cookie', $phpCookie);
     $this->assertEquals('foo', $fooCookie->getValue());
     $this->assertEquals('bar', $barCookie->getValue());
     $this->assertEquals('id', $phpCookie->getValue());
     $this->assertEquals($timestamp, $fooCookie->getExpiresTime());
     $this->assertNull($barCookie->getExpiresTime());
     $this->assertEquals($timestamp, $phpCookie->getExpiresTime());
 }
Example #3
0
 public function testCookieGetWithSubdirectory()
 {
     $cookieJar = new CookieJar();
     $cookieJar->set($cookie1 = new Cookie('foo', 'bar', null, '/test', '.example.com'));
     $cookieJar->set($cookie2 = new Cookie('foo1', 'bar1', null, '/', '.example.com'));
     $this->assertNull($cookieJar->get('foo', '/', '.example.com'));
     $this->assertNull($cookieJar->get('foo', '/bar', '.example.com'));
     $this->assertEquals($cookie1, $cookieJar->get('foo', '/test', 'example.com'));
     $this->assertEquals($cookie2, $cookieJar->get('foo1', '/', 'example.com'));
     $this->assertEquals($cookie2, $cookieJar->get('foo1', '/bar', 'example.com'));
 }
Example #4
0
 public function testCookieExpireWithNullPaths()
 {
     $cookieJar = new CookieJar();
     $cookieJar->set($cookie1 = new Cookie('foo', 'bar1', null, '/'));
     $cookieJar->expire('foo', null);
     $this->assertNull($cookieJar->get('foo'), '->get() returns null if the cookie is expired');
     $this->assertEquals(array(), array_keys($cookieJar->allValues('http://example.com/')));
 }