2019-07-13 00:31:14 +09:00
|
|
|
<?php
|
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
|
|
if (!defined('INSTALLDIR')) {
|
|
|
|
define('INSTALLDIR', dirname(dirname(__DIR__)));
|
|
|
|
}
|
2019-07-25 09:29:20 +09:00
|
|
|
if (!defined('PUBLICDIR')) {
|
|
|
|
define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
|
|
|
|
}
|
2019-07-13 00:31:14 +09:00
|
|
|
if (!defined('GNUSOCIAL')) {
|
|
|
|
define('GNUSOCIAL', true);
|
|
|
|
}
|
|
|
|
if (!defined('STATUSNET')) { // Compatibility
|
|
|
|
define('STATUSNET', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
use GeonamesPlugin;
|
|
|
|
use Location;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
2019-08-23 21:36:02 +09:00
|
|
|
require_once INSTALLDIR . '/lib/util/common.php';
|
2019-07-13 00:31:14 +09:00
|
|
|
|
|
|
|
// Make sure this is loaded
|
|
|
|
// XXX: how to test other plugins...?
|
|
|
|
|
|
|
|
addPlugin('Geonames');
|
|
|
|
|
|
|
|
final class LocationTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider locationNames
|
2020-06-24 21:08:11 +09:00
|
|
|
*
|
2019-07-13 00:31:14 +09:00
|
|
|
* @param $name
|
|
|
|
* @param $language
|
|
|
|
* @param $location
|
|
|
|
*/
|
|
|
|
public function testLocationFromName($name, $language, $location)
|
|
|
|
{
|
|
|
|
$result = Location::fromName($name, $language);
|
2020-06-24 21:08:11 +09:00
|
|
|
static::assertSame($result, $location);
|
2019-07-13 00:31:14 +09:00
|
|
|
}
|
|
|
|
|
2020-06-24 21:08:11 +09:00
|
|
|
public static function locationNames()
|
2019-07-13 00:31:14 +09:00
|
|
|
{
|
2020-06-24 21:08:11 +09:00
|
|
|
return [['Montreal', 'en', null],
|
|
|
|
['San Francisco, CA', 'en', null],
|
|
|
|
['Paris, France', 'en', null],
|
|
|
|
['Paris, Texas', 'en', null],];
|
2019-07-13 00:31:14 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider locationIds
|
2020-06-24 21:08:11 +09:00
|
|
|
*
|
2019-07-13 00:31:14 +09:00
|
|
|
* @param $id
|
|
|
|
* @param $ns
|
|
|
|
* @param $language
|
|
|
|
* @param $location
|
|
|
|
*/
|
|
|
|
public function testLocationFromId($id, $ns, $language, $location)
|
|
|
|
{
|
|
|
|
$result = Location::fromId($id, $ns, $language);
|
2020-06-24 21:08:11 +09:00
|
|
|
static::assertSame($result, $location);
|
2019-07-13 00:31:14 +09:00
|
|
|
}
|
|
|
|
|
2020-06-24 21:08:11 +09:00
|
|
|
public static function locationIds()
|
2019-07-13 00:31:14 +09:00
|
|
|
{
|
2020-06-24 21:08:11 +09:00
|
|
|
return [[6077243, GeonamesPlugin::LOCATION_NS, 'en', null],
|
|
|
|
[5391959, GeonamesPlugin::LOCATION_NS, 'en', null],];
|
2019-07-13 00:31:14 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider locationLatLons
|
2020-06-24 21:08:11 +09:00
|
|
|
*
|
2019-07-13 00:31:14 +09:00
|
|
|
* @param $lat
|
|
|
|
* @param $lon
|
|
|
|
* @param $language
|
|
|
|
* @param $location
|
|
|
|
*/
|
|
|
|
public function testLocationFromLatLon($lat, $lon, $language, $location)
|
|
|
|
{
|
|
|
|
$result = Location::fromLatLon($lat, $lon, $language);
|
2020-06-24 21:08:11 +09:00
|
|
|
static::assertSame($location, $result->location_id);
|
2019-07-13 00:31:14 +09:00
|
|
|
}
|
|
|
|
|
2020-06-24 21:08:11 +09:00
|
|
|
public static function locationLatLons()
|
2019-07-13 00:31:14 +09:00
|
|
|
{
|
2020-06-24 21:08:11 +09:00
|
|
|
return [[37.77493, -122.41942, 'en', null],
|
|
|
|
[45.509, -73.588, 'en', null],];
|
2019-07-13 00:31:14 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider nameOfLocation
|
2020-06-24 21:08:11 +09:00
|
|
|
*
|
2019-07-13 00:31:14 +09:00
|
|
|
* @param $location
|
|
|
|
* @param $language
|
|
|
|
* @param $name
|
|
|
|
*/
|
|
|
|
public function testLocationGetName($location, $language, $name)
|
|
|
|
{
|
|
|
|
$result = empty($location) ? null : $location->getName($language);
|
2020-06-24 21:08:11 +09:00
|
|
|
static::assertSame($name, $result);
|
2019-07-13 00:31:14 +09:00
|
|
|
}
|
|
|
|
|
2020-06-24 21:08:11 +09:00
|
|
|
public static function nameOfLocation()
|
2019-07-13 00:31:14 +09:00
|
|
|
{
|
|
|
|
$loc = Location::fromName('Montreal', 'en');
|
2020-06-24 21:08:11 +09:00
|
|
|
return [[$loc, 'en', null], //'Montreal'),
|
|
|
|
[$loc, 'fr', null],]; //'Montréal'));
|
2019-07-13 00:31:14 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|