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:
authorsgiehl <stefan@piwik.org>2016-11-02 23:27:29 +0300
committersgiehl <stefan@piwik.org>2016-11-07 22:32:55 +0300
commit1fcb31b597828b541fc29ca305d76d450b5ea85c (patch)
tree9ab8ca4223fa0c3644c2926b7cbacd9338aca9f4 /plugins
parent86be3c5f256b8789879984ef5c11fb59a6861268 (diff)
Move method for setting location provider from controller to api
Diffstat (limited to 'plugins')
-rw-r--r--plugins/UserCountry/API.php16
-rw-r--r--plugins/UserCountry/Controller.php25
-rw-r--r--plugins/UserCountry/angularjs/location-provider-selection/location-provider-selection.controller.js5
-rw-r--r--plugins/UserCountry/tests/Integration/APITest.php53
4 files changed, 71 insertions, 28 deletions
diff --git a/plugins/UserCountry/API.php b/plugins/UserCountry/API.php
index a9dbd0c414..f7d67e7424 100644
--- a/plugins/UserCountry/API.php
+++ b/plugins/UserCountry/API.php
@@ -198,6 +198,22 @@ class API extends \Piwik\Plugin\API
return $location;
}
+ /**
+ * Set the location provider
+ *
+ * @param string $providerId The ID of the provider to use eg 'default', 'geoip_php', ...
+ * @throws Exception if ID is invalid
+ */
+ public function setLocationProvider($providerId)
+ {
+ Piwik::checkUserHasSuperUserAccess();
+
+ $provider = LocationProvider::setCurrentProvider($providerId);
+ if ($provider === false) {
+ throw new Exception("Invalid provider ID: '$providerId'.");
+ }
+ }
+
protected function getDataTable($name, $idSite, $period, $date, $segment)
{
Piwik::checkUserHasViewAccess($idSite);
diff --git a/plugins/UserCountry/Controller.php b/plugins/UserCountry/Controller.php
index a089c60c28..a6a3bd9fbe 100644
--- a/plugins/UserCountry/Controller.php
+++ b/plugins/UserCountry/Controller.php
@@ -284,31 +284,6 @@ class Controller extends \Piwik\Plugin\ControllerAdmin
}
/**
- * Sets the current LocationProvider type.
- *
- * Input:
- * Requires the 'id' query parameter to be set to the desired LocationProvider's ID.
- *
- * Output:
- * Nothing.
- */
- public function setCurrentLocationProvider()
- {
- $this->dieIfGeolocationAdminIsDisabled();
- Piwik::checkUserHasSuperUserAccess();
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- $this->checkTokenInUrl();
-
- $providerId = Common::getRequestVar('id');
- $provider = LocationProvider::setCurrentProvider($providerId);
- if ($provider === false) {
- throw new Exception("Invalid provider ID: '$providerId'.");
- }
- return 1;
- }
- }
-
- /**
* Echo's a pretty formatted location using a specific LocationProvider.
*
* Input:
diff --git a/plugins/UserCountry/angularjs/location-provider-selection/location-provider-selection.controller.js b/plugins/UserCountry/angularjs/location-provider-selection/location-provider-selection.controller.js
index 1c431d76e8..5df7ba187c 100644
--- a/plugins/UserCountry/angularjs/location-provider-selection/location-provider-selection.controller.js
+++ b/plugins/UserCountry/angularjs/location-provider-selection/location-provider-selection.controller.js
@@ -51,9 +51,8 @@
piwikApi.withTokenInUrl();
piwikApi.fetch({
- module: 'UserCountry',
- action: 'setCurrentLocationProvider',
- id: this.selectedProvider
+ method: 'UserCountry.setLocationProvider',
+ providerId: this.selectedProvider
}).then(function () {
self.isLoading = false;
var UI = require('piwik/UI');
diff --git a/plugins/UserCountry/tests/Integration/APITest.php b/plugins/UserCountry/tests/Integration/APITest.php
new file mode 100644
index 0000000000..5be24ea326
--- /dev/null
+++ b/plugins/UserCountry/tests/Integration/APITest.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+
+namespace Piwik\Plugins\UserCountry\tests;
+
+use Piwik\Common;
+use Piwik\Plugins\UserCountry\API;
+use Piwik\Plugins\UserCountry\LocationProvider;
+use Piwik\Plugins\UserCountry\LocationProvider\DefaultProvider;
+use Piwik\Tests\Framework\Mock\FakeAccess;
+use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
+
+/**
+ * @group UserCountryAPI
+ * @group APITest
+ * @group Plugins
+ */
+class APITest extends IntegrationTestCase
+{
+ /**
+ * @var API
+ */
+ private $api;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ FakeAccess::$superUser = true;
+
+ $this->api = API::getInstance();
+
+ // reset location providers as they might be manipulated by other tests
+ LocationProvider::$providers = null;
+ LocationProvider::getAllProviders();
+ }
+
+ public function test_setLocationProvider()
+ {
+ $locationProvider = LocationProvider\GeoIp\Php::ID;
+ $this->api->setLocationProvider($locationProvider);
+ $this->assertEquals($locationProvider, Common::getCurrentLocationProviderId());
+
+ $locationProvider = DefaultProvider::ID;
+ $this->api->setLocationProvider($locationProvider);
+ $this->assertEquals($locationProvider, Common::getCurrentLocationProviderId());
+ }
+}