diff --git a/src/Utility/Number.php b/src/Utility/Number.php index a68a912553a..1a00b26eaee 100644 --- a/src/Utility/Number.php +++ b/src/Utility/Number.php @@ -372,7 +372,7 @@ public static function defaultCurrency($currency = null) { } if ($currency === false) { - self::$_defaultCurrency = null; + return self::$_defaultCurrency = null; } if (empty(self::$_defaultCurrency)) { diff --git a/tests/TestCase/Utility/NumberTest.php b/tests/TestCase/Utility/NumberTest.php index 0192ff5a3a1..1ad17710ac7 100644 --- a/tests/TestCase/Utility/NumberTest.php +++ b/tests/TestCase/Utility/NumberTest.php @@ -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()); } /** @@ -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); }