Пример #1
1
#!/usr/bin/php
<?php 
/**
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$time_start = microtime(true);
require_once __DIR__ . '/tests_common.php';
_wl('test "' . basename(__FILE__) . '');
require_once __DIR__ . '/../lib/OSM/Api.php';
$osmApi = new OSM_Api();
$node = $osmApi->getNode('611571');
$serialData = serialize($osmApi);
$osmApi = unserialize($serialData);
$node = $osmApi->getNode('611571');
$time_end = microtime(true);
_wl('Test well done in ' . number_format($time_end - $time_start, 3) . ' second(s).');
$relations = $osmApi->getRelations();
_assert(count($relations) == 1);
$ways = $osmApi->getWays();
_assert(count($ways) == 8);
$nodes = $osmApi->getNodes();
_assert(count($nodes) == 680);
$objects = $osmApi->getObjects();
_assert(count($objects) == 689);
// getRelation, getWay, getNode
$relation = $osmApi->getRelation('164211');
_assert($relation != null);
_assert($relation->isDirty() == false);
$way = $osmApi->getWay('34717700');
_assert($way != null);
_assert($way->isDirty() == false);
$node = $osmApi->getNode('691558211');
_assert($node != null);
_assert($node->isDirty() == false);
// getObjectsByTags
$objects = $osmApi->getObjectsByTags(array('ref:INSEE' => '37001'));
_assert(count($objects) == 2);
$objects = $osmApi->getObjectsByTags(array('ref:INSEE' => ''));
_assert(count($objects) == 2);
$objects = $osmApi->getObjectsByTags(array('ref:INSEE' => '', 'place' => ''));
_assert(count($objects) == 1);
// test removeObject
$osmApi->removeObject(OSM_Api::OBJTYPE_NODE, '691558211');
$node = $osmApi->hasNode('691558211');
_assert($node == null);
$time_end = microtime(true);
_wl('Test well done in ' . number_format($time_end - $time_start, 3) . ' second(s).');
if ($auth_method == 'Basic') {
    _wl(' using Basic auth with user="******"');
    $osmApi->setCredentials(new OSM_Auth_Basic($auth_basic_user, $auth_basic_password));
} else {
    if ($auth_method == 'OAuth') {
        _wl(' using OAuth auth with consumerKey="' . $auth_oauth_consumer_key . '"');
        $oauth = new OSM_Auth_OAuth($auth_oauth_consumer_key, $auth_oauth_consumer_secret);
        $oauth->setToken($auth_oauth_token, $auth_oauth_secret);
        $osmApi->setCredentials($oauth);
    }
}
// http://api06.dev.openstreetmap.org/api/0.6/relation/500
// http://api06.dev.openstreetmap.org/api/0.6/way/8184
// http://api06.dev.openstreetmap.org/api/0.6/node/611571
// get a node
$node = $osmApi->getNode('611571');
// add a tag
$tagName = 'yapafo.net::test::' . time();
$tagValue = 'Have a nice dev ;-)';
$node->addTag(new OSM_Objects_Tag($tagName, $tagValue));
$tags = $node->findTags(array($tagName => $tagValue));
_assert(count($tags) == 1);
_assert($node->hasTags(array($tagName => $tagValue)));
// save changes
_assert($node->isDirty());
_wl(' saving changes...');
$osmApi->saveChanges('A yapafo.net test');
_assert($node->isDirty());
$tags = $node->findTags(array($tagName => $tagValue));
_assert(count($tags) == 1);
_assert($node->hasTags(array($tagName => $tagValue)));