Exemplo n.º 1
0
/**
 * Returns an instance of Services_Twitter.
 *
 * @param string $ep      The endpoint to call (eg. )
 * @param bool   $auth    Whether to authenticate or not
 * @param array  $options An optional options array to pass to the 
 *                        Services_Twitter constructor
 *
 * @return Services_Twitter The twitter instance.
 */
function Services_Twitter_factory($ep, $auth = true, $options = array())
{
    //$options['raw_format'] = true;
    global $config;
    if ($auth) {
        $twitter = new Services_Twitter($config['user'], $config['pass'], $options);
    } else {
        $twitter = new Services_Twitter(null, null, $options);
    }
    if (!$config['live_test']) {
        if ($ep == 'exception1') {
            $resp = new HTTP_Request2_Response('HTTP/1.1 401 Unauthorized', false);
            $resp->appendBody('{"request":"\\/statuses\\/friends_timeline.json", ' . '"error":"Could not authenticate you."}');
        } else {
            if ($ep == 'exception2') {
                $resp = new HTTP_Request2_Response('HTTP/1.1 404 Not Found', false);
            } else {
                $resp = new HTTP_Request2_Response('HTTP/1.1 200 Success', false);
                $file = dirname(__FILE__) . '/data/' . $ep . '.dat';
                $resp->appendBody(file_get_contents($file));
            }
        }
        $mock = new HTTP_Request2_Adapter_Mock();
        $mock->addResponse($resp);
        $request = $twitter->getRequest()->setAdapter($mock);
    }
    return $twitter;
}
/**
 * Return the Services_GeoNames with either a mock adapter or the real adapter
 * depending whether the SERVICES_GEONAMES_LIVETEST environment variable is set
 * or not.
 *
 * @param string $testname The test name (without extension)
 * @param string $user     Username (optional)
 * @param string $token    Auth token (optional)
 *
 * @return Services_GeoNames
 */
function Services_GeoNames_factory($testname, $user = null, $token = null)
{
    $geo = new Services_GeoNames($user, $token);
    if (!getenv('SERVICES_GEONAMES_LIVETEST')) {
        // test with a mock adapter
        $mock = new HTTP_Request2_Adapter_Mock();
        if ($testname == 'test_other_04') {
            $resp = new HTTP_Request2_Response('HTTP/1.1 404 Not Found', false);
        } else {
            if ($testname == 'test_other_07') {
                $resp = new HTTP_Request2_Response('HTTP/1.1 404 Not Found', false);
                $mock->addResponse($resp);
                $resp = new HTTP_Request2_Response('HTTP/1.1 404 Not Found', false);
                $mock->addResponse($resp);
                $resp = new HTTP_Request2_Response('HTTP/1.1 404 Not Found', false);
            } else {
                $resp = new HTTP_Request2_Response('HTTP/1.1 200 Success', false);
                $file = dirname(__FILE__) . '/data/' . $testname . '.dat';
                $resp->appendBody(file_get_contents($file));
            }
        }
        $mock->addResponse($resp);
        $geo->getRequest()->setAdapter($mock);
    }
    return $geo;
}
 protected function createMockAdapter(array $responses)
 {
     $adapter = new HTTP_Request2_Adapter_Mock();
     foreach ($responses as $response) {
         $adapter->addResponse($response);
     }
     return $adapter;
 }
Exemplo n.º 4
0
 /**
  * @expectedException Services_Yadis_Exception
  * @expectedExceptionMessage Invalid response to Yadis protocol received: A test error
  */
 public function testGetException()
 {
     $httpMock = new HTTP_Request2_Adapter_Mock();
     $httpMock->addResponse(new HTTP_Request2_Exception('A test error', 500));
     $http = new HTTP_Request2();
     $http->setAdapter($httpMock);
     $sy = new Services_Yadis('http://example.org/openid');
     $sy->setHttpRequest($http);
     $xrds = $sy->discover();
 }
 /**
  * Should get an empty array (unauthorised connection)
  *
  * @return void
  */
 public function testPermissionsUnauthorised()
 {
     $mock = new HTTP_Request2_Adapter_Mock();
     $mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb'));
     $mock->addResponse(fopen(__DIR__ . '/responses/permissionsUnauthorised.xml', 'rb'));
     $config = array('adapter' => $mock, 'server' => 'http://api.openstreetmap.org/', 'user' => '*****@*****.**', 'password' => 'wilmaAevah');
     $osm = new Services_OpenStreetMap($config);
     $permissions = $osm->getPermissions();
     $expected = array();
     $this->assertEquals($permissions, $expected);
 }
