Skip to content

Commit

Permalink
Fixed Number::defaultCurrency()
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Aug 2, 2014
1 parent cec48ac commit 939bdb7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src/Utility/Number.php
Expand Up @@ -372,7 +372,7 @@ public static function defaultCurrency($currency = null) {
}

if ($currency === false) {
self::$_defaultCurrency = null;
return self::$_defaultCurrency = null;
}

if (empty(self::$_defaultCurrency)) {
Expand Down
62 changes: 9 additions & 53 deletions tests/TestCase/Utility/NumberTest.php
Expand Up @@ -295,29 +295,13 @@ public function _testCurrencyAddFormat() {
public function testDefaultCurrency() {
$result = $this->Number->defaultCurrency();
$this->assertEquals('USD', $result);
$this->Number->addFormat('NOK', array('before' => 'Kr. '));

$this->Number->defaultCurrency('NOK');
$result = $this->Number->defaultCurrency();
$this->assertEquals('NOK', $result);

$result = $this->Number->currency(1000);
$expected = 'Kr. 1,000.00';
$this->assertEquals($expected, $result);

$result = $this->Number->currency(2000);
$expected = 'Kr. 2,000.00';
$this->assertEquals($expected, $result);
$this->Number->defaultCurrency('EUR');
$result = $this->Number->currency(1000);
$expected = '€1.000,00';
$this->assertEquals($expected, $result);

$result = $this->Number->currency(2000);
$expected = '€2.000,00';
$this->assertEquals($expected, $result);
$this->Number->defaultCurrency(false);
I18n::defaultLocale('es_ES');
$this->assertEquals('EUR', $this->Number->defaultCurrency());

$this->Number->defaultCurrency('USD');
$this->Number->defaultCurrency('JPY');
$this->assertEquals('JPY', $this->Number->defaultCurrency());
}

/**
Expand Down Expand Up @@ -362,40 +346,12 @@ public function testCurrencyZero() {
public function testCurrencyOptions() {
$value = '1234567.89';

$result = $this->Number->currency($value, null, array('before' => 'GBP'));
$expected = 'GBP1,234,567.89';
$this->assertEquals($expected, $result);

$result = $this->Number->currency($value, 'GBP', array('places' => 0));
$expected = '£1,234,568';
$this->assertEquals($expected, $result);

$result = $this->Number->currency('1234567.8912345', null, array('before' => 'GBP', 'places' => 3));
$expected = 'GBP1,234,567.891';
$this->assertEquals($expected, $result);

$result = $this->Number->currency('650.120001', null, array('before' => 'GBP', 'places' => 4));
$expected = 'GBP650.1200';
$this->assertEquals($expected, $result);

$result = $this->Number->currency($value, 'GBP', array('before' => '£ ', 'escape' => true));
$expected = '£ 1,234,567.89';
$this->assertEquals($expected, $result);

$result = $this->Number->currency('0.35', 'USD', array('after' => false));
$expected = '$0.35';
$this->assertEquals($expected, $result);

$result = $this->Number->currency('0.35', 'GBP', array('before' => '£', 'after' => false, 'escape' => false));
$expected = '£0.35';
$this->assertEquals($expected, $result);

$result = $this->Number->currency('0.35', 'GBP');
$expected = '35p';
$result = $this->Number->currency($value, null, array('before' => 'Total: '));
$expected = 'Total: $1,234,567.89';
$this->assertEquals($expected, $result);

$result = $this->Number->currency('0.35', 'EUR');
$expected = '€0,35';
$result = $this->Number->currency($value, null, array('after' => ' in Total'));
$expected = '$1,234,567.89 in Total';
$this->assertEquals($expected, $result);
}

Expand Down

0 comments on commit 939bdb7

Please sign in to comment.