public function testUsesCookies() { $guzzle = $this->getGuzzle(); $client = new Client(); $client->setClient($guzzle); $client->getCookieJar()->set(new Cookie('test', '123')); $crawler = $client->request('GET', 'http://www.example.com/'); $request = $this->historyPlugin->getLastRequest(); $this->assertEquals('123', $request->getCookie('test')); }
public function testUsesCookiesWithCustomPort() { $guzzle = $this->getGuzzle(); $client = new Client(); $client->setClient($guzzle); $client->getCookieJar()->set(new Cookie('test', '123')); $client->request('GET', 'http://www.example.com:8000/'); $request = end($this->history)['request']; $this->assertEquals('test=123', $request->getHeaderLine('Cookie')); }
public function testFileCookieJar($testSaveSessionCookie = false) { $guzzle = $this->getGuzzle(); $client = new Client(); $client->setClient($guzzle); $filename = tempnam('/tmp', 'file-cookies'); $jar = new FileCookieJar($filename, $testSaveSessionCookie); $client->setGuzzleCookieJar($jar); $client->getCookieJar()->set(new Cookie('test', '123')); $client->getCookieJar()->set(new Cookie('foo', 'bar', time() + 1000)); $client->request('GET', 'http://www.example.com/'); // Call to destruct method manually to test saving cookies $jar->__destruct(); // Make sure it wrote to the file $contents = file_get_contents($filename); $this->assertNotEmpty($contents); // Load the cookieJar from the file $cookieJarReloaded = new FileCookieJar($filename); if ($testSaveSessionCookie) { $this->assertEquals(2, count($cookieJarReloaded)); } else { $this->assertEquals(1, count($cookieJarReloaded)); } unlink($filename); }
/** * Constructor */ public function __construct() { $this->client = new Client(); // @FIXME without this Cookie the website serves a JavaScript only version - see known issues $this->client->getCookieJar()->set(new Cookie('TS017d4e39', '01e0f702cf037f97362f62278696546776e7b67bec0aece008837daa4d94f77fe53d7d4c8a6fa39200300641d6aee20da460dd376505f7550bd18461d59d5c2489e7bc515b97917c372e044bb84fb8441a011139863d71d7b41a83ffdab5f7f5dc3492855c362d61bdddc129cdd1d60c4ac9a1b702547433a79abd2e4c7c9a2f9f21e7c748fe9f995fea959736b5aea76fe14d45d2181a39b1f45823787c1cd69e0457f53c')); }