Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Giehl <stefan@matomo.org>2022-01-26 22:50:47 +0300
committerGitHub <noreply@github.com>2022-01-26 22:50:47 +0300
commit2ba0f7a67cb4aa336ef312e2850de1f325adcb69 (patch)
tree62bbc9cd0b444607009d73008c33f4b58d97a120 /plugins/GeoIp2
parenta8e12af576ac4c5c33975e63865f02370a00c6d9 (diff)
Allow disabling the usage of the default geolocation provider as fallback (#18634)
* Allow disabling the usage of the default geolocation provider as fallback * Improve naming * add changelog entry * Introduce a disabled provider and setting to disable the default provider * fix tests * update changelog
Diffstat (limited to 'plugins/GeoIp2')
-rw-r--r--plugins/GeoIp2/GeoIp2.php2
-rw-r--r--plugins/GeoIp2/tests/Integration/LocationProviderTest.php35
2 files changed, 36 insertions, 1 deletions
diff --git a/plugins/GeoIp2/GeoIp2.php b/plugins/GeoIp2/GeoIp2.php
index 03ccd58b1c..3f9363a3f2 100644
--- a/plugins/GeoIp2/GeoIp2.php
+++ b/plugins/GeoIp2/GeoIp2.php
@@ -40,7 +40,7 @@ class GeoIp2 extends \Piwik\Plugin
{
// switch to default provider if GeoIP2 provider was in use
if (LocationProvider::getCurrentProvider() instanceof \Piwik\Plugins\GeoIp2\LocationProvider\GeoIp2) {
- LocationProvider::setCurrentProvider(LocationProvider\DefaultProvider::ID);
+ LocationProvider::setCurrentProvider(LocationProvider::getDefaultProviderId());
}
}
diff --git a/plugins/GeoIp2/tests/Integration/LocationProviderTest.php b/plugins/GeoIp2/tests/Integration/LocationProviderTest.php
index 938325c5bd..ea1fc20927 100644
--- a/plugins/GeoIp2/tests/Integration/LocationProviderTest.php
+++ b/plugins/GeoIp2/tests/Integration/LocationProviderTest.php
@@ -8,7 +8,11 @@
*/
namespace Piwik\Plugins\GeoIp2\tests\Integration;
+use Piwik\Config;
use Piwik\Plugins\GeoIp2\LocationProvider\GeoIp2;
+use Piwik\Plugins\UserCountry\LocationProvider\DefaultProvider;
+use Piwik\Plugins\UserCountry\VisitorGeolocator;
+use Piwik\Tests\Framework\Fixture;
/**
* @group GeoIp2
@@ -109,4 +113,35 @@ class LocationProviderTest extends \PHPUnit\Framework\TestCase
'org' => 'Innocraft'
], $result);
}
+
+ public function testGeoIP2NoResultFallback()
+ {
+ Fixture::loadAllTranslations();
+ $locationProvider = new GeoIp2\Php(['loc' => ['GeoIP2-City.mmdb'], 'isp' => []]);
+ $geolocator = new VisitorGeolocator($locationProvider, new DefaultProvider());
+
+ $result = $geolocator->getLocation(['ip' => '221.0.0.9', 'lang' => 'de-ch'], false);
+
+ $this->assertEquals([
+ 'country_code' => 'ch',
+ 'country_name' => 'Switzerland',
+ 'continent_code' => 'eur',
+ 'continent_name' => 'Europe',
+ ], $result);
+ }
+
+ public function testGeoIP2NoResultFallbackDisabled()
+ {
+ Fixture::loadAllTranslations();
+ Config::getInstance()->Tracker['enable_default_location_provider'] = 0;
+
+ $locationProvider = new GeoIp2\Php(['loc' => ['GeoIP2-City.mmdb'], 'isp' => []]);
+ $geolocator = new VisitorGeolocator($locationProvider);
+
+ $result = $geolocator->getLocation(['ip' => '221.0.0.9', 'lang' => 'de-ch'], false);
+
+ $this->assertEquals([
+ 'country_code' => 'xx',
+ ], $result);
+ }
} \ No newline at end of file