LocationTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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('PUBLICDIR')) {
  21. define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
  22. }
  23. if (!defined('GNUSOCIAL')) {
  24. define('GNUSOCIAL', true);
  25. }
  26. if (!defined('STATUSNET')) { // Compatibility
  27. define('STATUSNET', true);
  28. }
  29. use GeonamesPlugin;
  30. use Location;
  31. use PHPUnit\Framework\TestCase;
  32. require_once INSTALLDIR . '/lib/util/common.php';
  33. // Make sure this is loaded
  34. // XXX: how to test other plugins...?
  35. addPlugin('Geonames');
  36. final class LocationTest extends TestCase
  37. {
  38. /**
  39. * @dataProvider locationNames
  40. * @param $name
  41. * @param $language
  42. * @param $location
  43. */
  44. public function testLocationFromName($name, $language, $location)
  45. {
  46. $result = Location::fromName($name, $language);
  47. $this->assertEquals($result, $location);
  48. }
  49. static public function locationNames()
  50. {
  51. return array(array('Montreal', 'en', null),
  52. array('San Francisco, CA', 'en', null),
  53. array('Paris, France', 'en', null),
  54. array('Paris, Texas', 'en', null));
  55. }
  56. /**
  57. * @dataProvider locationIds
  58. * @param $id
  59. * @param $ns
  60. * @param $language
  61. * @param $location
  62. */
  63. public function testLocationFromId($id, $ns, $language, $location)
  64. {
  65. $result = Location::fromId($id, $ns, $language);
  66. $this->assertEquals($result, $location);
  67. }
  68. static public function locationIds()
  69. {
  70. return array(array(6077243, GeonamesPlugin::LOCATION_NS, 'en', null),
  71. array(5391959, GeonamesPlugin::LOCATION_NS, 'en', null));
  72. }
  73. /**
  74. * @dataProvider locationLatLons
  75. * @param $lat
  76. * @param $lon
  77. * @param $language
  78. * @param $location
  79. */
  80. public function testLocationFromLatLon($lat, $lon, $language, $location)
  81. {
  82. $result = Location::fromLatLon($lat, $lon, $language);
  83. $this->assertEquals($location, $result->location_id);
  84. }
  85. static public function locationLatLons()
  86. {
  87. return array(array(37.77493, -122.41942, 'en', null),
  88. array(45.509, -73.588, 'en', null));
  89. }
  90. /**
  91. * @dataProvider nameOfLocation
  92. * @param $location
  93. * @param $language
  94. * @param $name
  95. */
  96. public function testLocationGetName($location, $language, $name)
  97. {
  98. $result = empty($location) ? null : $location->getName($language);
  99. $this->assertEquals($name, $result);
  100. }
  101. static public function nameOfLocation()
  102. {
  103. $loc = Location::fromName('Montreal', 'en');
  104. return array(array($loc, 'en', null), //'Montreal'),
  105. array($loc, 'fr', null));//'Montréal'));
  106. }
  107. }