Exemplo n.º 6
0
 public function testSend()
 {
     $mockAdapter = new HTTP_Request2_Adapter_Mock();
     $mockAdapter->addResponse("HTTP/1.1 200 OK\n\nfoo");
     $mockReq = new HTTP_Request2('http://example.com');
     $mockReq->setAdapter($mockAdapter);
     $req = new HTTP_OAuth_Consumer_Request();
     $req->accept($mockReq);
     $res = $req->send();
     $this->assertInstanceOf('HTTP_OAuth_Consumer_Request', $req);
     $this->assertInstanceOf('HTTP_OAuth_Consumer_Response', $res);
     $this->assertEquals('foo', $res->getBody());
 }
Exemplo n.º 7
0
 public function setUp()
 {
     parent::setUp();
     Yii::configure(Yii::$app, ['components' => ['user' => ['class' => 'yii\\web\\User', 'identityClass' => 'common\\models\\User'], 'p24' => ['class' => \merigold\przelewy24\src\Przelewy24Component::className(), 'merchant_id' => $this->merchant_id, 'pos_id' => $this->merchant_id, 'CRC' => $this->CRC]]]);
     Yii::$container->set('HTTP_Request2', function () {
         $response = new HTTP_Request2_Response("HTTP/1.1 200 OK", true);
         $response->appendBody($this->succesresponse);
         $mockAdapter = new HTTP_Request2_Adapter_Mock();
         $mockAdapter->addResponse($response);
         $stub = new HTTP_Request2(\merigold\przelewy24\src\Przelewy24Component::TEST_URL, HTTP_Request2::METHOD_POST);
         $stub->setAdapter($mockAdapter);
         return $stub;
     });
 }
 public function testShouldCompleteTransaction()
 {
     $mock = new HTTP_Request2_Adapter_Mock();
     $mock->addResponse('HTTP/1.1 200 OK');
     $request = new HTTP_Request2();
     $request->setAdapter($mock);
     $object = Payment_Process2::factory('Dummy');
     $object->login = '******';
     $object->password = '******';
     $object->action = Payment_Process2::ACTION_NORMAL;
     $object->amount = 1;
     $object->setRequest($request);
     $object->setPayment($this->aValidPayment());
     $result = $object->process();
     $this->assertTrue($result instanceof Payment_Process2_Result_Dummy);
 }
 public function testShouldFailGracefullyOnFailedTransaction()
 {
     $mock = new HTTP_Request2_Adapter_Mock();
     $mock->addResponse('HTTP/1.1 404 Not Found');
     $request = new HTTP_Request2();
     $request->setAdapter($mock);
     $object = Payment_Process2::factory('PayPal');
     $object->login = '******';
     $object->password = '******';
     $object->amount = 1;
     $object->action = Payment_Process2::ACTION_NORMAL;
     $object->setRequest($request);
     $object->setPayment($this->aValidPayment());
     $result = $object->process();
     $this->assertTrue($result instanceof PEAR_Error);
 }
 public function testShouldFailGracefullyOnFailedTransaction()
 {
     $mock = new HTTP_Request2_Adapter_Mock();
     $mock->addResponse('HTTP/1.1 404 Not Found');
     $request = new HTTP_Request2();
     $request->setAdapter($mock);
     $options = array('keyfile' => __FILE__, 'authorizeUri' => "http://google.com/");
     $object = Payment_Process2::factory('LinkPoint', $options);
     $object->login = '******';
     $object->password = '******';
     $object->amount = 1;
     $object->action = Payment_Process2::ACTION_NORMAL;
     $object->setRequest($request);
     $object->setPayment($this->aValidPayment());
     $result = $object->process();
     $this->assertTrue($result instanceof PEAR_Error);
 }
