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:
Diffstat (limited to 'tests/PHPUnit/Unit/Metrics/Formatter/HtmlTest.php')
-rw-r--r--tests/PHPUnit/Unit/Metrics/Formatter/HtmlTest.php91
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/PHPUnit/Unit/Metrics/Formatter/HtmlTest.php b/tests/PHPUnit/Unit/Metrics/Formatter/HtmlTest.php
new file mode 100644
index 0000000000..fd9b996f50
--- /dev/null
+++ b/tests/PHPUnit/Unit/Metrics/Formatter/HtmlTest.php
@@ -0,0 +1,91 @@
+<?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\Tests\Unit\Metrics\Formatter;
+
+use Piwik\Metrics\Formatter\Html;
+use Piwik\Translate;
+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();
+
+ setlocale(LC_ALL, null);
+
+ Translate::loadEnglishTranslation();
+ $this->setSiteManagerApiMock();
+ }
+
+ public function tearDown()
+ {
+ Translate::unloadEnglishTranslation();
+ $this->unsetSiteManagerApiMock();
+
+ setlocale(LC_ALL, null);
+ }
+
+ public function test_getPrettyTimeFromSeconds_DefaultsToShowingSentences_AndUsesNonBreakingSpaces()
+ {
+ $expected = '1&nbsp;days&nbsp;10&nbsp;hours';
+ $value = $this->formatter->getPrettyTimeFromSeconds(86400 + 3600 * 10);
+
+ $this->assertEquals($expected, $value);
+ }
+
+ public function test_getPrettySizeFromBytes_UsesNonBreakingSpaces()
+ {
+ $expected = '1.5&nbsp;K';
+ $value = $this->formatter->getPrettySizeFromBytes(1536);
+
+ $this->assertEquals($expected, $value);
+ }
+
+ public function test_getPrettyMoney_UsesNonBreakingSpaces()
+ {
+ $expected = '1&nbsp;€';
+ $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);
+ }
+} \ No newline at end of file