blob: cc38c0f2f7db47f1d7d8b95e0529e78435337a23 (
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\UserCountry\tests\Unit;
use Piwik\Container\StaticContainer;
use Piwik\Intl\Data\Provider\RegionDataProvider;
require_once PIWIK_INCLUDE_PATH . '/plugins/UserCountry/UserCountry.php';
require_once PIWIK_INCLUDE_PATH . '/plugins/UserCountry/functions.php';
class UserCountryTest extends \PHPUnit\Framework\TestCase
{
/**
* @group Plugins
*/
public function testGetFlagFromCode()
{
$flag = \Piwik\Plugins\UserCountry\getFlagFromCode("us");
$this->assertEquals(basename($flag), "us.png");
}
/**
* @group Plugins
*/
public function testGetFlagFromInvalidCode()
{
$flag = \Piwik\Plugins\UserCountry\getFlagFromCode("foo");
$this->assertEquals(basename($flag), "xx.png");
}
/**
* @group Plugins
*/
public function testFlagsAndContinents()
{
/** @var RegionDataProvider $dataProvider */
$dataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider');
$continents = $dataProvider->getContinentList();
$countries = $dataProvider->getCountryList(true);
// Get list of existing flag icons
$flags = scandir(PIWIK_PATH_TEST_TO_ROOT . '/plugins/Morpheus/icons/dist/flags/');
// Get list of countries
foreach ($countries as $country => $continent) {
// test continent
self::assertTrue(in_array($continent, $continents));
// test flag
self::assertTrue(in_array($country . '.png', $flags));
}
foreach ($flags as $filename) {
if ($filename == '.' || $filename == '..') {
continue;
}
$country = substr($filename, 0, strpos($filename, '.png'));
// test country
$this->assertArrayHasKey($country, $countries, $filename);
}
}
}
|