Exemplo n.º 11
0
 /**
  * Ignore setting a cookie from "parallel" subdomain when relevant option is on
  *
  * @link http://pear.php.net/bugs/bug.php?id=20401
  */
 public function testRequest20401()
 {
     $this->jar->ignoreInvalidCookies(true);
     $response = HTTP_Request2_Adapter_Mock::createResponseFromFile(fopen(dirname(dirname(__FILE__)) . '/_files/response_cookies', 'rb'));
     $setter = new Net_URL2('http://pecl.php.net/');
     $this->assertFalse($this->jar->addCookiesFromResponse($response, $setter));
     $this->assertCount(3, $this->jar->getAll());
 }
 public function testShouldFailGracefullyOnFailedTransaction()
 {
     $response = new HTTP_Request2_Response('HTTP/1.1 200 OK');
     $response->appendBody(file_get_contents(dirname(__FILE__) . '/data/AuthorizeNet/error.html'));
     $mock = new HTTP_Request2_Adapter_Mock();
     $mock->addResponse($response);
     $request = new HTTP_Request2();
     $request->setAdapter($mock);
     $object = Payment_Process2::factory('AuthorizeNet');
     $object->login = '******';
     $object->password = '******';
     $object->amount = 1;
     $object->action = Payment_Process2::ACTION_NORMAL;
     $object->setRequest($request);
     $object->setPayment($this->aValidPayment());
     $result = $object->process();
     $this->assertTrue($result instanceof PEAR_Error);
 }
 /**
  * Test20205
  *
  * @return void
  */
 public function test20205()
 {
     $mock = new HTTP_Request2_Adapter_Mock();
     $mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb'));
     $mock->addResponse(fopen(__DIR__ . '/responses/PEARBug20205_moskau_ru.xml', 'rb'));
     $mock->addResponse(fopen(__DIR__ . '/responses/PEARBug20205_moskau_en.xml', 'rb'));
     $mock->addResponse(fopen(__DIR__ . '/responses/PEARBug20205_russia_en.xml', 'rb'));
     $mock->addResponse(fopen(__DIR__ . '/responses/PEARBug20205_russia_fr.xml', 'rb'));
     $config = array('adapter' => $mock, 'server' => 'http://api06.dev.openstreetmap.org/');
     $osm = new Services_OpenStreetMap($config);
     $osm->getConfig()->setAcceptLanguage('ru,en-AU');
     $test = $osm->getPlace('Moskau');
     $attribs = $test[0]->attributes();
     $display = (string) $attribs['display_name'];
     $expected = "Москва, " . "Центральный федеральный округ, " . "Российская Федерация";
     $this->assertEquals($display, $expected);
     $osm->getConfig()->setAcceptLanguage('en');
     $test = $osm->getPlace('Moskau');
     $attribs = $test[0]->attributes();
     $display = (string) $attribs['display_name'];
     $expected = 'Moscow, Central Federal District, Russian Federation';
     $this->assertEquals($display, $expected);
     $test = $osm->getPlace('Russia');
     $attribs = $test[0]->attributes();
     $display = (string) $attribs['display_name'];
     $expected = 'Russian Federation';
     $this->assertEquals($display, $expected);
     $osm->getConfig()->setAcceptLanguage('fr');
     $test = $osm->getPlace('Russia');
     $attribs = $test[0]->attributes();
     $display = (string) $attribs['display_name'];
     $expected = 'Fédération de Russie';
     $this->assertEquals($display, $expected);
 }
 /**
  * Test reverse lookup
  *
  * @return void
  */
 public function testReverse()
 {
     $mock = new HTTP_Request2_Adapter_Mock();
     $mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb'));
     $mock->addResponse(fopen(__DIR__ . '/responses/mapquestReverseGeocodeIrishTimes.xml', 'rb'));
     $mock->addResponse(fopen(__DIR__ . '/responses/mapquestReverseGeocodeChurchtown.xml', 'rb'));
     $config = array('server' => 'http://open.mapquestapi.com/nominatim/v1/', 'adapter' => $mock);
     $osm = new Services_OpenStreetMap($config);
     $nominatim = new Services_OpenStreetMap_Nominatim($osm->getTransport());
     $nominatim->setServer('mapquest');
     $xml = $nominatim->setFormat('xml')->reverseGeocode("53.3459641", "-6.2548149");
     $this->AssertEquals($xml[0]->addressparts->house, "The Irish Times");
     $this->AssertEquals($xml[0]->addressparts->house_number, "24-28");
     $this->AssertEquals($xml[0]->addressparts->road, "Tara Street");
     $this->AssertEquals($xml[0]->addressparts->city, "Dublin");
     $this->AssertEquals($xml[0]->addressparts->county, "County Dublin");
     $this->AssertEquals($xml[0]->addressparts->state_district, "Leinster");
     $this->AssertEquals($xml[0]->addressparts->postcode, "2");
     $this->AssertEquals($xml[0]->addressparts->country, "Ireland");
     $this->AssertEquals($xml[0]->addressparts->country_code, "ie");
     $nominatim->setCountryCodes('ie');
     $res = $nominatim->search('churchtown');
     $this->assertEquals(count($res), 10);
 }
