From 4720a46b66a5967a0ade7c93a576f133cf6eeb39 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Tue, 2 Jul 2013 14:50:54 +0200 Subject: [PATCH] Update geoname server service provider --- component.json | 3 +- composer.json | 3 +- composer.lock | 84 ++++++--- lib/Alchemy/Phrasea/Application.php | 5 +- .../Controller/Admin/ConnectedUsers.php | 33 ++++ .../Phrasea/Controller/Admin/Users.php | 2 +- .../Phrasea/Controller/Root/Account.php | 34 +++- .../Core/Provider/GeonamesServiceProvider.php | 30 --- lib/classes/User/Adapter.php | 30 ++- lib/classes/geonames.php | 173 ------------------ lib/conf.d/_GV_template.inc | 2 +- lib/conf.d/bases_structure.xml | 2 +- templates/web/account/account.html.twig | 2 +- templates/web/account/sessions.html.twig | 17 +- templates/web/admin/connected-users.html.twig | 18 +- templates/web/admin/editusers.html.twig | 2 +- templates/web/common/dialog_export.html.twig | 2 +- .../Provider/GeonamesServiceProviderTest.php | 16 -- tests/classes/geonamesTest.php | 76 -------- 19 files changed, 176 insertions(+), 358 deletions(-) delete mode 100644 lib/Alchemy/Phrasea/Core/Provider/GeonamesServiceProvider.php delete mode 100644 lib/classes/geonames.php delete mode 100644 tests/Alchemy/Tests/Phrasea/Core/Provider/GeonamesServiceProviderTest.php delete mode 100644 tests/classes/geonamesTest.php diff --git a/component.json b/component.json index b5da53e6da..d5c697ed50 100644 --- a/component.json +++ b/component.json @@ -23,6 +23,7 @@ "sinon-chai": "~2.4", "js-fixtures": "https://github.com/badunk/js-fixtures/archive/master.zip", "bootstrap-multiselect": "https://github.com/davidstutz/bootstrap-multiselect.git", - "zxcvbn" : "https://github.com/lowe/zxcvbn.git" + "zxcvbn" : "https://github.com/lowe/zxcvbn.git", + "geonames-server-jquery-plugin" : "~0.1.0" } } diff --git a/composer.json b/composer.json index 7b65d08750..a7f5d24a90 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ "facebook/php-sdk" : "~3.0", "gedmo/doctrine-extensions" : "~2.3.0", "alchemy/google-plus-api-client" : "~0.6.2", + "alchemy/geonames-api-consumer" : "~0.1.0", "guzzle/guzzle" : "~3.0", "neutron/imagine" : "dev-neutron-colorspace@dev", "jms/serializer" : "~0.10", @@ -49,7 +50,7 @@ "behat/mink-extension" : "~1.0", "behat/mink-goutte-driver" : "~1.0", "behat/mink-selenium2-driver" : "~1.0", - "fabpot/goutte" : "~1.0" + "fabpot/goutte" : "1.0.x-dev@dev" }, "autoload": { "psr-0": { diff --git a/composer.lock b/composer.lock index 45a5081c69..39dc5a6f91 100644 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "65785e460cf13c19d95073151e68f967", + "hash": "a265177770eb277554b943a7e807eac1", "packages": [ { "name": "alchemy/binary-driver", @@ -62,6 +62,44 @@ ], "time": "2013-06-21 15:51:20" }, + { + "name": "alchemy/geonames-api-consumer", + "version": "0.1.1", + "source": { + "type": "git", + "url": "https://github.com/alchemy-fr/GeonamesServer-PHP-Plugin.git", + "reference": "0.1.1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/alchemy-fr/GeonamesServer-PHP-Plugin/zipball/0.1.1", + "reference": "0.1.1", + "shasum": "" + }, + "require": { + "guzzle/guzzle": "~3.5", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~3.7", + "silex/silex": "~1.0" + }, + "type": "library", + "autoload": { + "psr-0": { + "Alchemy": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A connector to a geonames server", + "keywords": [ + "geonames" + ], + "time": "2013-07-02 11:28:34" + }, { "name": "alchemy/ghostscript", "version": "0.4.0", @@ -894,16 +932,16 @@ }, { "name": "guzzle/guzzle", - "version": "v3.3.1", + "version": "v3.6.0", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "v3.3.1" + "reference": "v3.6.0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/v3.3.1", - "reference": "v3.3.1", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/v3.6.0", + "reference": "v3.6.0", "shasum": "" }, "require": { @@ -939,16 +977,15 @@ "doctrine/cache": "*", "monolog/monolog": "1.*", "phpunit/phpunit": "3.7.*", + "psr/log": "1.0.*", "symfony/class-loader": "*", - "zend/zend-cache1": "1.12", - "zend/zend-log1": "1.12", "zendframework/zend-cache": "2.0.*", "zendframework/zend-log": "2.0.*" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.3-dev" + "dev-master": "3.6-dev" } }, "autoload": { @@ -983,7 +1020,7 @@ "rest", "web service" ], - "time": "2013-03-10 23:05:38" + "time": "2013-05-30 07:01:25" }, { "name": "jms/metadata", @@ -3292,27 +3329,31 @@ }, { "name": "fabpot/goutte", - "version": "v1.0.1", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/fabpot/Goutte.git", - "reference": "v1.0.1" + "reference": "2f5104765152d51b501de452a83153ac0b1492df" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fabpot/Goutte/zipball/v1.0.1", - "reference": "v1.0.1", + "url": "https://api.github.com/repos/fabpot/Goutte/zipball/2f5104765152d51b501de452a83153ac0b1492df", + "reference": "2f5104765152d51b501de452a83153ac0b1492df", "shasum": "" }, "require": { "ext-curl": "*", - "guzzle/guzzle": ">=3.0, <3.4", + "guzzle/http": ">=3.0.5,<3.7-dev", "php": ">=5.3.0", - "symfony/browser-kit": ">=2.1,<3.0", - "symfony/css-selector": ">=2.1,<3.0", - "symfony/dom-crawler": ">=2.1,<3.0", - "symfony/finder": ">=2.1,<3.0", - "symfony/process": ">=2.1,<3.0" + "symfony/browser-kit": "~2.1", + "symfony/css-selector": "~2.1", + "symfony/dom-crawler": "~2.1", + "symfony/finder": "~2.1", + "symfony/process": "~2.1" + }, + "require-dev": { + "guzzle/plugin-history": ">=3.0.5,<3.7-dev", + "guzzle/plugin-mock": ">=3.0.5,<3.7-dev" }, "type": "application", "extra": { @@ -3340,7 +3381,7 @@ "keywords": [ "scraper" ], - "time": "2013-03-08 08:00:58" + "time": "2013-07-02 07:48:02" }, { "name": "instaclick/php-webdriver", @@ -3766,7 +3807,8 @@ "media-alchemyst/media-alchemyst": 20, "php-ffmpeg/php-ffmpeg": 20, "mrclay/minify": 20, - "doctrine/data-fixtures": 20 + "doctrine/data-fixtures": 20, + "fabpot/goutte": 20 }, "platform": { "php": ">=5.3.3" diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index e7bdcebda7..eaa56e4a9f 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -85,7 +85,7 @@ use Alchemy\Phrasea\Core\Provider\ConfigurationServiceProvider; use Alchemy\Phrasea\Core\Provider\ConfigurationTesterServiceProvider; use Alchemy\Phrasea\Core\Provider\FileServeServiceProvider; use Alchemy\Phrasea\Core\Provider\FtpServiceProvider; -use Alchemy\Phrasea\Core\Provider\GeonamesServiceProvider; +use Alchemy\Geonames\GeonamesServiceProvider; use Alchemy\Phrasea\Core\Provider\InstallerServiceProvider; use Alchemy\Phrasea\Core\Provider\JMSSerializerServiceProvider; use Alchemy\Phrasea\Core\Provider\LocaleServiceProvider; @@ -204,6 +204,9 @@ class Application extends SilexApplication $this->register(new FilesystemServiceProvider()); $this->register(new FtpServiceProvider()); $this->register(new GeonamesServiceProvider()); + $this['geonames.server-uri'] = $this->share(function (Application $app) { + return $app['phraseanet.registry']->get('GV_i18n_service', 'http://geoloc.preprod.alchemyasp.com/'); + }); $this->register(new MediaAlchemystServiceProvider()); $this['media-alchemyst.configuration'] = $this->share(function(Application $app) { diff --git a/lib/Alchemy/Phrasea/Controller/Admin/ConnectedUsers.php b/lib/Alchemy/Phrasea/Controller/Admin/ConnectedUsers.php index 19bf730716..38bad374ec 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/ConnectedUsers.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/ConnectedUsers.php @@ -11,6 +11,7 @@ namespace Alchemy\Phrasea\Controller\Admin; +use Alchemy\Geonames\Exception\ExceptionInterface as GeonamesExceptionInterface; use Silex\Application; use Silex\ControllerProviderInterface; use Symfony\Component\HttpFoundation\Request; @@ -44,6 +45,38 @@ class ConnectedUsers implements ControllerProviderInterface $query = $app['EM']->createQuery($dql); $sessions = $query->getResult(); + $result = array(); + + foreach ($sessions as $session) { + $info = ''; + try { + $geoname = $app['geonames.connector']->ip($session->getIpAddress()); + $country = $geoname->get('country'); + $city = $geoname->get('city'); + $region = $geoname->get('region'); + + $countryName = isset($country['name']) ? $country['name'] : null; + $regionName = isset($region['name']) ? $region['name'] : null; + + if (null !== $city) { + $info = $city . ($countryName ? ' (' . $countryName . ')' : null); + } elseif (null !== $regionName) { + $info = $regionName . ($countryName ? ' (' . $countryName . ')' : null); + } elseif (null !== $countryName) { + $info = $countryName; + } else { + $info = ''; + } + } catch (GeonamesExceptionInterface $e) { + + } + + $result[] = array( + 'session' => $session, + 'info' => $info, + ); + } + $ret = array( 'sessions' => $sessions, 'applications' => array( diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Users.php b/lib/Alchemy/Phrasea/Controller/Admin/Users.php index 744a59ddea..2769be9a1b 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Users.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Users.php @@ -317,7 +317,7 @@ class Users implements ControllerProviderInterface , $user->get_address() , $user->get_city() , $user->get_zipcode() - , $app['geonames']->get_country($user->get_geonameid()) + , $user->get_country() , $user->get_tel() , $user->get_fax() , $user->get_job() diff --git a/lib/Alchemy/Phrasea/Controller/Root/Account.php b/lib/Alchemy/Phrasea/Controller/Root/Account.php index 6839330895..405102ce87 100644 --- a/lib/Alchemy/Phrasea/Controller/Root/Account.php +++ b/lib/Alchemy/Phrasea/Controller/Root/Account.php @@ -11,6 +11,7 @@ namespace Alchemy\Phrasea\Controller\Root; +use Alchemy\Geonames\Exception\ExceptionInterface as GeonamesExceptionInterface; use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Notification\Receiver; @@ -276,7 +277,38 @@ class Account implements ControllerProviderInterface $query->setParameters(array('usr_id' => $app['session']->get('usr_id'))); $sessions = $query->getResult(); - return $app['twig']->render('account/sessions.html.twig', array('sessions' => $sessions)); + $result = array(); + foreach ($sessions as $session) { + $info = ''; + try { + $geoname = $app['geonames.connector']->ip($session->getIpAddress()); + $country = $geoname->get('country'); + $city = $geoname->get('city'); + $region = $geoname->get('region'); + + $countryName = isset($country['name']) ? $country['name'] : null; + $regionName = isset($region['name']) ? $region['name'] : null; + + if (null !== $city) { + $info = $city . ($countryName ? ' (' . $countryName . ')' : null); + } elseif (null !== $regionName) { + $info = $regionName . ($countryName ? ' (' . $countryName . ')' : null); + } elseif (null !== $countryName) { + $info = $countryName; + } else { + $info = ''; + } + } catch (GeonamesExceptionInterface $e) { + + } + + $result[] = array( + 'session' => $session, + 'info' => $info, + ); + } + + return $app['twig']->render('account/sessions.html.twig', array('sessions' => $result)); } /** diff --git a/lib/Alchemy/Phrasea/Core/Provider/GeonamesServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/GeonamesServiceProvider.php deleted file mode 100644 index 89fd2119cc..0000000000 --- a/lib/Alchemy/Phrasea/Core/Provider/GeonamesServiceProvider.php +++ /dev/null @@ -1,30 +0,0 @@ -share(function($app) { - return new \geonames($app); - }); - } - - public function boot(Application $app) - { - } -} diff --git a/lib/classes/User/Adapter.php b/lib/classes/User/Adapter.php index ccac1b9908..4f00455adb 100644 --- a/lib/classes/User/Adapter.php +++ b/lib/classes/User/Adapter.php @@ -12,6 +12,7 @@ use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Exception\SessionNotFound; +use Alchemy\Geonames\Exception\ExceptionInterface as GeonamesExceptionInterface; /** * @@ -521,7 +522,17 @@ class User_Adapter implements User_Interface, cache_cacheableInterface public function get_country() { if ($this->geonameid) { - return $this->app['geonames']->get_country($this->geonameid); + try { + $country = $this->app['geonames.connector'] + ->geoname($this->geonameid) + ->get('country'); + + if (isset($country['name'])) { + return $country['name']; + } + } catch (GeonamesExceptionInterface $e) { + + } } return ''; @@ -751,7 +762,20 @@ class User_Adapter implements User_Interface, cache_cacheableInterface public function set_geonameid($geonameid) { - $country_code = $this->app['geonames']->get_country_code($geonameid); + $country_code = null; + + try { + $country = $this->app['geonames.connector'] + ->geoname($this->geonameid) + ->get('country'); + + if (isset($country['code'])) { + $country_code = $country['code']; + } + } catch (GeonamesExceptionInterface $e) { + + } + $sql = 'UPDATE usr SET geonameid = :geonameid, pays=:country_code WHERE usr_id = :usr_id'; $datas = array( @@ -1102,7 +1126,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface $this->modificationdate = new DateTime($row['usr_modificationdate']); $this->applied_template = $row['lastModel']; - $this->country = $this->app['geonames']->get_country($row['geonameid']); + $this->country = $this->get_country(); $this->is_guest = ($row['invite'] == '1'); diff --git a/lib/classes/geonames.php b/lib/classes/geonames.php deleted file mode 100644 index f6c940c3d2..0000000000 --- a/lib/classes/geonames.php +++ /dev/null @@ -1,173 +0,0 @@ -app = $app; - } - - public function name_from_id($geonameid) - { - $url = $this->app['phraseanet.registry']->get('GV_i18n_service', 'http://localization.webservice.alchemyasp.com/') - . 'get_name.php?geonameid=' - . $geonameid; - - $ret = ''; - - $xml = http_query::getUrl($url); - if ($xml) { - - $sxe = simplexml_load_string($xml); - - if ($sxe !== false && ($geoname = $sxe->geoname)) { - $ret = (string) $geoname->city . ', ' . (string) $geoname->country; - } - } - - return $ret; - } - - public function get_country($geonameid) - { - if (trim($geonameid) === '' || trim($geonameid) <= 0) { - return ''; - } - - $url = $this->app['phraseanet.registry']->get('GV_i18n_service', 'http://localization.webservice.alchemyasp.com/') - . 'get_name.php?geonameid=' - . $geonameid; - - $ret = ''; - $xml = http_query::getUrl($url); - if ($xml) { - $sxe = simplexml_load_string($xml); - - if ($sxe !== false && ($geoname = $sxe->geoname)) { - $ret = (string) $geoname->country; - } - } - - return $ret; - } - - public function get_country_code($geonameid) - { - $url = $this->app['phraseanet.registry']->get('GV_i18n_service', 'http://localization.webservice.alchemyasp.com/') - . 'get_name.php?geonameid=' - . $geonameid; - - $ret = ''; - - $xml = http_query::getUrl($url); - if ($xml) { - $sxe = simplexml_load_string($xml); - - if ($sxe !== false && ($geoname = $sxe->geoname)) { - $ret = (string) $geoname->country_code; - } - } - - return $ret; - } - - protected static function clean_input($input) - { - return strip_tags(trim($input)); - } - - protected static function highlight($title, $length) - { - return '' . mb_substr($title, 0, $length) . '' - . mb_substr($title, $length); - } - - public function find_city($cityName) - { - $output = array(); - $cityName = self::clean_input($cityName); - - if (strlen($cityName) === 0) { - return $output; - } - - $url = $this->app['phraseanet.registry']->get('GV_i18n_service', 'http://localization.webservice.alchemyasp.com/') - . 'find_city.php?city=' - . urlencode($cityName) . '&maxResult=30'; - - $sxe = simplexml_load_string(http_query::getUrl($url)); - - foreach ($sxe->geoname as $geoname) { - $length = mb_strlen($geoname->title_match); - - $title_highlight = self::highlight($geoname->title, $length); - - $country_highlight = (string) $geoname->country; - if (trim($geoname->country_match) !== '') { - $length = mb_strlen($geoname->country_match); - $country_highlight = self::highlight($geoname->country, $length); - } - - $output[] = array( - 'title_highlighted' => $title_highlight - , 'title' => (string) $geoname->title - , 'country_highlighted' => $country_highlight - , 'country' => (string) $geoname->country - , 'geoname_id' => (int) $geoname->geonameid - , 'region' => (string) $geoname->region - ); - } - - return $output; - } - protected $cache_ips = array(); - - public function find_geoname_from_ip($ip) - { - if (array_key_exists($ip, $this->cache_ips)) { - return $this->cache_ips[$ip]; - } - - $output = array( - 'city' => '', - 'country_code' => '', - 'country' => '', - 'fips' => '', - 'longitude' => '', - 'latitude' => '' - ); - - $url = $this->app['phraseanet.registry']->get('GV_i18n_service', 'http://localization.webservice.alchemyasp.com/') - . 'geoip.php?ip=' - . urlencode($ip); - - $xml = http_query::getUrl($url); - if ($xml) { - $sxe = simplexml_load_string($xml); - if ($sxe !== false && $sxe->geoname) { - $output['city'] = (string) $sxe->geoname->city; - $output['country_code'] = (string) $sxe->geoname->country_code; - $output['country'] = (string) $sxe->geoname->country; - $output['fips'] = (string) $sxe->geoname->fips; - $output['longitude'] = (string) $sxe->geoname->longitude; - $output['latitude'] = (string) $sxe->geoname->latitude; - } - } - $this->cache_ips[$ip] = $output; - - return $output; - } -} diff --git a/lib/conf.d/_GV_template.inc b/lib/conf.d/_GV_template.inc index b9d6d7cde0..61066bb27e 100644 --- a/lib/conf.d/_GV_template.inc +++ b/lib/conf.d/_GV_template.inc @@ -79,7 +79,7 @@ return call_user_func_array(function(Application $app) { 'type' => \registry::TYPE_STRING, 'name' => 'GV_i18n_service', 'comment' => _('Geonames server address'), - 'default' => 'http://localization.webservice.alchemyasp.com/', + 'default' => 'http://geoloc.preprod.alchemyasp.com/', 'end_slash' => true, 'required' => true ), diff --git a/lib/conf.d/bases_structure.xml b/lib/conf.d/bases_structure.xml index 21a85dcc54..9f97898e53 100644 --- a/lib/conf.d/bases_structure.xml +++ b/lib/conf.d/bases_structure.xml @@ -3903,7 +3903,7 @@ pays varchar(64) - + YES diff --git a/templates/web/account/account.html.twig b/templates/web/account/account.html.twig index bce54e5f93..d61437c31b 100644 --- a/templates/web/account/account.html.twig +++ b/templates/web/account/account.html.twig @@ -94,7 +94,7 @@
- +

diff --git a/templates/web/account/sessions.html.twig b/templates/web/account/sessions.html.twig index 369d28326a..f203ed4051 100644 --- a/templates/web/account/sessions.html.twig +++ b/templates/web/account/sessions.html.twig @@ -34,7 +34,8 @@ - {% for row in sessions %} + {% for session in sessions %} + {% set row = session['session'] %} {% if app['session'].get('phrasea_session_id') != row.Id() %} @@ -48,20 +49,8 @@ {{ app['date-formatter'].getDate(row.getUpdated()) }} - {% set geoname = app['geonames'].find_geoname_from_ip(row.getIpAddress()) %} - - {% if geoname['city'] %} - {% set ip_infos = geoname['city'] ~ ' (' ~ geoname['country'] ~ ')' %} - {% elseif geoname['fips'] %} - {% set ip_infos = geoname['fips'] ~ ' (' ~ geoname['country'] ~ ')' %} - {% elseif geoname['country'] %} - {% set ip_infos = geoname['country'] %} - {% else %} - {% set ip_infos = '' %} - {% endif %} - {{ row.getIpAddress() }} - {{ ip_infos }} + {{ session['info'] }} {{ row.getBrowserName() }} {{ row.getBrowserVersion() }} diff --git a/templates/web/admin/connected-users.html.twig b/templates/web/admin/connected-users.html.twig index 86d48fd84c..2bef2def0e 100644 --- a/templates/web/admin/connected-users.html.twig +++ b/templates/web/admin/connected-users.html.twig @@ -97,7 +97,8 @@ - {% for row in data['sessions'] %} + {% for session in data['sessions'] %} + {% set row = session['session'] %} {% if row.getId() == app['session'].get('session_id') %} @@ -112,20 +113,7 @@ {% endfor %} - {% set geoname = app['geonames'].find_geoname_from_ip(row.getIpAddress()) %} - - {% if geoname['city'] %} - {% set ip_infos = geoname['city'] ~ ' (' ~ geoname['country'] ~ ')' %} - {% elseif geoname['fips'] %} - {% set ip_infos = geoname['fips'] ~ ' (' ~ geoname['country'] ~ ')' %} - {% elseif geoname['country'] %} - {% set ip_infos = geoname['country'] %} - {% else %} - {% set ip_infos = '' %} - {% endif %} - - - {{ row.getIpAddress() }}
{{ ip_infos }} + {{ row.getIpAddress() }}
{{ session['info'] }} {{ app['date-formatter'].getDate(row.getCreated()) }} {{ app['date-formatter'].getPrettyString(row.getUpdated()) }} diff --git a/templates/web/admin/editusers.html.twig b/templates/web/admin/editusers.html.twig index 769cd92607..b819fea544 100644 --- a/templates/web/admin/editusers.html.twig +++ b/templates/web/admin/editusers.html.twig @@ -515,7 +515,7 @@ {% trans 'admin::compte-utilisateur ville' %} - + diff --git a/templates/web/common/dialog_export.html.twig b/templates/web/common/dialog_export.html.twig index cf8f10821a..059169e2eb 100644 --- a/templates/web/common/dialog_export.html.twig +++ b/templates/web/common/dialog_export.html.twig @@ -365,7 +365,7 @@
- +
diff --git a/tests/Alchemy/Tests/Phrasea/Core/Provider/GeonamesServiceProviderTest.php b/tests/Alchemy/Tests/Phrasea/Core/Provider/GeonamesServiceProviderTest.php deleted file mode 100644 index f8fd54de62..0000000000 --- a/tests/Alchemy/Tests/Phrasea/Core/Provider/GeonamesServiceProviderTest.php +++ /dev/null @@ -1,16 +0,0 @@ -object = new geonames(self::$DI['app']); - } - - public function testName_from_id() - { - $result = $this->object->name_from_id(2989317); - $this->assertEquals("Orléans, France", $result); - } - - public function testGet_country() - { - $orleans = $this->object->find_city('orléans, france'); - $this->assertTrue(is_array($orleans)); - $this->assertTrue(count($orleans) === 1); - $orleans = array_pop($orleans); - - $found = $this->object->get_country($orleans['geoname_id']); - - $this->assertEquals($found, $orleans['country']); - $this->assertEquals($found, 'France'); - } - - public function testGet_country_code() - { - $this->assertEquals('FR', $this->object->get_country_code(2989317)); - $this->assertEquals('', $this->object->get_country_code(298945135163153317)); - $this->assertEquals('', $this->object->get_country_code('29894513516315331dsfsd7')); - $this->assertEquals('', $this->object->get_country_code('dsfsd')); - } - - public function testFind_city() - { - $orleans = $this->object->find_city('orléa'); - $this->assertTrue(is_array($orleans)); - foreach ($orleans as $potential) { - $this->assertArrayHasKey('region', $potential); - $this->assertArrayHasKey('title_highlighted', $potential); - $this->assertArrayHasKey('country', $potential); - $this->assertArrayHasKey('title', $potential); - $this->assertArrayHasKey('country_highlighted', $potential); - $this->assertArrayHasKey('geoname_id', $potential); - $this->assertTrue(is_int($potential['geoname_id'])); - $this->assertTrue(is_string($potential['country_highlighted'])); - $this->assertTrue(is_string($potential['title'])); - $this->assertTrue(is_string($potential['country'])); - $this->assertTrue(is_string($potential['title_highlighted'])); - $this->assertTrue(is_string($potential['region'])); - } - } - - public function testFind_geoname_from_ip() - { - $result = $this->object->find_geoname_from_ip('80.12.81.18'); - $this->assertArrayHasKey('city', $result); - $this->assertArrayHasKey('country_code', $result); - $this->assertArrayHasKey('country', $result); - $this->assertArrayHasKey('fips', $result); - $this->assertArrayHasKey('longitude', $result); - $this->assertArrayHasKey('latitude', $result); - $this->assertEquals("Paris", $result['city']); - $this->assertEquals("FR", $result['country_code']); - $this->assertEquals("France", $result['country']); - } -}