Ejemplo n.º 1
0
 public function testRestFixesPathWithMissingSlashes()
 {
     $expXml = file_get_contents($this->path . 'returnString.xml');
     $response = "HTTP/1.0 200 OK\r\n" . "X-powered-by: PHP/5.2.0\r\n" . "Content-type: text/xml\r\n" . "Content-length: " . strlen($expXml) . "\r\n" . "Server: Apache/1.3.34 (Unix) PHP/5.2.0)\r\n" . "Date: Tue, 06 Feb 2007 15:01:47 GMT\r\n" . "Connection: close\r\n" . "\r\n" . $expXml;
     $this->adapter->setResponse($response);
     $rest = new Client\RestClient('http://framework.zend.com');
     $rest->setHttpClient($this->rest->getHttpClient());
     $response = $rest->restGet('rest');
     $this->assertTrue($response instanceof Response);
     $this->assertContains($expXml, $response->getBody(), $response->getBody());
 }
Ejemplo n.º 2
0
 public function findLocationByLocationName($locationName)
 {
     //http://maps.google.com/maps/geo?q=Kiev%20/%20Kyiv,%20Ukraine&output=json&oe=utf8
     $client = new Rest\Client\RestClient();
     $client->setUri("http://maps.google.com");
     $client->setHeaders('Accept-Charset', 'ISO-8859-1,utf-8');
     $_query = array('q' => $locationName, 'output'=>'json', 'oe'=>'utf8');
     $response = $client->restGet('/maps/geo', $_query);
     $location = Json\Json::decode($response->getBody());
     if (empty($location->Placemark)) return null;
     $placemark = $location->Placemark;
     if (!count($placemark)) return null;
     $place = current($placemark);
     list($long, $lat) = $place->Point->coordinates;
     return new Location($lat, $long);
 }
Ejemplo n.º 3
0
 /**
  *
  * @return void
  */
 public function setUp()
 {
     if (!constant('TESTS_ZEND_SERVICE_DELICIOUS_ENABLED')) {
         $this->markTestSkipped('\\Zend\\Service\\Delicious online tests are not enabled');
     }
     $httpClient = new Http\Client();
     $httpClient->setConfig(array('useragent' => 'Zend\\Service\\Delicious - Unit tests/0.1', 'keepalive' => true));
     RestClient\RestClient::setDefaultHttpClient($httpClient);
     $this->_delicious = new Delicious\Delicious(self::TEST_UNAME, self::TEST_PASS);
 }
Ejemplo n.º 4
0
    public function testRestPut()
    {
        $expXml   = file_get_contents($this->path . 'returnString.xml');
        $response = "HTTP/1.0 200 OK\r\n"
                  . "X-powered-by: PHP/5.2.0\r\n"
                  . "Content-type: text/xml\r\n"
                  . "Content-length: " . strlen($expXml) . "\r\n"
                  . "Server: Apache/1.3.34 (Unix) PHP/5.2.0)\r\n"
                  . "Date: Tue, 06 Feb 2007 15:01:47 GMT\r\n"
                  . "Connection: close\r\n"
                  . "\r\n"
                  . $expXml;
        $this->adapter->setResponse($response);

        $reqXml   = file_get_contents($this->path . 'returnInt.xml');
        $response = $this->rest->restPut('/rest/', $reqXml);
        $this->assertTrue($response instanceof Response);
        $body = $response->getBody();
        $this->assertContains($expXml, $response->getBody());

        $request = Client\RestClient::getDefaultHttpClient()->getLastRequest();
        $this->assertContains($reqXml, $request, $request);
    }