Exemplo n.º 15
0
 protected function addHttpResponse($response, $url = null)
 {
     $this->adapter->addResponse($response, $url);
     return $this;
 }
 public function sendRequest(HTTP_Request2 $request)
 {
     $this->requests[] = array('config' => $request->getConfig(), 'url' => $request->getUrl(), 'method' => $request->getMethod(), 'headers' => $request->getHeaders(), 'auth' => $request->getAuth(), 'body' => (string) $request->getBody());
     return parent::sendRequest($request);
 }
 public function sendRequest(HTTP_Request2 $request)
 {
     $this->requestedUrls[] = (string) $request->getUrl();
     return parent::sendRequest($request);
 }
 /**
  * Open a new changeset, create a node and save it by associating it with
  * that changeset and then committing.
  * The id of the node should change from -1 to a positive integer/double.
  *
  * @return void
  */
 public function testSaveNode()
 {
     if (!file_exists($this->credentialsFile)) {
         $this->markTestSkipped('Credentials file does not exist.');
     }
     $mock = new HTTP_Request2_Adapter_Mock();
     $mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb'));
     $mock->addResponse(fopen(__DIR__ . '/responses/changeset_id', 'rb'));
     $mock->addResponse(fopen(__DIR__ . '/responses/diff_create_node.xml', 'rb'));
     $mock->addResponse(fopen(__DIR__ . '/responses/changeset_closed', 'rb'));
     $config = array('adapter' => $mock, 'server' => 'http://api06.dev.openstreetmap.org/', 'passwordfile' => $this->credentialsFile);
     $osm = new Services_OpenStreetMap($config);
     $lat = 52.8638729;
     $lon = -8.1983611;
     $node = $osm->createNode($lat, $lon, array('building' => 'yes', 'amenity' => 'vet'));
     $this->assertEquals($node->getTags(), array('building' => 'yes', 'amenity' => 'vet'));
     $this->assertEquals($lat, $node->getlat());
     $this->assertEquals($lon, $node->getlon());
     $node->setTag('amenity', 'veterinary')->setTag('name', 'O\'Kennedy');
     $this->assertEquals($node->getTags(), array('building' => 'yes', 'amenity' => 'veterinary', 'name' => 'O\'Kennedy'));
     $this->assertEquals(-1, $node->getId());
     $changeset = $osm->createChangeset();
     $changeset->begin("Add O'Kennedy vets in Nenagh");
     $changeset->add($node);
     $changeset->commit();
     $this->assertEquals($node->getId(), 1448499623);
 }
