Esempio n. 1
0
 public function testUnsubscriptionRequestSendsExpectedPostData()
 {
     $this->_subscriber->setTopicUrl('http://www.example.com/topic');
     $this->_subscriber->addHubUrl($this->_baseuri . '/testRawPostData.php');
     $this->_subscriber->setCallbackUrl('http://www.example.com/callback');
     $this->_subscriber->setTestStaticToken('abc');
     //override for testing
     $this->_subscriber->unsubscribeAll();
     $this->assertEquals('hub.callback=http%3A%2F%2Fwww.example.com%2Fcallback%3Fxhub.subscription%3D5536df06b5d' . 'cb966edab3a4c4d56213c16a8184b&hub.mode=unsubscribe&hub.topic=http' . '%3A%2F%2Fwww.example.com%2Ftopic&hub.verify=sync&hub.verify=async' . '&hub.verify_token=abc', $this->_client->getResponse()->getBody());
 }
Esempio n. 2
0
    public function testIfCookiesAreSticky()
    {
        $initialCookies = array(
            new SetCookie('foo', 'far', null, '/', 'www.domain.com' ),
            new SetCookie('bar', 'biz', null, '/', 'www.domain.com')
        );

        $requestString = "GET http://www.domain.com/index.php HTTP/1.1\r\nHost: domain.com\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:16.0) Gecko/20100101 Firefox/16.0\r\nAccept: */*\r\nAccept-Language: en-US,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive\r\n";
        $request = Request::fromString($requestString);

        $client = new Client('http://www.domain.com/');
        $client->setRequest($request);
        $client->addCookie($initialCookies);

        $cookies = new Cookies($client->getRequest()->getHeaders());
        $rawHeaders = "HTTP/1.1 200 OK\r\nAccess-Control-Allow-Origin: *\r\nContent-Encoding: gzip\r\nContent-Type: application/javascript\r\nDate: Sun, 18 Nov 2012 16:16:08 GMT\r\nServer: nginx/1.1.19\r\nSet-Cookie: baz=bah; domain=www.domain.com; path=/\r\nSet-Cookie: joe=test; domain=www.domain.com; path=/\r\nVary: Accept-Encoding\r\nX-Powered-By: PHP/5.3.10-1ubuntu3.4\r\nConnection: keep-alive\r\n";
        $response = Response::fromString($rawHeaders);
        $client->setResponse($response);

        $cookies->addCookiesFromResponse($client->getResponse(), $client->getUri());

        $client->addCookie( $cookies->getMatchingCookies($client->getUri()) );

        $this->assertEquals(4, count($client->getCookies()));
    }
Esempio n. 3
0
 /**
  * Test the getLastRawResponse() method actually returns the last response
  *
  */
 public function testGetLastRawResponse()
 {
     // First, make sure we get null before the request
     $this->assertEquals(null, $this->_client->getLastRawResponse(), 'getLastRawResponse() is still expected to return null');
     // Now, test we get a proper response after the request
     $this->_client->setUri('http://example.com/foo/bar');
     $this->_client->setAdapter('Zend\\Http\\Client\\Adapter\\Test');
     $response = $this->_client->send();
     $this->assertTrue($response === $this->_client->getResponse(), 'Response is expected to be identical to the result of getResponse()');
 }
Esempio n. 4
0
 /**
  * ustawia wspolrzedne geograficzne dla lokalizacji
  *
  * @param Entity\Location $location
  * @return Entity\Location
  */
 public function setCoordinates(Entity\Location $location)
 {
     $location->getAddress();
     $client = new Http\Client('http://maps.googleapis.com/maps/api/geocode/json');
     $client->setParameterGet(array('address' => $location->getAddress()));
     $client->send();
     $response = json_decode($client->getResponse()->getBody());
     /**
      * w wymaganiach nie ma obslugi przypadkow uzycia
      * - zapisuje lokalizacje pierwszego 'dopasowanego' przez google adresu
      *
      */
     if ($response->status === 'OK' && !empty($results = $response->results[0])) {
         $location->setLatitude($results->geometry->location->lat)->setLongitude($results->geometry->location->lng);
     }
     return $location;
 }
Esempio n. 5
0
 /**
  * 发起请求
  * @param $requestUrl
  * @param $adapterOpt
  * @return \Zend\Http\Response
  */
 public function doRequest($requestUrl, $adapterOpt = [])
 {
     $client = new Client();
     $client->setAdapter($this->session->getSessionAdapter($adapterOpt));
     $client->setUri($requestUrl);
     $client->setMethod(Request::METHOD_POST);
     $client->send();
     $response = $client->getResponse();
     $setCookies = $response->getCookie();
     $this->session->updateSessionCookie($setCookies);
     return $response;
 }