2009-10-23 05:19:25 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
|
|
|
|
print "This script must be run from the command line\n";
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
|
2013-09-28 22:20:10 +09:00
|
|
|
define('GNUSOCIAL', true);
|
|
|
|
define('STATUSNET', true); // compatibility
|
2009-10-23 05:19:25 +09:00
|
|
|
|
|
|
|
require_once INSTALLDIR . '/lib/common.php';
|
|
|
|
|
|
|
|
// Make sure this is loaded
|
|
|
|
// XXX: how to test other plugins...?
|
|
|
|
|
|
|
|
addPlugin('Geonames');
|
|
|
|
|
|
|
|
class LocationTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider locationNames
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function testLocationFromName($name, $language, $location)
|
|
|
|
{
|
|
|
|
$result = Location::fromName($name, $language);
|
|
|
|
$this->assertEquals($result, $location);
|
|
|
|
}
|
|
|
|
|
|
|
|
static public function locationNames()
|
|
|
|
{
|
|
|
|
return array(array('Montreal', 'en', null),
|
|
|
|
array('San Francisco, CA', 'en', null),
|
|
|
|
array('Paris, France', 'en', null),
|
|
|
|
array('Paris, Texas', 'en', null));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider locationIds
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function testLocationFromId($id, $ns, $language, $location)
|
|
|
|
{
|
|
|
|
$result = Location::fromId($id, $ns, $language);
|
|
|
|
$this->assertEquals($result, $location);
|
|
|
|
}
|
|
|
|
|
|
|
|
static public function locationIds()
|
|
|
|
{
|
2009-11-18 09:56:43 +09:00
|
|
|
return array(array(6077243, GeonamesPlugin::LOCATION_NS, 'en', null),
|
|
|
|
array(5391959, GeonamesPlugin::LOCATION_NS, 'en', null));
|
2009-10-23 05:19:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider locationLatLons
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function testLocationFromLatLon($lat, $lon, $language, $location)
|
|
|
|
{
|
|
|
|
$result = Location::fromLatLon($lat, $lon, $language);
|
2016-08-09 13:12:25 +09:00
|
|
|
$this->assertEquals($location, $result->location_id);
|
2009-10-23 05:19:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
static public function locationLatLons()
|
|
|
|
{
|
|
|
|
return array(array(37.77493, -122.41942, 'en', null),
|
|
|
|
array(45.509, -73.588, 'en', null));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider nameOfLocation
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function testLocationGetName($location, $language, $name)
|
|
|
|
{
|
2016-08-09 13:12:25 +09:00
|
|
|
$result = empty($location)?null:$location->getName($language);
|
|
|
|
$this->assertEquals($name, $result);
|
2009-10-23 05:19:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
static public function nameOfLocation()
|
|
|
|
{
|
2016-08-09 13:12:25 +09:00
|
|
|
$loc = Location::fromName('Montreal', 'en');
|
|
|
|
return array(array($loc, 'en', null), //'Montreal'),
|
|
|
|
array($loc, 'fr', null));//'Montréal'));
|
2009-10-23 05:19:25 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|