LocationTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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($result, $location);
  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 = $location->getName($language);
  62. $this->assertEquals($result, $name);
  63. }
  64. static public function nameOfLocation()
  65. {
  66. return array(array(new Location(), 'en', 'Montreal'),
  67. array(new Location(), 'fr', 'Montréal'));
  68. }
  69. }