| 1 |
|
<?php |
| 2 |
|
/** |
| 3 |
|
* NodeTest.php |
| 4 |
|
* 29-Sep-2011 |
| 5 |
|
* |
| 6 |
|
* PHP Version 5 |
| 7 |
|
* |
| 8 |
|
* @category Services |
| 9 |
|
* @package Services_Openstreetmap |
| 10 |
|
* @subpackage UnitTesting |
| 11 |
|
* @author Ken Guest <kguest@php.net> |
| 12 |
|
* @license BSD http://www.opensource.org/licenses/bsd-license.php |
| 13 |
|
* @version Release: @package_version@ |
| 14 |
|
* @link NodeTest.php |
| 15 |
|
*/ |
| 16 |
|
|
| 17 |
|
$version = '@package_version@'; |
| 18 |
|
if (strstr($version, 'package_version')) { |
| 19 |
|
set_include_path(dirname(dirname(__FILE__)) . ':' . get_include_path()); |
| 20 |
|
} |
| 21 |
|
|
| 22 |
|
require_once 'Services/Openstreetmap.php'; |
| 23 |
|
|
| 24 |
|
require_once 'HTTP/Request2.php'; |
| 25 |
|
require_once 'HTTP/Request2/Adapter/Mock.php'; |
| 26 |
|
require_once 'PHPUnit/Framework/TestCase.php'; |
| 27 |
|
|
| 28 |
|
/** |
| 29 |
|
* Unit tests for retrieving and manipulating nodes. |
| 30 |
|
* |
| 31 |
|
* @category Services |
| 32 |
|
* @package Services_Openstreetmap |
| 33 |
|
* @subpackage UnitTesting |
| 34 |
|
* @author Ken Guest <kguest@php.net> |
| 35 |
|
* @license BSD http://www.opensource.org/licenses/bsd-license.php |
| 36 |
|
* @link NodeTest.php |
| 37 |
|
*/ |
| 38 |
|
class NodeTest extends PHPUnit_Framework_TestCase |
| 39 |
|
{ |
| 40 |
|
public function testGetNode() |
| 41 |
|
{ |
| 42 |
1 |
$id = 52245107; |
| 43 |
|
|
| 44 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 45 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 46 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/node.xml', 'rb')); |
| 47 |
|
|
| 48 |
|
$config = array( |
| 49 |
1 |
'adapter' => $mock, |
| 50 |
|
'server' => 'http://api06.dev.openstreetmap.org/' |
| 51 |
1 |
); |
| 52 |
1 |
$osm = new Services_Openstreetmap($config); |
| 53 |
1 |
$node = $osm->getNode($id); |
| 54 |
1 |
$getTags = $node->getTags(); |
| 55 |
|
|
| 56 |
1 |
$this->assertEquals($id, $node->getId()); |
| 57 |
1 |
$this->assertEquals($getTags['name'], 'Nenagh Bridge'); |
| 58 |
1 |
$this->assertEquals("52.881667", $node->getLat()); |
| 59 |
1 |
$this->assertEquals("-8.195833", $node->getLon()); |
| 60 |
|
} |
| 61 |
|
|
| 62 |
|
public function testGetSpecifiedVersionOfNode() |
| 63 |
|
{ |
| 64 |
1 |
$id = 52245107; |
| 65 |
|
|
| 66 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 67 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 68 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/node.xml', 'rb')); |
| 69 |
|
|
| 70 |
|
$config = array( |
| 71 |
1 |
'adapter' => $mock, |
| 72 |
|
'server' => 'http://api06.dev.openstreetmap.org/' |
| 73 |
1 |
); |
| 74 |
1 |
$osm = new Services_Openstreetmap($config); |
| 75 |
1 |
$node = $osm->getNode($id, 2); |
| 76 |
1 |
$getTags = $node->getTags(); |
| 77 |
|
|
| 78 |
1 |
$this->assertEquals($id, $node->getId()); |
| 79 |
1 |
$this->assertEquals($getTags['name'], 'Nenagh Bridge'); |
| 80 |
1 |
$this->assertEquals("52.881667", $node->getLat()); |
| 81 |
1 |
$this->assertEquals("-8.195833", $node->getLon()); |
| 82 |
|
} |
| 83 |
|
|
| 84 |
|
public function testGetNode404() |
| 85 |
|
{ |
| 86 |
1 |
$id = 52245107; |
| 87 |
|
|
| 88 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 89 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 90 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/404', 'rb')); |
| 91 |
|
|
| 92 |
|
$config = array( |
| 93 |
1 |
'adapter' => $mock, |
| 94 |
|
'server' => 'http://api06.dev.openstreetmap.org/' |
| 95 |
1 |
); |
| 96 |
1 |
$osm = new Services_Openstreetmap($config); |
| 97 |
1 |
$node = $osm->getNode($id); |
| 98 |
1 |
$this->assertFalse($node); |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
public function testGetNode410() |
| 102 |
|
{ |
| 103 |
1 |
$id = 52245107; |
| 104 |
|
|
| 105 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 106 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 107 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/410', 'rb')); |
| 108 |
|
|
| 109 |
|
$config = array( |
| 110 |
1 |
'adapter' => $mock, |
| 111 |
|
'server' => 'http://api06.dev.openstreetmap.org/' |
| 112 |
1 |
); |
| 113 |
1 |
$osm = new Services_Openstreetmap($config); |
| 114 |
1 |
$node = $osm->getNode($id); |
| 115 |
1 |
$this->assertFalse($node); |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
/** |
| 119 |
|
* Test how a 500 status code is handled. |
| 120 |
|
* |
| 121 |
|
* @expectedException Services_Openstreetmap_Exception |
| 122 |
|
* @expectedExceptionMessage Unexpected HTTP status: 500 Internal Server Error |
| 123 |
|
*/ |
| 124 |
|
public function testGetNode500() |
| 125 |
|
{ |
| 126 |
1 |
$id = 52245107; |
| 127 |
|
|
| 128 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 129 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 130 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/500', 'rb')); |
| 131 |
|
|
| 132 |
|
$config = array( |
| 133 |
1 |
'adapter' => $mock, |
| 134 |
|
'server' => 'http://api06.dev.openstreetmap.org/' |
| 135 |
1 |
); |
| 136 |
1 |
$osm = new Services_Openstreetmap($config); |
| 137 |
1 |
$node = $osm->getNode($id); |
| 138 |
|
} |
| 139 |
|
|
| 140 |
|
public function testCreateNode() |
| 141 |
|
{ |
| 142 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 143 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 144 |
|
|
| 145 |
|
$config = array( |
| 146 |
1 |
'adapter' => $mock, |
| 147 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 148 |
1 |
); |
| 149 |
1 |
$osm = new Services_Openstreetmap($config); |
| 150 |
1 |
$lat = 52.8638729; |
| 151 |
1 |
$lon = -8.1983611; |
| 152 |
1 |
$node = $osm->createNode($lat, $lon, array( |
| 153 |
1 |
'building' => 'yes', |
| 154 |
1 |
'amenity' => 'vet') |
| 155 |
1 |
); |
| 156 |
1 |
$this->assertEquals('', ($node->getUser())); |
| 157 |
1 |
$this->assertEquals(1, $node->getVersion()); |
| 158 |
1 |
$this->assertEquals(-1, $node->getId()); |
| 159 |
1 |
$this->assertEquals( |
| 160 |
1 |
$node->getTags(), |
| 161 |
|
array( |
| 162 |
1 |
'created_by' => 'Services_Openstreetmap', |
| 163 |
1 |
'building' => 'yes', |
| 164 |
1 |
'amenity' => 'vet', |
| 165 |
|
) |
| 166 |
1 |
); |
| 167 |
1 |
$this->assertEquals($lat, $node->getlat()); |
| 168 |
1 |
$this->assertEquals($lon, $node->getlon()); |
| 169 |
1 |
$this->assertEquals(-1, $node->getId()); |
| 170 |
|
} |
| 171 |
|
|
| 172 |
|
/** |
| 173 |
|
* Test invalid latitude value in constructor |
| 174 |
|
* |
| 175 |
|
* @expectedException InvalidArgumentException |
| 176 |
|
* @expectedExceptionMessage Latitude can't be greater than 180 |
| 177 |
|
*/ |
| 178 |
|
public function testCreateNodeInvalidLatitude() |
| 179 |
|
{ |
| 180 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 181 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 182 |
|
|
| 183 |
|
$config = array( |
| 184 |
1 |
'adapter' => $mock, |
| 185 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 186 |
1 |
); |
| 187 |
1 |
$osm = new Services_Openstreetmap($config); |
| 188 |
1 |
$lat = 252.8638729; |
| 189 |
1 |
$lon = -8.1983611; |
| 190 |
1 |
$node = $osm->createNode($lat, $lon); |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
/** |
| 194 |
|
* Test invalid latitude value in constructor |
| 195 |
|
* |
| 196 |
|
* @expectedException InvalidArgumentException |
| 197 |
|
* @expectedExceptionMessage Latitude can't be less than -180 |
| 198 |
|
*/ |
| 199 |
|
public function testCreateNodeInvalidLessThanMinus90() |
| 200 |
|
{ |
| 201 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 202 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 203 |
|
|
| 204 |
|
$config = array( |
| 205 |
1 |
'adapter' => $mock, |
| 206 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 207 |
1 |
); |
| 208 |
1 |
$osm = new Services_Openstreetmap($config); |
| 209 |
1 |
$lat = -180.000010123; |
| 210 |
1 |
$lon = -8.1983611; |
| 211 |
1 |
$node = $osm->createNode($lat, $lon); |
| 212 |
|
} |
| 213 |
|
|
| 214 |
|
/** |
| 215 |
|
* Test invalid latitude value in constructor |
| 216 |
|
* |
| 217 |
|
* @expectedException InvalidArgumentException |
| 218 |
|
* @expectedExceptionMessage Latitude must be numeric |
| 219 |
|
*/ |
| 220 |
|
public function testCreateNodeNonnumericLatInConstructor() |
| 221 |
|
{ |
| 222 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 223 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 224 |
|
|
| 225 |
|
$config = array( |
| 226 |
1 |
'adapter' => $mock, |
| 227 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 228 |
1 |
); |
| 229 |
1 |
$osm = new Services_Openstreetmap($config); |
| 230 |
1 |
$lat = 'ArticCircle'; |
| 231 |
1 |
$lon = -8.1983611; |
| 232 |
1 |
$node = $osm->createNode($lat, $lon); |
| 233 |
|
} |
| 234 |
|
|
| 235 |
|
|
| 236 |
|
/** |
| 237 |
|
* Test invalid longitude value in constructor |
| 238 |
|
* |
| 239 |
|
* @expectedException InvalidArgumentException |
| 240 |
|
* @expectedExceptionMessage Longitude can't be greater than 90 |
| 241 |
|
*/ |
| 242 |
|
public function testCreateNodeInvalidLongitude() |
| 243 |
|
{ |
| 244 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 245 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 246 |
|
|
| 247 |
|
$config = array( |
| 248 |
1 |
'adapter' => $mock, |
| 249 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 250 |
1 |
); |
| 251 |
1 |
$osm = new Services_Openstreetmap($config); |
| 252 |
1 |
$lat = 52.8638729; |
| 253 |
1 |
$lon = 90.1983611; |
| 254 |
1 |
$node = $osm->createNode($lat, $lon); |
| 255 |
|
} |
| 256 |
|
|
| 257 |
|
/** |
| 258 |
|
* Test invalid longitude value in constructor |
| 259 |
|
* |
| 260 |
|
* @expectedException InvalidArgumentException |
| 261 |
|
* @expectedExceptionMessage Longitude can't be less than -90 |
| 262 |
|
*/ |
| 263 |
|
public function testCreateNodeInvalidLongitudeLessThanMinus90() |
| 264 |
|
{ |
| 265 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 266 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 267 |
|
|
| 268 |
|
$config = array( |
| 269 |
1 |
'adapter' => $mock, |
| 270 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 271 |
1 |
); |
| 272 |
1 |
$osm = new Services_Openstreetmap($config); |
| 273 |
1 |
$lat = 52.8638729; |
| 274 |
1 |
$lon = -90.1983611; |
| 275 |
1 |
$node = $osm->createNode($lat, $lon); |
| 276 |
|
} |
| 277 |
|
|
| 278 |
|
/** |
| 279 |
|
* Test invalid longitude value in constructor |
| 280 |
|
* |
| 281 |
|
* @expectedException InvalidArgumentException |
| 282 |
|
* @expectedExceptionMessage Longitude must be numeric |
| 283 |
|
*/ |
| 284 |
|
public function testCreateNodeNonnumericLonInConstructor() |
| 285 |
|
{ |
| 286 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 287 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 288 |
|
|
| 289 |
|
$config = array( |
| 290 |
1 |
'adapter' => $mock, |
| 291 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 292 |
1 |
); |
| 293 |
1 |
$osm = new Services_Openstreetmap($config); |
| 294 |
1 |
$lat = 52.8638729; |
| 295 |
1 |
$lon = 'TheBlessing'; |
| 296 |
1 |
$node = $osm->createNode($lat, $lon); |
| 297 |
|
} |
| 298 |
|
|
| 299 |
|
public function testGetNodes() |
| 300 |
|
{ |
| 301 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 302 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 303 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/nodes_621953926_621953928_621953939.xml', 'rb')); |
| 304 |
|
|
| 305 |
|
$config = array( |
| 306 |
1 |
'adapter' => $mock, |
| 307 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 308 |
1 |
); |
| 309 |
1 |
$osm = new Services_Openstreetmap($config); |
| 310 |
1 |
$nodes = $osm->getNodes(array(621953926,621953928,621953939)); |
| 311 |
1 |
$this->assertEquals(3, sizeof($nodes)); |
| 312 |
|
|
| 313 |
|
$nodes_info = array( |
| 314 |
1 |
array('id' => 621953926, 'source' => 'survey', 'address' => null), |
| 315 |
1 |
array('id' => 621953928, 'source' => 'survey', 'address' => null), |
| 316 |
|
array( |
| 317 |
1 |
'id' => 621953939, |
| 318 |
1 |
'source' => 'survey', |
| 319 |
|
'address' => array ( |
| 320 |
1 |
'addr_housename' => NULL, |
| 321 |
1 |
'addr_housenumber' => '5', |
| 322 |
1 |
'addr_street' => 'Castle Street', |
| 323 |
1 |
'addr_city' => 'Cahir', |
| 324 |
|
'addr_country' => 'IE' |
| 325 |
1 |
) |
| 326 |
1 |
) |
| 327 |
1 |
); |
| 328 |
1 |
foreach($nodes as $key=>$node) { |
| 329 |
1 |
$tags = $node->getTags(); |
| 330 |
1 |
$this->assertEquals($node->getId(), $nodes_info[$key]['id']); |
| 331 |
1 |
$this->assertEquals($tags['source'], $nodes_info[$key]['source']); |
| 332 |
1 |
$this->assertEquals($node->getAddress(), $nodes_info[$key]['address']); |
| 333 |
1 |
} |
| 334 |
|
} |
| 335 |
|
|
| 336 |
|
public function testGetNodes401() |
| 337 |
|
{ |
| 338 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 339 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 340 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/401', 'rb')); |
| 341 |
|
|
| 342 |
|
$config = array( |
| 343 |
1 |
'adapter' => $mock, |
| 344 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 345 |
1 |
); |
| 346 |
1 |
$osm = new Services_Openstreetmap($config); |
| 347 |
1 |
$nodes = $osm->getNodes(array(621953926,621953928,621953939)); |
| 348 |
1 |
$this->assertFalse($nodes); |
| 349 |
|
} |
| 350 |
|
|
| 351 |
|
public function testGetNodes404() |
| 352 |
|
{ |
| 353 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 354 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 355 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/404', 'rb')); |
| 356 |
|
|
| 357 |
|
$config = array( |
| 358 |
1 |
'adapter' => $mock, |
| 359 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 360 |
1 |
); |
| 361 |
1 |
$osm = new Services_Openstreetmap($config); |
| 362 |
1 |
$nodes = $osm->getNodes(array(621953926,621953928,621953939)); |
| 363 |
1 |
$this->assertFalse($nodes); |
| 364 |
|
} |
| 365 |
|
|
| 366 |
|
public function testGetNodes410() |
| 367 |
|
{ |
| 368 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 369 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 370 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/410', 'rb')); |
| 371 |
|
|
| 372 |
|
$config = array( |
| 373 |
1 |
'adapter' => $mock, |
| 374 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 375 |
1 |
); |
| 376 |
1 |
$osm = new Services_Openstreetmap($config); |
| 377 |
1 |
$nodes = $osm->getNodes(array(621953926,621953928,621953939)); |
| 378 |
1 |
$this->assertFalse($nodes); |
| 379 |
|
} |
| 380 |
|
|
| 381 |
|
/** |
| 382 |
|
* Test how a 500 status code is handled. |
| 383 |
|
* |
| 384 |
|
* @expectedException Services_Openstreetmap_Exception |
| 385 |
|
* @expectedExceptionMessage Unexpected HTTP status: 500 Internal Server Error |
| 386 |
|
*/ |
| 387 |
|
public function testGetNodes500() |
| 388 |
|
{ |
| 389 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 390 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 391 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/500', 'rb')); |
| 392 |
|
|
| 393 |
|
$config = array( |
| 394 |
1 |
'adapter' => $mock, |
| 395 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 396 |
1 |
); |
| 397 |
1 |
$osm = new Services_Openstreetmap($config); |
| 398 |
1 |
$nodes = $osm->getNodes(array(621953926,621953928,621953939)); |
| 399 |
|
} |
| 400 |
|
|
| 401 |
|
public function testGetNodesHistory() |
| 402 |
|
{ |
| 403 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 404 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 405 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/nodes_621953926_621953928_621953939.xml', 'rb')); |
| 406 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/node_621953926.xml', 'rb')); |
| 407 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/node_621953928.xml', 'rb')); |
| 408 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/node_621953939_history.xml', 'rb')); |
| 409 |
|
|
| 410 |
|
$config = array( |
| 411 |
1 |
'adapter' => $mock, |
| 412 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 413 |
1 |
); |
| 414 |
1 |
$osm = new Services_Openstreetmap($config); |
| 415 |
1 |
$nodes = $osm->getNodes(array(621953926, 621953928, 621953939)); |
| 416 |
|
$versions = array( |
| 417 |
1 |
621953926 => array(1), |
| 418 |
1 |
621953928 => array(1), |
| 419 |
1 |
621953939 => array(1, 2) |
| 420 |
1 |
); |
| 421 |
1 |
foreach ($nodes as $node) { |
| 422 |
1 |
$history = $node->history(); |
| 423 |
1 |
$id = $node->getId(); |
| 424 |
1 |
foreach ($history as $item) { |
| 425 |
1 |
$version = $item->getVersion(); |
| 426 |
1 |
$this->assertEquals(true, in_array($version, $versions[$id])); |
| 427 |
1 |
} |
| 428 |
1 |
} |
| 429 |
|
} |
| 430 |
|
|
| 431 |
|
public function testGetWayBackRef() |
| 432 |
|
{ |
| 433 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 434 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 435 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/node_248081837.xml', 'rb')); |
| 436 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/way_23010474.xml', 'rb')); |
| 437 |
|
|
| 438 |
|
$config = array( |
| 439 |
1 |
'adapter' => $mock, |
| 440 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 441 |
1 |
); |
| 442 |
|
|
| 443 |
1 |
$osm = new Services_Openstreetmap($config); |
| 444 |
|
|
| 445 |
1 |
$ways = $osm->getNode(248081837)->getWays(); |
| 446 |
1 |
$this->assertInstanceOf('Services_Openstreetmap_Ways', $ways); |
| 447 |
1 |
$this->assertEquals(sizeof($ways), 1); |
| 448 |
1 |
$this->assertEquals($ways[0]->getTags(), array ( |
| 449 |
1 |
'highway' => 'residential', |
| 450 |
1 |
'maxspeed' => '50', |
| 451 |
1 |
'name' => 'Kingston Park', |
| 452 |
1 |
'name:en' => 'Kingston Park', |
| 453 |
1 |
'name:ga' => 'Páirc Kingston', |
| 454 |
1 |
)); |
| 455 |
|
} |
| 456 |
|
|
| 457 |
|
public function testGetRelations() |
| 458 |
|
{ |
| 459 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 460 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 461 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/node_597697114.xml', 'rb')); |
| 462 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/relation_405053.xml', 'rb')); |
| 463 |
|
|
| 464 |
|
$config = array( |
| 465 |
1 |
'adapter' => $mock, |
| 466 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 467 |
1 |
); |
| 468 |
|
|
| 469 |
1 |
$osm = new Services_Openstreetmap($config); |
| 470 |
|
|
| 471 |
1 |
$relations = $osm->getNode(597697114)->getRelations(); |
| 472 |
1 |
$this->assertInstanceOf('Services_Openstreetmap_Relations', $relations); |
| 473 |
1 |
$this->assertEquals(sizeof($relations), 1); |
| 474 |
1 |
$this->assertInstanceOf('Services_Openstreetmap_Relation', $relations[0]); |
| 475 |
1 |
$this->assertEquals($relations[0]->getTags(), array ( |
| 476 |
1 |
'complete'=> 'no', |
| 477 |
1 |
'name'=> 'Dublin Bus route 75', |
| 478 |
1 |
'operator'=> 'Dublin Bus', |
| 479 |
1 |
'ref'=> '75', |
| 480 |
1 |
'route'=> 'bus', |
| 481 |
1 |
'type'=> 'route', |
| 482 |
1 |
)); |
| 483 |
|
} |
| 484 |
|
} |
| 485 |
|
|
| 486 |
|
?> |