2 require_once('modules/Currencies/Currency.php');
4 class CurrencyTest extends Sugar_PHPUnit_Framework_TestCase {
6 var $previousCurrentUser;
8 public function setUp()
11 $this->previousCurrentUser = $current_user;
12 $current_user = SugarTestUserUtilities::createAnonymousUser();
13 $current_user->setPreference('num_grp_sep', ',', 0, 'global');
14 $current_user->setPreference('dec_sep', '.', 0, 'global');
15 $current_user->save();
16 //Force reset on dec_sep and num_grp_sep because the dec_sep and num_grp_sep values are stored as static variables
17 get_number_seperators(true);
20 public function tearDown()
22 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
24 $current_user = $this->previousCurrentUser;
27 public function testUnformatNumber()
30 $testValue = "$100,000.50";
32 $unformattedValue = unformat_number($testValue);
33 $this->assertEquals($unformattedValue, 100000.50, "Assert that $100,000.50 becomes 100000.50");
35 //Switch the num_grp_sep and dec_sep values
36 $current_user->setPreference('num_grp_sep', '.');
37 $current_user->setPreference('dec_sep', ',');
38 $current_user->save();
40 //Force reset on dec_sep and num_grp_sep because the dec_sep and num_grp_sep values are stored as static variables
41 get_number_seperators(true);
43 $testValue = "$100.000,50";
44 $unformattedValue = unformat_number($testValue);
45 $this->assertEquals($unformattedValue, 100000.50, "Assert that $100.000,50 becomes 100000.50");
49 public function testFormatNumber()
52 $testValue = "100000.50";
54 $formattedValue = format_number($testValue);
55 $this->assertEquals($formattedValue, "100,000.50", "Assert that 100000.50 becomes 100,000.50");
57 //Switch the num_grp_sep and dec_sep values
58 $current_user->setPreference('num_grp_sep', '.');
59 $current_user->setPreference('dec_sep', ',');
60 $current_user->save();
62 //Force reset on dec_sep and num_grp_sep because the dec_sep and num_grp_sep values are stored as static variables
63 get_number_seperators(true);
65 $testValue = "100000.50";
66 $formattedValue = format_number($testValue);
67 $this->assertEquals($formattedValue, "100.000,50", "Assert that 100000.50 becomes 100.000,50");