LocationTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
  3. print "This script must be run from the command line\n";
  4. exit();
  5. }
  6. define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
  7. define('GNUSOCIAL', true);
  8. define('STATUSNET', true); // compatibility
  9. require_once INSTALLDIR . '/lib/common.php';
  10. // Make sure this is loaded
  11. // XXX: how to test other plugins...?
  12. addPlugin('Geonames');
  13. class LocationTest extends PHPUnit_Framework_TestCase
  14. {
  15. /**
  16. * @dataProvider locationNames
  17. */
  18. public function testLocationFromName($name, $language, $location)
  19. {
  20. $result = Location::fromName($name, $language);
  21. $this->assertEquals($result, $location);
  22. }
  23. static public function locationNames()
  24. {
  25. return array(array('Montreal', 'en', null),
  26. array('San Francisco, CA', 'en', null),
  27. array('Paris, France', 'en', null),
  28. array('Paris, Texas', 'en', null));
  29. }
  30. /**
  31. * @dataProvider locationIds
  32. */
  33. public function testLocationFromId($id, $ns, $language, $location)
  34. {
  35. $result = Location::fromId($id, $ns, $language);
  36. $this->assertEquals($result, $location);
  37. }
  38. static public function locationIds()
  39. {
  40. return array(array(6077243, GeonamesPlugin::LOCATION_NS, 'en', null),
  41. array(5391959, GeonamesPlugin::LOCATION_NS, 'en', null));
  42. }
  43. /**
  44. * @dataProvider locationLatLons
  45. */
  46. public function testLocationFromLatLon($lat, $lon, $language, $location)
  47. {
  48. $result = Location::fromLatLon($lat, $lon, $language);
  49. $this->assertEquals($location, $result->location_id);
  50. }
  51. static public function locationLatLons()
  52. {
  53. return array(array(37.77493, -122.41942, 'en', null),
  54. array(45.509, -73.588, 'en', null));
  55. }
  56. /**
  57. * @dataProvider nameOfLocation
  58. */
  59. public function testLocationGetName($location, $language, $name)
  60. {
  61. $result = empty($location)?null:$location->getName($language);
  62. $this->assertEquals($name, $result);
  63. }
  64. static public function nameOfLocation()
  65. {
  66. $loc = Location::fromName('Montreal', 'en');
  67. return array(array($loc, 'en', null), //'Montreal'),
  68. array($loc, 'fr', null));//'Montréal'));
  69. }
  70. }