| 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 |
|
/** |
| 41 |
|
* Test the getNodee method. |
| 42 |
|
* |
| 43 |
|
* @return void |
| 44 |
|
*/ |
| 45 |
|
public function testGetNode() |
| 46 |
|
{ |
| 47 |
1 |
$id = 52245107; |
| 48 |
|
|
| 49 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 50 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 51 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/node.xml', 'rb')); |
| 52 |
|
|
| 53 |
|
$config = array( |
| 54 |
1 |
'adapter' => $mock, |
| 55 |
|
'server' => 'http://api06.dev.openstreetmap.org/' |
| 56 |
1 |
); |
| 57 |
1 |
$osm = new Services_OpenStreetMap($config); |
| 58 |
1 |
$node = $osm->getNode($id); |
| 59 |
1 |
$getTags = $node->getTags(); |
| 60 |
|
|
| 61 |
1 |
$this->assertEquals($id, $node->getId()); |
| 62 |
1 |
$this->assertEquals($getTags['name'], 'Nenagh Bridge'); |
| 63 |
1 |
$this->assertEquals("52.881667", $node->getLat()); |
| 64 |
1 |
$this->assertEquals("-8.195833", $node->getLon()); |
| 65 |
|
} |
| 66 |
|
|
| 67 |
|
/** |
| 68 |
|
* Test retrieving a specific version of an identified node. |
| 69 |
|
* |
| 70 |
|
* @return void |
| 71 |
|
*/ |
| 72 |
|
public function testGetSpecifiedVersionOfNode() |
| 73 |
|
{ |
| 74 |
1 |
$id = 52245107; |
| 75 |
|
|
| 76 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 77 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 78 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/node.xml', 'rb')); |
| 79 |
|
|
| 80 |
|
$config = array( |
| 81 |
1 |
'adapter' => $mock, |
| 82 |
|
'server' => 'http://api06.dev.openstreetmap.org/' |
| 83 |
1 |
); |
| 84 |
1 |
$osm = new Services_OpenStreetMap($config); |
| 85 |
1 |
$node = $osm->getNode($id, 2); |
| 86 |
1 |
$getTags = $node->getTags(); |
| 87 |
|
|
| 88 |
1 |
$this->assertEquals($id, $node->getId()); |
| 89 |
1 |
$this->assertEquals($getTags['name'], 'Nenagh Bridge'); |
| 90 |
1 |
$this->assertEquals("52.881667", $node->getLat()); |
| 91 |
1 |
$this->assertEquals("-8.195833", $node->getLon()); |
| 92 |
|
} |
| 93 |
|
|
| 94 |
|
/** |
| 95 |
|
* When a 404 response is issued by the server, the getNode method |
| 96 |
|
* should return the boolean false value. |
| 97 |
|
* |
| 98 |
|
* @return void |
| 99 |
|
*/ |
| 100 |
|
public function testGetNode404() |
| 101 |
|
{ |
| 102 |
1 |
$id = 52245107; |
| 103 |
|
|
| 104 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 105 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 106 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/404', 'rb')); |
| 107 |
|
|
| 108 |
|
$config = array( |
| 109 |
1 |
'adapter' => $mock, |
| 110 |
|
'server' => 'http://api06.dev.openstreetmap.org/' |
| 111 |
1 |
); |
| 112 |
1 |
$osm = new Services_OpenStreetMap($config); |
| 113 |
1 |
$node = $osm->getNode($id); |
| 114 |
1 |
$this->assertFalse($node); |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
/** |
| 118 |
|
* When a 'GONE' response is issued by the server, the getNode method |
| 119 |
|
* should return the boolean false value. |
| 120 |
|
* |
| 121 |
|
* @return void |
| 122 |
|
*/ |
| 123 |
|
public function testGetNode410() |
| 124 |
|
{ |
| 125 |
1 |
$id = 52245107; |
| 126 |
|
|
| 127 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 128 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 129 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/410', 'rb')); |
| 130 |
|
|
| 131 |
|
$config = array( |
| 132 |
1 |
'adapter' => $mock, |
| 133 |
|
'server' => 'http://api06.dev.openstreetmap.org/' |
| 134 |
1 |
); |
| 135 |
1 |
$osm = new Services_OpenStreetMap($config); |
| 136 |
1 |
$node = $osm->getNode($id); |
| 137 |
1 |
$this->assertFalse($node); |
| 138 |
|
} |
| 139 |
|
|
| 140 |
|
/** |
| 141 |
|
* Test how a 500 status code is handled. |
| 142 |
|
* |
| 143 |
|
* @expectedException Services_OpenStreetMap_Exception |
| 144 |
|
* @expectedExceptionMessage Unexpected HTTP status: 500 Internal Server Error |
| 145 |
|
* |
| 146 |
|
* @return void |
| 147 |
|
*/ |
| 148 |
|
public function testGetNode500() |
| 149 |
|
{ |
| 150 |
1 |
$id = 52245107; |
| 151 |
|
|
| 152 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 153 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 154 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/500', 'rb')); |
| 155 |
|
|
| 156 |
|
$config = array( |
| 157 |
1 |
'adapter' => $mock, |
| 158 |
|
'server' => 'http://api06.dev.openstreetmap.org/' |
| 159 |
1 |
); |
| 160 |
1 |
$osm = new Services_OpenStreetMap($config); |
| 161 |
1 |
$node = $osm->getNode($id); |
| 162 |
|
} |
| 163 |
|
|
| 164 |
|
/** |
| 165 |
|
* Test creating a node with the createNode method, including default and |
| 166 |
|
* explicitly set values. |
| 167 |
|
* |
| 168 |
|
* @return void |
| 169 |
|
*/ |
| 170 |
|
public function testCreateNode() |
| 171 |
|
{ |
| 172 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 173 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 174 |
|
|
| 175 |
|
$config = array( |
| 176 |
1 |
'adapter' => $mock, |
| 177 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 178 |
1 |
); |
| 179 |
1 |
$osm = new Services_OpenStreetMap($config); |
| 180 |
1 |
$lat = 52.8638729; |
| 181 |
1 |
$lon = -8.1983611; |
| 182 |
1 |
$node = $osm->createNode( |
| 183 |
1 |
$lat, |
| 184 |
1 |
$lon, |
| 185 |
|
array( |
| 186 |
1 |
'building' => 'yes', |
| 187 |
|
'amenity' => 'vet' |
| 188 |
1 |
) |
| 189 |
1 |
); |
| 190 |
1 |
$this->assertEquals('', ($node->getUser())); |
| 191 |
1 |
$this->assertEquals(1, $node->getVersion()); |
| 192 |
1 |
$this->assertEquals(-1, $node->getId()); |
| 193 |
1 |
$this->assertEquals( |
| 194 |
1 |
$node->getTags(), |
| 195 |
|
array( |
| 196 |
1 |
'created_by' => 'Services_OpenStreetMap', |
| 197 |
1 |
'building' => 'yes', |
| 198 |
1 |
'amenity' => 'vet', |
| 199 |
|
) |
| 200 |
1 |
); |
| 201 |
1 |
$this->assertEquals($lat, $node->getlat()); |
| 202 |
1 |
$this->assertEquals($lon, $node->getlon()); |
| 203 |
1 |
$this->assertEquals(-1, $node->getId()); |
| 204 |
|
} |
| 205 |
|
|
| 206 |
|
/** |
| 207 |
|
* Test invalid latitude value in constructor |
| 208 |
|
* |
| 209 |
|
* @expectedException InvalidArgumentException |
| 210 |
|
* @expectedExceptionMessage Latitude can't be greater than 180 |
| 211 |
|
* |
| 212 |
|
* @return void |
| 213 |
|
*/ |
| 214 |
|
public function testCreateNodeInvalidLatitude() |
| 215 |
|
{ |
| 216 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 217 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 218 |
|
|
| 219 |
|
$config = array( |
| 220 |
1 |
'adapter' => $mock, |
| 221 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 222 |
1 |
); |
| 223 |
1 |
$osm = new Services_OpenStreetMap($config); |
| 224 |
1 |
$lat = 252.8638729; |
| 225 |
1 |
$lon = -8.1983611; |
| 226 |
1 |
$node = $osm->createNode($lat, $lon); |
| 227 |
|
} |
| 228 |
|
|
| 229 |
|
/** |
| 230 |
|
* Test invalid latitude value in constructor |
| 231 |
|
* |
| 232 |
|
* @expectedException InvalidArgumentException |
| 233 |
|
* @expectedExceptionMessage Latitude can't be less than -180 |
| 234 |
|
* |
| 235 |
|
* @return void |
| 236 |
|
*/ |
| 237 |
|
public function testCreateNodeInvalidLessThanMinus90() |
| 238 |
|
{ |
| 239 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 240 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 241 |
|
|
| 242 |
|
$config = array( |
| 243 |
1 |
'adapter' => $mock, |
| 244 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 245 |
1 |
); |
| 246 |
1 |
$osm = new Services_OpenStreetMap($config); |
| 247 |
1 |
$lat = -180.000010123; |
| 248 |
1 |
$lon = -8.1983611; |
| 249 |
1 |
$node = $osm->createNode($lat, $lon); |
| 250 |
|
} |
| 251 |
|
|
| 252 |
|
/** |
| 253 |
|
* Test invalid latitude value in constructor |
| 254 |
|
* |
| 255 |
|
* @expectedException InvalidArgumentException |
| 256 |
|
* @expectedExceptionMessage Latitude must be numeric |
| 257 |
|
* |
| 258 |
|
* @return void |
| 259 |
|
*/ |
| 260 |
|
public function testCreateNodeNonnumericLatInConstructor() |
| 261 |
|
{ |
| 262 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 263 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 264 |
|
|
| 265 |
|
$config = array( |
| 266 |
1 |
'adapter' => $mock, |
| 267 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 268 |
1 |
); |
| 269 |
1 |
$osm = new Services_OpenStreetMap($config); |
| 270 |
1 |
$lat = 'ArticCircle'; |
| 271 |
1 |
$lon = -8.1983611; |
| 272 |
1 |
$node = $osm->createNode($lat, $lon); |
| 273 |
|
} |
| 274 |
|
|
| 275 |
|
|
| 276 |
|
/** |
| 277 |
|
* Test invalid longitude value in constructor |
| 278 |
|
* |
| 279 |
|
* @expectedException InvalidArgumentException |
| 280 |
|
* @expectedExceptionMessage Longitude can't be greater than 90 |
| 281 |
|
* |
| 282 |
|
* @return void |
| 283 |
|
*/ |
| 284 |
|
public function testCreateNodeInvalidLongitude() |
| 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 = 90.1983611; |
| 296 |
1 |
$node = $osm->createNode($lat, $lon); |
| 297 |
|
} |
| 298 |
|
|
| 299 |
|
/** |
| 300 |
|
* Test invalid longitude value in constructor |
| 301 |
|
* |
| 302 |
|
* @expectedException InvalidArgumentException |
| 303 |
|
* @expectedExceptionMessage Longitude can't be less than -90 |
| 304 |
|
* |
| 305 |
|
* @return void |
| 306 |
|
*/ |
| 307 |
|
public function testCreateNodeInvalidLongitudeLessThanMinus90() |
| 308 |
|
{ |
| 309 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 310 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 311 |
|
|
| 312 |
|
$config = array( |
| 313 |
1 |
'adapter' => $mock, |
| 314 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 315 |
1 |
); |
| 316 |
1 |
$osm = new Services_OpenStreetMap($config); |
| 317 |
1 |
$lat = 52.8638729; |
| 318 |
1 |
$lon = -90.1983611; |
| 319 |
1 |
$node = $osm->createNode($lat, $lon); |
| 320 |
|
} |
| 321 |
|
|
| 322 |
|
/** |
| 323 |
|
* Test invalid longitude value in constructor |
| 324 |
|
* |
| 325 |
|
* @expectedException InvalidArgumentException |
| 326 |
|
* @expectedExceptionMessage Longitude must be numeric |
| 327 |
|
* @return void |
| 328 |
|
*/ |
| 329 |
|
public function testCreateNodeNonnumericLonInConstructor() |
| 330 |
|
{ |
| 331 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 332 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 333 |
|
|
| 334 |
|
$config = array( |
| 335 |
1 |
'adapter' => $mock, |
| 336 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 337 |
1 |
); |
| 338 |
1 |
$osm = new Services_OpenStreetMap($config); |
| 339 |
1 |
$lat = 52.8638729; |
| 340 |
1 |
$lon = 'TheBlessing'; |
| 341 |
1 |
$node = $osm->createNode($lat, $lon); |
| 342 |
|
} |
| 343 |
|
|
| 344 |
|
/** |
| 345 |
|
* test retrieving a number of nodes simultaneously with the getNodes |
| 346 |
|
* method. |
| 347 |
|
* |
| 348 |
|
* @return void |
| 349 |
|
*/ |
| 350 |
|
public function testGetNodes() |
| 351 |
|
{ |
| 352 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 353 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 354 |
1 |
$mock->addResponse( |
| 355 |
1 |
fopen( |
| 356 |
1 |
__DIR__ . '/responses/nodes_621953926_621953928_621953939.xml', |
| 357 |
|
'rb' |
| 358 |
1 |
) |
| 359 |
1 |
); |
| 360 |
|
|
| 361 |
|
$config = array( |
| 362 |
1 |
'adapter' => $mock, |
| 363 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 364 |
1 |
); |
| 365 |
1 |
$osm = new Services_OpenStreetMap($config); |
| 366 |
1 |
$nodes = $osm->getNodes(array(621953926, 621953928, 621953939)); |
| 367 |
1 |
$this->assertEquals(3, sizeof($nodes)); |
| 368 |
|
|
| 369 |
|
$nodesInfo = array( |
| 370 |
1 |
array('id' => 621953926, 'source' => 'survey', 'address' => null), |
| 371 |
1 |
array('id' => 621953928, 'source' => 'survey', 'address' => null), |
| 372 |
|
array( |
| 373 |
1 |
'id' => 621953939, |
| 374 |
1 |
'source' => 'survey', |
| 375 |
|
'address' => array ( |
| 376 |
1 |
'addr_housename' => null, |
| 377 |
1 |
'addr_housenumber' => '5', |
| 378 |
1 |
'addr_street' => 'Castle Street', |
| 379 |
1 |
'addr_city' => 'Cahir', |
| 380 |
|
'addr_country' => 'IE' |
| 381 |
1 |
) |
| 382 |
1 |
) |
| 383 |
1 |
); |
| 384 |
1 |
foreach ($nodes as $key => $node) { |
| 385 |
1 |
$tags = $node->getTags(); |
| 386 |
1 |
$this->assertEquals($node->getId(), $nodesInfo[$key]['id']); |
| 387 |
1 |
$this->assertEquals($tags['source'], $nodesInfo[$key]['source']); |
| 388 |
1 |
$this->assertEquals($node->getAddress(), $nodesInfo[$key]['address']); |
| 389 |
1 |
} |
| 390 |
|
} |
| 391 |
|
|
| 392 |
|
/** |
| 393 |
|
* When an 'UNAUTHORISED' response is issued by the server, the getNodes method |
| 394 |
|
* should return the boolean false value. |
| 395 |
|
* |
| 396 |
|
* @return void |
| 397 |
|
*/ |
| 398 |
|
public function testGetNodes401() |
| 399 |
|
{ |
| 400 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 401 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 402 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/401', 'rb')); |
| 403 |
|
|
| 404 |
|
$config = array( |
| 405 |
1 |
'adapter' => $mock, |
| 406 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 407 |
1 |
); |
| 408 |
1 |
$osm = new Services_OpenStreetMap($config); |
| 409 |
1 |
$nodes = $osm->getNodes(array(621953926, 621953928, 621953939)); |
| 410 |
1 |
$this->assertFalse($nodes); |
| 411 |
|
} |
| 412 |
|
|
| 413 |
|
/** |
| 414 |
|
* When a 404 response is issued by the server, the getNodes method |
| 415 |
|
* should return the boolean false value. |
| 416 |
|
* |
| 417 |
|
* @return void |
| 418 |
|
*/ |
| 419 |
|
public function testGetNodes404() |
| 420 |
|
{ |
| 421 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 422 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 423 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/404', 'rb')); |
| 424 |
|
|
| 425 |
|
$config = array( |
| 426 |
1 |
'adapter' => $mock, |
| 427 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 428 |
1 |
); |
| 429 |
1 |
$osm = new Services_OpenStreetMap($config); |
| 430 |
1 |
$nodes = $osm->getNodes(array(621953926, 621953928, 621953939)); |
| 431 |
1 |
$this->assertFalse($nodes); |
| 432 |
|
} |
| 433 |
|
|
| 434 |
|
/** |
| 435 |
|
* When a 'GONE' response is issued by the server, the getNodes method |
| 436 |
|
* should return the boolean false value. |
| 437 |
|
* |
| 438 |
|
* @return void |
| 439 |
|
*/ |
| 440 |
|
public function testGetNodes410() |
| 441 |
|
{ |
| 442 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 443 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 444 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/410', 'rb')); |
| 445 |
|
|
| 446 |
|
$config = array( |
| 447 |
1 |
'adapter' => $mock, |
| 448 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 449 |
1 |
); |
| 450 |
1 |
$osm = new Services_OpenStreetMap($config); |
| 451 |
1 |
$nodes = $osm->getNodes(array(621953926, 621953928, 621953939)); |
| 452 |
1 |
$this->assertFalse($nodes); |
| 453 |
|
} |
| 454 |
|
|
| 455 |
|
/** |
| 456 |
|
* Test how a 500 status code is handled. |
| 457 |
|
* |
| 458 |
|
* @expectedException Services_OpenStreetMap_Exception |
| 459 |
|
* @expectedExceptionMessage Unexpected HTTP status: 500 Internal Server Error |
| 460 |
|
* @return void |
| 461 |
|
*/ |
| 462 |
|
public function testGetNodes500() |
| 463 |
|
{ |
| 464 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 465 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 466 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/500', 'rb')); |
| 467 |
|
|
| 468 |
|
$config = array( |
| 469 |
1 |
'adapter' => $mock, |
| 470 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 471 |
1 |
); |
| 472 |
1 |
$osm = new Services_OpenStreetMap($config); |
| 473 |
1 |
$nodes = $osm->getNodes(array(621953926, 621953928, 621953939)); |
| 474 |
|
} |
| 475 |
|
|
| 476 |
|
/** |
| 477 |
|
* Test retrieving all versions, current and past, of a specified node. |
| 478 |
|
* |
| 479 |
|
* @return void |
| 480 |
|
*/ |
| 481 |
|
public function testGetNodesHistory() |
| 482 |
|
{ |
| 483 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 484 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 485 |
1 |
$mock->addResponse( |
| 486 |
1 |
fopen( |
| 487 |
1 |
__DIR__ . '/responses/nodes_621953926_621953928_621953939.xml', |
| 488 |
|
'rb' |
| 489 |
1 |
) |
| 490 |
1 |
); |
| 491 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/node_621953926.xml', 'rb')); |
| 492 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/node_621953928.xml', 'rb')); |
| 493 |
1 |
$mock->addResponse( |
| 494 |
1 |
fopen(__DIR__ . '/responses/node_621953939_history.xml', 'rb') |
| 495 |
1 |
); |
| 496 |
|
|
| 497 |
|
$config = array( |
| 498 |
1 |
'adapter' => $mock, |
| 499 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 500 |
1 |
); |
| 501 |
1 |
$osm = new Services_OpenStreetMap($config); |
| 502 |
1 |
$nodes = $osm->getNodes(array(621953926, 621953928, 621953939)); |
| 503 |
|
$versions = array( |
| 504 |
1 |
621953926 => array(1), |
| 505 |
1 |
621953928 => array(1), |
| 506 |
1 |
621953939 => array(1, 2) |
| 507 |
1 |
); |
| 508 |
1 |
foreach ($nodes as $node) { |
| 509 |
1 |
$history = $node->history(); |
| 510 |
1 |
$id = $node->getId(); |
| 511 |
1 |
foreach ($history as $item) { |
| 512 |
1 |
$version = $item->getVersion(); |
| 513 |
1 |
$this->assertEquals(true, in_array($version, $versions[$id])); |
| 514 |
1 |
} |
| 515 |
1 |
} |
| 516 |
|
} |
| 517 |
|
|
| 518 |
|
/** |
| 519 |
|
* Test retrieving way back references - i.e. retrieving all ways that a |
| 520 |
|
* specific node is connected to. |
| 521 |
|
* |
| 522 |
|
* @return void |
| 523 |
|
*/ |
| 524 |
|
public function testGetWayBackRef() |
| 525 |
|
{ |
| 526 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 527 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 528 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/node_248081837.xml', 'rb')); |
| 529 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/way_23010474.xml', 'rb')); |
| 530 |
|
|
| 531 |
|
$config = array( |
| 532 |
1 |
'adapter' => $mock, |
| 533 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 534 |
1 |
); |
| 535 |
|
|
| 536 |
1 |
$osm = new Services_OpenStreetMap($config); |
| 537 |
|
|
| 538 |
1 |
$ways = $osm->getNode(248081837)->getWays(); |
| 539 |
1 |
$this->assertInstanceOf('Services_OpenStreetMap_Ways', $ways); |
| 540 |
1 |
$this->assertEquals(sizeof($ways), 1); |
| 541 |
1 |
$this->assertEquals( |
| 542 |
1 |
$ways[0]->getTags(), |
| 543 |
|
array ( |
| 544 |
1 |
'highway' => 'residential', |
| 545 |
1 |
'maxspeed' => '50', |
| 546 |
1 |
'name' => 'Kingston Park', |
| 547 |
1 |
'name:en' => 'Kingston Park', |
| 548 |
1 |
'name:ga' => 'Páirc Kingston', |
| 549 |
|
) |
| 550 |
1 |
); |
| 551 |
|
} |
| 552 |
|
|
| 553 |
|
/** |
| 554 |
|
* Test retrieving relations that refer to a specific node. |
| 555 |
|
* |
| 556 |
|
* @return void |
| 557 |
|
*/ |
| 558 |
|
public function testGetRelations() |
| 559 |
|
{ |
| 560 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 561 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 562 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/node_597697114.xml', 'rb')); |
| 563 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/relation_405053.xml', 'rb')); |
| 564 |
|
|
| 565 |
|
$config = array( |
| 566 |
1 |
'adapter' => $mock, |
| 567 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 568 |
1 |
); |
| 569 |
|
|
| 570 |
1 |
$osm = new Services_OpenStreetMap($config); |
| 571 |
|
|
| 572 |
1 |
$relations = $osm->getNode(597697114)->getRelations(); |
| 573 |
1 |
$this->assertInstanceOf('Services_OpenStreetMap_Relations', $relations); |
| 574 |
1 |
$this->assertEquals(sizeof($relations), 1); |
| 575 |
1 |
$this->assertInstanceOf('Services_OpenStreetMap_Relation', $relations[0]); |
| 576 |
1 |
$this->assertEquals( |
| 577 |
1 |
$relations[0]->getTags(), |
| 578 |
|
array ( |
| 579 |
1 |
'complete'=> 'no', |
| 580 |
1 |
'name'=> 'Dublin Bus route 75', |
| 581 |
1 |
'operator'=> 'Dublin Bus', |
| 582 |
1 |
'ref'=> '75', |
| 583 |
1 |
'route'=> 'bus', |
| 584 |
1 |
'type'=> 'route', |
| 585 |
|
) |
| 586 |
1 |
); |
| 587 |
|
} |
| 588 |
|
} |
| 589 |
|
|
| 590 |
|
?> |