Exemplo n.º 19
0
 /**
  * Test retrieving relations which refer to a specific way.
  *
  * @return void
  */
 public function testWayBackRelations()
 {
     $mock = new HTTP_Request2_Adapter_Mock();
     $mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb'));
     $mock->addResponse(fopen(__DIR__ . '/responses/way_5850969.xml', 'rb'));
     $mock->addResponse(fopen(__DIR__ . '/responses/way_5850969_relations.xml', 'rb'));
     $config = array('adapter' => $mock, 'server' => 'http://api06.dev.openstreetmap.org');
     $osm = new Services_OpenStreetMap($config);
     $relations = $osm->getWay(5850969)->getRelations();
     $this->assertInstanceOf('Services_OpenStreetMap_Relations', $relations);
     $this->assertEquals(2, sizeof($relations));
     $this->assertEquals($relations[0]->getTag('name'), 'Dublin Bus route 14');
     $this->assertEquals($relations[1]->getTag('name'), 'Dublin Bus route 75');
 }
 /**
  * User value must be numeric.
  *
  * @expectedException        Services_OpenStreetMap_InvalidArgumentException
  * @expectedExceptionMessage User UID must be numeric
  *
  * @return void
  */
 public function testInvalidUserValue()
 {
     $mock = new HTTP_Request2_Adapter_Mock();
     $mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb'));
     $config = array('adapter' => $mock, 'server' => 'http://api06.dev.openstreetmap.org/');
     $osm = new Services_OpenStreetMap($config);
     $user = new Services_OpenStreetMap_Criterion('user', 'mustbenumeric');
 }
Exemplo n.º 21
0
 /**
  * Test the bboxToMinMax method
  *
  * @return void
  */
 public function testBboxToMinMax()
 {
     $mock = new HTTP_Request2_Adapter_Mock();
     $mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb'));
     $config = array('adapter' => $mock);
     $osm = new Services_OpenStreetMap($config);
     $this->assertEquals($osm->bboxToMinMax('0.0327873', '52.260074599999996', '0.0767326', '52.282047299999995'), array('52.260074599999996', '0.0327873', '52.282047299999995', '0.0767326'));
 }
 /**
  * Test reverse geocode.
  *
  * This is also a good example of how to use Services_OpenStreetMap_Nominatim
  * separate from the core Services_OpenStreetMap object.
  *
  * @return void
  */
 public function testNomimatimReverseGeocode()
 {
     $mock = new HTTP_Request2_Adapter_Mock();
     $mock->addResponse(fopen(__DIR__ . '/responses/nominatim_reverse_it.xml', 'rb'));
     $osm = new Services_OpenStreetMap(array('adapter' => $mock));
     $nominatim = new Services_OpenStreetMap_Nominatim($osm->getTransport());
     $xml = $nominatim->setFormat('xml')->reverseGeocode("53.3459641", "-6.2548149");
     $this->AssertEquals($xml[0]->result, "The Irish Times, 24-28, Tara Street, Dublin 2, Dublin, " . "County Dublin, Leinster, D02, Ireland");
     $this->AssertEquals($xml[0]->addressparts->road, "Tara Street");
     $this->AssertEquals($xml[0]->addressparts->city, "Dublin");
 }
Exemplo n.º 23
0
 /**
  * testCheckAuthentication 
  * 
  * @return void
  */
 public function testCheckAuthentication()
 {
     $opEndpoint = new OpenID_ServiceEndpoint();
     $opEndpoint->setURIs(array($this->opEndpointURL));
     $opEndpoints = new OpenID_ServiceEndpoints($this->claimedID, $opEndpoint);
     $this->discover = $this->getMock('OpenID_Discover', array('__get'), array($this->claimedID));
     $this->discover->expects($this->once())->method('__get')->will($this->returnValue($opEndpoints));
     $this->store->expects($this->once())->method('getDiscover')->will($this->returnValue($this->discover));
     $this->store->expects($this->once())->method('getNonce')->will($this->returnValue(false));
     $this->createObjects();
     $adapter = new HTTP_Request2_Adapter_Mock();
     $content = "HTTP/1.1 200\n";
     $content .= "Content-Type: text/html; charset=iso-8859-1\n\n\n";
     $content .= "foo:bar\n";
     $adapter->addResponse($content);
     $httpRequest = new HTTP_Request2();
     $httpRequest->setAdapter($adapter);
     $this->assertion->expects($this->once())->method('getHTTPRequest2Instance')->will($this->returnValue($httpRequest));
     $result = $this->assertion->checkAuthentication();
 }
