gnu-social/tests/LocationTest.php
Nym Coy 1f866fcaed ActivityGenerationTests.php fails but doesn't crash anymore.
Fixed an error where a profile id was reused after another profile was
deleted, and the new profile still had the deleted role.

Fixed ActivityGenerationTests::testNoticeInfoRepeated() which was passing
User instead of Profile, throwing errors.

tests/ActivityGenerationTests.php now passes.

CommandInterpreterTest now passes.

Moved JidValidateTest to XmppValidateTest, since Jabber functionality has
moved to the XmppPlugin. Tests work but don't pass, but they are at least
skipped if XmppPlugin is not active.

LocationTest passes, but the tests are not very good. Lots of nulls.

MediaFileTest passes.

NicknameTest passes. Nickname::normalize() now throws an error if the
nickname is too long with underscores.

UserFeedParseTest passes.

URLDetectionTest passes if $config['linkify']['(bare_ipv4|bare_ipv6|
bare_domains)'] are false. Untested otherwise.

Fixed Nickname::isBlacklisted() so it does not throw an error if
$config['nickname]['blacklist'] not set.
2016-08-14 11:55:49 +05:30

90 lines
2.3 KiB
PHP

<?php
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
print "This script must be run from the command line\n";
exit();
}
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('GNUSOCIAL', true);
define('STATUSNET', true); // compatibility
require_once INSTALLDIR . '/lib/common.php';
// Make sure this is loaded
// XXX: how to test other plugins...?
addPlugin('Geonames');
class LocationTest extends PHPUnit_Framework_TestCase
{
/**
* @dataProvider locationNames
*/
public function testLocationFromName($name, $language, $location)
{
$result = Location::fromName($name, $language);
$this->assertEquals($result, $location);
}
static public function locationNames()
{
return array(array('Montreal', 'en', null),
array('San Francisco, CA', 'en', null),
array('Paris, France', 'en', null),
array('Paris, Texas', 'en', null));
}
/**
* @dataProvider locationIds
*/
public function testLocationFromId($id, $ns, $language, $location)
{
$result = Location::fromId($id, $ns, $language);
$this->assertEquals($result, $location);
}
static public function locationIds()
{
return array(array(6077243, GeonamesPlugin::LOCATION_NS, 'en', null),
array(5391959, GeonamesPlugin::LOCATION_NS, 'en', null));
}
/**
* @dataProvider locationLatLons
*/
public function testLocationFromLatLon($lat, $lon, $language, $location)
{
$result = Location::fromLatLon($lat, $lon, $language);
$this->assertEquals($location, $result->location_id);
}
static public function locationLatLons()
{
return array(array(37.77493, -122.41942, 'en', null),
array(45.509, -73.588, 'en', null));
}
/**
* @dataProvider nameOfLocation
*/
public function testLocationGetName($location, $language, $name)
{
$result = empty($location)?null:$location->getName($language);
$this->assertEquals($name, $result);
}
static public function nameOfLocation()
{
$loc = Location::fromName('Montreal', 'en');
return array(array($loc, 'en', null), //'Montreal'),
array($loc, 'fr', null));//'Montréal'));
}
}