Esempio n. 1
0
 /**
  * @covers Guzzle\Http\Message\Request::setResponse
  * @covers Guzzle\Http\Message\Request::getResponse
  * @covers Guzzle\Http\Message\Request::getState
  */
 public function testSetManualResponse()
 {
     $response = new Response(200, array('Date' => 'Sat, 16 Oct 2010 17:27:14 GMT', 'Expires' => '-1', 'Cache-Control' => 'private, max-age=0', 'Content-Type' => 'text/html; charset=ISO-8859-1'), 'response body');
     $this->assertSame($this->request, $this->request->setResponse($response), '-> setResponse() must use a fluent interface');
     $this->assertEquals('complete', $this->request->getState(), '-> setResponse() must change the state of the request to complete');
     $this->assertSame($response, $this->request->getResponse(), '-> setResponse() must set the exact same response that was passed in to it');
 }
 /**
  * @covers Guzzle\Http\Plugin\CookiePlugin
  */
 public function testAddsCookiesToRequests()
 {
     ArrayCookieJarTest::addCookies($this->storage);
     $this->storage->save(array('domain' => '.y.example.com', 'path' => '/acme/', 'cookie' => array('secure', 'sec'), 'expires' => Guzzle::getHttpDate('+1 day'), 'secure' => true));
     // Add a cookie that is only set on a specific port, so it wont be
     // added to the following requests
     $this->storage->save(array('domain' => '.y.example.com', 'path' => '/acme/', 'cookie' => array('test', 'port'), 'expires' => Guzzle::getHttpDate('+1 day'), 'secure' => false, 'port' => array(8192)));
     $request1 = new Request('GET', 'https://a.y.example.com/acme/');
     $request1->setClient(new Client());
     $request2 = new Request('GET', 'https://a.y.example.com/acme/');
     $request2->setClient(new Client());
     $request3 = new Request('GET', 'http://a.y.example.com/acme/');
     $request3->setClient(new Client());
     $request4 = new Request('GET', 'http://a.y.example.com/acme/');
     $request4->setClient(new Client());
     $request1->getEventDispatcher()->addSubscriber($this->plugin);
     $request2->getEventDispatcher()->addSubscriber($this->plugin);
     $request3->getEventDispatcher()->addSubscriber($this->plugin);
     $request4->getEventDispatcher()->addSubscriber($this->plugin);
     // Set a secure cookie
     $response1 = Response::fromMessage("HTTP/1.1 200 OK\r\nSet-Cookie: a=b; c=d; Max-Age=86400; domain=.example.com; secure;\r\n\r\n");
     // Set a regular cookie
     $response2 = Response::fromMessage("HTTP/1.1 200 OK\r\nSet-Cookie: e=f h; discard; domain=.example.com;\r\n\r\n");
     $response3 = Response::fromMessage("HTTP/1.1 200 OK\r\n\r\n");
     $request1->setResponse($response1, true);
     $request2->setResponse($response2, true);
     $request3->setResponse($response3, true);
     $request1->send();
     $request2->send();
     $request3->send();
     $this->assertEquals('muppet=cookie_monster;secure=sec', (string) $request1->getCookie());
     $this->assertEquals('muppet=cookie_monster;secure=sec;a=b;c=d', (string) $request2->getCookie());
     $this->assertEquals('muppet=cookie_monster;e=f h', (string) $request3->getCookie());
     // Clear the e=f h temporary cookie
     $this->plugin->clearTemporaryCookies();
     $request4->setResponse($response3, true);
     $request4->send();
     $this->assertEquals('muppet=cookie_monster', (string) $request4->getCookie());
 }