Exemplo n.º 24
0
 /**
  * Test getRelations called with more than one argument/parameter.
  *
  * @return void
  */
 public function testGetRelationsManyArgs()
 {
     $mock = new HTTP_Request2_Adapter_Mock();
     $mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb'));
     $mock->addResponse(fopen(__DIR__ . '/responses/relations_917266_20645_2740.xml', 'rb'));
     $mock->addResponse(fopen(__DIR__ . '/responses/relation_changeset.xml', 'rb'));
     $config = array('adapter' => $mock, 'server' => 'http://api06.dev.openstreetmap.org/');
     $osm = new Services_OpenStreetMap($config);
     $relations = $osm->getRelations(917266, 20645, 2740);
     $this->assertEquals(3, sizeof($relations));
     $relationsInfo = array(array('id' => 2740, 'name' => 'The Wicklow Way', 'type' => 'route', 'members' => array('role' => '', 'count' => 113, 'type' => 'node')), array('id' => 20645, 'name' => 'International E-road network', 'type' => 'network', 'members' => array('role' => '', 'type' => 'relation', 'count' => 48)), array('id' => 917266, 'name' => 'Dublin Bus route 14', 'type' => 'route', 'members' => array('role' => 'forward', 'type' => 'way', 'count' => 112)));
     foreach ($relations as $key => $relation) {
         $tags = $relation->getTags();
         $members = $relation->getMembers();
         $this->assertEquals($tags['name'], $relationsInfo[$key]['name']);
         $this->assertEquals($tags['type'], $relationsInfo[$key]['type']);
         $this->assertEquals($relation->getId(), $relationsInfo[$key]['id']);
         $this->assertEquals(sizeof($members), $relationsInfo[$key]['members']['count']);
         $this->assertEquals($members[0]['type'], $relationsInfo[$key]['members']['type']);
         $this->assertEquals($members[0]['role'], $relationsInfo[$key]['members']['role']);
     }
 }
 public function testResponseException()
 {
     $mock = new HTTP_Request2_Adapter_Mock();
     $mock->addResponse(new HTTP_Request2_Exception('Shit happens'));
     $req = new HTTP_Request2('http://www.example.com/');
     $req->setAdapter($mock);
     try {
         $req->send();
     } catch (Exception $e) {
         $this->assertEquals('Shit happens', $e->getMessage());
         return;
     }
     $this->fail('Expected HTTP_Request2_Exception was not thrown');
 }
Exemplo n.º 26
0
 /**
  * Test retrieving relations that refer to a specific node.
  *
  * @return void
  */
 public function testGetRelations()
 {
     $mock = new HTTP_Request2_Adapter_Mock();
     $mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb'));
     $mock->addResponse(fopen(__DIR__ . '/responses/node_597697114.xml', 'rb'));
     $mock->addResponse(fopen(__DIR__ . '/responses/relation_405053.xml', 'rb'));
     $config = array('adapter' => $mock, 'server' => 'http://api06.dev.openstreetmap.org/');
     $osm = new Services_OpenStreetMap($config);
     $relations = $osm->getNode(597697114)->getRelations();
     $this->assertInstanceOf('Services_OpenStreetMap_Relations', $relations);
     $this->assertEquals(sizeof($relations), 1);
     $this->assertInstanceOf('Services_OpenStreetMap_Relation', $relations[0]);
     $this->assertEquals($relations[0]->getTags(), array('complete' => 'no', 'name' => 'Dublin Bus route 75', 'operator' => 'Dublin Bus', 'ref' => '75', 'route' => 'bus', 'type' => 'route'));
 }
