/** * @dataProvider getMatchingCookiesDataProvider */ public function testReturnsCookiesMatchingRequests($url, $cookies) { $bag = array(new Cookie(array('name' => 'foo', 'value' => 'bar', 'domain' => 'example.com', 'path' => '/', 'max_age' => '86400', 'port' => array(443, 8080), 'version' => '1', 'secure' => true)), new Cookie(array('name' => 'baz', 'value' => 'foobar', 'domain' => 'example.com', 'path' => '/', 'max_age' => '86400', 'port' => array(80, 8080), 'version' => '1', 'secure' => true)), new Cookie(array('name' => 'test', 'value' => '123', 'domain' => 'www.foobar.com', 'path' => '/path/', 'discard' => true)), new Cookie(array('name' => 'muppet', 'value' => 'cookie_monster', 'domain' => '.y.example.com', 'path' => '/acme/', 'comment' => 'Comment goes here...', 'expires' => time() + 86400)), new Cookie(array('name' => 'googoo', 'value' => 'gaga', 'domain' => '.example.com', 'path' => '/test/acme/', 'max_age' => 1500, 'version' => 2))); foreach ($bag as $cookie) { $this->jar->add($cookie); } $request = new Request('GET', $url); $results = $this->jar->getMatchingCookies($request); $this->assertEquals(count($results), count($cookies)); foreach ($cookies as $i) { $this->assertContains($bag[$i], $results); } }
public function testCookiesAreNotAddedWhenParamIsSet() { $jar = new ArrayCookieJar(); $plugin = new CookiePlugin($jar); $jar->add(new Cookie(array('domain' => 'example.com', 'path' => '/', 'name' => 'test', 'value' => 'hi', 'expires' => time() + 3600))); $client = new Client('http://example.com'); $client->getEventDispatcher()->addSubscriber($plugin); // Ensure that it is normally added $request = $client->get(); $request->setResponse(new Response(200), true); $request->send(); $this->assertEquals('hi', $request->getCookie('test')); // Now ensure that it is not added $request = $client->get(); $request->getParams()->set('cookies.disable', true); $request->setResponse(new Response(200), true); $request->send(); $this->assertNull($request->getCookie('test')); }