Browse Source

Fixed Number::defaultCurrency()

Jose Lorenzo Rodriguez 11 years ago
parent
commit
939bdb7f09
2 changed files with 10 additions and 54 deletions
  1. 1 1
      src/Utility/Number.php
  2. 9 53
      tests/TestCase/Utility/NumberTest.php

+ 1 - 1
src/Utility/Number.php

@@ -372,7 +372,7 @@ class Number {
 		}
 
 		if ($currency === false) {
-			self::$_defaultCurrency = null;
+			return self::$_defaultCurrency = null;
 		}
 
 		if (empty(self::$_defaultCurrency)) {

+ 9 - 53
tests/TestCase/Utility/NumberTest.php

@@ -295,29 +295,13 @@ class NumberTest extends TestCase {
 	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 @@ class NumberTest extends TestCase {
 	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);
 	}