Exemplo n.º 27
0
 /**
  * Test getting user info for user other than authorised user
  *
  * @return void
  */
 public function testUser11324()
 {
     $mock = new HTTP_Request2_Adapter_Mock();
     $mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb'));
     $mock->addResponse(fopen(__DIR__ . '/responses/user11324.xml', 'rb'));
     $config = array('adapter' => $mock, 'server' => 'http://api06.dev.openstreetmap.org/', 'user' => '*****@*****.**', 'password' => 'w1lma4evah');
     $osm = new Services_OpenStreetMap($config);
     $user = $osm->getUserById(6367);
     $this->assertEquals($user->getDisplayName(), 'kenguest');
     $this->assertEquals($user->getId(), 11324);
     $this->assertEquals($user->getChangesets(), 1910);
     $this->assertEquals($user->getTraces(), 115);
     $this->assertEquals($user->getBlocksReceived(), 0);
     $this->assertEquals($user->getActiveBlocksReceived(), 0);
     $this->assertNull($user->getBlocksIssued());
     $this->assertNull($user->getActiveBlocksIssued());
     $this->assertNull($user->getLanguages());
     $this->assertEquals($user->getRoles(), array());
 }
 *
 * @category Services
 * @package  Services_OpenStreetMap
 * @author   Ken Guest <*****@*****.**>
 * @license  BSD http://www.opensource.org/licenses/bsd-license.php
 * @link     osmx.php
 */
$version = '@package_version@';
if (strstr($version, 'package_version')) {
    set_include_path(dirname(dirname(__FILE__)) . ':' . get_include_path());
}
require_once 'Services/OpenStreetMap.php';
require_once 'HTTP/Request2.php';
require_once 'HTTP/Request2/Adapter/Mock.php';
$osm = new Services_OpenStreetMap();
$mock = new HTTP_Request2_Adapter_Mock();
$mock->addResponse(fopen(__DIR__ . '/../tests/responses/capabilities.xml', 'rb'));
$mock->addResponse(fopen(__DIR__ . '/../tests/responses/changeset.xml', 'rb'));
$mock->addResponse(fopen(__DIR__ . '/../tests/responses/changeset.xml', 'rb'));
$mock->addResponse(fopen(__DIR__ . '/../tests/responses/diff_create_node.xml', 'rb'));
$mock->addResponse(fopen(__DIR__ . '/../tests/responses/changeset_closed', 'rb'));
$config = array('adapter' => $mock, 'server' => 'http://api.openstreetmap.org/', 'passwordfile' => __DIR__ . '/credentials');
$osm = new Services_OpenStreetMap($config);
$mm = $osm->bboxToMinMax(-8.6519835, 52.638735499999996, -8.6214513, 52.649915099999994);
$osm->get($mm[0], $mm[1], $mm[2], $mm[3]);
$results = $osm->search(array("building" => "yes"));
$changeset = $osm->createChangeset();
$changeset->begin('Additional details for ballinacurra gardens.');
foreach ($results as $result) {
    $addrStreet = $result->getTag('addr:street');
    if ($addrStreet != 'Oakview Drive') {
Exemplo n.º 29
0
 /**
  * Testa
  *
  * @return void
  */
 public function testa()
 {
     $mock = new HTTP_Request2_Adapter_Mock();
     $mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb'));
     $mock->addResponse(fopen(__DIR__ . '/responses/get_notes.xml', 'rb'));
     $server = 'http://api06.dev.openstreetmap.org/';
     $config = array('adapter' => $mock, 'server' => $server);
     $osm = new Services_OpenStreetMap($config);
     $minlon = "-8.2456593";
     $minlat = "52.8488977";
     $maxlon = "-8.1751247";
     $maxlat = "52.8839662";
     $notes = $osm->getNotesByBbox($minlon, $minlat, $maxlon, $maxlat, 200, 14);
     $note = $notes[0];
     $this->assertInstanceOf('Services_OpenStreetMap_Notes', $notes);
     $this->assertInstanceOf('Services_OpenStreetMap_Note', $note);
     $comments = $note->getComments();
     $comment = $comments[0];
     $this->assertInstanceOf('Services_OpenStreetMap_Comment', $comment);
     $this->assertInstanceOf('Services_OpenStreetMap_Comments', $comments);
 }
Exemplo n.º 30
0
 protected function addHttpResponse($body, $status = 'HTTP/1.1 200 OK')
 {
     $response = new HTTP_Request2_Response($status);
     $response->appendBody($body);
     $this->mock->addResponse($response);
 }