LocationTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. *
  41. * @param $name
  42. * @param $language
  43. * @param $location
  44. */
  45. public function testLocationFromName($name, $language, $location)
  46. {
  47. $result = Location::fromName($name, $language);
  48. static::assertSame($result, $location);
  49. }
  50. public static function locationNames()
  51. {
  52. return [['Montreal', 'en', null],
  53. ['San Francisco, CA', 'en', null],
  54. ['Paris, France', 'en', null],
  55. ['Paris, Texas', 'en', null],];
  56. }
  57. /**
  58. * @dataProvider locationIds
  59. *
  60. * @param $id
  61. * @param $ns
  62. * @param $language
  63. * @param $location
  64. */
  65. public function testLocationFromId($id, $ns, $language, $location)
  66. {
  67. $result = Location::fromId($id, $ns, $language);
  68. static::assertSame($result, $location);
  69. }
  70. public static function locationIds()
  71. {
  72. return [[6077243, GeonamesPlugin::LOCATION_NS, 'en', null],
  73. [5391959, GeonamesPlugin::LOCATION_NS, 'en', null],];
  74. }
  75. /**
  76. * @dataProvider locationLatLons
  77. *
  78. * @param $lat
  79. * @param $lon
  80. * @param $language
  81. * @param $location
  82. */
  83. public function testLocationFromLatLon($lat, $lon, $language, $location)
  84. {
  85. $result = Location::fromLatLon($lat, $lon, $language);
  86. static::assertSame($location, $result->location_id);
  87. }
  88. public static function locationLatLons()
  89. {
  90. return [[37.77493, -122.41942, 'en', null],
  91. [45.509, -73.588, 'en', null],];
  92. }
  93. /**
  94. * @dataProvider nameOfLocation
  95. *
  96. * @param $location
  97. * @param $language
  98. * @param $name
  99. */
  100. public function testLocationGetName($location, $language, $name)
  101. {
  102. $result = empty($location) ? null : $location->getName($language);
  103. static::assertSame($name, $result);
  104. }
  105. public static function nameOfLocation()
  106. {
  107. $loc = Location::fromName('Montreal', 'en');
  108. return [[$loc, 'en', null], //'Montreal'),
  109. [$loc, 'fr', null],]; //'Montréal'));
  110. }
  111. }