blob: 387ea4bbd348e9e1a32b10c477551720c3701d9f (
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
<?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\Tests\Unit\Metrics\Formatter;
use Piwik\Container\StaticContainer;
use Piwik\Metrics\Formatter\Html;
use Piwik\Tests\Framework\Fixture;
use Piwik\Plugins\SitesManager\API as SitesManagerAPI;
/**
* @group Core
*/
class HtmlTest extends \PHPUnit\Framework\TestCase
{
/**
* @var Html
*/
private $formatter;
private $sitesInfo;
public function setUp()
{
$this->sitesInfo = array(
1 => array(
'idsite' => '1',
'currency' => 'EUR'
)
);
$this->formatter = new Html();
Fixture::loadAllTranslations();
$this->setSiteManagerApiMock();
}
public function tearDown()
{
Fixture::resetTranslations();
$this->unsetSiteManagerApiMock();
}
public function test_getPrettyTimeFromSeconds_DefaultsToShowingSentences_AndUsesNonBreakingSpaces()
{
$expected = '1 days 10 hours';
$value = $this->formatter->getPrettyTimeFromSeconds(86400 + 3600 * 10);
$this->assertEquals($expected, $value);
}
public function test_getPrettySizeFromBytes_UsesNonBreakingSpaces()
{
$expected = '1.5 K';
$value = $this->formatter->getPrettySizeFromBytes(1536);
$this->assertEquals($expected, $value);
}
public function test_getPrettySizeFromBytes_InFixedUnitThatIsHigherThanBestUnit()
{
$expected = '0.001465 M';
$value = $this->formatter->getPrettySizeFromBytes(1536, 'M', 6);
$this->assertEquals($expected, $value);
}
public function test_getPrettySizeFromBytes_InUnitThatIsLowerThanBestUnit()
{
$expected = '1536 B';
$value = $this->formatter->getPrettySizeFromBytes(1536, 'B');
$this->assertEquals($expected, $value);
}
public function test_getPrettyMoney_UsesNonBreakingSpaces()
{
StaticContainer::get('Piwik\Translation\Translator')->setCurrentLanguage('de');
$expected = html_entity_decode('1 €');
$value = $this->formatter->getPrettyMoney(1, 1);
$this->assertEquals($expected, $value);
}
private function unsetSiteManagerApiMock()
{
SitesManagerAPI::unsetInstance();
}
private function setSiteManagerApiMock()
{
$sitesInfo = $this->sitesInfo;
$mock = $this->getMock('stdClass', array('getSiteFromId'));
$mock->expects($this->any())->method('getSiteFromId')->willReturnCallback(function ($idSite) use ($sitesInfo) {
return $sitesInfo[$idSite];
});
SitesManagerAPI::setSingletonInstance($mock);
}
}
|