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

MockLocationProvider.php « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9d613ae18f46625210c796dae74dcce2f7086530 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

use Piwik\Plugins\UserCountry\LocationProvider;

class MockLocationProvider extends LocationProvider
{
    public static $locations = array();
    private $currentLocation = 0;
    private $ipToLocations = array();

    public function getLocation($info)
    {
        $ip = $info['ip'];

        if (isset($this->ipToLocations[$ip])) {
            $result = $this->ipToLocations[$ip];
        } else {
            $result = self::$locations[$this->currentLocation];
            $this->currentLocation = ($this->currentLocation + 1) % count(self::$locations);

            $this->ipToLocations[$ip] = $result;
        }
        $this->completeLocationResult($result);
        return $result;
    }

    public function getInfo()
    {
        return array('id' => 'mock_provider', 'title' => 'mock provider', 'description' => 'mock provider');
    }

    public function isAvailable()
    {
        return true;
    }

    public function isWorking()
    {
        return true;
    }

    public function getSupportedLocationInfo()
    {
        return array(); // unimplemented
    }
}