2 // This file is part of GNU social - https://www.gnu.org/software/social
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.
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.
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/>.
19 if (!defined('INSTALLDIR')) {
20 define('INSTALLDIR', dirname(dirname(__DIR__)));
22 if (!defined('GNUSOCIAL')) {
23 define('GNUSOCIAL', true);
25 if (!defined('STATUSNET')) { // Compatibility
26 define('STATUSNET', true);
31 use PHPUnit\Framework\TestCase;
33 require_once INSTALLDIR . '/lib/common.php';
35 // Make sure this is loaded
36 // XXX: how to test other plugins...?
38 addPlugin('Geonames');
40 final class LocationTest extends TestCase
44 * @dataProvider locationNames
50 public function testLocationFromName($name, $language, $location)
52 $result = Location::fromName($name, $language);
53 $this->assertEquals($result, $location);
56 static public function locationNames()
58 return array(array('Montreal', 'en', null),
59 array('San Francisco, CA', 'en', null),
60 array('Paris, France', 'en', null),
61 array('Paris, Texas', 'en', null));
65 * @dataProvider locationIds
72 public function testLocationFromId($id, $ns, $language, $location)
74 $result = Location::fromId($id, $ns, $language);
75 $this->assertEquals($result, $location);
78 static public function locationIds()
80 return array(array(6077243, GeonamesPlugin::LOCATION_NS, 'en', null),
81 array(5391959, GeonamesPlugin::LOCATION_NS, 'en', null));
85 * @dataProvider locationLatLons
92 public function testLocationFromLatLon($lat, $lon, $language, $location)
94 $result = Location::fromLatLon($lat, $lon, $language);
95 $this->assertEquals($location, $result->location_id);
98 static public function locationLatLons()
100 return array(array(37.77493, -122.41942, 'en', null),
101 array(45.509, -73.588, 'en', null));
105 * @dataProvider nameOfLocation
111 public function testLocationGetName($location, $language, $name)
113 $result = empty($location) ? null : $location->getName($language);
114 $this->assertEquals($name, $result);
117 static public function nameOfLocation()
119 $loc = Location::fromName('Montreal', 'en');
120 return array(array($loc, 'en', null), //'Montreal'),
121 array($loc, 'fr', null));//'Montréal'));