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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
<?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\SitesManager\tests\Unit;
use Piwik\Container\StaticContainer;
use Piwik\Plugins\SitesManager\API;
use Piwik\SettingsServer;
use Piwik\Translate;
/**
* @group SitesManaager
* @group APITest
* @group Plugins
*/
class APITest extends \PHPUnit_Framework_TestCase
{
/**
* @var Api
*/
private $api;
public function setUp()
{
parent::setUp();
if (!SettingsServer::isTimezoneSupportEnabled()) {
$this->markTestSkipped('timezones needs to be supported');
}
Translate::loadAllTranslations();
$this->api = API::getInstance();
}
public function tearDown()
{
parent::tearDown();
Translate::reset();
}
public function getTimezoneNameTestData()
{
return array(
array('Europe/Rome', 'en', 'Italy'),
array('Europe/Rome', 'it', 'Italia'),
array('America/New_York', 'en', 'United States - New York'),
array('America/New_York', 'ru', 'Соединенные Штаты - Нью-Йорк'),
array('Asia/Foo_Bar', 'en', 'Foo Bar'),
array('Etc/UTC', 'en', 'UTC'),
array('UTC', 'en', 'UTC'),
array('UTC+1', 'en', 'UTC+1'),
array('UTC+1.5', 'en', 'UTC+1:30'),
array('UTC-1.5', 'en', 'UTC-1:30'),
);
}
/**
* @dataProvider getTimezoneNameTestData
*/
public function testGetTimezoneName($timezone, $language, $expected)
{
$translator = StaticContainer::get('Piwik\Translation\Translator');
$translator->setCurrentLanguage($language);
$name = $this->api->getTimezoneName($timezone);
$this->assertEquals($expected, $name);
}
public function testGetTimezonesList()
{
$timezones = $this->api->getTimezonesList();
$this->assertArrayHasKey('Asia', $timezones);
$this->assertArrayHasKey('North America', $timezones);
$this->assertArrayHasKey('Central America', $timezones);
$this->assertArrayHasKey('UTC', $timezones);
$this->assertEquals('Japan', $timezones['Asia']['Asia/Tokyo']);
$this->assertEquals('United States - New York', $timezones['North America']['America/New_York']);
$this->assertEquals('Antarctica - Dumont d’Urville', $timezones['Antarctica']['Antarctica/DumontDUrville']);
$this->assertArrayHasKey('UTC', $timezones['UTC']);
$this->assertArrayHasKey('UTC+6', $timezones['UTC']);
$this->assertArrayHasKey('UTC+13.75', $timezones['UTC']);
$this->assertArrayHasKey('UTC-11.5', $timezones['UTC']);
}
}
|