|
|
@@ -8,26 +8,47 @@ use Tools\TestSuite\TestCase;
|
|
|
use Tools\Utility\Number;
|
|
|
use Tools\View\Helper\NumberHelper;
|
|
|
|
|
|
-/**
|
|
|
- * Number Test Case
|
|
|
- */
|
|
|
class NumberHelperTest extends TestCase {
|
|
|
|
|
|
/**
|
|
|
+ * @var \Tools\View\Helper\NumberHelper
|
|
|
+ */
|
|
|
+ protected $Number;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $locale;
|
|
|
+
|
|
|
+ /**
|
|
|
* @return void
|
|
|
*/
|
|
|
public function setUp() {
|
|
|
parent::setUp();
|
|
|
|
|
|
+ $this->locale = ini_get('intl.default_locale');
|
|
|
+ ini_set('intl.default_locale', 'de-DE');
|
|
|
+
|
|
|
Configure::write('Localization', [
|
|
|
'decimals' => ',',
|
|
|
'thousands' => '.'
|
|
|
]);
|
|
|
- Number::config('en_EN');
|
|
|
+ Number::config('de_DE');
|
|
|
$this->Number = new NumberHelper(new View(null));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function tearDown() {
|
|
|
+ parent::tearDown();
|
|
|
+
|
|
|
+ ini_set('intl.default_locale', $this->locale);
|
|
|
+
|
|
|
+ unset($this->Number);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Test calling Utility.Number class
|
|
|
*
|
|
|
* @return void
|
|
|
@@ -45,47 +66,47 @@ class NumberHelperTest extends TestCase {
|
|
|
public function testFormat() {
|
|
|
$is = $this->Number->format('22');
|
|
|
$expected = '22';
|
|
|
- $this->assertEquals($expected, $is);
|
|
|
+ $this->assertSame($expected, $is);
|
|
|
|
|
|
$is = $this->Number->format('22.01');
|
|
|
$expected = '22,01';
|
|
|
- $this->assertEquals($expected, $is);
|
|
|
+ $this->assertSame($expected, $is);
|
|
|
|
|
|
$is = $this->Number->format('22', ['places' => 2]);
|
|
|
$expected = '22,00';
|
|
|
- $this->assertEquals($expected, $is);
|
|
|
+ $this->assertSame($expected, $is);
|
|
|
|
|
|
$is = $this->Number->format('22.30', ['places' => 1]);
|
|
|
$expected = '22,3';
|
|
|
- $this->assertEquals($expected, $is);
|
|
|
+ $this->assertSame($expected, $is);
|
|
|
|
|
|
$is = $this->Number->format('22.30', ['precision' => -1]);
|
|
|
- $expected = '22';
|
|
|
- $this->assertEquals($expected, $is);
|
|
|
+ $expected = '22'; // Why 22,3 locally?
|
|
|
+ $this->assertSame($expected, $is);
|
|
|
|
|
|
$is = $this->Number->format('22.30', ['places' => 3]);
|
|
|
$expected = '22,300';
|
|
|
- $this->assertEquals($expected, $is);
|
|
|
+ $this->assertSame($expected, $is);
|
|
|
|
|
|
$is = $this->Number->format('abc', ['places' => 2]);
|
|
|
$expected = '0,00';
|
|
|
- $this->assertEquals($expected, $is);
|
|
|
+ $this->assertSame($expected, $is);
|
|
|
|
|
|
$is = $this->Number->format('22.3', ['places' => 2, 'before' => 'EUR ']);
|
|
|
$expected = 'EUR 22,30';
|
|
|
- $this->assertEquals($expected, $is);
|
|
|
+ $this->assertSame($expected, $is);
|
|
|
|
|
|
$is = $this->Number->format('22.3', ['places' => 2, 'after' => ' EUR']);
|
|
|
$expected = '22,30 EUR';
|
|
|
- $this->assertEquals($expected, $is);
|
|
|
+ $this->assertSame($expected, $is);
|
|
|
|
|
|
$is = $this->Number->format('22.3', ['places' => 2, 'after' => 'x', 'before' => 'v']);
|
|
|
$expected = 'v22,30x';
|
|
|
- $this->assertEquals($expected, $is);
|
|
|
+ $this->assertSame($expected, $is);
|
|
|
|
|
|
$is = $this->Number->format('22.3', ['places' => 2, 'locale' => 'en-US']);
|
|
|
$expected = '22.30';
|
|
|
- $this->assertEquals($expected, $is);
|
|
|
+ $this->assertSame($expected, $is);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -95,10 +116,10 @@ class NumberHelperTest extends TestCase {
|
|
|
*/
|
|
|
public function testCurrency() {
|
|
|
$is = Number::defaultCurrency();
|
|
|
- $this->assertEquals('EUR', $is);
|
|
|
+ $this->assertSame('EUR', $is);
|
|
|
|
|
|
$is = $this->Number->currency(22.2);
|
|
|
- $this->assertEquals('22,20 €', $is);
|
|
|
+ $this->assertSame('22,20 €', $is);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -108,22 +129,13 @@ class NumberHelperTest extends TestCase {
|
|
|
*/
|
|
|
public function testToReadableSize() {
|
|
|
$is = $this->Number->toReadableSize(1206);
|
|
|
- $this->assertEquals('1,18 KB', $is);
|
|
|
+ $this->assertSame('1,18 KB', $is);
|
|
|
|
|
|
$is = $this->Number->toReadableSize(1024 * 1024 * 1024);
|
|
|
- $this->assertEquals('1 GB', $is);
|
|
|
+ $this->assertSame('1 GB', $is);
|
|
|
|
|
|
$is = $this->Number->toReadableSize(1024 * 1024 * 1024 * 1024 * 2.5);
|
|
|
- $this->assertEquals('2,5 TB', $is);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function tearDown() {
|
|
|
- parent::tearDown();
|
|
|
-
|
|
|
- unset($this->Number);
|
|
|
+ $this->assertSame('2,5 TB', $is);
|
|
|
}
|
|
|
|
|
|
}
|