Commit 225804a1 authored by lyricnz's avatar lyricnz
Browse files

Split simpletest into two executable units

parent 983e26b9
......@@ -13,3 +13,4 @@ files[] = geonames.module
files[] = geonames_config.inc
; files[] = geonames_tools.module
files[] = tests/geonames.test
files[] = tests/geonames.all.test
<?php
// $Id$
/**
* @file
* Tests for geonames module.
*/
class GeoNamesAllTestCase extends DrupalWebTestCase {
/**
* Implementation of getInfo().
*/
function getInfo() {
return array(
'name' => t('GeoNames All'),
'description' => t('Exercise every query supported by the GeoNames module - requires internet access.'),
'group' => t('GeoNames'),
);
}
/**
* Implementation of setUp().
*/
function setUp() {
parent::setUp('geonames');
variable_set('geonames_commercial_active', FALSE);
variable_set('geonames_cache', FALSE);
}
/**
* Make a call to (the real) geonames_query, and keep track of which services
* have been executed in $this->services (an array of service name keys).
* @see geonames_query
*/
function geonames_query($service, $query = array(), $options = NULL) {
unset($this->services[$service]);
return geonames_query($service, $query, $options);
}
function testAllServices() {
// Store a list of services in $this->services so we can "cross them off" as
// each is executed via $this->geonames_query
module_load_include('inc', 'geonames', 'geonames_config');
$this->services = array_flip(geonames_config('services'));
ksort($this->services);
// $this->verbose("All Services: ". join(', ', array_keys($this->services)));
// Test the astergdem service
$query = array('lat' => 50.01, 'lng' => 10.2);
$results = $this->geonames_query('astergdem', $query);
$this->assertEqual($results->total_results_count, 1, t('One result for astergdem service'));
$result = $results->results[0];
$this->assertEqual($result['astergdem'], "192", t('Found expected result for fixed coordinates for astergdem service'));
// Test the "children" service
$query = array('geonameid' => 3175395);
$results = $this->geonames_query('children', $query);
$this->assertTrue($results->total_results_count > 5, t('At least 5 regions found for Italy'));
$all_ok = TRUE;
foreach ($results->results as $result) {
$all_ok = $all_ok && ($result['countrycode'] == 'IT');
}
$this->assert($all_ok, "All regions from 'children' are in Italy");
// Test the "cities" service
$query = array('north' => 44.1, 'south' => -9.9, 'east' => -22.4, 'west' => 55.2, 'maxrows' => 8);
$results = $this->geonames_query('cities', $query);
$this->assertEqual($results->total_results_count, 8, 'Found 8 result from "city"');
$result = $results->results[0];
$this->assertEqual($result['name'], 'Mexico City', t('Found "Mexico City" from "cities"'));
$this->assertEqual($result['countrycode'], 'MX', t('Found MX from "cities"'));
// Test the "countryCode" service
$query = array('lat' => 47.03, 'lng' => 10.2);
$results = $this->geonames_query('countrycode', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "countryCode"');
$result = $results->results[0];
$this->assertEqual($result['countrycode'], 'AT', t('Found "AT" from "countryCode"'));
$this->assertEqual($result['countryname'], 'Austria', t('Found "Austria" from "countryCode"'));
// Test the "countryInfo" service
$query = array('country' => 'DE');
$results = $this->geonames_query('countryinfo', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "countryInfo"');
$result = $results->results[0];
$this->assertEqual($result['countrycode'], 'DE', t('Found "DE" from "countryInfo"'));
$this->assertEqual($result['countryname'], 'Germany', t('Found "Germany" from "countryInfo"'));
$this->assertEqual($result['continent'], 'EU', t('Found "EU" from "countryInfo"'));
// Test the "countrySubdivision" service: Lookup Tyrol, AT by lat/long
$query = array('lat' => 47.03, 'lng' => 10.2);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "countrySubdivision"');
$results = $this->geonames_query('countrysubdivision', $query);
$result = $results->results[0];
$this->assertEqual($result['countrycode'], 'AT', t('Found AT by lat/lng'));
$this->assertEqual($result['countryname'], 'Austria', t('Found Austria by lat/lng'));
$this->assertEqual($result['adminname1'], 'Tyrol', t('Found Tyrol, Austria by lat/lng'));
// Test the "extendedFindNearby" service : US
$query = array('lat' => 37.451, 'lng' => -122.18);
$results = $this->geonames_query('extendedFindNearby', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "extendedFindNearby" A');
$result = $results->results[0];
$this->assertEqual($result['street'], 'Roble Ave', t('Found "Roble Ave" from "extendedFindNearby" A'));
$this->assertEqual($result['streetnumber'], '671', t('Found "61" from "extendedFindNearby" A'));
// Test the "extendedFindNearby" service : other countries
$query = array('lat' => 47.3, 'lng' => 9);
$results = $this->geonames_query('extendedFindNearby', $query);
$this->assertTrue($results->total_results_count >= 5, 'Found at least 5 levels in "extendedFindNearby" B');
$this->assertEqual($results->results[0]['name'], 'Earth', t('Found "Earth" from "extendedFindNearby" B'));
$this->assertEqual($results->results[1]['name'], 'Europe', t('Found "Europe" from "extendedFindNearby" B'));
$this->assertEqual($results->results[2]['name'], 'Switzerland', t('Found "Switzerland" from "extendedFindNearby" B'));
$this->assertEqual($results->results[3]['name'], 'Kanton St. Gallen', t('Found "Kanton St. Gallen" from "extendedFindNearby" B'));
$this->assertEqual($results->results[$results->total_results_count - 1]['geonameid'], 6559633, t('Found (geonameid) "6559633" from "extendedFindNearby" B'));
// Test the "extendedFindNearby" service : ocean
$query = array('lat' => 40.78343, 'lng' => -43.96625);
$results = $this->geonames_query('extendedFindNearby', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "extendedFindNearby" C');
$result = $results->results[0];
$this->assertEqual($result['name'], 'North Atlantic Ocean', t('Found "North Atlantic Ocean" from "extendedFindNearby" C'));
// Test the "findNearByWeather" service
$query = array('lat' => 43, 'lng' => -2);
$results = $this->geonames_query('findNearByWeather', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "findNearByWeather"');
$result = $results->results[0];
$this->assertEqual($result['stationname'], 'San Sebastian / Fuenterrabia', t('Found "San Sebastian / Fuenterrabia" from "findNearByWeather"'));
// Test the "findNearbyStreets" service
$query = array('lat' => 37.451, 'lng' => -122.18);
$results = $this->geonames_query('findNearbyStreets', $query);
$this->assertEqual($results->total_results_count, 10, 'Found 8 result from "findNearbyStreets"');
$result = $results->results[0];
$this->assertEqual($result['name'], 'Roble Ave', t('Found "Roble Ave" from "findNearbyStreets"'));
// Test the "findNearestAddress" service
$query = array('lat' => 37.451, 'lng' => -122.18);
$results = $this->geonames_query('findNearestAddress', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "findNearestAddress"');
$result = $results->results[0];
$this->assertEqual($result['street'], 'Roble Ave', t('Found "Roble Ave" from "findNearestAddress"'));
$this->assertEqual($result['streetnumber'], '671', t('Found "61" from "findNearestAddress"'));
// Test the "findNearestIntersection" service
$query = array('lat' => 37.451, 'lng' => -122.18);
$results = $this->geonames_query('findNearestIntersection', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "findNearestIntersection"');
$result = $results->results[0];
$this->assertEqual($result['street1'], 'Roble Ave', t('Found "Roble Ave" from "findNearestIntersection"'));
$this->assertEqual($result['street2'], 'Curtis St', t('Found "Curtis St" from "findNearestIntersection"'));
// Check the "get" service (this uses a different XML format)
// 2158177 is the geonameid for Melbourne, Australia
$results = $this->geonames_query('get', array('geonameid' => 2158177));
$result = $results->results[0];
$this->assertEqual($result['name'], 'Melbourne', t('Found Melbourne (name) by geonameid'));
$this->assertEqual($result['countrycode'], 'AU', t('Found Melbourne (countrycode) by geonameid'));
$this->assertEqual($result['fcode'], 'PPLA', t('Found Melbourne (fcode) by geonameid'));
// Test the "gtopo30" service - different XML format: doesn't work yet!
$query = array('lat' => 47.01, 'lng' => 10.2);
$results = $this->geonames_query('gtopo30', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "gtopo30"');
// Test the "hierarchy" service
$results = $this->geonames_query('hierarchy', array('geonameid' => 2657896 ));
$this->assertTrue($results->total_results_count >= 5, 'Found at least 5 result from "hierarchy"');
$this->assertEqual($results->results[0]['name'], 'Earth', 'Found "Earth" in hierarchy to Zurich');
$this->assertEqual($results->results[1]['name'], 'Europe', 'Found "Europe" in hierarchy to Zurich');
$this->assertEqual($results->results[2]['name'], 'Switzerland', 'Found "Switzerland" in hierarchy to Zurich');
$this->assertEqual($results->results[$results->total_results_count - 1]['name'], 'Zurich', 'Found "Zurich" in hierarchy to Zurich');
// Test the "nearby" service
$results = $this->geonames_query('nearby', array('lat' => 47.03, 'lng' => 10.2));
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "nearby"');
$result = $results->results[0];
$this->assertEqual($result['name'], 'Talliger', t('Found "Talliger" from "nearby"'));
$this->assertEqual($result['countrycode'], 'AT', t('Found AT by lat/lng from "nearby"'));
// Test the "nearbyPlaceName" service
$query = array('lat' => '28.500103', 'lng' => '-81.357992', 'radius' => 50, 'style' => 'full', 'maxrows' => 10);
$options = array('sortby' => 'population', 'sortorder' => 'desc');
$results = $this->geonames_query('nearbyplace', $query, $options);
$this->assertEqual($results->total_results_count, 10, 'Found 10 result from "nearbyPlaceName"');
$all_ok = TRUE;
foreach ($results->results as $result) {
$all_ok = $all_ok && ($result['adminname1'] == 'Florida');
}
$this->assert($all_ok, "All nearbyPlaceName are in Florida");
// Test the "findNearbyPostalCodes" service (by lat/lon)
$query = array('lat' => '28.500103', 'lng' => '-81.357992', 'radius' => 10, 'style' => 'full');
$results = $this->geonames_query('nearbypostalcodes', $query);
$this->assertTrue($results->total_results_count > 3, 'Found >3 result from "nearbypostalcodes" A');
$all_ok = TRUE;
foreach ($results->results as $result) {
$all_ok = $all_ok && ($result['adminname1'] == 'Florida');
}
$this->assert($all_ok, "All findNearbyPostalCodes-A are in Florida");
// Test the "findNearbyPostalCodes" service (by postalcode)
$query = array('postalcode' => 8775, 'country' => 'CH', 'radius' => 10);
$results = $this->geonames_query('nearbypostalcodes', $query);
$this->assertTrue($results->total_results_count > 3, 'Found >3 result from "nearbypostalcodes" B');
$all_ok = TRUE;
foreach ($results->results as $result) {
$all_ok = $all_ok && ($result['countrycode'] == 'CH');
}
$this->assert($all_ok, "All findNearbyPostalCodes-B are in Florida");
// Test the "findNearbyWikipedia" service (by lat/lon)
$query = array('lat' => '28.500103', 'lng' => '-81.357992', 'radius' => 10, 'style' => 'full');
$results = $this->geonames_query('nearbywikipedia', $query);
$this->assertTrue($results->total_results_count > 3, 'Found >3 result from "nearbywikipedia" A');
$all_ok = TRUE;
foreach ($results->results as $result) {
$all_ok = $all_ok && $result['wikipediaurl'];
}
$this->assert($all_ok, "All findNearbyWikipedia-A have wikipedia URLs");
// Test the "findNearbyWikipedia" service (by postalcode)
$query = array('postalcode' => 8775, 'country' => 'CH', 'radius' => 10);
$results = $this->geonames_query('nearbywikipedia', $query);
$this->assertTrue($results->total_results_count > 3, 'Found >3 result from "nearbywikipedia" B');
$all_ok = TRUE;
foreach ($results->results as $result) {
$all_ok = $all_ok && $result['wikipediaurl'];
}
$this->assert($all_ok, "All findNearbyWikipedia-B have wikipedia URLs");
// Test the "neighbourhood" service
$query = array('lat' => 40.78343, 'lng' => -73.96625);
$results = $this->geonames_query('neighbourhood', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "neighbourhood"');
$result = $results->results[0];
$this->assertEqual($result['name'], 'Central Park', t('Found "Central Park" from "neighbourhood"'));
// Test the "neighbours" service
$results = $this->geonames_query('neighbours', array('geonameid' => 3017382 )); // France
$this->assert($results->total_results_count > 5, 'Found at least 5 results for neighbours to France');
$known = 0;
foreach ($results->results as $result) {
if ($result['name'] == 'Italy' || $result['name'] == 'Germany' || $result['name'] == 'Spain') {
$known++;
}
}
$this->assertEqual($known, 3, t('Found all known neighbours of France'));
// Test the "ocean" service
$query = array('lat' => 40.78343, 'lng' => -43.96625);
$results = $this->geonames_query('ocean', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "ocean"');
$result = $results->results[0];
$this->assertEqual($result['name'], 'North Atlantic Ocean', t('Found "North Atlantic Ocean" from "ocean"'));
// Test the "postalCodeCountryInfo" service
$results = $this->geonames_query('postalcodecountryinfo');
$this->assert($results->total_results_count > 50, 'Found >50 results for postalcodecountryinfo');
$all_ok = TRUE;
foreach ($results->results as $result) {
$all_ok = $all_ok && $result['numpostalcodes'];
}
$this->assert($all_ok, "All postalcodecountryinfo have postalcodes");
// Test the "postalCodeSearch" service
$query = array('postalcode' => 3805, 'country' => 'AU');
$results = $this->geonames_query('postalcodesearch', $query);
$this->assert($results->total_results_count > 0, 'Found at least one results for postalcodesearch');
$found = FALSE;
foreach ($results->results as $result) {
$found = $found || ($result['name'] == 'Narre Warren');
}
$this->assert($found, "Found 'Narre Warren' for postalcode 3805 in AU");
// Test the "siblings" service
$results = $this->geonames_query('siblings', array('geonameid' => 3017382 )); // France
$this->assert($results->total_results_count > 20, 'Found at least 20 results for siblings');
// Test the "srtm3" service
$query = array('lat' => 50.01, 'lng' => 10.2);
$results = $this->geonames_query('srtm3', $query);
$this->assertEqual($results->total_results_count, 1, t('One result for srtm3 service'));
$result = $results->results[0];
$this->assertEqual($result['srtm3'], 206, t('Found expected result for fixed coordinates for srtm3 service'));
// Test the "timezone" service
$query = array('lat' => '28.500103', 'lng' => '-81.357992', 'radius' => 10);
$results = $this->geonames_query('timezone', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result for timezone');
$result = $results->results[0];
$this->assertEqual($result['timezoneid'], 'America/New_York', 'Found TZ "America/New_York" result for timezone');
// Test the "wikipediaBoundingBox" service
// http://ws.geonames.org/wikipediaBoundingBox?north=44.1&south=-9.9&east=-22.4&west=55.2
$query = array('north' => 44.1, 'south' => -9.9, 'east' => -22.4, 'west' => 55.2);
$results = $this->geonames_query('wikipediabbox', $query);
$this->assert($results->total_results_count > 10, 'Found >10 result for wikipediaBoundingBox');
// Test the "wikipediaSearch" service
$query = array('query' => 'Melbourne');
$results = $this->geonames_query('wikipediasearch', $query);
$this->assert($results->total_results_count > 10, 'Found >10 result for wikipediasearch');
// Test the "search" service
$query = array('query' => 'Melbourne', 'maxrows' => 5);
$result = $this->geonames_query('search', $query);
$this->assertTrue($result->total_results_count > 5, t('At least FIVE results found for "Melbourne"'));
$this->assertEqual(count($result->results), 5, t('FIVE results returned (maxrows)'));
// Test the astergdem service
$query = array('lat' => 50.01, 'lng' => 10.2);
$results = $this->geonames_query('gtopo30', $query);
$this->assertEqual($results->total_results_count, 1, t('One result for gtopo30 service'));
$result = $results->results[0];
$this->assertEqual($result['gtopo30'], "205", t('Found expected result for fixed coordinates for gtopo30 service'));
// Check that ALL services have been executed
$unused_services = count($this->services);
if ($unused_services) {
$this->assert(FALSE, "$unused_services services have not been called: ". join(', ', array_keys($this->services)));
}
else {
$num_services = count(geonames_config('services'));
$this->assert(TRUE, "All $num_services services called.");
}
}
}
......@@ -24,10 +24,6 @@ class GeoNamesTestCase extends DrupalWebTestCase {
*/
function setUp() {
parent::setUp('geonames');
// Create and login user
// $admin_user = $this->drupalCreateUser(array('access administration pages'));
// $this->drupalLogin($admin_user);
variable_set('geonames_commercial_active', FALSE);
variable_set('geonames_cache', FALSE);
}
......@@ -86,308 +82,6 @@ class GeoNamesTestCase extends DrupalWebTestCase {
// error_log(print_r($result3, TRUE));
}
/**
* Make a call to (the real) geonames_query, and keep track of which services
* have been executed in $this->services (an array of service name keys).
* @see geonames_query
*/
function geonames_query($service, $query = array(), $options = NULL) {
unset($this->services[$service]);
return geonames_query($service, $query, $options);
}
function testAllServices() {
// Store a list of services in $this->services so we can "cross them off" as
// each is executed via $this->geonames_query
$this->services = array_flip(geonames_config('services'));
ksort($this->services);
// $this->verbose("All Services: ". join(', ', array_keys($this->services)));
// Test the astergdem service
$query = array('lat' => 50.01, 'lng' => 10.2);
$results = $this->geonames_query('astergdem', $query);
$this->assertEqual($results->total_results_count, 1, t('One result for astergdem service'));
$result = $results->results[0];
$this->assertEqual($result['astergdem'], "192", t('Found expected result for fixed coordinates for astergdem service'));
// Test the "children" service
$query = array('geonameid' => 3175395);
$results = $this->geonames_query('children', $query);
$this->assertTrue($results->total_results_count > 5, t('At least 5 regions found for Italy'));
$all_ok = TRUE;
foreach ($results->results as $result) {
$all_ok = $all_ok && ($result['countrycode'] == 'IT');
}
$this->assert($all_ok, "All regions from 'children' are in Italy");
// Test the "cities" service
$query = array('north' => 44.1, 'south' => -9.9, 'east' => -22.4, 'west' => 55.2, 'maxrows' => 8);
$results = $this->geonames_query('cities', $query);
$this->assertEqual($results->total_results_count, 8, 'Found 8 result from "city"');
$result = $results->results[0];
$this->assertEqual($result['name'], 'Mexico City', t('Found "Mexico City" from "cities"'));
$this->assertEqual($result['countrycode'], 'MX', t('Found MX from "cities"'));
// Test the "countryCode" service
$query = array('lat' => 47.03, 'lng' => 10.2);
$results = $this->geonames_query('countrycode', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "countryCode"');
$result = $results->results[0];
$this->assertEqual($result['countrycode'], 'AT', t('Found "AT" from "countryCode"'));
$this->assertEqual($result['countryname'], 'Austria', t('Found "Austria" from "countryCode"'));
// Test the "countryInfo" service
$query = array('country' => 'DE');
$results = $this->geonames_query('countryinfo', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "countryInfo"');
$result = $results->results[0];
$this->assertEqual($result['countrycode'], 'DE', t('Found "DE" from "countryInfo"'));
$this->assertEqual($result['countryname'], 'Germany', t('Found "Germany" from "countryInfo"'));
$this->assertEqual($result['continent'], 'EU', t('Found "EU" from "countryInfo"'));
// Test the "countrySubdivision" service: Lookup Tyrol, AT by lat/long
$query = array('lat' => 47.03, 'lng' => 10.2);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "countrySubdivision"');
$results = $this->geonames_query('countrysubdivision', $query);
$result = $results->results[0];
$this->assertEqual($result['countrycode'], 'AT', t('Found AT by lat/lng'));
$this->assertEqual($result['countryname'], 'Austria', t('Found Austria by lat/lng'));
$this->assertEqual($result['adminname1'], 'Tyrol', t('Found Tyrol, Austria by lat/lng'));
// Test the "extendedFindNearby" service : US
$query = array('lat' => 37.451, 'lng' => -122.18);
$results = $this->geonames_query('extendedFindNearby', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "extendedFindNearby" A');
$result = $results->results[0];
$this->assertEqual($result['street'], 'Roble Ave', t('Found "Roble Ave" from "extendedFindNearby" A'));
$this->assertEqual($result['streetnumber'], '671', t('Found "61" from "extendedFindNearby" A'));
// Test the "extendedFindNearby" service : other countries
$query = array('lat' => 47.3, 'lng' => 9);
$results = $this->geonames_query('extendedFindNearby', $query);
$this->assertTrue($results->total_results_count >= 5, 'Found at least 5 levels in "extendedFindNearby" B');
$this->assertEqual($results->results[0]['name'], 'Earth', t('Found "Earth" from "extendedFindNearby" B'));
$this->assertEqual($results->results[1]['name'], 'Europe', t('Found "Europe" from "extendedFindNearby" B'));
$this->assertEqual($results->results[2]['name'], 'Switzerland', t('Found "Switzerland" from "extendedFindNearby" B'));
$this->assertEqual($results->results[3]['name'], 'Kanton St. Gallen', t('Found "Kanton St. Gallen" from "extendedFindNearby" B'));
$this->assertEqual($results->results[$results->total_results_count - 1]['geonameid'], 6559633, t('Found (geonameid) "6559633" from "extendedFindNearby" B'));
// Test the "extendedFindNearby" service : ocean
$query = array('lat' => 40.78343, 'lng' => -43.96625);
$results = $this->geonames_query('extendedFindNearby', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "extendedFindNearby" C');
$result = $results->results[0];
$this->assertEqual($result['name'], 'North Atlantic Ocean', t('Found "North Atlantic Ocean" from "extendedFindNearby" C'));
// Test the "findNearByWeather" service
$query = array('lat' => 43, 'lng' => -2);
$results = $this->geonames_query('findNearByWeather', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "findNearByWeather"');
$result = $results->results[0];
$this->assertEqual($result['stationname'], 'San Sebastian / Fuenterrabia', t('Found "San Sebastian / Fuenterrabia" from "findNearByWeather"'));
// Test the "findNearbyStreets" service
$query = array('lat' => 37.451, 'lng' => -122.18);
$results = $this->geonames_query('findNearbyStreets', $query);
$this->assertEqual($results->total_results_count, 10, 'Found 8 result from "findNearbyStreets"');
$result = $results->results[0];
$this->assertEqual($result['name'], 'Roble Ave', t('Found "Roble Ave" from "findNearbyStreets"'));
// Test the "findNearestAddress" service
$query = array('lat' => 37.451, 'lng' => -122.18);
$results = $this->geonames_query('findNearestAddress', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "findNearestAddress"');
$result = $results->results[0];
$this->assertEqual($result['street'], 'Roble Ave', t('Found "Roble Ave" from "findNearestAddress"'));
$this->assertEqual($result['streetnumber'], '671', t('Found "61" from "findNearestAddress"'));
// Test the "findNearestIntersection" service
$query = array('lat' => 37.451, 'lng' => -122.18);
$results = $this->geonames_query('findNearestIntersection', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "findNearestIntersection"');
$result = $results->results[0];
$this->assertEqual($result['street1'], 'Roble Ave', t('Found "Roble Ave" from "findNearestIntersection"'));
$this->assertEqual($result['street2'], 'Curtis St', t('Found "Curtis St" from "findNearestIntersection"'));
// Check the "get" service (this uses a different XML format)
// 2158177 is the geonameid for Melbourne, Australia
$results = $this->geonames_query('get', array('geonameid' => 2158177));
$result = $results->results[0];
$this->assertEqual($result['name'], 'Melbourne', t('Found Melbourne (name) by geonameid'));
$this->assertEqual($result['countrycode'], 'AU', t('Found Melbourne (countrycode) by geonameid'));
$this->assertEqual($result['fcode'], 'PPLA', t('Found Melbourne (fcode) by geonameid'));
// Test the "gtopo30" service - different XML format: doesn't work yet!
$query = array('lat' => 47.01, 'lng' => 10.2);
$results = $this->geonames_query('gtopo30', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "gtopo30"');
// Test the "hierarchy" service
$results = $this->geonames_query('hierarchy', array('geonameid' => 2657896 ));
$this->assertTrue($results->total_results_count >= 5, 'Found at least 5 result from "hierarchy"');
$this->assertEqual($results->results[0]['name'], 'Earth', 'Found "Earth" in hierarchy to Zurich');
$this->assertEqual($results->results[1]['name'], 'Europe', 'Found "Europe" in hierarchy to Zurich');
$this->assertEqual($results->results[2]['name'], 'Switzerland', 'Found "Switzerland" in hierarchy to Zurich');
$this->assertEqual($results->results[$results->total_results_count - 1]['name'], 'Zurich', 'Found "Zurich" in hierarchy to Zurich');
// Test the "nearby" service
$results = $this->geonames_query('nearby', array('lat' => 47.03, 'lng' => 10.2));
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "nearby"');
$result = $results->results[0];
$this->assertEqual($result['name'], 'Talliger', t('Found "Talliger" from "nearby"'));
$this->assertEqual($result['countrycode'], 'AT', t('Found AT by lat/lng from "nearby"'));
// Test the "nearbyPlaceName" service
$query = array('lat' => '28.500103', 'lng' => '-81.357992', 'radius' => 50, 'style' => 'full', 'maxrows' => 10);
$options = array('sortby' => 'population', 'sortorder' => 'desc');
$results = $this->geonames_query('nearbyplace', $query, $options);
$this->assertEqual($results->total_results_count, 10, 'Found 10 result from "nearbyPlaceName"');
$all_ok = TRUE;
foreach ($results->results as $result) {
$all_ok = $all_ok && ($result['adminname1'] == 'Florida');
}
$this->assert($all_ok, "All nearbyPlaceName are in Florida");
// Test the "findNearbyPostalCodes" service (by lat/lon)
$query = array('lat' => '28.500103', 'lng' => '-81.357992', 'radius' => 10, 'style' => 'full');
$results = $this->geonames_query('nearbypostalcodes', $query);
$this->assertTrue($results->total_results_count > 3, 'Found >3 result from "nearbypostalcodes" A');
$all_ok = TRUE;
foreach ($results->results as $result) {
$all_ok = $all_ok && ($result['adminname1'] == 'Florida');
}
$this->assert($all_ok, "All findNearbyPostalCodes-A are in Florida");
// Test the "findNearbyPostalCodes" service (by postalcode)
$query = array('postalcode' => 8775, 'country' => 'CH', 'radius' => 10);
$results = $this->geonames_query('nearbypostalcodes', $query);
$this->assertTrue($results->total_results_count > 3, 'Found >3 result from "nearbypostalcodes" B');
$all_ok = TRUE;
foreach ($results->results as $result) {
$all_ok = $all_ok && ($result['countrycode'] == 'CH');
}
$this->assert($all_ok, "All findNearbyPostalCodes-B are in Florida");
// Test the "findNearbyWikipedia" service (by lat/lon)
$query = array('lat' => '28.500103', 'lng' => '-81.357992', 'radius' => 10, 'style' => 'full');
$results = $this->geonames_query('nearbywikipedia', $query);
$this->assertTrue($results->total_results_count > 3, 'Found >3 result from "nearbywikipedia" A');
$all_ok = TRUE;
foreach ($results->results as $result) {
$all_ok = $all_ok && $result['wikipediaurl'];
}
$this->assert($all_ok, "All findNearbyWikipedia-A have wikipedia URLs");
// Test the "findNearbyWikipedia" service (by postalcode)
$query = array('postalcode' => 8775, 'country' => 'CH', 'radius' => 10);
$results = $this->geonames_query('nearbywikipedia', $query);
$this->assertTrue($results->total_results_count > 3, 'Found >3 result from "nearbywikipedia" B');
$all_ok = TRUE;
foreach ($results->results as $result) {
$all_ok = $all_ok && $result['wikipediaurl'];
}
$this->assert($all_ok, "All findNearbyWikipedia-B have wikipedia URLs");
// Test the "neighbourhood" service
$query = array('lat' => 40.78343, 'lng' => -73.96625);
$results = $this->geonames_query('neighbourhood', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "neighbourhood"');
$result = $results->results[0];
$this->assertEqual($result['name'], 'Central Park', t('Found "Central Park" from "neighbourhood"'));
// Test the "neighbours" service
$results = $this->geonames_query('neighbours', array('geonameid' => 3017382 )); // France
$this->assert($results->total_results_count > 5, 'Found at least 5 results for neighbours to France');
$known = 0;
foreach ($results->results as $result) {
if ($result['name'] == 'Italy' || $result['name'] == 'Germany' || $result['name'] == 'Spain') {
$known++;
}
}
$this->assertEqual($known, 3, t('Found all known neighbours of France'));
// Test the "ocean" service
$query = array('lat' => 40.78343, 'lng' => -43.96625);
$results = $this->geonames_query('ocean', $query);
$this->assertEqual($results->total_results_count, 1, 'Found 1 result from "ocean"');
$result = $results->results[0];
$this->assertEqual($result['name'], 'North Atlantic Ocean', t('Found "North Atlantic Ocean" from "ocean"'));
// Test the "postalCodeCountryInfo" service
$results = $this->geonames_query('postalcodecountryinfo');
$this->assert($results->total_results_count > 50, 'Found >50 results for postalcodecountryinfo');