LocationTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. namespace Tests\Unit;
  17. if (!defined('INSTALLDIR')) {
  18. define('INSTALLDIR', dirname(dirname(__DIR__)));
  19. }
  20. if (!defined('GNUSOCIAL')) {
  21. define('GNUSOCIAL', true);
  22. }
  23. if (!defined('STATUSNET')) { // Compatibility
  24. define('STATUSNET', true);
  25. }
  26. use GeonamesPlugin;
  27. use Location;
  28. use PHPUnit\Framework\TestCase;
  29. require_once INSTALLDIR . '/lib/common.php';
  30. // Make sure this is loaded
  31. // XXX: how to test other plugins...?
  32. addPlugin('Geonames');
  33. final class LocationTest extends TestCase
  34. {
  35. /**
  36. * @dataProvider locationNames
  37. * @param $name
  38. * @param $language
  39. * @param $location
  40. */
  41. public function testLocationFromName($name, $language, $location)
  42. {
  43. $result = Location::fromName($name, $language);
  44. $this->assertEquals($result, $location);
  45. }
  46. static public function locationNames()
  47. {
  48. return array(array('Montreal', 'en', null),
  49. array('San Francisco, CA', 'en', null),
  50. array('Paris, France', 'en', null),
  51. array('Paris, Texas', 'en', null));
  52. }
  53. /**
  54. * @dataProvider locationIds
  55. * @param $id
  56. * @param $ns
  57. * @param $language
  58. * @param $location
  59. */
  60. public function testLocationFromId($id, $ns, $language, $location)
  61. {
  62. $result = Location::fromId($id, $ns, $language);
  63. $this->assertEquals($result, $location);
  64. }
  65. static public function locationIds()
  66. {
  67. return array(array(6077243, GeonamesPlugin::LOCATION_NS, 'en', null),
  68. array(5391959, GeonamesPlugin::LOCATION_NS, 'en', null));
  69. }
  70. /**
  71. * @dataProvider locationLatLons
  72. * @param $lat
  73. * @param $lon
  74. * @param $language
  75. * @param $location
  76. */
  77. public function testLocationFromLatLon($lat, $lon, $language, $location)
  78. {
  79. $result = Location::fromLatLon($lat, $lon, $language);
  80. $this->assertEquals($location, $result->location_id);
  81. }
  82. static public function locationLatLons()
  83. {
  84. return array(array(37.77493, -122.41942, 'en', null),
  85. array(45.509, -73.588, 'en', null));
  86. }
  87. /**
  88. * @dataProvider nameOfLocation
  89. * @param $location
  90. * @param $language
  91. * @param $name
  92. */
  93. public function testLocationGetName($location, $language, $name)
  94. {
  95. $result = empty($location) ? null : $location->getName($language);
  96. $this->assertEquals($name, $result);
  97. }
  98. static public function nameOfLocation()
  99. {
  100. $loc = Location::fromName('Montreal', 'en');
  101. return array(array($loc, 'en', null), //'Montreal'),
  102. array($loc, 'fr', null));//'Montréal'));
  103. }
  104. }